JAMES-2186 Remove WrappedException from StoreMessageIdManager
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/39661533 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/39661533 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/39661533 Branch: refs/heads/master Commit: 3966153324a665616d30a10058a58a1b79e40537 Parents: b3d89ac Author: benwa <btell...@linagora.com> Authored: Thu Oct 19 16:37:54 2017 +0700 Committer: Matthieu Baechler <matth...@apache.org> Committed: Fri Oct 20 12:34:52 2017 +0200 ---------------------------------------------------------------------- .../mailbox/store/StoreMessageIdManager.java | 54 ++++++-------------- 1 file changed, 16 insertions(+), 38 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/39661533/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java index 09f0e29..4ae53af 100644 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java @@ -26,7 +26,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.function.Function; import java.util.function.Predicate; import javax.inject.Inject; @@ -63,6 +62,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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; import com.google.common.collect.ImmutableSet; @@ -102,18 +102,6 @@ public class StoreMessageIdManager implements MessageIdManager { } } - private static class WrappedException extends RuntimeException { - private final MailboxException cause; - - public WrappedException(MailboxException cause) { - this.cause = cause; - } - - public MailboxException unwrap() throws MailboxException { - throw cause; - } - } - private static MetadataWithMailboxId toMetadataWithMailboxId(MailboxMessage message) { return new MetadataWithMailboxId(new SimpleMessageMetaData(message), message.getMailboxId()); } @@ -163,23 +151,19 @@ public class StoreMessageIdManager implements MessageIdManager { @Override public List<MessageResult> getMessages(List<MessageId> messageIds, MessageResult.FetchGroup fetchGroup, MailboxSession mailboxSession) throws MailboxException { - try { - MessageIdMapper messageIdMapper = mailboxSessionMapperFactory.getMessageIdMapper(mailboxSession); - List<MailboxMessage> messageList = messageIdMapper.find(messageIds, MessageMapper.FetchType.Full); - - ImmutableSet<MailboxId> allowedMailboxIds = messageList.stream() - .map(MailboxMessage::getMailboxId) - .distinct() - .filter(hasRightsOnMailbox(mailboxSession, Right.Read)) - .collect(Guavate.toImmutableSet()); - - return messageList.stream() - .filter(inMailboxes(allowedMailboxIds)) - .map(messageResultConverter(fetchGroup)) - .collect(Guavate.toImmutableList()); - } catch (WrappedException wrappedException) { - throw wrappedException.unwrap(); - } + MessageIdMapper messageIdMapper = mailboxSessionMapperFactory.getMessageIdMapper(mailboxSession); + List<MailboxMessage> messageList = messageIdMapper.find(messageIds, MessageMapper.FetchType.Full); + + ImmutableSet<MailboxId> allowedMailboxIds = messageList.stream() + .map(MailboxMessage::getMailboxId) + .distinct() + .filter(hasRightsOnMailbox(mailboxSession, Right.Read)) + .collect(Guavate.toImmutableSet()); + + return messageList.stream() + .filter(inMailboxes(allowedMailboxIds)) + .map(Throwing.function(messageResultConverter(fetchGroup)).sneakyThrow()) + .collect(Guavate.toImmutableList()); } @Override @@ -325,14 +309,8 @@ public class StoreMessageIdManager implements MessageIdManager { messageIdMapper.copyInMailbox(mailboxMessage); } - private Function<MailboxMessage, MessageResult> messageResultConverter(MessageResult.FetchGroup fetchGroup) { - return input -> { - try { - return ResultUtils.loadMessageResult(input, fetchGroup); - } catch (MailboxException e) { - throw new WrappedException(e); - } - }; + private ThrowingFunction<MailboxMessage, MessageResult> messageResultConverter(MessageResult.FetchGroup fetchGroup) { + return input -> ResultUtils.loadMessageResult(input, fetchGroup); } private Predicate<MailboxMessage> inMailboxes(Collection<MailboxId> mailboxIds) { --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org