# HG changeset patch # User Sebastien Jodogne # Date 1543508129 -3600 # Node ID 2e751f615e0360b95ca3ee3feced0ad986052a97 # Parent 3c636087d060c33b69cc63c115246d67e8a89d1e new configuration options: DicomModalitiesInDatabase and OrthancPeersInDatabase diff -r 3c636087d060 -r 2e751f615e03 NEWS --- a/NEWS Thu Nov 29 16:35:18 2018 +0100 +++ b/NEWS Thu Nov 29 17:15:29 2018 +0100 @@ -7,6 +7,9 @@ * Possibility to restrict the allowed DICOM commands for each modality * The Orthanc configuration file can use environment variables +* New configuration options: + - "DicomModalitiesInDatabase" to store the definitions of modalities in the database + - "OrthancPeersInDatabase" to store the definitions of Orthanc peers in the database Orthanc Explorer ---------------- diff -r 3c636087d060 -r 2e751f615e03 OrthancServer/OrthancConfiguration.cpp --- a/OrthancServer/OrthancConfiguration.cpp Thu Nov 29 16:35:18 2018 +0100 +++ b/OrthancServer/OrthancConfiguration.cpp Thu Nov 29 17:15:29 2018 +0100 @@ -44,8 +44,9 @@ static const char* const DICOM_MODALITIES = "DicomModalities"; +static const char* const DICOM_MODALITIES_IN_DB = "DicomModalitiesInDatabase"; static const char* const ORTHANC_PEERS = "OrthancPeers"; - +static const char* const ORTHANC_PEERS_IN_DB = "OrthancPeersInDatabase"; namespace Orthanc { @@ -210,20 +211,6 @@ } - void OrthancConfiguration::SaveModalitiesToJson(Json::Value& target) - { - target = Json::objectValue; - - for (Modalities::const_iterator it = modalities_.begin(); it != modalities_.end(); ++it) - { - Json::Value modality; - it->second.Serialize(modality, true /* force advanced format */); - - target[it->first] = modality; - } - } - - void OrthancConfiguration::LoadPeersFromJson(const Json::Value& source) { peers_.clear(); @@ -248,6 +235,101 @@ } + void OrthancConfiguration::LoadModalities() + { + if (GetBooleanParameter(DICOM_MODALITIES_IN_DB, false)) + { + // Modalities are stored in the database + if (serverIndex_ == NULL) + { + throw Orthanc::OrthancException(ErrorCode_BadSequenceOfCalls); + } + else + { + std::string property = serverIndex_->GetGlobalProperty(GlobalProperty_Modalities, "{}"); + + Json::Reader reader; + Json::Value modalities; + if (reader.parse(property, modalities)) + { + LoadModalitiesFromJson(modalities); + } + else + { + LOG(ERROR) << "Cannot unserialize the list of modalities from the Orthanc database"; + throw OrthancException(ErrorCode_InternalError); + } + } + } + else + { + // Modalities are stored in the configuration files + if (json_.isMember(DICOM_MODALITIES)) + { + LoadModalitiesFromJson(json_[DICOM_MODALITIES]); + } + else + { + modalities_.clear(); + } + } + } + + void OrthancConfiguration::LoadPeers() + { + if (GetBooleanParameter(ORTHANC_PEERS_IN_DB, false)) + { + // Peers are stored in the database + if (serverIndex_ == NULL) + { + throw Orthanc::OrthancException(ErrorCode_BadSequenceOfCalls); + } + else + { + std::string property = serverIndex_->GetGlobalProperty(GlobalProperty_Peers, "{}"); + + Json::Reader reader; + Json::Value peers; + if (reader.parse(property, peers)) + { + LoadPeersFromJson(peers); + } + else + { + LOG(ERROR) << "Cannot unserialize the list of peers from the Orthanc database"; + throw OrthancException(ErrorCode_InternalError); + } + } + } + else + { + // Peers are stored in the configuration files + if (json_.isMember(ORTHANC_PEERS)) + { + LoadPeersFromJson(json_[ORTHANC_PEERS]); + } + else + { + peers_.clear(); + } + } + } + + + void OrthancConfiguration::SaveModalitiesToJson(Json::Value& target) + { + target = Json::objectValue; + + for (Modalities::const_iterator it = modalities_.begin(); it != modalities_.end(); ++it) + { + Json::Value modality; + it->second.Serialize(modality, true /* force advanced format */); + + target[it->first] = modality; + } + } + + void OrthancConfiguration::SavePeersToJson(Json::Value& target) { target = Json::objectValue; @@ -264,51 +346,67 @@ } - void OrthancConfiguration::LoadModalitiesAndPeers() + void OrthancConfiguration::SaveModalities() { - if (json_.isMember(DICOM_MODALITIES)) + if (GetBooleanParameter(DICOM_MODALITIES_IN_DB, false)) { - LoadModalitiesFromJson(json_[DICOM_MODALITIES]); + // Modalities are stored in the database + if (serverIndex_ == NULL) + { + throw Orthanc::OrthancException(ErrorCode_BadSequenceOfCalls); + } + else + { + Json::Value modalities; + SaveModalitiesToJson(modalities); + + Json::FastWriter writer; + std::string s = writer.write(modalities); + + serverIndex_->SetGlobalProperty(GlobalProperty_Modalities, s); + } } else { - // TODO - Read from DB - modalities_.clear(); - } - - if (json_.isMember(ORTHANC_PEERS)) - { - LoadPeersFromJson(json_[ORTHANC_PEERS]); - } - else - { - // TODO - Read from DB - peers_.clear(); + // Modalities are stored in the configuration files + if (!modalities_.empty() || + json_.isMember(DICOM_MODALITIES)) + { + SaveModalitiesToJson(json_[DICOM_MODALITIES]); + } } } - void OrthancConfiguration::SaveModalities() - { - if (!modalities_.empty() || - json_.isMember(DICOM_MODALITIES)) - { - SaveModalitiesToJson(json_[DICOM_MODALITIES]); - } - - // TODO - Write to DB - } - - void OrthancConfiguration::SavePeers() { - if (!peers_.empty() || - json_.isMember(ORTHANC_PEERS)) + if (GetBooleanParameter(ORTHANC_PEERS_IN_DB, false)) { - SavePeersToJson(json_[ORTHANC_PEERS]); + // Peers are stored in the database + if (serverIndex_ == NULL) + { + throw Orthanc::OrthancException(ErrorCode_BadSequenceOfCalls); + } + else + { + Json::Value peers; + SavePeersToJson(peers); + + Json::FastWriter writer; + std::string s = writer.write(peers); + + serverIndex_->SetGlobalProperty(GlobalProperty_Peers, s); + } } - - // TODO - Write to DB + else + { + // Peers are stored in the configuration files + if (!peers_.empty() || + json_.isMember(ORTHANC_PEERS)) + { + SavePeersToJson(json_[ORTHANC_PEERS]); + } + } } @@ -439,8 +537,13 @@ configurationAbsolutePath_ = boost::filesystem::absolute(p).string(); #endif } + } - LoadModalitiesAndPeers(); + + void OrthancConfiguration::LoadModalitiesAndPeers() + { + LoadModalities(); + LoadPeers(); } diff -r 3c636087d060 -r 2e751f615e03 OrthancServer/OrthancConfiguration.h --- a/OrthancServer/OrthancConfiguration.h Thu Nov 29 16:35:18 2018 +0100 +++ b/OrthancServer/OrthancConfiguration.h Thu Nov 29 17:15:29 2018 +0100 @@ -71,13 +71,15 @@ void LoadModalitiesFromJson(const Json::Value& source); - void SaveModalitiesToJson(Json::Value& target); - void LoadPeersFromJson(const Json::Value& source); - void SavePeersToJson(Json::Value& target); + void LoadModalities(); + + void LoadPeers(); - void LoadModalitiesAndPeers(); + void SaveModalitiesToJson(Json::Value& target); + + void SavePeersToJson(Json::Value& target); void SaveModalities(); @@ -152,6 +154,8 @@ } void Read(const char* configurationFile); + + void LoadModalitiesAndPeers(); void RegisterFont(EmbeddedResources::FileResourceId resource) { diff -r 3c636087d060 -r 2e751f615e03 OrthancServer/ServerEnumerations.h --- a/OrthancServer/ServerEnumerations.h Thu Nov 29 16:35:18 2018 +0100 +++ b/OrthancServer/ServerEnumerations.h Thu Nov 29 17:15:29 2018 +0100 @@ -93,8 +93,10 @@ GlobalProperty_FlushSleep = 2, GlobalProperty_AnonymizationSequence = 3, GlobalProperty_JobsRegistry = 5, - GlobalProperty_TotalCompressedSize = 6, // Reserved for Orthanc > 1.4.1 - GlobalProperty_TotalUncompressedSize = 7, // Reserved for Orthanc > 1.4.1 + GlobalProperty_TotalCompressedSize = 6, // Reserved for Orthanc > 1.4.3 + GlobalProperty_TotalUncompressedSize = 7, // Reserved for Orthanc > 1.4.3 + GlobalProperty_Modalities = 20, // New in Orthanc 1.4.3 + GlobalProperty_Peers = 21, // New in Orthanc 1.4.3 // Reserved values for internal use by the database plugins GlobalProperty_DatabasePatchLevel = 4, diff -r 3c636087d060 -r 2e751f615e03 OrthancServer/main.cpp --- a/OrthancServer/main.cpp Thu Nov 29 16:35:18 2018 +0100 +++ b/OrthancServer/main.cpp Thu Nov 29 17:15:29 2018 +0100 @@ -736,7 +736,8 @@ } else { - LOG(WARNING) << "A SIGHUP signal has been received, but is ignored as the configuration has not changed"; + LOG(WARNING) << "A SIGHUP signal has been received, but is ignored " + << "as the configuration has not changed on the disk"; Logging::Flush(); continue; } @@ -1131,6 +1132,12 @@ { ServerContextConfigurator configurator(context, plugins); + + { + OrthancConfiguration::WriterLock lock; + lock.GetConfiguration().LoadModalitiesAndPeers(); + } + return ConfigureHttpHandler(context, plugins, loadJobsFromDatabase); } } diff -r 3c636087d060 -r 2e751f615e03 Resources/Configuration.json --- a/Resources/Configuration.json Thu Nov 29 16:35:18 2018 +0100 +++ b/Resources/Configuration.json Thu Nov 29 17:15:29 2018 +0100 @@ -198,6 +198,10 @@ //} }, + // Whether to store the DICOM modalities in the Orthanc database + // instead of in this configuration file (new in Orthanc 1.4.3) + "DicomModalitiesInDatabase" : false, + // Whether the Orthanc SCP allows incoming C-Echo requests, even // from SCU modalities it does not know about (i.e. that are not // listed in the "DicomModalities" option above). Orthanc 1.3.0 @@ -248,6 +252,10 @@ // } }, + // Whether to store the Orthanc peers in the Orthanc database + // instead of in this configuration file (new in Orthanc 1.4.3) + "OrthancPeersInDatabase" : false, + // Parameters of the HTTP proxy to be used by Orthanc. If set to the // empty string, no HTTP proxy is used. For instance: // "HttpProxy" : "192.168.0.1:3128"