comparison OrthancServer/ServerContext.cpp @ 3677:4182cde57afb

refactoring FindStorageAccessMode
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 19 Feb 2020 17:17:27 +0100
parents 94f4a18a79cc
children 6358923d3ced
comparison
equal deleted inserted replaced
3676:231b46ce1984 3677:4182cde57afb
252 new SharedArchive(lock.GetConfiguration().GetUnsignedIntegerParameter("MediaArchiveSize", 1))); 252 new SharedArchive(lock.GetConfiguration().GetUnsignedIntegerParameter("MediaArchiveSize", 1)));
253 defaultLocalAet_ = lock.GetConfiguration().GetStringParameter("DicomAet", "ORTHANC"); 253 defaultLocalAet_ = lock.GetConfiguration().GetStringParameter("DicomAet", "ORTHANC");
254 jobsEngine_.SetWorkersCount(lock.GetConfiguration().GetUnsignedIntegerParameter("ConcurrentJobs", 2)); 254 jobsEngine_.SetWorkersCount(lock.GetConfiguration().GetUnsignedIntegerParameter("ConcurrentJobs", 2));
255 saveJobs_ = lock.GetConfiguration().GetBooleanParameter("SaveJobs", true); 255 saveJobs_ = lock.GetConfiguration().GetBooleanParameter("SaveJobs", true);
256 metricsRegistry_->SetEnabled(lock.GetConfiguration().GetBooleanParameter("MetricsEnabled", true)); 256 metricsRegistry_->SetEnabled(lock.GetConfiguration().GetBooleanParameter("MetricsEnabled", true));
257
258 // New configuration options in Orthanc 1.5.1
259 findStorageAccessMode_ = StringToFindStorageAccessMode(lock.GetConfiguration().GetStringParameter("StorageAccessOnFind", "Always"));
260 limitFindInstances_ = lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindInstances", 0);
261 limitFindResults_ = lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindResults", 0);
257 } 262 }
258 263
259 jobsEngine_.SetThreadSleep(unitTesting ? 20 : 200); 264 jobsEngine_.SetThreadSleep(unitTesting ? 20 : 200);
260 265
261 listeners_.push_back(ServerListener(luaListener_, "Lua")); 266 listeners_.push_back(ServerListener(luaListener_, "Lua"));
794 const DatabaseLookup& lookup, 799 const DatabaseLookup& lookup,
795 ResourceType queryLevel, 800 ResourceType queryLevel,
796 size_t since, 801 size_t since,
797 size_t limit) 802 size_t limit)
798 { 803 {
799 LookupMode mode; 804 unsigned int databaseLimit = (queryLevel == ResourceType_Instance ? limitFindInstances_ : limitFindResults_);
800 unsigned int databaseLimit;
801 805
802 {
803 // New configuration option in 1.5.1
804 OrthancConfiguration::ReaderLock lock;
805
806 std::string value = lock.GetConfiguration().GetStringParameter("StorageAccessOnFind", "Always");
807
808 if (value == "Always")
809 {
810 mode = LookupMode_DiskOnLookupAndAnswer;
811 }
812 else if (value == "Never")
813 {
814 mode = LookupMode_DatabaseOnly;
815 }
816 else if (value == "Answers")
817 {
818 mode = LookupMode_DiskOnAnswer;
819 }
820 else
821 {
822 throw OrthancException(ErrorCode_ParameterOutOfRange,
823 "Configuration option \"StorageAccessOnFind\" "
824 "should be \"Always\", \"Never\" or \"Answers\": " + value);
825 }
826
827 if (queryLevel == ResourceType_Instance)
828 {
829 databaseLimit = lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindInstances", 0);
830 }
831 else
832 {
833 databaseLimit = lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindResults", 0);
834 }
835 }
836
837 std::vector<std::string> resources, instances; 806 std::vector<std::string> resources, instances;
838 807
839 { 808 {
840 const size_t lookupLimit = (databaseLimit == 0 ? 0 : databaseLimit + 1); 809 const size_t lookupLimit = (databaseLimit == 0 ? 0 : databaseLimit + 1);
841 GetIndex().ApplyLookupResources(resources, &instances, lookup, queryLevel, lookupLimit); 810 GetIndex().ApplyLookupResources(resources, &instances, lookup, queryLevel, lookupLimit);
861 std::auto_ptr<Json::Value> dicomAsJson; 830 std::auto_ptr<Json::Value> dicomAsJson;
862 831
863 bool hasOnlyMainDicomTags; 832 bool hasOnlyMainDicomTags;
864 DicomMap dicom; 833 DicomMap dicom;
865 834
866 if (mode == LookupMode_DatabaseOnly || 835 if (findStorageAccessMode_ == FindStorageAccessMode_DatabaseOnly ||
867 mode == LookupMode_DiskOnAnswer || 836 findStorageAccessMode_ == FindStorageAccessMode_DiskOnAnswer ||
868 lookup.HasOnlyMainDicomTags()) 837 lookup.HasOnlyMainDicomTags())
869 { 838 {
870 // Case (1): The main DICOM tags, as stored in the database, 839 // Case (1): The main DICOM tags, as stored in the database,
871 // are sufficient to look for match 840 // are sufficient to look for match
872 841
905 complete = false; 874 complete = false;
906 break; 875 break;
907 } 876 }
908 else 877 else
909 { 878 {
910 if ((mode == LookupMode_DiskOnLookupAndAnswer || 879 if ((findStorageAccessMode_ == FindStorageAccessMode_DiskOnLookupAndAnswer ||
911 mode == LookupMode_DiskOnAnswer) && 880 findStorageAccessMode_ == FindStorageAccessMode_DiskOnAnswer) &&
912 dicomAsJson.get() == NULL && 881 dicomAsJson.get() == NULL &&
913 isDicomAsJsonNeeded) 882 isDicomAsJsonNeeded)
914 { 883 {
915 dicomAsJson.reset(new Json::Value); 884 dicomAsJson.reset(new Json::Value);
916 ReadDicomAsJson(*dicomAsJson, instances[i]); 885 ReadDicomAsJson(*dicomAsJson, instances[i]);