changeset 391:d14e6ff04a5c db-protobuf

added primitives to handle labels
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 Apr 2023 12:09:46 +0200
parents eb80f7c5e7d8
children d941568543a0
files Framework/Plugins/DatabaseBackendAdapterV2.cpp Framework/Plugins/DatabaseBackendAdapterV3.cpp Framework/Plugins/DatabaseBackendAdapterV4.cpp Framework/Plugins/IDatabaseBackend.h Framework/Plugins/IndexBackend.cpp Framework/Plugins/IndexBackend.h MySQL/Plugins/MySQLIndex.h Odbc/Plugins/OdbcIndex.h PostgreSQL/Plugins/PostgreSQLIndex.h SQLite/Plugins/SQLiteIndex.h
diffstat 10 files changed, 101 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Plugins/DatabaseBackendAdapterV2.cpp	Wed Apr 05 11:18:08 2023 +0200
+++ b/Framework/Plugins/DatabaseBackendAdapterV2.cpp	Wed Apr 05 12:09:46 2023 +0200
@@ -1419,7 +1419,10 @@
         lookup.push_back(Orthanc::DatabaseConstraint(constraints[i]));
       }
         
-      adapter->GetBackend().LookupResources(*output, accessor.GetManager(), lookup, queryLevel, limit, (requestSomeInstance != 0));
+      std::set<std::string> noLabels;
+      adapter->GetBackend().LookupResources(*output, accessor.GetManager(), lookup, queryLevel,
+                                            noLabels, noLabels, limit, (requestSomeInstance != 0));
+      
       return OrthancPluginErrorCode_Success;
     }
     ORTHANC_PLUGINS_DATABASE_CATCH;
--- a/Framework/Plugins/DatabaseBackendAdapterV3.cpp	Wed Apr 05 11:18:08 2023 +0200
+++ b/Framework/Plugins/DatabaseBackendAdapterV3.cpp	Wed Apr 05 12:09:46 2023 +0200
@@ -1646,7 +1646,9 @@
         lookup.push_back(Orthanc::DatabaseConstraint(constraints[i]));
       }
         
-      t->GetBackend().LookupResources(t->GetOutput(), t->GetManager(), lookup, queryLevel, limit, (requestSomeInstanceId != 0));
+      std::set<std::string> noLabels;
+      t->GetBackend().LookupResources(t->GetOutput(), t->GetManager(), lookup, queryLevel,
+                                      noLabels, noLabels, limit, (requestSomeInstanceId != 0));
       return OrthancPluginErrorCode_Success;
     }
     ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext());
--- a/Framework/Plugins/DatabaseBackendAdapterV4.cpp	Wed Apr 05 11:18:08 2023 +0200
+++ b/Framework/Plugins/DatabaseBackendAdapterV4.cpp	Wed Apr 05 12:09:46 2023 +0200
@@ -567,9 +567,21 @@
 
     assert(values.size() == countValues);
 
+    std::set<std::string> withLabels, withoutLabels;
+
+    for (int i = 0; i < request.with_labels().size(); i++)
+    {
+      withLabels.insert(request.with_labels(i));
+    }
+
+    for (int i = 0; i < request.without_labels().size(); i++)
+    {
+      withoutLabels.insert(request.without_labels(i));
+    }
+    
     Output output(response);
     backend.LookupResources(output, manager, lookup, Convert(request.query_level()),
-                            request.limit(), request.retrieve_instances_ids());
+                            withLabels, withoutLabels, request.limit(), request.retrieve_instances_ids());
   }
 
   
--- a/Framework/Plugins/IDatabaseBackend.h	Wed Apr 05 11:18:08 2023 +0200
+++ b/Framework/Plugins/IDatabaseBackend.h	Wed Apr 05 12:09:46 2023 +0200
@@ -271,6 +271,8 @@
                                  DatabaseManager& manager,
                                  const std::vector<Orthanc::DatabaseConstraint>& lookup,
                                  OrthancPluginResourceType queryLevel,
