# HG changeset patch # User Alain Mazy # Date 1727098827 -7200 # Node ID 25df40a274fd4198013dfcf13fdab9d3eabb007b # Parent e219e272650d40dfbd51ddc24a4be1565caaec4d /changes: allowing filtering on multiple changes diff -r e219e272650d -r 25df40a274fd OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp --- 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& 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::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(); diff -r e219e272650d -r 25df40a274fd OrthancServer/Plugins/Include/orthanc/OrthancDatabasePlugin.proto --- 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 { diff -r e219e272650d -r 25df40a274fd OrthancServer/Sources/Database/BaseDatabaseWrapper.cpp --- 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& filterType) { throw OrthancException(ErrorCode_NotImplemented); // Not supported } diff -r e219e272650d -r 25df40a274fd OrthancServer/Sources/Database/BaseDatabaseWrapper.h --- 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& filterType) ORTHANC_OVERRIDE; }; virtual uint64_t MeasureLatency() ORTHANC_OVERRIDE; diff -r e219e272650d -r 25df40a274fd OrthancServer/Sources/Database/IDatabaseWrapper.h --- 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& filterType) = 0; }; diff -r e219e272650d -r 25df40a274fd OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp --- 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& changeTypes) + { + std::set changeTypesString; + for (std::set::const_iterator it = changeTypes.begin(); it != changeTypes.end(); ++it) + { + changeTypesString.insert(boost::lexical_cast(static_cast(*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 filter; + GetChangesExtended(target, done, since, -1, limit, filter); } virtual void GetChangesExtended(std::list& target /*out*/, @@ -1256,12 +1271,12 @@ int64_t since, int64_t to, uint32_t limit, - ChangeType filterType) ORTHANC_OVERRIDE + const std::set& filterType) ORTHANC_OVERRIDE { std::vector 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); } diff -r e219e272650d -r 25df40a274fd OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp --- 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) { - class Operations : public ReadOnlyOperationsT5 + class Operations : public ReadOnlyOperationsT5&> { 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(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(); diff -r e219e272650d -r 25df40a274fd OrthancServer/Sources/Database/StatelessDatabaseOperations.h --- 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& 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& filterType); void GetLastChange(Json::Value& target); diff -r e219e272650d -r 25df40a274fd OrthancServer/Sources/OrthancRestApi/OrthancRestChanges.cpp --- 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 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 filterTypeStrings; + Toolbox::SplitString(filterTypeStrings, filterArgument, ';'); + + for (std::set::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)"); } diff -r e219e272650d -r 25df40a274fd OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp --- 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); - } + } }