changeset 5804:25df40a274fd find-refactoring

/changes: allowing filtering on multiple changes
author Alain Mazy <am@orthanc.team>
date Mon, 23 Sep 2024 15:40:27 +0200
parents e219e272650d
children 8a8756b2dd0b
files OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp OrthancServer/Plugins/Include/orthanc/OrthancDatabasePlugin.proto OrthancServer/Sources/Database/BaseDatabaseWrapper.cpp OrthancServer/Sources/Database/BaseDatabaseWrapper.h OrthancServer/Sources/Database/IDatabaseWrapper.h OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp OrthancServer/Sources/Database/StatelessDatabaseOperations.h OrthancServer/Sources/OrthancRestApi/OrthancRestChanges.cpp OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp
diffstat 10 files changed, 50 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp	Fri Sep 20 18:18:52 2024 +0200
+++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp	Mon Sep 23 15:40:27 2024 +0200
@@ -631,7 +631,7 @@
                                     int64_t since,
                                     int64_t to,
                                     uint32_t limit,
-                                    ChangeType changeType) ORTHANC_OVERRIDE
+                                    const std::set<ChangeType>& changeTypes) ORTHANC_OVERRIDE
     {
       assert(database_.GetDatabaseCapabilities().HasExtendedChanges());
 
@@ -641,7 +641,11 @@
       request.mutable_get_changes_extended()->set_since(since);
       request.mutable_get_changes_extended()->set_limit(limit);
       request.mutable_get_changes_extended()->set_to(to);
-      request.mutable_get_changes_extended()->set_change_type(changeType);
+      for (std::set<ChangeType>::const_iterator it = changeTypes.begin(); it != changeTypes.end(); ++it)
+      {
+        request.mutable_get_changes_extended()->add_change_type(*it);
+      }
+      
       ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_CHANGES_EXTENDED, request);
 
       done = response.get_changes_extended().done();
--- a/OrthancServer/Plugins/Include/orthanc/OrthancDatabasePlugin.proto	Fri Sep 20 18:18:52 2024 +0200
+++ b/OrthancServer/Plugins/Include/orthanc/OrthancDatabasePlugin.proto	Mon Sep 23 15:40:27 2024 +0200
@@ -421,7 +421,7 @@
   message Request {
     int64 since = 1;
     int64 to = 2;
-    int32 change_type = 3;
+    repeated int32 change_type = 3;
     uint32 limit = 4;
   }
   message Response {
--- a/OrthancServer/Sources/Database/BaseDatabaseWrapper.cpp	Fri Sep 20 18:18:52 2024 +0200
+++ b/OrthancServer/Sources/Database/BaseDatabaseWrapper.cpp	Mon Sep 23 15:40:27 2024 +0200
@@ -51,7 +51,7 @@
                                                                 int64_t since,
                                                                 int64_t to,
                                                                 uint32_t limit,
-                                                                ChangeType filterType)
+                                                                const std::set<ChangeType>& filterType)
   {
     throw OrthancException(ErrorCode_NotImplemented);  // Not supported
   }
--- a/OrthancServer/Sources/Database/BaseDatabaseWrapper.h	Fri Sep 20 18:18:52 2024 +0200
+++ b/OrthancServer/Sources/Database/BaseDatabaseWrapper.h	Mon Sep 23 15:40:27 2024 +0200
@@ -66,7 +66,7 @@
                                       int64_t since,
                                       int64_t to,
                                       uint32_t limit,
-                                      ChangeType filterType) ORTHANC_OVERRIDE;
+                                      const std::set<ChangeType>& filterType) ORTHANC_OVERRIDE;
     };
 
     virtual uint64_t MeasureLatency() ORTHANC_OVERRIDE;
--- a/OrthancServer/Sources/Database/IDatabaseWrapper.h	Fri Sep 20 18:18:52 2024 +0200
+++ b/OrthancServer/Sources/Database/IDatabaseWrapper.h	Mon Sep 23 15:40:27 2024 +0200
@@ -413,7 +413,7 @@
                                       int64_t since,
                                       int64_t to,
                                       uint32_t limit,
-                                      ChangeType filterType) = 0;
+                                      const std::set<ChangeType>& filterType) = 0;
     };
 
 
--- a/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp	Fri Sep 20 18:18:52 2024 +0200
+++ b/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp	Mon Sep 23 15:40:27 2024 +0200
@@ -76,6 +76,20 @@
     return sql;
   }
 
