comparison OrthancServer/Sources/ServerContext.cpp @ 5058:d4e5ca0c9307

Fix the "Never" option of the "StorageAccessOnFind" that was sill accessing files (bug introduced in 1.11.0)
author Alain Mazy <am@osimis.io>
date Wed, 03 Aug 2022 10:49:50 +0200
parents 22966345eaba
children e69a3ff39bc5
comparison
equal deleted inserted replaced
5057:e6f26be401fa 5058:d4e5ca0c9307
1440 for (size_t i = 0; i < instances.size(); i++) 1440 for (size_t i = 0; i < instances.size(); i++)
1441 { 1441 {
1442 // Optimization in Orthanc 1.5.1 - Don't read the full JSON from 1442 // Optimization in Orthanc 1.5.1 - Don't read the full JSON from
1443 // the disk if only "main DICOM tags" are to be returned 1443 // the disk if only "main DICOM tags" are to be returned
1444 1444
1445 std::unique_ptr<Json::Value> dicomAsJson; 1445 boost::shared_ptr<Json::Value> dicomAsJson;
1446 1446
1447 bool hasOnlyMainDicomTags; 1447 bool hasOnlyMainDicomTags;
1448 DicomMap dicom; 1448 DicomMap dicom;
1449 DicomMap allMainDicomTagsFromDB; 1449 DicomMap allMainDicomTagsFromDB;
1450 1450
1451 if (findStorageAccessMode_ == FindStorageAccessMode_DatabaseOnly || 1451 if (!IsStorageAccessAllowedForAnswers(findStorageAccessMode_)
1452 findStorageAccessMode_ == FindStorageAccessMode_DiskOnAnswer || 1452 || fastLookup->HasOnlyMainDicomTags())
1453 fastLookup->HasOnlyMainDicomTags())
1454 { 1453 {
1455 // Case (1): The main DICOM tags, as stored in the database, 1454 // Case (1): The main DICOM tags, as stored in the database,
1456 // are sufficient to look for match 1455 // are sufficient to look for match
1457 1456
1458 if (!GetIndex().GetAllMainDicomTags(allMainDicomTagsFromDB, instances[i])) 1457 if (!GetIndex().GetAllMainDicomTags(allMainDicomTagsFromDB, instances[i]))
1536 complete = false; 1535 complete = false;
1537 break; 1536 break;
1538 } 1537 }
1539 else 1538 else
1540 { 1539 {
1541 if ((findStorageAccessMode_ == FindStorageAccessMode_DiskOnLookupAndAnswer || 1540 if (IsStorageAccessAllowedForAnswers(findStorageAccessMode_) &&
1542 findStorageAccessMode_ == FindStorageAccessMode_DiskOnAnswer) &&
1543 dicomAsJson.get() == NULL && 1541 dicomAsJson.get() == NULL &&
1544 isDicomAsJsonNeeded) 1542 isDicomAsJsonNeeded)
1545 { 1543 {
1546 dicomAsJson.reset(new Json::Value); 1544 dicomAsJson.reset(new Json::Value);
1547 ReadDicomAsJson(*dicomAsJson, instances[i]); 1545 ReadDicomAsJson(*dicomAsJson, instances[i]);
2334 2332
2335 bool ServerContext::ExpandResource(Json::Value& target, 2333 bool ServerContext::ExpandResource(Json::Value& target,
2336 const std::string& publicId, 2334 const std::string& publicId,
2337 ResourceType level, 2335 ResourceType level,
2338 DicomToJsonFormat format, 2336 DicomToJsonFormat format,
2339 const std::set<DicomTag>& requestedTags) 2337 const std::set<DicomTag>& requestedTags,
2338 bool allowStorageAccess)
2340 { 2339 {
2341 std::string unusedInstanceId; 2340 std::string unusedInstanceId;
2342 Json::Value* unusedDicomAsJson = NULL; 2341 Json::Value* unusedDicomAsJson = NULL;
2343 DicomMap unusedMainDicomTags; 2342 DicomMap unusedMainDicomTags;
2344 2343
2345 return ExpandResource(target, publicId, unusedMainDicomTags, unusedInstanceId, unusedDicomAsJson, level, format, requestedTags); 2344 return ExpandResource(target, publicId, unusedMainDicomTags, unusedInstanceId, unusedDicomAsJson, level, format, requestedTags, allowStorageAccess);
2346 } 2345 }
2347 2346
2348 bool ServerContext::ExpandResource(Json::Value& target, 2347 bool ServerContext::ExpandResource(Json::Value& target,
2349 const std::string& publicId, 2348 const std::string& publicId,
2350 const DicomMap& mainDicomTags, // optional: the main dicom tags for the resource (if already available) 2349 const DicomMap& mainDicomTags, // optional: the main dicom tags for the resource (if already available)
2351 const std::string& instanceId, // optional: the id of an instance for the resource (if already available) 2350 const std::string& instanceId, // optional: the id of an instance for the resource (if already available)
2352 const Json::Value* dicomAsJson, // optional: the dicom-as-json for the resource (if already available) 2351 const Json::Value* dicomAsJson, // optional: the dicom-as-json for the resource (if already available)
2353 ResourceType level, 2352 ResourceType level,
2354 DicomToJsonFormat format, 2353 DicomToJsonFormat format,
2355 const std::set<DicomTag>& requestedTags) 2354 const std::set<DicomTag>& requestedTags,
2355 bool allowStorageAccess)
2356 { 2356 {
2357 ExpandedResource resource; 2357 ExpandedResource resource;
2358 2358
2359 if (ExpandResource(resource, publicId, mainDicomTags, instanceId, dicomAsJson, level, requestedTags, ExpandResourceDbFlags_Default)) 2359 if (ExpandResource(resource, publicId, mainDicomTags, instanceId, dicomAsJson, level, requestedTags, ExpandResourceDbFlags_Default, allowStorageAccess))
2360 { 2360 {
2361 SerializeExpandedResource(target, resource, format, requestedTags); 2361 SerializeExpandedResource(target, resource, format, requestedTags);
2362 return true; 2362 return true;
2363 } 2363 }
2364 2364
2370 const DicomMap& mainDicomTags, // optional: the main dicom tags for the resource (if already available) 2370 const DicomMap& mainDicomTags, // optional: the main dicom tags for the resource (if already available)
2371 const std::string& instanceId, // optional: the id of an instance for the resource (if already available) 2371 const std::string& instanceId, // optional: the id of an instance for the resource (if already available)
2372 const Json::Value* dicomAsJson, // optional: the dicom-as-json for the resource (if already available) 2372 const Json::Value* dicomAsJson, // optional: the dicom-as-json for the resource (if already available)
2373 ResourceType level, 2373 ResourceType level,
2374 const std::set<DicomTag>& requestedTags, 2374 const std::set<DicomTag>& requestedTags,
2375 ExpandResourceDbFlags expandFlags) 2375 ExpandResourceDbFlags expandFlags,
2376 bool allowStorageAccess)
2376 { 2377 {
2377 // first try to get the tags from what is already available 2378 // first try to get the tags from what is already available
2378 2379
2379 if ((expandFlags & ExpandResourceDbFlags_IncludeMainDicomTags) 2380 if ((expandFlags & ExpandResourceDbFlags_IncludeMainDicomTags)
2380 && (mainDicomTags.GetSize() > 0) 2381 && (mainDicomTags.GetSize() > 0)
2418 LOG(WARNING) << "W002: " << Orthanc::GetResourceTypeText(resource.type_, false , false) << " has been stored with another version of Main Dicom Tags list, you should POST to /" << Orthanc::GetResourceTypeText(resource.type_, true, false) << "/" << resource.id_ << "/reconstruct to update the list of tags saved in DB. Some MainDicomTags might be missing from this answer."; 2419 LOG(WARNING) << "W002: " << Orthanc::GetResourceTypeText(resource.type_, false , false) << " has been stored with another version of Main Dicom Tags list, you should POST to /" << Orthanc::GetResourceTypeText(resource.type_, true, false) << "/" << resource.id_ << "/reconstruct to update the list of tags saved in DB. Some MainDicomTags might be missing from this answer.";
2419 } 2420 }
2420 } 2421 }
2421 2422
2422 // possibly merge missing requested tags from dicom-as-json 2423 // possibly merge missing requested tags from dicom-as-json
2423 if (!resource.missingRequestedTags_.empty() && !DicomMap::HasOnlyComputedTags(resource.missingRequestedTags_)) 2424 if (allowStorageAccess
2425 && !resource.missingRequestedTags_.empty() && !DicomMap::HasOnlyComputedTags(resource.missingRequestedTags_))
2424 { 2426 {
2425 OrthancConfiguration::ReaderLock lock; 2427 OrthancConfiguration::ReaderLock lock;
2426 if (lock.GetConfiguration().IsWarningEnabled(Warnings_001_TagsBeingReadFromStorage)) 2428 if (lock.GetConfiguration().IsWarningEnabled(Warnings_001_TagsBeingReadFromStorage))
2427 { 2429 {
2428 std::set<DicomTag> missingTags; 2430 std::set<DicomTag> missingTags;