james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [09/14] james-project git commit: JAMES-2556 Fix limit and offset behaviour in multi-repository context
Date Wed, 10 Oct 2018 08:48:22 GMT
JAMES-2556 Fix limit and offset behaviour in multi-repository context


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/d68a63ef
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/d68a63ef
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/d68a63ef

Branch: refs/heads/master
Commit: d68a63efda3734eb0b34bc2c7abde327762a02c5
Parents: ea70abc
Author: Benoit Tellier <btellier@linagora.com>
Authored: Wed Oct 10 10:22:00 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Wed Oct 10 15:46:19 2018 +0700

----------------------------------------------------------------------
 .../service/MailRepositoryStoreService.java       | 18 +++++++-----------
 .../routes/MailRepositoriesRoutesTest.java        |  2 --
 2 files changed, 7 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d68a63ef/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/MailRepositoryStoreService.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/MailRepositoryStoreService.java
b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/MailRepositoryStoreService.java
index ff4ee76..a626655 100644
--- a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/MailRepositoryStoreService.java
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/MailRepositoryStoreService.java
@@ -48,8 +48,8 @@ import org.apache.mailet.Mail;
 import org.eclipse.jetty.http.HttpStatus;
 
 import com.github.fge.lambdas.Throwing;
-import com.github.fge.lambdas.functions.ThrowingFunction;
 import com.github.steveash.guavate.Guavate;
+import com.google.common.collect.ImmutableList;
 
 public class MailRepositoryStoreService {
     private final MailRepositoryStore mailRepositoryStore;
@@ -70,17 +70,13 @@ public class MailRepositoryStoreService {
     }
 
     public Optional<List<MailKeyDTO>> listMails(MailRepositoryPath path, Offset
offset, Limit limit) throws MailRepositoryStore.MailRepositoryStoreException, MessagingException
{
-        ThrowingFunction<MailRepository, Stream<MailKeyDTO>> list = repository
-> list(repository, offset, limit);
-        return Optional.of(getRepositories(path)
-                .flatMap(Throwing.function(list).sneakyThrow())
-                .collect(Guavate.toImmutableList()));
-    }
+        Optional<Stream<MailKeyDTO>> maybeMails = Optional.of(getRepositories(path)
+            .flatMap(Throwing.function((MailRepository repository) -> Iterators.toStream(repository.list())).sneakyThrow())
+            .map(MailKeyDTO::new)
+            .skip(offset.getOffset()));
 
-    private Stream<MailKeyDTO> list(MailRepository mailRepository, Offset offset, Limit
limit) throws MessagingException {
-        return limit.applyOnStream(
-                Iterators.toStream(mailRepository.list())
-                    .skip(offset.getOffset()))
-                .map(MailKeyDTO::new);
+        return maybeMails.map(limit::applyOnStream)
+            .map(stream -> stream.collect(ImmutableList.toImmutableList()));
     }
 
     public Optional<Long> size(MailRepositoryPath path) throws MailRepositoryStore.MailRepositoryStoreException
{

http://git-wip-us.apache.org/repos/asf/james-project/blob/d68a63ef/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
index f17b20c..ea78e4c 100644
--- a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
@@ -329,7 +329,6 @@ public class MailRepositoriesRoutesTest {
             .body("", contains("name2"));
     }
 
-    @Ignore("Limit and offset are applied on a per repository bases")
     @Test
     public void listingKeysShouldApplyLimitWhenSeveralRepositories() throws Exception {
         MailRepository mailRepository1 = mailRepositoryStore.create(URL_MY_REPO);
@@ -403,7 +402,6 @@ public class MailRepositoriesRoutesTest {
             .body("", hasSize(0));
     }
 
-    @Ignore("Offset is applied on a per mail repository basis")
     @Test
     public void offsetShouldBeAplliedOnTheMergedViewOfMailRepositories() throws Exception
{
         MailRepository mailRepository1 = mailRepositoryStore.create(URL_MY_REPO);


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


Mime
View raw message