+                                 const std::set<std::string>& withLabels,     // New in Orthanc 1.12.0
+                                 const std::set<std::string>& withoutLabels,  // New in Orthanc 1.12.0
                                  uint32_t limit,
                                  bool requestSomeInstance) = 0;
 #endif
@@ -307,23 +309,30 @@
     virtual void TagMostRecentPatient(DatabaseManager& manager,
                                       int64_t patientId) = 0;
 
-#if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE)      // Macro introduced in 1.3.1
-#  if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4)
     // NB: "parentPublicId" must be cleared if the resource has no parent
     virtual bool LookupResourceAndParent(int64_t& id,
                                          OrthancPluginResourceType& type,
                                          std::string& parentPublicId,
                                          DatabaseManager& manager,
                                          const char* publicId) = 0;
-#  endif
-#endif
 
-#if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE)      // Macro introduced in 1.3.1
-#  if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4)
     virtual void GetAllMetadata(std::map<int32_t, std::string>& result,
                                 DatabaseManager& manager,
                                 int64_t id) = 0;
-#  endif
-#endif
+
+    // New in Orthanc 1.12.0
+    virtual bool HasLabelsSupport() const = 0;
+
+    // New in Orthanc 1.12.0
+    virtual void AddLabel(int64_t resource,
+                          const std::string& label) = 0;
+
+    // New in Orthanc 1.12.0
+    virtual void RemoveLabel(int64_t resource,
+                             const std::string& label) = 0;
+
+    // New in Orthanc 1.12.0
+    virtual void ListLabels(std::set<std::string>& target,
+                            int64_t resource) = 0;
   };
 }
--- a/Framework/Plugins/IndexBackend.cpp	Wed Apr 05 11:18:08 2023 +0200
+++ b/Framework/Plugins/IndexBackend.cpp	Wed Apr 05 12:09:46 2023 +0200
@@ -2065,9 +2065,17 @@
                                      DatabaseManager& manager,
                                      const std::vector<Orthanc::DatabaseConstraint>& lookup,
                                      OrthancPluginResourceType queryLevel,
+                                     const std::set<std::string>& withLabels,
+                                     const std::set<std::string>& withoutLabels,
                                      uint32_t limit,
                                      bool requestSomeInstance)
   {
+    if (!withLabels.empty() ||
+        !withoutLabels.empty())
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
+    }
+
     LookupFormatter formatter(manager.GetDialect());
 
     std::string sql;
@@ -2609,6 +2617,27 @@
 #endif
 
 
+  void IndexBackend::AddLabel(int64_t resource,
+                              const std::string& label)
+  {
+    throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
+  }
+
+
+  void IndexBackend::RemoveLabel(int64_t resource,
+                                 const std::string& label)
+  {
+    throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
+  }
+
+
+  void IndexBackend::ListLabels(std::set<std::string>& target,
+                                int64_t resource)
+  {
+    throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
+  }
+  
+
   void IndexBackend::Register(IndexBackend* backend,
                               size_t countConnections,
                               unsigned int maxDatabaseRetries)
--- a/Framework/Plugins/IndexBackend.h	Wed Apr 05 11:18:08 2023 +0200
+++ b/Framework/Plugins/IndexBackend.h	Wed Apr 05 12:09:46 2023 +0200
@@ -302,6 +302,8 @@
                                  DatabaseManager& manager,
                                  const std::vector<Orthanc::DatabaseConstraint>& lookup,
                                  OrthancPluginResourceType queryLevel,
+                                 const std::set<std::string>& withLabels,
+                                 const std::set<std::string>& withoutLabels,
                                  uint32_t limit,
                                  bool requestSomeInstance) ORTHANC_OVERRIDE;
 #endif
@@ -327,25 +329,17 @@
     virtual void TagMostRecentPatient(DatabaseManager& manager,
                                       int64_t patient) ORTHANC_OVERRIDE;
 
