changeset 577:991b9b285e1a attach-custom-data tip

fix custom-data handling
author Alain Mazy <am@orthanc.team>
date Wed, 02 Oct 2024 09:40:20 +0200
parents b0533b703c2c
children
files Framework/Plugins/DatabaseBackendAdapterV4.cpp Framework/Plugins/IDatabaseBackend.h Framework/Plugins/IndexBackend.cpp Framework/Plugins/IndexBackend.h Framework/Plugins/MessagesToolbox.h PostgreSQL/NEWS
diffstat 6 files changed, 80 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Plugins/DatabaseBackendAdapterV4.cpp	Tue Oct 01 16:02:48 2024 +0200
+++ b/Framework/Plugins/DatabaseBackendAdapterV4.cpp	Wed Oct 02 09:40:20 2024 +0200
@@ -225,6 +225,9 @@
       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
     }
 
     virtual void SignalDeletedResource(const std::string& publicId,
@@ -288,6 +291,9 @@
         lookupAttachment_->mutable_attachment()->set_compression_type(compressionType);
         lookupAttachment_->mutable_attachment()->set_compressed_size(compressedSize);
         lookupAttachment_->mutable_attachment()->set_compressed_hash(compressedHash);
+#if ORTHANC_PLUGINS_HAS_ATTACHMENTS_CUSTOM_DATA==1
+        lookupAttachment_->mutable_attachment()->set_custom_data(customData);
+#endif
       }
       else
       {
@@ -684,6 +690,9 @@
       
       case Orthanc::DatabasePluginMessages::OPERATION_ADD_ATTACHMENT:
       {
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 6)
+        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();
@@ -694,9 +703,9 @@
         attachment.compressedHash = request.add_attachment().attachment().compressed_hash().c_str();
         
         backend.AddAttachment(manager, request.add_attachment().id(), attachment, request.add_attachment().revision());
+#endif
         break;
       }
-      
       case Orthanc::DatabasePluginMessages::OPERATION_CLEAR_CHANGES:
       {
         backend.ClearChanges(manager);
--- a/Framework/Plugins/IDatabaseBackend.h	Tue Oct 01 16:02:48 2024 +0200
+++ b/Framework/Plugins/IDatabaseBackend.h	Wed Oct 02 09:40:20 2024 +0200
@@ -66,13 +66,20 @@
                                const OrthancPluginAttachment& attachment,
                                int64_t revision) = 0;
 
-#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0)
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 6)
+    // New in Orthanc 1.12.6
+    virtual void AddAttachment(Orthanc::DatabasePluginMessages::TransactionResponse& response,
+                               DatabaseManager& manager,
+                               const Orthanc::DatabasePluginMessages::AddAttachment_Request& request) = 0;
+#endif
 
-    virtual void AddAttachment2(DatabaseManager& manager,
-                               int64_t id,
-                               const OrthancPluginAttachment2& attachment,
-                               int64_t revision) = 0;
-#endif
+// #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 6)
+
+//     virtual void AddAttachment2(DatabaseManager& manager,
+//                                int64_t id,
+//                                const OrthancPluginAttachment2& attachment,
+//                                int64_t revision) = 0;
+// #endif
 
     virtual void AttachChild(DatabaseManager& manager,
                              int64_t parent,
@@ -406,5 +413,6 @@
                              DatabaseManager& manager,
                              const Orthanc::DatabasePluginMessages::Find_Request& request) = 0;
 #endif
+
   };
 }
--- a/Framework/Plugins/IndexBackend.cpp	Tue Oct 01 16:02:48 2024 +0200
+++ b/Framework/Plugins/IndexBackend.cpp	Wed Oct 02 09:40:20 2024 +0200
@@ -400,17 +400,38 @@
                          attachment.compressionType, attachment.compressedSize, attachment.compressedHash, "", revision);
   }
 
