Mercurial > hg > orthanc
changeset 1773:613df4362575
New UpdatedAttachment and UpdatedMetadata events in plugins
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 12 Nov 2015 15:24:23 +0100 |
parents | 53e045b5a8ec |
children | 784a6b92d2f1 |
files | Core/Enumerations.cpp Core/Enumerations.h NEWS OrthancServer/OrthancRestApi/OrthancRestResources.cpp OrthancServer/ServerEnumerations.cpp OrthancServer/ServerEnumerations.h OrthancServer/ServerIndex.cpp Plugins/Engine/PluginsEnumerations.cpp Plugins/Include/orthanc/OrthancCPlugin.h |
diffstat | 9 files changed, 75 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/Enumerations.cpp Thu Nov 12 14:36:27 2015 +0100 +++ b/Core/Enumerations.cpp Thu Nov 12 15:24:23 2015 +0100 @@ -1135,4 +1135,11 @@ return HttpStatus_500_InternalServerError; } } + + + bool IsUserContentType(FileContentType type) + { + return (type >= FileContentType_StartUser && + type <= FileContentType_EndUser); + } }
--- a/Core/Enumerations.h Thu Nov 12 14:36:27 2015 +0100 +++ b/Core/Enumerations.h Thu Nov 12 15:24:23 2015 +0100 @@ -463,4 +463,6 @@ const char* GetDicomSpecificCharacterSet(Encoding encoding); HttpStatus ConvertErrorCodeToHttpStatus(ErrorCode error); + + bool IsUserContentType(FileContentType type); }
--- a/NEWS Thu Nov 12 14:36:27 2015 +0100 +++ b/NEWS Thu Nov 12 15:24:23 2015 +0100 @@ -17,7 +17,8 @@ * New function "OrthancPluginRegisterErrorCode()" to declare custom error codes * New function "OrthancPluginRegisterDictionaryTag()" to declare custom DICOM tags -* New "OrthancStarted" and "OrthancStopped" events in change callbacks +* New "OrthancStarted", "OrthancStopped", "UpdatedAttachment" + and "UpdatedMetadata" events in change callbacks Lua ---
--- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Thu Nov 12 14:36:27 2015 +0100 +++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Thu Nov 12 15:24:23 2015 +0100 @@ -405,10 +405,8 @@ std::string name = call.GetUriComponent("name", ""); MetadataType metadata = StringToMetadata(name); - if (metadata >= MetadataType_StartUser && - metadata <= MetadataType_EndUser) - { - // It is forbidden to modify internal metadata + if (IsUserMetadata(metadata)) // It is forbidden to modify internal metadata + { OrthancRestApi::GetIndex(call).DeleteMetadata(publicId, metadata); call.GetOutput().AnswerBuffer("", "text/plain"); } @@ -426,8 +424,7 @@ std::string value; call.BodyToString(value); - if (metadata >= MetadataType_StartUser && - metadata <= MetadataType_EndUser) + if (IsUserMetadata(metadata)) // It is forbidden to modify internal metadata { // It is forbidden to modify internal metadata OrthancRestApi::GetIndex(call).SetMetadata(publicId, metadata, value); @@ -638,8 +635,7 @@ std::string name = call.GetUriComponent("name", ""); FileContentType contentType = StringToContentType(name); - if (contentType >= FileContentType_StartUser && // It is forbidden to modify internal attachments - contentType <= FileContentType_EndUser && + if (IsUserContentType(contentType) && // It is forbidden to modify internal attachments context.AddAttachment(publicId, StringToContentType(name), call.GetBodyData(), call.GetBodySize())) { call.GetOutput().AnswerBuffer("{}", "application/json"); @@ -655,10 +651,8 @@ std::string name = call.GetUriComponent("name", ""); FileContentType contentType = StringToContentType(name); - if (contentType >= FileContentType_StartUser && - contentType <= FileContentType_EndUser) + if (IsUserContentType(contentType)) // It is forbidden to delete internal attachments { - // It is forbidden to delete internal attachments OrthancRestApi::GetIndex(call).DeleteAttachment(publicId, contentType); call.GetOutput().AnswerBuffer("{}", "application/json"); }
--- a/OrthancServer/ServerEnumerations.cpp Thu Nov 12 14:36:27 2015 +0100 +++ b/OrthancServer/ServerEnumerations.cpp Thu Nov 12 15:24:23 2015 +0100 @@ -73,8 +73,10 @@ { boost::mutex::scoped_lock lock(enumerationsMutex_); - if (metadata < static_cast<int>(MetadataType_StartUser) || - metadata > static_cast<int>(MetadataType_EndUser)) + MetadataType type = static_cast<MetadataType>(metadata); + + if (metadata < 0 || + !IsUserMetadata(type)) { LOG(ERROR) << "A user content type must have index between " << static_cast<int>(MetadataType_StartUser) << " and " @@ -84,8 +86,6 @@ throw OrthancException(ErrorCode_ParameterOutOfRange); } - MetadataType type = static_cast<MetadataType>(metadata); - if (dictMetadataType_.Contains(type)) { LOG(ERROR) << "Cannot associate user content type \"" @@ -118,8 +118,10 @@ { boost::mutex::scoped_lock lock(enumerationsMutex_); - if (contentType < static_cast<int>(FileContentType_StartUser) || - contentType > static_cast<int>(FileContentType_EndUser)) + FileContentType type = static_cast<FileContentType>(contentType); + + if (contentType < 0 || + !IsUserContentType(type)) { LOG(ERROR) << "A user content type must have index between " << static_cast<int>(FileContentType_StartUser) << " and " @@ -129,7 +131,6 @@ throw OrthancException(ErrorCode_ParameterOutOfRange); } - FileContentType type = static_cast<FileContentType>(contentType); if (dictContentType_.Contains(type)) { LOG(ERROR) << "Cannot associate user content type \"" @@ -301,6 +302,12 @@ case ChangeType_NewChildInstance: return "NewChildInstance"; + case ChangeType_UpdatedAttachment: + return "UpdatedAttachment"; + + case ChangeType_UpdatedMetadata: + return "UpdatedMetadata"; + default: throw OrthancException(ErrorCode_ParameterOutOfRange); } @@ -428,4 +435,11 @@ throw OrthancException(ErrorCode_ParameterOutOfRange); } } + + + bool IsUserMetadata(MetadataType metadata) + { + return (metadata >= MetadataType_StartUser && + metadata <= MetadataType_EndUser); + } }
--- a/OrthancServer/ServerEnumerations.h Thu Nov 12 14:36:27 2015 +0100 +++ b/OrthancServer/ServerEnumerations.h Thu Nov 12 15:24:23 2015 +0100 @@ -178,6 +178,8 @@ ChangeType_StablePatient = 12, ChangeType_StableStudy = 13, ChangeType_StableSeries = 14, + ChangeType_UpdatedAttachment = 15, + ChangeType_UpdatedMetadata = 16, ChangeType_INTERNAL_LastLogged = 4095, @@ -223,4 +225,6 @@ const char* EnumerationToString(TransferSyntax syntax); ModalityManufacturer StringToModalityManufacturer(const std::string& manufacturer); + + bool IsUserMetadata(MetadataType type); }
--- a/OrthancServer/ServerIndex.cpp Thu Nov 12 14:36:27 2015 +0100 +++ b/OrthancServer/ServerIndex.cpp Thu Nov 12 15:24:23 2015 +0100 @@ -1525,6 +1525,7 @@ const std::string& value) { boost::mutex::scoped_lock lock(mutex_); + Transaction t(*this); ResourceType rtype; int64_t id; @@ -1534,6 +1535,13 @@ } db_.SetMetadata(id, type, value); + + if (IsUserMetadata(type)) + { + LogChange(id, ChangeType_UpdatedMetadata, rtype, publicId); + } + + t.Commit(0); } @@ -1541,6 +1549,7 @@ MetadataType type) { boost::mutex::scoped_lock lock(mutex_); + Transaction t(*this); ResourceType rtype; int64_t id; @@ -1550,6 +1559,13 @@ } db_.DeleteMetadata(id, type); + + if (IsUserMetadata(type)) + { + LogChange(id, ChangeType_UpdatedMetadata, rtype, publicId); + } + + t.Commit(0); } @@ -1958,6 +1974,11 @@ db_.AddAttachment(resourceId, attachment); + if (IsUserContentType(attachment.GetContentType())) + { + LogChange(resourceId, ChangeType_UpdatedAttachment, resourceType, publicId); + } + t.Commit(attachment.GetCompressedSize()); return StoreStatus_Success; @@ -1979,6 +2000,11 @@ db_.DeleteAttachment(id, type); + if (IsUserContentType(type)) + { + LogChange(id, ChangeType_UpdatedAttachment, rtype, publicId); + } + t.Commit(0); }
--- a/Plugins/Engine/PluginsEnumerations.cpp Thu Nov 12 14:36:27 2015 +0100 +++ b/Plugins/Engine/PluginsEnumerations.cpp Thu Nov 12 15:24:23 2015 +0100 @@ -122,6 +122,12 @@ case ChangeType_StableStudy: return OrthancPluginChangeType_StableStudy; + case ChangeType_UpdatedAttachment: + return OrthancPluginChangeType_UpdatedAttachment; + + case ChangeType_UpdatedMetadata: + return OrthancPluginChangeType_UpdatedMetadata; + default: throw OrthancException(ErrorCode_ParameterOutOfRange); }
--- a/Plugins/Include/orthanc/OrthancCPlugin.h Thu Nov 12 14:36:27 2015 +0100 +++ b/Plugins/Include/orthanc/OrthancCPlugin.h Thu Nov 12 15:24:23 2015 +0100 @@ -576,6 +576,8 @@ OrthancPluginChangeType_StableStudy = 9, /*!< Timeout: No new instance in this study */ OrthancPluginChangeType_OrthancStarted = 10, /*!< Orthanc has started */ OrthancPluginChangeType_OrthancStopped = 11, /*!< Orthanc is stopping */ + OrthancPluginChangeType_UpdatedAttachment = 12, /*!< Some user-defined attachment has changed for this resource */ + OrthancPluginChangeType_UpdatedMetadata = 13, /*!< Some user-defined metadata has changed for this resource */ _OrthancPluginChangeType_INTERNAL = 0x7fffffff } OrthancPluginChangeType;