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 2020/12/18 07:27:30 UTC
[james-project] 02/13: JAMES-3463 MemoryMailboxChangeRepository
State.INITIAL handling
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 8420b5b8a879bab189db8bb4f0b8fc3d70558e94
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Dec 15 10:26:34 2020 +0700
JAMES-3463 MemoryMailboxChangeRepository State.INITIAL handling
When used we should return all changes from the start
---
.../james/jmap/api/change/MailboxChange.java | 1 +
.../change/MemoryMailboxChangeRepository.java | 7 ++++-
.../change/MailboxChangeRepositoryContract.java | 36 ++++++++++++++++++++++
.../scala/org/apache/james/jmap/core/Session.scala | 7 +++--
4 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/change/MailboxChange.java b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/change/MailboxChange.java
index 2ed3c64..52461e6 100644
--- a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/change/MailboxChange.java
+++ b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/change/MailboxChange.java
@@ -44,6 +44,7 @@ import com.google.common.collect.ImmutableList;
public class MailboxChange {
public static class State {
+ public static State INITIAL = of(UUID.fromString("2c9f1b12-b35a-43e6-9af2-0106fb53a943"));
public static State of(UUID value) {
return new State(value);
diff --git a/server/data/data-jmap/src/main/java/org/apache/james/jmap/memory/change/MemoryMailboxChangeRepository.java b/server/data/data-jmap/src/main/java/org/apache/james/jmap/memory/change/MemoryMailboxChangeRepository.java
index e9a2a79..0ff0fa5 100644
--- a/server/data/data-jmap/src/main/java/org/apache/james/jmap/memory/change/MemoryMailboxChangeRepository.java
+++ b/server/data/data-jmap/src/main/java/org/apache/james/jmap/memory/change/MemoryMailboxChangeRepository.java
@@ -39,8 +39,8 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
public class MemoryMailboxChangeRepository implements MailboxChangeRepository {
-
public static final Limit DEFAULT_NUMBER_OF_CHANGES = Limit.of(5);
+
private final Multimap<AccountId, MailboxChange> mailboxChangeMap;
public MemoryMailboxChangeRepository() {
@@ -60,6 +60,11 @@ public class MemoryMailboxChangeRepository implements MailboxChangeRepository {
Preconditions.checkNotNull(accountId);
Preconditions.checkNotNull(state);
maxChanges.ifPresent(limit -> Preconditions.checkArgument(limit.getValue() > 0, "maxChanges must be a positive integer"));
+ if (state.equals(State.INITIAL)) {
+ return Flux.fromIterable(mailboxChangeMap.get(accountId))
+ .sort(Comparator.comparing(MailboxChange::getDate))
+ .collect(new MailboxChangeCollector(state, maxChanges.orElse(DEFAULT_NUMBER_OF_CHANGES)));
+ }
return findByState(accountId, state)
.flatMapMany(currentState -> Flux.fromIterable(mailboxChangeMap.get(accountId))
diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/change/MailboxChangeRepositoryContract.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/change/MailboxChangeRepositoryContract.java
index 2f3209b..75f10af 100644
--- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/change/MailboxChangeRepositoryContract.java
+++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/change/MailboxChangeRepositoryContract.java
@@ -128,6 +128,42 @@ public interface MailboxChangeRepositoryContract {
}
@Test
+ default void getChangesShouldReturnAllFromInitial() {
+ MailboxChangeRepository repository = mailboxChangeRepository();
+
+ MailboxChange oldState = MailboxChange.of(ACCOUNT_ID, STATE_0, DATE.minusHours(3), ImmutableList.of(TestId.of(1)), ImmutableList.of(), ImmutableList.of());
+ MailboxChange change1 = MailboxChange.of(ACCOUNT_ID, State.of(UUID.randomUUID()), DATE.minusHours(2), ImmutableList.of(TestId.of(2)), ImmutableList.of(), ImmutableList.of());
+ MailboxChange change2 = MailboxChange.of(ACCOUNT_ID, State.of(UUID.randomUUID()), DATE.minusHours(1), ImmutableList.of(TestId.of(3)), ImmutableList.of(), ImmutableList.of());
+ MailboxChange change3 = MailboxChange.of(ACCOUNT_ID, State.of(UUID.randomUUID()), DATE, ImmutableList.of(TestId.of(4)), ImmutableList.of(), ImmutableList.of());
+ repository.save(oldState);
+ repository.save(change1);
+ repository.save(change2);
+ repository.save(change3);
+
+ assertThat(repository.getSinceState(ACCOUNT_ID, State.INITIAL, Optional.of(Limit.of(3))).block().getCreated())
+ .containsExactlyInAnyOrder(TestId.of(1), TestId.of(2), TestId.of(3));
+ }
+
+ @Test
+ default void getChangesFromInitialShouldReturnNewState() {
+ MailboxChangeRepository repository = mailboxChangeRepository();
+
+ MailboxChange oldState = MailboxChange.of(ACCOUNT_ID, STATE_0, DATE.minusHours(3), ImmutableList.of(TestId.of(1)), ImmutableList.of(), ImmutableList.of());
+ MailboxChange change1 = MailboxChange.of(ACCOUNT_ID, State.of(UUID.randomUUID()), DATE.minusHours(2), ImmutableList.of(TestId.of(2)), ImmutableList.of(), ImmutableList.of());
+ State state2 = State.of(UUID.randomUUID());
+ MailboxChange change2 = MailboxChange.of(ACCOUNT_ID, state2, DATE.minusHours(1), ImmutableList.of(TestId.of(3)), ImmutableList.of(), ImmutableList.of());
+ MailboxChange change3 = MailboxChange.of(ACCOUNT_ID, State.of(UUID.randomUUID()), DATE, ImmutableList.of(TestId.of(4)), ImmutableList.of(), ImmutableList.of());
+ repository.save(oldState);
+ repository.save(change1);
+ repository.save(change2);
+ repository.save(change3);
+
+
+ assertThat(repository.getSinceState(ACCOUNT_ID, State.INITIAL, Optional.of(Limit.of(3))).block().getNewState())
+ .isEqualTo(state2);
+ }
+
+ @Test
default void getChangesShouldLimitChangesWhenMaxChangesOmitted() {
MailboxChangeRepository repository = mailboxChangeRepository();
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/Session.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/Session.scala
index 123aa3d..6949488 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/Session.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/Session.scala
@@ -30,6 +30,7 @@ import eu.timepit.refined.refineV
import eu.timepit.refined.string.Uuid
import org.apache.james.core.Username
import org.apache.james.jmap.api.change.MailboxChanges
+import org.apache.james.jmap.api.change.MailboxChange.{State => JavaState}
import org.apache.james.jmap.core.CapabilityIdentifier.CapabilityIdentifier
import org.apache.james.jmap.core.Id.Id
import org.apache.james.jmap.core.State.INSTANCE
@@ -79,11 +80,13 @@ final case class Account private(accountId: AccountId,
object State {
type UUIDString = String Refined Uuid
- val INSTANCE: State = fromString("2c9f1b12-b35a-43e6-9af2-0106fb53a943")
+ val INSTANCE: State = fromJava(JavaState.INITIAL)
def fromString(value: UUIDString): State = State(UUID.fromString(value.value))
- def fromMailboxChanges(mailboxChanges: MailboxChanges): State = State(mailboxChanges.getNewState.getValue)
+ def fromMailboxChanges(mailboxChanges: MailboxChanges): State = fromJava(mailboxChanges.getNewState)
+
+ def fromJava(javaState: JavaState): State = State(javaState.getValue)
}
case class State(value: UUID)
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org