diff OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp @ 5249:f22c8fac764b db-protobuf

added "/tools/labels" to list all the labels that are associated with any resource
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 07 Apr 2023 22:54:57 +0200
parents a7d95f951f8a
children fafdb6179829
line wrap: on
line diff
--- a/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp	Fri Apr 07 22:18:37 2023 +0200
+++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp	Fri Apr 07 22:54:57 2023 +0200
@@ -223,6 +223,33 @@
     }
 
 
+    void ListLabelsInternal(std::set<std::string>& target,
+                            bool isSingleResource,
+                            int64_t resource)
+    {
+      if (database_.HasLabelsSupport())
+      {
+        DatabasePluginMessages::TransactionRequest request;
+        request.mutable_list_labels()->set_single_resource(isSingleResource);
+        request.mutable_list_labels()->set_id(resource);
+
+        DatabasePluginMessages::TransactionResponse response;
+        ExecuteTransaction(response, DatabasePluginMessages::OPERATION_LIST_LABELS, request);
+
+        target.clear();
+        for (int i = 0; i < response.list_labels().labels().size(); i++)
+        {
+          target.insert(response.list_labels().labels(i));
+        }
+      }
+      else
+      {
+        // This method shouldn't have been called
+        throw OrthancException(ErrorCode_InternalError);
+      }
+    }
+    
+
   public:
     Transaction(OrthancPluginDatabaseV4& database,
                 IDatabaseListener& listener,
@@ -1206,25 +1233,13 @@
     virtual void ListLabels(std::set<std::string>& target,
                             int64_t resource) ORTHANC_OVERRIDE
     {
-      if (database_.HasLabelsSupport())
-      {
-        DatabasePluginMessages::TransactionRequest request;
-        request.mutable_list_labels()->set_id(resource);
-
-        DatabasePluginMessages::TransactionResponse response;
-        ExecuteTransaction(response, DatabasePluginMessages::OPERATION_LIST_LABELS, request);
+      ListLabelsInternal(target, true, resource);
+    }
 
-        target.clear();
-        for (int i = 0; i < response.list_labels().labels().size(); i++)
-        {
-          target.insert(response.list_labels().labels(i));
-        }
-      }
-      else
-      {
-        // This method shouldn't have been called
-        throw OrthancException(ErrorCode_InternalError);
-      }
+    
+    virtual void ListAllLabels(std::set<std::string>& target) ORTHANC_OVERRIDE
+    {
+      ListLabelsInternal(target, false, -1);
     }
   };