Mercurial > hg > orthanc-databases
changeset 686:88b03f7120f0 attach-custom-data
replaced GetAttachment() by GetAttachmentCustomData()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 12 Jun 2025 16:07:26 +0200 |
parents | 08ebec631f74 |
children | 28e7b1270486 |
files | Framework/Plugins/DatabaseBackendAdapterV4.cpp Framework/Plugins/IDatabaseBackend.h Framework/Plugins/IndexBackend.cpp Framework/Plugins/IndexBackend.h |
diffstat | 4 files changed, 60 insertions(+), 72 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Plugins/DatabaseBackendAdapterV4.cpp Thu Jun 12 14:02:35 2025 +0200 +++ b/Framework/Plugins/DatabaseBackendAdapterV4.cpp Thu Jun 12 16:07:26 2025 +0200 @@ -225,6 +225,7 @@ attachment->set_compression_type(compressionType); attachment->set_compressed_size(compressedSize); attachment->set_compressed_hash(compressedHash); + #if ORTHANC_PLUGINS_HAS_ATTACHMENTS_CUSTOM_DATA == 1 attachment->set_custom_data(customData); #endif @@ -702,9 +703,6 @@ case Orthanc::DatabasePluginMessages::OPERATION_ADD_ATTACHMENT: { -#if ORTHANC_PLUGINS_HAS_ATTACHMENTS_CUSTOM_DATA == 1 - backend.AddAttachment(response, manager, request.add_attachment()); -#else OrthancPluginAttachment attachment; attachment.uuid = request.add_attachment().attachment().uuid().c_str(); attachment.contentType = request.add_attachment().attachment().content_type(); @@ -713,9 +711,14 @@ attachment.compressionType = request.add_attachment().attachment().compression_type(); attachment.compressedSize = request.add_attachment().attachment().compressed_size(); attachment.compressedHash = request.add_attachment().attachment().compressed_hash().c_str(); - + +#if ORTHANC_PLUGINS_HAS_ATTACHMENTS_CUSTOM_DATA == 1 + backend.AddAttachment(manager, request.add_attachment().id(), attachment, request.add_attachment().revision(), + request.add_attachment().attachment().custom_data()); +#else backend.AddAttachment(manager, request.add_attachment().id(), attachment, request.add_attachment().revision()); #endif + break; } case Orthanc::DatabasePluginMessages::OPERATION_CLEAR_CHANGES: @@ -1429,19 +1432,18 @@ #endif #if ORTHANC_PLUGINS_HAS_ATTACHMENTS_CUSTOM_DATA == 1 - case Orthanc::DatabasePluginMessages::OPERATION_GET_ATTACHMENT: + case Orthanc::DatabasePluginMessages::OPERATION_GET_ATTACHMENT_CUSTOM_DATA: { - bool found = backend.GetAttachment(response, - manager, - request.get_attachment()); - response.mutable_get_attachment()->set_found(found); + std::string customData; + backend.GetAttachmentCustomData(customData, manager, request.get_attachment_custom_data().uuid()); + response.mutable_get_attachment_custom_data()->set_custom_data(customData); }; break; case Orthanc::DatabasePluginMessages::OPERATION_SET_ATTACHMENT_CUSTOM_DATA: { - backend.UpdateAttachmentCustomData(manager, - request.set_attachment_custom_data().uuid(), - request.set_attachment_custom_data().custom_data()); + backend.SetAttachmentCustomData(manager, + request.set_attachment_custom_data().uuid(), + request.set_attachment_custom_data().custom_data()); }; break; #endif
--- a/Framework/Plugins/IDatabaseBackend.h Thu Jun 12 14:02:35 2025 +0200 +++ b/Framework/Plugins/IDatabaseBackend.h Thu Jun 12 16:07:26 2025 +0200 @@ -71,10 +71,12 @@ int64_t revision) = 0; #if ORTHANC_PLUGINS_HAS_ATTACHMENTS_CUSTOM_DATA == 1 - // New in Orthanc 1.12.7 - virtual void AddAttachment(Orthanc::DatabasePluginMessages::TransactionResponse& response, - DatabaseManager& manager, - const Orthanc::DatabasePluginMessages::AddAttachment_Request& request) = 0; + // New in Orthanc 1.12.8 + virtual void AddAttachment(DatabaseManager& manager, + int64_t id, + const OrthancPluginAttachment& attachment, + int64_t revision, + const std::string& customData) = 0; #endif virtual void AttachChild(DatabaseManager& manager, @@ -448,13 +450,13 @@ #endif #if ORTHANC_PLUGINS_HAS_ATTACHMENTS_CUSTOM_DATA == 1 - virtual bool GetAttachment(Orthanc::DatabasePluginMessages::TransactionResponse& response, - DatabaseManager& manager, - const Orthanc::DatabasePluginMessages::GetAttachment_Request& request) = 0; + virtual void GetAttachmentCustomData(std::string& customData, + DatabaseManager& manager, + const std::string& attachmentUuid) = 0; - virtual void UpdateAttachmentCustomData(DatabaseManager& manager, - const std::string& attachmentUuid, - const std::string& customData) = 0; + virtual void SetAttachmentCustomData(DatabaseManager& manager, + const std::string& attachmentUuid, + const std::string& customData) = 0; #endif virtual bool HasPerformDbHousekeeping() = 0;
--- a/Framework/Plugins/IndexBackend.cpp Thu Jun 12 14:02:35 2025 +0200 +++ b/Framework/Plugins/IndexBackend.cpp Thu Jun 12 16:07:26 2025 +0200 @@ -406,29 +406,23 @@ const OrthancPluginAttachment& attachment, int64_t revision) { - assert(HasRevisionsSupport() && HasAttachmentCustomDataSupport()); // all plugins support these features now + assert(HasRevisionsSupport()); // all plugins support these features now ExecuteAddAttachment(manager, id, attachment.uuid, attachment.contentType, attachment.uncompressedSize, attachment.uncompressedHash, attachment.compressionType, attachment.compressedSize, attachment.compressedHash, NULL, 0, revision); } + #if ORTHANC_PLUGINS_HAS_ATTACHMENTS_CUSTOM_DATA == 1 - void IndexBackend::AddAttachment(Orthanc::DatabasePluginMessages::TransactionResponse& response, - DatabaseManager& manager, - const Orthanc::DatabasePluginMessages::AddAttachment_Request& request) + void IndexBackend::AddAttachment(DatabaseManager& manager, + int64_t id, + const OrthancPluginAttachment& attachment, + int64_t revision, + const std::string& customData) { - assert(HasRevisionsSupport() && HasAttachmentCustomDataSupport()); // all plugins support these features now - ExecuteAddAttachment(manager, - request.id(), - request.attachment().uuid().c_str(), - request.attachment().content_type(), - request.attachment().uncompressed_size(), - request.attachment().uncompressed_hash().c_str(), - request.attachment().compression_type(), - request.attachment().compressed_size(), - request.attachment().compressed_hash().c_str(), - request.attachment().custom_data().empty() ? NULL : request.attachment().custom_data().c_str(), - request.attachment().custom_data().size(), - request.revision()); + assert(HasRevisionsSupport() && HasAttachmentCustomDataSupport()); + ExecuteAddAttachment(manager, id, attachment.uuid, attachment.contentType, attachment.uncompressedSize, attachment.uncompressedHash, + attachment.compressionType, attachment.compressedSize, attachment.compressedHash, + customData.empty() ? NULL : customData.c_str(), customData.size(), revision); } #endif @@ -976,7 +970,7 @@ if (statement.IsDone()) { - throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource, "No resource type found for internal id."); + throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource, "No resource type found for internal id"); } else { @@ -4644,48 +4638,36 @@ #endif #if ORTHANC_PLUGINS_HAS_ATTACHMENTS_CUSTOM_DATA == 1 - bool IndexBackend::GetAttachment(Orthanc::DatabasePluginMessages::TransactionResponse& response, - DatabaseManager& manager, - const Orthanc::DatabasePluginMessages::GetAttachment_Request& request) + void IndexBackend::GetAttachmentCustomData(std::string& customData, + DatabaseManager& manager, + const std::string& attachmentUuid) { DatabaseManager::CachedStatement statement( STATEMENT_FROM_HERE, manager, - "SELECT uuid, fileType, uncompressedSize, uncompressedHash, compressionType, " - "compressedSize, compressedHash, revision, customData FROM AttachedFiles WHERE uuid = ${uuid}"); + "SELECT customData FROM AttachedFiles WHERE uuid = ${uuid}"); statement.SetReadOnly(true); statement.SetParameterType("uuid", ValueType_Utf8String); Dictionary args; - args.SetUtf8Value("uuid", request.uuid()); + args.SetUtf8Value("uuid", attachmentUuid); statement.Execute(args); statement.SetResultFieldType(8, ValueType_BinaryString); if (statement.IsDone()) { - return false; + throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource, "Nonexistent attachment: " + attachmentUuid); } else { - response.mutable_get_attachment()->set_revision(statement.ReadInteger64(7)); - response.mutable_get_attachment()->mutable_attachment()->set_uuid(statement.ReadString(0)); - response.mutable_get_attachment()->mutable_attachment()->set_content_type(statement.ReadInteger32(1)); - response.mutable_get_attachment()->mutable_attachment()->set_uncompressed_size(statement.ReadInteger64(2)); - response.mutable_get_attachment()->mutable_attachment()->set_uncompressed_hash(statement.ReadString(3)); - response.mutable_get_attachment()->mutable_attachment()->set_compression_type(statement.ReadInteger32(4)); - response.mutable_get_attachment()->mutable_attachment()->set_compressed_size(statement.ReadInteger64(5)); - response.mutable_get_attachment()->mutable_attachment()->set_compressed_hash(statement.ReadString(6)); - response.mutable_get_attachment()->mutable_attachment()->set_custom_data(statement.ReadStringOrNull(8)); - - return true; + customData = statement.ReadStringOrNull(0); } - } - void IndexBackend::UpdateAttachmentCustomData(DatabaseManager& manager, - const std::string& attachmentUuid, - const std::string& customData) + void IndexBackend::SetAttachmentCustomData(DatabaseManager& manager, + const std::string& attachmentUuid, + const std::string& customData) { DatabaseManager::CachedStatement statement( STATEMENT_FROM_HERE, manager,
--- a/Framework/Plugins/IndexBackend.h Thu Jun 12 14:02:35 2025 +0200 +++ b/Framework/Plugins/IndexBackend.h Thu Jun 12 16:07:26 2025 +0200 @@ -111,10 +111,12 @@ int64_t revision) ORTHANC_OVERRIDE; #if ORTHANC_PLUGINS_HAS_ATTACHMENTS_CUSTOM_DATA == 1 - // New in Orthanc 1.12.7 - virtual void AddAttachment(Orthanc::DatabasePluginMessages::TransactionResponse& response, - DatabaseManager& manager, - const Orthanc::DatabasePluginMessages::AddAttachment_Request& request) ORTHANC_OVERRIDE; + // New in Orthanc 1.12.8 + virtual void AddAttachment(DatabaseManager& manager, + int64_t id, + const OrthancPluginAttachment& attachment, + int64_t revision, + const std::string& customData) ORTHANC_OVERRIDE; #endif virtual void AttachChild(DatabaseManager& manager, @@ -509,13 +511,13 @@ #endif #if ORTHANC_PLUGINS_HAS_ATTACHMENTS_CUSTOM_DATA == 1 - virtual bool GetAttachment(Orthanc::DatabasePluginMessages::TransactionResponse& response, - DatabaseManager& manager, - const Orthanc::DatabasePluginMessages::GetAttachment_Request& request) ORTHANC_OVERRIDE; + virtual void GetAttachmentCustomData(std::string& customData, + DatabaseManager& manager, + const std::string& attachmentUuid) ORTHANC_OVERRIDE; - virtual void UpdateAttachmentCustomData(DatabaseManager& manager, - const std::string& attachmentUuid, - const std::string& customData) ORTHANC_OVERRIDE; + virtual void SetAttachmentCustomData(DatabaseManager& manager, + const std::string& attachmentUuid, + const std::string& customData) ORTHANC_OVERRIDE; #endif