james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [06/10] james-project git commit: JAMES-2456 ParsedContent constructor should take an Optional
Date Wed, 11 Jul 2018 03:34:35 GMT
JAMES-2456 ParsedContent constructor should take an Optional


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

Branch: refs/heads/master
Commit: bc9802c80554a55b7bc160273a45a405199e4e1a
Parents: 51a6fa8
Author: Antoine Duprat <aduprat@linagora.com>
Authored: Tue Jul 10 09:25:07 2018 +0200
Committer: benwa <btellier@linagora.com>
Committed: Wed Jul 11 10:29:00 2018 +0700

----------------------------------------------------------------------
 .../org/apache/james/mailbox/extractor/ParsedContent.java   | 4 ++--
 .../apache/james/mailbox/elasticsearch/json/MimePart.java   | 4 ++--
 .../mailbox/elasticsearch/json/IndexableMessageTest.java    | 5 +++--
 .../apache/james/mailbox/inmemory/JsoupTextExtractor.java   | 5 +++--
 .../apache/james/mailbox/store/search/PDFTextExtractor.java | 9 +++++----
 .../james/mailbox/store/extractor/DefaultTextExtractor.java | 5 +++--
 .../org/apache/james/mailbox/tika/TikaTextExtractor.java    | 2 +-
 .../apache/james/mailbox/tika/CachingTextExtractorTest.java | 5 +++--
 8 files changed, 22 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/bc9802c8/mailbox/api/src/main/java/org/apache/james/mailbox/extractor/ParsedContent.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/extractor/ParsedContent.java