+  static std::string JoinChanges(const std::set<ChangeType>& changeTypes)
+  {
+    std::set<std::string> changeTypesString;
+    for (std::set<ChangeType>::const_iterator it = changeTypes.begin(); it != changeTypes.end(); ++it)
+    {
+      changeTypesString.insert(boost::lexical_cast<std::string>(static_cast<uint32_t>(*it)));
+    }
+
+    std::string joinedChangesTypes;
+    Orthanc::Toolbox::JoinStrings(joinedChangesTypes, changeTypesString, ", ");
+
+    return joinedChangesTypes;
+  }
+
   class SQLiteDatabaseWrapper::LookupFormatter : public ISqlLookupFormatter
   {
   private:
@@ -1248,7 +1262,8 @@
                             int64_t since,
                             uint32_t limit) ORTHANC_OVERRIDE
     {
-      GetChangesExtended(target, done, since, -1, limit, ChangeType_INTERNAL_All);
+      std::set<ChangeType> filter;
+      GetChangesExtended(target, done, since, -1, limit, filter);
     }
 
     virtual void GetChangesExtended(std::list<ServerIndexChange>& target /*out*/,
@@ -1256,12 +1271,12 @@
                                     int64_t since,
                                     int64_t to,
                                     uint32_t limit,
-                                    ChangeType filterType) ORTHANC_OVERRIDE
+                                    const std::set<ChangeType>& filterType) ORTHANC_OVERRIDE
     {
       std::vector<std::string> filters;
       bool hasSince = false;
       bool hasTo = false;
-      bool hasFilterType = false;
+      // bool hasFilterType = false;
 
       if (since > 0)
       {
@@ -1273,10 +1288,10 @@
         hasTo = true;
         filters.push_back("seq<=?");
       }
-      if (filterType != ChangeType_INTERNAL_All)
+      if (filterType.size() != 0)
       {
-        hasFilterType = true;
-        filters.push_back("changeType=?");
+        // hasFilterType = true;
+        filters.push_back("changeType IN ( " + JoinChanges(filterType) +  " )");
       }
 
       std::string filtersString;
@@ -1312,10 +1327,10 @@
       {
         s.BindInt64(paramCounter++, to);
       }
-      if (hasFilterType)
-      {
-        s.BindInt(paramCounter++, filterType);
-      }
+      // if (hasFilterType)
+      // {
+      //   s.BindInt(paramCounter++, filterType);
+      // }
       s.BindInt(paramCounter++, limit + 1); // we take limit+1 because we use the +1 to know if "Done" must be set to true
       GetChangesInternal(target, done, s, limit, returnFirstResults);
     }
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Fri Sep 20 18:18:52 2024 +0200
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Mon Sep 23 15:40:27 2024 +0200
@@ -1096,9 +1096,9 @@
                                                        int64_t since,
                                                        int64_t to,                               
                                                        unsigned int maxResults,
-                                                       ChangeType changeType)
+                                                       const std::set<ChangeType>& changeType)
   {
-    class Operations : public ReadOnlyOperationsT5<Json::Value&, int64_t, int64_t, unsigned int, unsigned int>
+    class Operations : public ReadOnlyOperationsT5<Json::Value&, int64_t, int64_t, unsigned int, const std::set<ChangeType>&>
     {
     public:
       virtual void ApplyTuple(ReadOnlyTransaction& transaction,
@@ -1109,7 +1109,7 @@
         bool hasLast = false;
         int64_t last = 0;
 
-        transaction.GetChangesExtended(changes, done, tuple.get<1>(), tuple.get<2>(), tuple.get<3>(), static_cast<ChangeType>(tuple.get<4>()));
+        transaction.GetChangesExtended(changes, done, tuple.get<1>(), tuple.get<2>(), tuple.get<3>(), tuple.get<4>());
         if (changes.empty())
         {
           last = transaction.GetLastChangeIndex();
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.h	Fri Sep 20 18:18:52 2024 +0200
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.h	Mon Sep 23 15:40:27 2024 +0200
@@ -264,7 +264,7 @@
                               int64_t since,
                               int64_t to,
                               uint32_t limit,
-                              ChangeType filterType)
+                              const std::set<ChangeType>& filterType)
       {
         transaction_.GetChangesExtended(target, done, since, to, limit, filterType);
       }
@@ -674,7 +674,7 @@
                             int64_t since,
                             int64_t to,
                             uint32_t limit,
-                            ChangeType filterType);
+                            const std::set<ChangeType>& filterType);
 
     void GetLastChange(Json::Value& target);
 
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestChanges.cpp	Fri Sep 20 18:18:52 2024 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestChanges.cpp	Mon Sep 23 15:40:27 2024 +0200
@@ -89,7 +89,7 @@
     ServerContext& context = OrthancRestApi::GetContext(call);
 
     int64_t since, to;
-    ChangeType filterType = ChangeType_INTERNAL_All;
+    std::set<ChangeType> filterType; // = ChangeType_INTERNAL_All;
 
     unsigned int limit;
     bool last;
@@ -98,7 +98,13 @@
     std::string filterArgument = call.GetArgument("type", "all");
     if (filterArgument != "all" && filterArgument != "All")
     {
-      filterType = StringToChangeType(filterArgument);
+      std::set<std::string> filterTypeStrings;
+      Toolbox::SplitString(filterTypeStrings, filterArgument, ';');
+
+      for (std::set<std::string>::const_iterator it = filterTypeStrings.begin(); it != filterTypeStrings.end(); ++it)
+      {
+        filterType.insert(StringToChangeType(*it));
+      }
     }
 
     Json::Value result;
@@ -112,7 +118,7 @@
     }
     else
     {
-      if (filterType != ChangeType_INTERNAL_All)
+      if (filterType.size() > 0)
       {
         throw OrthancException(ErrorCode_ParameterOutOfRange, "CAPABILITIES: Trying to filter changes while the Database backend does not support it (requires a DB backend with support for ExtendedChanges)");
       }
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Fri Sep 20 18:18:52 2024 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Mon Sep 23 15:40:27 2024 +0200
@@ -4536,5 +4536,5 @@
     }
 
     Register("/tools/bulk-content", BulkContent);
-  }
+   }
 }