You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ma...@apache.org on 2017/09/11 08:56:29 UTC
[06/18] james-project git commit: MAILBOX-304 Logging empty should be
a responsibility from AttachmentMapper
MAILBOX-304 Logging empty should be a responsibility from AttachmentMapper
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/683e2fa8
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/683e2fa8
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/683e2fa8
Branch: refs/heads/master
Commit: 683e2fa8d7ec358864cb1e0d3de93cee26bb05ad
Parents: c0ca66f
Author: benwa <bt...@linagora.com>
Authored: Thu Sep 7 10:22:18 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Thu Sep 7 10:22:18 2017 +0700
----------------------------------------------------------------------
.../cassandra/mail/CassandraAttachmentDAO.java | 13 +--------
.../mail/CassandraAttachmentDAOV2.java | 19 +------------
.../mail/CassandraAttachmentMapper.java | 28 +++++++++++---------
3 files changed, 17 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/683e2fa8/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentDAO.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentDAO.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentDAO.java
index 386d8df..b0b3ca4 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentDAO.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentDAO.java
@@ -81,24 +81,13 @@ public class CassandraAttachmentDAO {
}
public CompletableFuture<Optional<Attachment>> getAttachment(AttachmentId attachmentId) {
- return getAttachment(attachmentId, NO_LOG_IF_EMPTY);
- }
-
- public CompletableFuture<Optional<Attachment>> getAttachment(AttachmentId attachmentId, boolean logIfEmpty) {
Preconditions.checkArgument(attachmentId != null);
return cassandraAsyncExecutor.executeSingleRow(
selectStatement.bind()
.setString(ID, attachmentId.getId()))
- .thenApply(optional -> optional.map(this::attachment))
- .thenApply(optional -> logNotFound(attachmentId, logIfEmpty, optional));
+ .thenApply(optional -> optional.map(this::attachment));
}
- private Optional<Attachment> logNotFound(AttachmentId attachmentId, boolean logIfEmpty, Optional<Attachment> optional) {
- if (!optional.isPresent() && logIfEmpty) {
- LOGGER.warn("Failed retrieving attachment {}", attachmentId);
- }
- return optional;
- }
public CompletableFuture<Void> storeAttachment(Attachment attachment) throws IOException {
return cassandraAsyncExecutor.executeVoid(
http://git-wip-us.apache.org/repos/asf/james-project/blob/683e2fa8/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentDAOV2.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentDAOV2.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentDAOV2.java
index 3cc9ee5..4a6037e 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentDAOV2.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentDAOV2.java
@@ -40,8 +40,6 @@ import org.apache.james.backends.cassandra.utils.CassandraAsyncExecutor;
import org.apache.james.mailbox.cassandra.ids.BlobId;
import org.apache.james.mailbox.model.Attachment;
import org.apache.james.mailbox.model.AttachmentId;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.datastax.driver.core.PreparedStatement;
import com.datastax.driver.core.Row;
@@ -49,9 +47,6 @@ import com.datastax.driver.core.Session;
import com.google.common.base.Preconditions;
public class CassandraAttachmentDAOV2 {
- private static final Logger LOGGER = LoggerFactory.getLogger(CassandraAttachmentMapper.class);
- private static final boolean NO_LOG_IF_EMPTY = false;
-
private final CassandraAsyncExecutor cassandraAsyncExecutor;
private final PreparedStatement insertStatement;
private final CassandraBlobsDAO blobsDAO;
@@ -83,23 +78,11 @@ public class CassandraAttachmentDAOV2 {
}
public CompletableFuture<Optional<Attachment>> getAttachment(AttachmentId attachmentId) {
- return getAttachment(attachmentId, NO_LOG_IF_EMPTY);
- }
-
- public CompletableFuture<Optional<Attachment>> getAttachment(AttachmentId attachmentId, boolean logIfEmpty) {
Preconditions.checkArgument(attachmentId != null);
return cassandraAsyncExecutor.executeSingleRow(
selectStatement.bind()
.setUUID(ID_AS_UUID, attachmentId.asUUID()))
- .thenCompose(this::attachment)
- .thenApply(optional -> logNotFound(attachmentId, logIfEmpty, optional));
- }
-
- private Optional<Attachment> logNotFound(AttachmentId attachmentId, boolean logIfEmpty, Optional<Attachment> optional) {
- if (!optional.isPresent() && logIfEmpty) {
- LOGGER.warn("Failed retrieving attachment {}", attachmentId);
- }
- return optional;
+ .thenCompose(this::attachment);
}
public CompletableFuture<Void> storeAttachment(Attachment attachment) {
http://git-wip-us.apache.org/repos/asf/james-project/blob/683e2fa8/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
index a0cdc71..8c2b970 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
@@ -34,16 +34,15 @@ import org.apache.james.mailbox.model.Attachment;
import org.apache.james.mailbox.model.AttachmentId;
import org.apache.james.mailbox.store.mail.AttachmentMapper;
import org.apache.james.util.FluentFutureStream;
-import org.apache.james.util.OptionalUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.github.steveash.guavate.Guavate;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
public class CassandraAttachmentMapper implements AttachmentMapper {
-
- private static final boolean LOG_IF_EMPTY = true;
- private static final boolean NO_LOG_IF_EMPTY = !LOG_IF_EMPTY;
+ private static final Logger LOGGER = LoggerFactory.getLogger(CassandraAttachmentMapper.class);
private final CassandraAttachmentDAO attachmentDAO;
private final CassandraAttachmentDAOV2 attachmentDAOV2;
@@ -83,24 +82,20 @@ public class CassandraAttachmentMapper implements AttachmentMapper {
Stream<CompletableFuture<Optional<Attachment>>> attachments = attachmentIds
.stream()
.distinct()
- .map(id -> attachmentDAOV2.getAttachment(id, LOG_IF_EMPTY)
- .thenCompose(v2Value -> fallbackToV1(id, v2Value, LOG_IF_EMPTY)));
+ .map(id -> attachmentDAOV2.getAttachment(id)
+ .thenCompose(v2Value -> fallbackToV1(id, v2Value))
+ .thenApply(finalValue -> logNotFound(id, finalValue)));
return FluentFutureStream
- .of(attachments)
- .flatMap(OptionalUtils::toStream)
+ .ofOptionals(attachments)
.collect(Guavate.toImmutableList());
}
private CompletionStage<Optional<Attachment>> fallbackToV1(AttachmentId attachmentId, Optional<Attachment> v2Value) {
- return fallbackToV1(attachmentId, v2Value, NO_LOG_IF_EMPTY);
- }
-
- private CompletionStage<Optional<Attachment>> fallbackToV1(AttachmentId attachmentId, Optional<Attachment> v2Value, boolean logIfEmpty) {
if (v2Value.isPresent()) {
return CompletableFuture.completedFuture(v2Value);
}
- return attachmentDAO.getAttachment(attachmentId, logIfEmpty);
+ return attachmentDAO.getAttachment(attachmentId);
}
@Override
@@ -115,4 +110,11 @@ public class CassandraAttachmentMapper implements AttachmentMapper {
.map(attachmentDAOV2::storeAttachment))
.join();
}
+
+ private Optional<Attachment> logNotFound(AttachmentId attachmentId, Optional<Attachment> optional) {
+ if (!optional.isPresent()) {
+ LOGGER.warn("Failed retrieving attachment {}", attachmentId);
+ }
+ return optional;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org