b/mailbox/api/src/main/java/org/apache/james/mailbox/extractor/ParsedContent.java
index 6dcdc81..8ba90ab 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/extractor/ParsedContent.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/extractor/ParsedContent.java
@@ -28,8 +28,8 @@ public class ParsedContent {
     private final Optional<String> textualContent;
     private final Map<String, List<String>> metadata;
 
-    public ParsedContent(String textualContent, Map<String, List<String>> metadata)
{
-        this.textualContent = Optional.ofNullable(textualContent);
+    public ParsedContent(Optional<String> textualContent, Map<String, List<String>>
metadata) {
+        this.textualContent = textualContent;
         this.metadata = metadata;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/bc9802c8/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePart.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePart.java
b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePart.java
index bb5c98f..1a2128f 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePart.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePart.java
@@ -154,8 +154,8 @@ public class MimePart {
         private ParsedContent extractText(TextExtractor textExtractor, InputStream bodyContent)
throws Exception {
             if (isTextBody()) {
                 return new ParsedContent(
-                    IOUtils.toString(bodyContent, charset.orElse(StandardCharsets.UTF_8)),
-                    ImmutableMap.of());
+                        Optional.ofNullable(IOUtils.toString(bodyContent, charset.orElse(StandardCharsets.UTF_8))),
+                        ImmutableMap.of());
             }
             return textExtractor.extractContent(
                 bodyContent,

http://git-wip-us.apache.org/repos/asf/james-project/blob/bc9802c8/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageTest.java
b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageTest.java
index 5be57f5..5119130 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageTest.java
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.when;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.time.ZoneId;
+import java.util.Optional;
 
 import javax.mail.Flags;
 
@@ -457,9 +458,9 @@ public class IndexableMessageTest {
 
         TextExtractor textExtractor = mock(TextExtractor.class);
         when(textExtractor.extractContent(any(), any()))
-            .thenReturn(new ParsedContent("first attachment content", ImmutableMap.of()))
+            .thenReturn(new ParsedContent(Optional.of("first attachment content"), ImmutableMap.of()))
             .thenThrow(new RuntimeException("second cannot be parsed"))
-            .thenReturn(new ParsedContent("third attachment content", ImmutableMap.of()));
+            .thenReturn(new ParsedContent(Optional.of("third attachment content"), ImmutableMap.of()));
 
         // When
         IndexableMessage indexableMessage = IndexableMessage.builder()

http://git-wip-us.apache.org/repos/asf/james-project/blob/bc9802c8/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/JsoupTextExtractor.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/JsoupTextExtractor.java
b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/JsoupTextExtractor.java
index 1860cd5..c876f2d 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/JsoupTextExtractor.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/JsoupTextExtractor.java
@@ -23,6 +23,7 @@ import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.james.mailbox.extractor.ParsedContent;
@@ -41,12 +42,12 @@ public class JsoupTextExtractor implements TextExtractor {
         Map<String, List<String>> emptyMetadata = Maps.newHashMap();
         if (contentType != null) {
            if (contentType.equals("text/plain")) {
-            return new ParsedContent(IOUtils.toString(inputStream, StandardCharsets.UTF_8),
emptyMetadata);
+            return new ParsedContent(Optional.ofNullable(IOUtils.toString(inputStream, StandardCharsets.UTF_8)),
emptyMetadata);
            }
            if (contentType.equals("text/html")) {
                Document doc = Jsoup.parse(IOUtils.toString(inputStream, StandardCharsets.UTF_8));
                doc.select(TITLE_HTML_TAG).remove();
-               return new ParsedContent(doc.text(), emptyMetadata);
+               return new ParsedContent(Optional.ofNullable(doc.text()), emptyMetadata);
            }
         }
         return new ParsedContent(null, emptyMetadata);

http://git-wip-us.apache.org/repos/asf/james-project/blob/bc9802c8/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/PDFTextExtractor.java
----------------------------------------------------------------------
diff --git a/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/PDFTextExtractor.java
b/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/PDFTextExtractor.java
index 0e9e6a8..8a6f583 100644
--- a/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/PDFTextExtractor.java
+++ b/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/PDFTextExtractor.java
@@ -21,6 +21,7 @@ package org.apache.james.mailbox.store.search;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
+import java.util.Optional;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.james.mailbox.extractor.ParsedContent;
@@ -43,7 +44,7 @@ public class PDFTextExtractor implements TextExtractor {
         if (isPDF(contentType)) {
             return extractTextFromPDF(inputStream);
         }
-        return new ParsedContent(IOUtils.toString(inputStream, StandardCharsets.UTF_8), ImmutableMap.of());
+        return new ParsedContent(Optional.ofNullable(IOUtils.toString(inputStream, StandardCharsets.UTF_8)),
ImmutableMap.of());
     }
 
     private boolean isPDF(String contentType) {
@@ -52,8 +53,8 @@ public class PDFTextExtractor implements TextExtractor {
 
     private ParsedContent extractTextFromPDF(InputStream inputStream) throws IOException
{
         return new ParsedContent(
-            new PDFTextStripper().getText(
-                PDDocument.load(inputStream)),
-            ImmutableMap.of());
+                Optional.ofNullable(new PDFTextStripper().getText(
+                        PDDocument.load(inputStream))),
+                ImmutableMap.of());
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bc9802c8/mailbox/store/src/main/java/org/apache/james/mailbox/store/extractor/DefaultTextExtractor.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/extractor/DefaultTextExtractor.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/extractor/DefaultTextExtractor.java
index a12a8d4..23e574e 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/extractor/DefaultTextExtractor.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/extractor/DefaultTextExtractor.java
@@ -22,6 +22,7 @@ package org.apache.james.mailbox.store.extractor;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
+import java.util.Optional;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.james.mailbox.extractor.ParsedContent;
@@ -37,9 +38,9 @@ public class DefaultTextExtractor implements TextExtractor {
     @Override
     public ParsedContent extractContent(InputStream inputStream, String contentType) throws
Exception {
         if (contentType != null && contentType.startsWith("text/")) {
-            return new ParsedContent(IOUtils.toString(inputStream, StandardCharsets.UTF_8),
new HashMap<>());
+            return new ParsedContent(Optional.ofNullable(IOUtils.toString(inputStream, StandardCharsets.UTF_8)),
new HashMap<>());
         } else {
-            return new ParsedContent(null, new HashMap<>());
+            return new ParsedContent(Optional.empty(), new HashMap<>());
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bc9802c8/mailbox/tika/src/main/java/org/apache/james/mailbox/tika/TikaTextExtractor.java
----------------------------------------------------------------------
diff --git a/mailbox/tika/src/main/java/org/apache/james/mailbox/tika/TikaTextExtractor.java
b/mailbox/tika/src/main/java/org/apache/james/mailbox/tika/TikaTextExtractor.java
index 305e2a1..c4ff6cf 100644
--- a/mailbox/tika/src/main/java/org/apache/james/mailbox/tika/TikaTextExtractor.java
+++ b/mailbox/tika/src/main/java/org/apache/james/mailbox/tika/TikaTextExtractor.java
@@ -84,7 +84,7 @@ public class TikaTextExtractor implements TextExtractor {
 
     public ParsedContent performContentExtraction(InputStream inputStream, String contentType)
throws IOException {
         ContentAndMetadata contentAndMetadata = convert(tikaHttpClient.recursiveMetaDataAsJson(inputStream,
contentType));
-        return new ParsedContent(contentAndMetadata.getContent().orElse(null), contentAndMetadata.getMetadata());
+        return new ParsedContent(contentAndMetadata.getContent(), contentAndMetadata.getMetadata());
     }
 
     private ContentAndMetadata convert(Optional<InputStream> maybeInputStream) throws
IOException, JsonParseException, JsonMappingException {

http://git-wip-us.apache.org/repos/asf/james-project/blob/bc9802c8/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/CachingTextExtractorTest.java
----------------------------------------------------------------------
diff --git a/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/CachingTextExtractorTest.java
b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/CachingTextExtractorTest.java
index 637bedb..e5b4d02 100644
--- a/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/CachingTextExtractorTest.java
+++ b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/CachingTextExtractorTest.java
@@ -34,6 +34,7 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
+import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 import java.util.function.Supplier;
@@ -54,9 +55,9 @@ import com.google.common.collect.ImmutableMap;
 
 public class CachingTextExtractorTest {
 
-    private static final ParsedContent RESULT = new ParsedContent("content", ImmutableMap.of());
+    private static final ParsedContent RESULT = new ParsedContent(Optional.of("content"),
ImmutableMap.of());
     public static final String BIG_STRING = Strings.repeat("0123456789", 103 * 1024);
-    private static final ParsedContent _2MiB_RESULT = new ParsedContent(BIG_STRING, ImmutableMap.of());
+    private static final ParsedContent _2MiB_RESULT = new ParsedContent(Optional.of(BIG_STRING),
ImmutableMap.of());
     private static final Function<Integer, InputStream> STREAM_GENERATOR =
         i -> new ByteArrayInputStream(String.format("content%d", i).getBytes(StandardCharsets.UTF_8));
     private static final Supplier<InputStream> INPUT_STREAM = () -> STREAM_GENERATOR.apply(1);


---------------------------------------------------------------------
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