-#if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE)      // Macro introduced in 1.3.1
-#  if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4)
     // New primitive since Orthanc 1.5.4
     virtual bool LookupResourceAndParent(int64_t& id,
                                          OrthancPluginResourceType& type,
                                          std::string& parentPublicId,
                                          DatabaseManager& manager,
                                          const char* publicId) ORTHANC_OVERRIDE;
-#  endif
-#endif
 
-#if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE)      // Macro introduced in 1.3.1
-#  if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4)
     // New primitive since Orthanc 1.5.4
     virtual void GetAllMetadata(std::map<int32_t, std::string>& result,
                                 DatabaseManager& manager,
                                 int64_t id) ORTHANC_OVERRIDE;
-#  endif
-#endif
 
     virtual bool HasCreateInstance() const ORTHANC_OVERRIDE
     {
@@ -387,6 +381,15 @@
                                   int32_t property,
                                   int value);
 
+    virtual void AddLabel(int64_t resource,
+                          const std::string& label) ORTHANC_OVERRIDE;
+
+    virtual void RemoveLabel(int64_t resource,
+                             const std::string& label) ORTHANC_OVERRIDE;
+
+    virtual void ListLabels(std::set<std::string>& target,
+                            int64_t resource) ORTHANC_OVERRIDE;
+    
     /**
      * "maxDatabaseRetries" is to handle
      * "OrthancPluginErrorCode_DatabaseCannotSerialize" if there is a
--- a/MySQL/Plugins/MySQLIndex.h	Wed Apr 05 11:18:08 2023 +0200
+++ b/MySQL/Plugins/MySQLIndex.h	Wed Apr 05 12:09:46 2023 +0200
@@ -76,5 +76,11 @@
                                 const char* hashInstance)
       ORTHANC_OVERRIDE;
 #endif
+
+    // New primitive since Orthanc 1.12.0
+    virtual bool HasLabelsSupport() const ORTHANC_OVERRIDE
+    {
+      return false;
+    }
   };
 }
--- a/Odbc/Plugins/OdbcIndex.h	Wed Apr 05 11:18:08 2023 +0200
+++ b/Odbc/Plugins/OdbcIndex.h	Wed Apr 05 12:09:46 2023 +0200
@@ -83,5 +83,11 @@
                                   DatabaseManager& manager,
                                   int64_t id,
                                   int32_t attachment) ORTHANC_OVERRIDE;
+    
+    // New primitive since Orthanc 1.12.0
+    virtual bool HasLabelsSupport() const ORTHANC_OVERRIDE
+    {
+      return false;
+    }
   };
 }
--- a/PostgreSQL/Plugins/PostgreSQLIndex.h	Wed Apr 05 11:18:08 2023 +0200
+++ b/PostgreSQL/Plugins/PostgreSQLIndex.h	Wed Apr 05 12:09:46 2023 +0200
@@ -82,5 +82,11 @@
 
     virtual void TagMostRecentPatient(DatabaseManager& manager,
                                       int64_t patient) ORTHANC_OVERRIDE;
+
+    // New primitive since Orthanc 1.12.0
+    virtual bool HasLabelsSupport() const ORTHANC_OVERRIDE
+    {
+      return false;
+    }
   };
 }
--- a/SQLite/Plugins/SQLiteIndex.h	Wed Apr 05 11:18:08 2023 +0200
+++ b/SQLite/Plugins/SQLiteIndex.h	Wed Apr 05 12:09:46 2023 +0200
@@ -58,5 +58,11 @@
 
     // New primitive since Orthanc 1.5.2
     virtual int64_t GetLastChangeIndex(DatabaseManager& manager) ORTHANC_OVERRIDE;
+
+    // New primitive since Orthanc 1.12.0
+    virtual bool HasLabelsSupport() const ORTHANC_OVERRIDE
+    {
+      return false;
+    }
   };
 }