You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2022/09/20 02:20:22 UTC
[james-project] branch master updated: [Clean code] CassandraMessageDAO - check null & remove un-used parameter
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
The following commit(s) were added to refs/heads/master by this push:
new ae5e162484 [Clean code] CassandraMessageDAO - check null & remove un-used parameter
ae5e162484 is described below
commit ae5e162484454b00db3045b43b4960cbf333f723
Author: Tung Van TRAN <vt...@linagora.com>
AuthorDate: Fri Sep 16 08:05:18 2022 +0700
[Clean code] CassandraMessageDAO - check null & remove un-used parameter
---
.../mailbox/cassandra/mail/CassandraMessageDAO.java | 19 +++++++++----------
.../mailbox/cassandra/mail/CassandraMessageDAOV3.java | 9 ++++-----
2 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java
index f4c26fcc1f..a852986ec8 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java
@@ -256,12 +256,11 @@ public class CassandraMessageDAO {
private Mono<MessageRepresentation> message(Row row, CassandraMessageId cassandraMessageId, FetchType fetchType) {
BlobId headerId = retrieveBlobId(HEADER_CONTENT, row);
BlobId bodyId = retrieveBlobId(BODY_CONTENT, row);
- int bodyStartOctet = row.getInt(BODY_START_OCTET);
- return buildContentRetriever(fetchType, headerId, bodyId, bodyStartOctet).map(content ->
+ return buildContentRetriever(fetchType, headerId, bodyId).map(content ->
new MessageRepresentation(
cassandraMessageId,
- Date.from(row.getInstant(INTERNAL_DATE)),
+ Optional.ofNullable(row.getInstant(INTERNAL_DATE)).map(Date::from).orElse(null),
row.getLong(FULL_CONTENT_OCTETS),
row.getInt(BODY_START_OCTET),
new ByteContent(content),
@@ -278,7 +277,7 @@ public class CassandraMessageDAO {
return new MessageRepresentation(
messageId,
- Date.from(row.getInstant(INTERNAL_DATE)),
+ Optional.ofNullable(row.getInstant(INTERNAL_DATE)).map(Date::from).orElse(null),
row.getLong(FULL_CONTENT_OCTETS),
row.getInt(BODY_START_OCTET),
new ByteContent(EMPTY_BYTE_ARRAY),
@@ -289,10 +288,10 @@ public class CassandraMessageDAO {
}
private org.apache.james.mailbox.store.mail.model.impl.Properties getProperties(Row row) {
- PropertyBuilder property = new PropertyBuilder(
- row.getList(PROPERTIES, UdtValue.class).stream()
- .map(this::toProperty)
- .collect(Collectors.toList()));
+ PropertyBuilder property = new PropertyBuilder(Optional.ofNullable(row.getList(PROPERTIES, UdtValue.class))
+ .map(list -> list.stream().map(this::toProperty)
+ .collect(Collectors.toList()))
+ .orElse(List.of()));
property.setTextualLineCount(row.getLong(TEXTUAL_LINE_COUNT));
return property.build();
}
@@ -302,7 +301,7 @@ public class CassandraMessageDAO {
}
private Stream<MessageAttachmentRepresentation> getAttachments(Row row) {
- List<UdtValue> udtValues = row.getList(ATTACHMENTS, UdtValue.class);
+ List<UdtValue> udtValues = Optional.ofNullable(row.getList(ATTACHMENTS, UdtValue.class)).orElse(List.of());
return attachmentByIds(udtValues);
}
@@ -325,7 +324,7 @@ public class CassandraMessageDAO {
.setUuid(MESSAGE_ID, messageId.get()));
}
- private Mono<byte[]> buildContentRetriever(FetchType fetchType, BlobId headerId, BlobId bodyId, int bodyStartOctet) {
+ private Mono<byte[]> buildContentRetriever(FetchType fetchType, BlobId headerId, BlobId bodyId) {
switch (fetchType) {
case FULL:
return getFullContent(headerId, bodyId);
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOV3.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOV3.java
index 05d9cccedc..5e6240279c 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOV3.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOV3.java
@@ -343,13 +343,12 @@ public class CassandraMessageDAOV3 {
private Mono<MessageRepresentation> message(Row row, CassandraMessageId cassandraMessageId, FetchType fetchType) {
BlobId headerId = retrieveBlobId(HEADER_CONTENT, row);
BlobId bodyId = retrieveBlobId(BODY_CONTENT, row);
- int bodyStartOctet = row.getInt(BODY_START_OCTET);
- return buildContentRetriever(fetchType, headerId, bodyId, bodyStartOctet)
+ return buildContentRetriever(fetchType, headerId, bodyId)
.map(content ->
new MessageRepresentation(
cassandraMessageId,
- Date.from(row.getInstant(INTERNAL_DATE_LOWERCASE)),
+ Optional.ofNullable(row.getInstant(INTERNAL_DATE_LOWERCASE)).map(Date::from).orElse(null),
row.getLong(FULL_CONTENT_OCTETS_LOWERCASE),
row.getInt(BODY_START_OCTET_LOWERCASE),
content,
@@ -377,7 +376,7 @@ public class CassandraMessageDAOV3 {
}
private Stream<MessageAttachmentRepresentation> getAttachments(Row row) {
- List<UdtValue> udtValues = row.get(ATTACHMENTS, CodecRegistry.DEFAULT.codecFor(listOf(attachmentsType)));
+ List<UdtValue> udtValues = Optional.<List<UdtValue>>ofNullable(row.get(ATTACHMENTS, CodecRegistry.DEFAULT.codecFor(listOf(attachmentsType)))).orElse(List.of());
return attachmentByIds(udtValues);
}
@@ -400,7 +399,7 @@ public class CassandraMessageDAOV3 {
.setUuid(MESSAGE_ID, messageId.get()));
}
- private Mono<Content> buildContentRetriever(FetchType fetchType, BlobId headerId, BlobId bodyId, int bodyStartOctet) {
+ private Mono<Content> buildContentRetriever(FetchType fetchType, BlobId headerId, BlobId bodyId) {
switch (fetchType) {
case FULL:
return getFullContent(headerId, bodyId);
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org