-#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0)
-  void IndexBackend::AddAttachment2(DatabaseManager& manager,
-                                   int64_t id,
-                                   const OrthancPluginAttachment2& attachment,
-                                   int64_t revision)
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 6)
+  void IndexBackend::AddAttachment(Orthanc::DatabasePluginMessages::TransactionResponse& response,
+                                   DatabaseManager& manager,
+                                   const Orthanc::DatabasePluginMessages::AddAttachment_Request& request)
   {
     assert(HasRevisionsSupport() && HasAttachmentCustomDataSupport()); // all plugins supports these features now
-    ExecuteAddAttachment(manager, id, attachment.uuid, attachment.contentType, attachment.uncompressedSize, attachment.uncompressedHash,
-                         attachment.compressionType, attachment.compressedSize, attachment.compressedHash, attachment.customData, revision);
+    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().c_str(),
+                         request.revision());
   }
 #endif
+
+
+// #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 6)
+//   void IndexBackend::AddAttachment2(DatabaseManager& manager,
+//                                    int64_t id,
+//                                    const OrthancPluginAttachment2& attachment,
+//                                    int64_t revision)
+//   {
+//     assert(HasRevisionsSupport() && HasAttachmentCustomDataSupport()); // all plugins supports these features now
+//     ExecuteAddAttachment(manager, id, attachment.uuid, attachment.contentType, attachment.uncompressedSize, attachment.uncompressedHash,
+//                          attachment.compressionType, attachment.compressedSize, attachment.compressedHash, attachment.customData, revision);
+//   }
+// #endif
     
   void IndexBackend::AttachChild(DatabaseManager& manager,
                                  int64_t parent,
--- a/Framework/Plugins/IndexBackend.h	Tue Oct 01 16:02:48 2024 +0200
+++ b/Framework/Plugins/IndexBackend.h	Wed Oct 02 09:40:20 2024 +0200
@@ -91,14 +91,21 @@
                                const OrthancPluginAttachment& attachment,
                                int64_t revision) ORTHANC_OVERRIDE;
 
-#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0)
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 6)
+    // New in Orthanc 1.12.6
+    virtual void AddAttachment(Orthanc::DatabasePluginMessages::TransactionResponse& response,
+                               DatabaseManager& manager,
+                               const Orthanc::DatabasePluginMessages::AddAttachment_Request& request) ORTHANC_OVERRIDE;
+#endif
 
-    virtual void AddAttachment2(DatabaseManager& manager,
-                               int64_t id,
-                               const OrthancPluginAttachment2& attachment,
-                               int64_t revision) ORTHANC_OVERRIDE;
+// #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 6)
 
-#endif
+//     virtual void AddAttachment2(DatabaseManager& manager,
+//                                int64_t id,
+//                                const OrthancPluginAttachment2& attachment,
+//                                int64_t revision) ORTHANC_OVERRIDE;
+
+// #endif
 
     virtual void AttachChild(DatabaseManager& manager,
                              int64_t parent,
--- a/Framework/Plugins/MessagesToolbox.h	Tue Oct 01 16:02:48 2024 +0200
+++ b/Framework/Plugins/MessagesToolbox.h	Wed Oct 02 09:40:20 2024 +0200
@@ -59,6 +59,15 @@
 #endif
 
 
+#define ORTHANC_PLUGINS_HAS_ATTACHMENTS_CUSTOM_DATA 0
+
+#if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE)
+#  if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 6)
+#    undef  ORTHANC_PLUGINS_HAS_ATTACHMENTS_CUSTOM_DATA
+#    define ORTHANC_PLUGINS_HAS_ATTACHMENTS_CUSTOM_DATA 1
+#  endif
+#endif
+
 #include <Enumerations.h>
 
 
--- a/PostgreSQL/NEWS	Tue Oct 01 16:02:48 2024 +0200
+++ b/PostgreSQL/NEWS	Wed Oct 02 09:40:20 2024 +0200
@@ -1,9 +1,14 @@
 Pending changes in the mainline
 ===============================
 
-DB schema revision: 2
+DB schema revision: 3
+
 Minimum plugin SDK (for build): 1.12.3
+Optimal plugin SDK: 1.12.6
+
 Minimum Orthanc runtime: 1.12.3
+Optimal Orthanc runtime: 1.12.6
+
 
 * Fix updates from plugin version 3.3 to latest version
 * Added support for ExtendedChanges: