Mercurial > hg > orthanc
changeset 696:4c1860179cc5
dictionary of user-defined content types
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 05 Feb 2014 15:00:29 +0100 |
parents | c59bc408fb10 |
children | dd1ce9a2844c |
files | Core/Enumerations.h OrthancServer/OrthancInitialization.cpp OrthancServer/ServerContext.cpp OrthancServer/ServerEnumerations.cpp OrthancServer/ServerEnumerations.h Resources/Configuration.json UnitTestsSources/ServerIndex.cpp |
diffstat | 7 files changed, 94 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/Enumerations.h Wed Feb 05 13:58:00 2014 +0100 +++ b/Core/Enumerations.h Wed Feb 05 15:00:29 2014 +0100 @@ -226,7 +226,11 @@ enum FileContentType { FileContentType_Dicom = 1, - FileContentType_Json = 2 + FileContentType_JsonSummary = 2, + + // Make sure that the value "65535" can be stored into this enumeration + FileContentType_StartUser = 1024, + FileContentType_EndUser = 65535 }; enum ResourceType
--- a/OrthancServer/OrthancInitialization.cpp Wed Feb 05 13:58:00 2014 +0100 +++ b/OrthancServer/OrthancInitialization.cpp Wed Feb 05 15:00:29 2014 +0100 @@ -108,7 +108,7 @@ for (size_t i = 0; i < members.size(); i++) { std::string info = "\"" + members[i] + "\" = " + parameter[members[i]].toStyledString(); - LOG(WARNING) << "Registering user-defined metadata: " << info; + LOG(INFO) << "Registering user-defined metadata: " << info; if (!parameter[members[i]].asBool()) { @@ -132,6 +132,40 @@ } + static void RegisterUserContentType() + { + if (configuration_->isMember("UserContentType")) + { + const Json::Value& parameter = (*configuration_) ["UserContentType"]; + + Json::Value::Members members = parameter.getMemberNames(); + for (size_t i = 0; i < members.size(); i++) + { + std::string info = "\"" + members[i] + "\" = " + parameter[members[i]].toStyledString(); + LOG(INFO) << "Registering user-defined attachment type: " << info; + + if (!parameter[members[i]].asBool()) + { + LOG(ERROR) << "Not a number in this user-defined attachment type: " << info; + throw OrthancException(ErrorCode_BadParameterType); + } + + int contentType = parameter[members[i]].asInt(); + + try + { + RegisterUserContentType(contentType, members[i]); + } + catch (OrthancException&) + { + LOG(ERROR) << "Cannot register this user-defined attachment type: " << info; + throw; + } + } + } + } + + void OrthancInitialize(const char* configurationFile) { boost::mutex::scoped_lock lock(globalMutex_); @@ -143,6 +177,7 @@ HttpClient::GlobalInitialize(); RegisterUserMetadata(); + RegisterUserContentType(); DicomServer::InitializeDictionary(); }
--- a/OrthancServer/ServerContext.cpp Wed Feb 05 13:58:00 2014 +0100 +++ b/OrthancServer/ServerContext.cpp Wed Feb 05 15:00:29 2014 +0100 @@ -116,7 +116,7 @@ } FileInfo dicomInfo = accessor_.Write(dicomInstance, dicomSize, FileContentType_Dicom); - FileInfo jsonInfo = accessor_.Write(dicomJson.toStyledString(), FileContentType_Json); + FileInfo jsonInfo = accessor_.Write(dicomJson.toStyledString(), FileContentType_JsonSummary); ServerIndex::Attachments attachments; attachments.push_back(dicomInfo); @@ -176,7 +176,7 @@ const std::string& instancePublicId) { std::string s; - ReadFile(s, instancePublicId, FileContentType_Json); + ReadFile(s, instancePublicId, FileContentType_JsonSummary); Json::Reader reader; if (!reader.parse(s, result))
--- a/OrthancServer/ServerEnumerations.cpp Wed Feb 05 13:58:00 2014 +0100 +++ b/OrthancServer/ServerEnumerations.cpp Wed Feb 05 15:00:29 2014 +0100 @@ -41,6 +41,7 @@ { static boost::mutex enumerationsMutex_; static Toolbox::EnumerationDictionary<MetadataType> dictMetadataType_; + static Toolbox::EnumerationDictionary<FileContentType> dictContentType_; void InitializeServerEnumerations() { @@ -53,6 +54,9 @@ dictMetadataType_.Add(MetadataType_ModifiedFrom, "ModifiedFrom"); dictMetadataType_.Add(MetadataType_AnonymizedFrom, "AnonymizedFrom"); dictMetadataType_.Add(MetadataType_LastUpdate, "LastUpdate"); + + dictContentType_.Add(FileContentType_Dicom, "dicom"); + dictContentType_.Add(FileContentType_JsonSummary, "json-summary"); } void RegisterUserMetadata(int metadata, @@ -83,6 +87,34 @@ return dictMetadataType_.Translate(str); } + void RegisterUserContentType(int contentType, + const std::string& name) + { + boost::mutex::scoped_lock lock(enumerationsMutex_); + + if (contentType < static_cast<int>(FileContentType_StartUser) || + contentType > static_cast<int>(FileContentType_EndUser)) + { + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + + dictContentType_.Add(static_cast<FileContentType>(contentType), name); + } + + std::string EnumerationToString(FileContentType type) + { + // This function MUST return a "std::string" and not "const + // char*", as the result is not a static string + boost::mutex::scoped_lock lock(enumerationsMutex_); + return dictContentType_.Translate(type); + } + + FileContentType StringToContentType(const std::string& str) + { + boost::mutex::scoped_lock lock(enumerationsMutex_); + return dictContentType_.Translate(str); + } + std::string GetBasePath(ResourceType type, const std::string& publicId) {
--- a/OrthancServer/ServerEnumerations.h Wed Feb 05 13:58:00 2014 +0100 +++ b/OrthancServer/ServerEnumerations.h Wed Feb 05 15:00:29 2014 +0100 @@ -121,13 +121,20 @@ void RegisterUserMetadata(int metadata, const std::string& name); - std::string GetBasePath(ResourceType type, - const std::string& publicId); - MetadataType StringToMetadata(const std::string& str); std::string EnumerationToString(MetadataType type); + void RegisterUserContentType(int contentType, + const std::string& name); + + FileContentType StringToContentType(const std::string& str); + + std::string EnumerationToString(FileContentType type); + + std::string GetBasePath(ResourceType type, + const std::string& publicId); + const char* EnumerationToString(SeriesStatus status); const char* EnumerationToString(StoreStatus status);
--- a/Resources/Configuration.json Wed Feb 05 13:58:00 2014 +0100 +++ b/Resources/Configuration.json Wed Feb 05 15:00:29 2014 +0100 @@ -130,6 +130,13 @@ // "Sample" : 1024 }, + // Dictionary of symbolic names for the user-defined types of + // attached files. Each entry must map a number between 1024 and + // 65535 to an unique string. + "UserContentType" : { + // "sample" : 1024 + }, + // Number of seconds without receiving any instance before a // patient, a study or a series is considered as stable. "StableAge" : 60,
--- a/UnitTestsSources/ServerIndex.cpp Wed Feb 05 13:58:00 2014 +0100 +++ b/UnitTestsSources/ServerIndex.cpp Wed Feb 05 15:00:29 2014 +0100 @@ -140,7 +140,7 @@ index.ListAvailableMetadata(md, a[4]); ASSERT_EQ(0u, md.size()); - index.AddAttachment(a[4], FileInfo("my json file", FileContentType_Json, 42, "md5", + index.AddAttachment(a[4], FileInfo("my json file", FileContentType_JsonSummary, 42, "md5", CompressionType_Zlib, 21, "compressedMD5")); index.AddAttachment(a[4], FileInfo("my dicom file", FileContentType_Dicom, 42, "md5")); index.AddAttachment(a[6], FileInfo("world", FileContentType_Dicom, 44, "md5")); @@ -183,7 +183,7 @@ ASSERT_EQ("None", index.GetGlobalProperty(static_cast<GlobalProperty>(42), "None")); FileInfo att; - ASSERT_TRUE(index.LookupAttachment(att, a[4], FileContentType_Json)); + ASSERT_TRUE(index.LookupAttachment(att, a[4], FileContentType_JsonSummary)); ASSERT_EQ("my json file", att.GetUuid()); ASSERT_EQ(21u, att.GetCompressedSize()); ASSERT_EQ("md5", att.GetUncompressedMD5());