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 2016/07/26 07:46:43 UTC
[04/17] james-project git commit: JAMES-1804 Introduce type for
Set (Subjects)
JAMES-1804 Introduce type for Set<String> (Subjects)
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/62f6ad9d
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/62f6ad9d
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/62f6ad9d
Branch: refs/heads/master
Commit: 62f6ad9dd91cfe8c788b972c7e34f475d411a639
Parents: 4295a7f
Author: Antoine Duprat <ad...@linagora.com>
Authored: Tue Jul 19 16:48:13 2016 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Tue Jul 26 08:57:04 2016 +0200
----------------------------------------------------------------------
.../elasticsearch/json/IndexableMessage.java | 7 +--
.../mailbox/elasticsearch/json/Subjects.java | 50 +++++++++++++++
.../elasticsearch/json/SubjectsTest.java | 66 ++++++++++++++++++++
3 files changed, 119 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/62f6ad9d/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java
index d36b1ec..ec58c3c 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java
@@ -25,7 +25,6 @@ import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Optional;
-import java.util.Set;
import java.util.stream.Collectors;
import org.apache.james.mailbox.MailboxSession.User;
@@ -67,7 +66,7 @@ public class IndexableMessage {
private void copyHeaderFields(HeaderCollection headerCollection, ZonedDateTime internalDate) {
this.headers = headerCollection.getHeaders();
- this.subjects = headerCollection.getSubjectSet();
+ this.subjects = Subjects.from(headerCollection.getSubjectSet());
this.from = EMailers.from(headerCollection.getFromAddressSet());
this.to = EMailers.from(headerCollection.getToAddressSet());
this.replyTo = EMailers.from(headerCollection.getReplyToAddressSet());
@@ -124,7 +123,7 @@ public class IndexableMessage {
private EMailers cc;
private EMailers bcc;
private EMailers replyTo;
- private Set<String> subjects;
+ private Subjects subjects;
private String sentDate;
private List<Property> properties;
private List<MimePart> attachments;
@@ -211,7 +210,7 @@ public class IndexableMessage {
}
@JsonProperty(JsonMessageConstants.SUBJECT)
- public Set<String> getSubjects() {
+ public Subjects getSubjects() {
return subjects;
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/62f6ad9d/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/Subjects.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/Subjects.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/Subjects.java
new file mode 100644
index 0000000..214d312
--- /dev/null
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/Subjects.java
@@ -0,0 +1,50 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.mailbox.elasticsearch.json;
+
+import java.util.Set;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
+
+public class Subjects implements Serializable {
+
+ public static Subjects from(Set<String> subjects) {
+ Preconditions.checkNotNull(subjects, "'subjects' is mandatory");
+ return new Subjects(subjects);
+ }
+
+ private final Set<String> subjects;
+
+ private Subjects(Set<String> subjects) {
+ this.subjects = subjects;
+ }
+
+ @JsonValue
+ public Set<String> getSubjects() {
+ return subjects;
+ }
+
+ @Override
+ public String serialize() {
+ return Joiner.on(" ").join(subjects);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/62f6ad9d/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/SubjectsTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/SubjectsTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/SubjectsTest.java
new file mode 100644
index 0000000..a4398d1
--- /dev/null
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/SubjectsTest.java
@@ -0,0 +1,66 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.mailbox.elasticsearch.json;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.Test;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableSet;
+
+public class SubjectsTest {
+
+ @Test
+ public void fromShouldThrowWhenSetIsNull() {
+ assertThatThrownBy(() -> Subjects.from(null))
+ .isInstanceOf(NullPointerException.class)
+ .hasMessage("'subjects' is mandatory");
+ }
+
+ @Test
+ public void serializeShouldReturnEmptyWhenEmptySet() {
+ Subjects subjects = Subjects.from(ImmutableSet.of());
+
+ assertThat(subjects.serialize()).isEmpty();
+ }
+
+ @Test
+ public void serializeShouldNotJoinWhenOneElement() {
+ String expected = "subject";
+ Subjects subjects = Subjects.from(ImmutableSet.of(expected));
+
+ assertThat(subjects.serialize()).isEqualTo(expected);
+ }
+
+ @Test
+ public void serializeShouldJoinWhenMultipleElements() {
+ String subject = "subject";
+ String subject2 = "subject2";
+ String subject3 = "subject3";
+
+ String expected = Joiner.on(" ").join(subject, subject2, subject3);
+
+ Subjects subjects = Subjects.from(ImmutableSet.of(subject, subject2, subject3));
+
+ assertThat(subjects.serialize()).isEqualTo(expected);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org