You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2023/04/21 04:19:40 UTC

[james-project] 03/06: JAMES-3777 Filtering aggregate should rely on increments

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 893a98d23f75f631c2397c407601c0fbba4b9061
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Apr 19 10:09:15 2023 +0700

    JAMES-3777 Filtering aggregate should rely on increments
---
 .../apache/james/jmap/api/filtering/impl/FilteringAggregate.java | 9 +++++++--
 .../james/jmap/api/filtering/impl/IncrementalRuleChange.java     | 4 ++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/impl/FilteringAggregate.java b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/impl/FilteringAggregate.java
index 6e3baf1878..51648f2e2b 100644
--- a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/impl/FilteringAggregate.java
+++ b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/impl/FilteringAggregate.java
@@ -70,8 +70,10 @@ public class FilteringAggregate {
     public List<? extends Event> defineRules(DefineRulesCommand storeCommand) {
         Preconditions.checkArgument(shouldNotContainDuplicates(storeCommand.getRules()));
         StateMismatchException.checkState(expectedState(storeCommand.getIfInState()), "Provided state must be as same as the current state");
-        ImmutableList<RuleSetDefined> events = ImmutableList.of(
-            new RuleSetDefined(aggregateId, history.getNextEventId(), ImmutableList.copyOf(storeCommand.getRules())));
+
+        ImmutableList<Event> events = IncrementalRuleChange.ofDiff(aggregateId, history.getNextEventId(), state.rules, storeCommand.getRules())
+            .map(ImmutableList::<Event>of)
+            .orElseGet(() -> ImmutableList.of(new RuleSetDefined(aggregateId, history.getNextEventId(), ImmutableList.copyOf(storeCommand.getRules()))));
         events.forEach(this::apply);
         return events;
     }
@@ -101,5 +103,8 @@ public class FilteringAggregate {
         if (event instanceof RuleSetDefined) {
             state = state.set(((RuleSetDefined)event).getRules());
         }
+        if (event instanceof IncrementalRuleChange) {
+            state = state.set(((IncrementalRuleChange)event).apply(state.rules));
+        }
     }
 }
diff --git a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/impl/IncrementalRuleChange.java b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/impl/IncrementalRuleChange.java
index 9207663b35..8d3c7d26e8 100644
--- a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/impl/IncrementalRuleChange.java
+++ b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/impl/IncrementalRuleChange.java
@@ -162,6 +162,10 @@ public class IncrementalRuleChange implements Event {
         return rulesDeleted;
     }
 
+    public ImmutableList<Rule> getRulesUpdated() {
+        return rulesUpdated;
+    }
+
     public ImmutableList<Rule> apply(ImmutableList<Rule> rules) {
         ImmutableMap<Rule.Id, Rule> indexedUpdates = rulesUpdated.stream()
             .collect(ImmutableMap.toImmutableMap(


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org