You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/06/07 06:39:19 UTC

[camel] branch master updated (a493724 -> 75cb351)

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from a493724  CAMEL-12547 - Fix tests
     new a50f44f  CAMEL-12547 - Manage labels the right way
     new 75cb351  CAMEL-12547 - Fixed CS

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../mail/stream/GoogleMailStreamConfiguration.java |  4 ++--
 .../mail/stream/GoogleMailStreamConsumer.java      | 16 +++++---------
 .../mail/stream/GoogleMailStreamEndpoint.java      | 25 ++++++++++++++++++++--
 .../AbstractGoogleMailStreamTestSupport.java       |  2 --
 4 files changed, 30 insertions(+), 17 deletions(-)

-- 
To stop receiving notification emails like this one, please contact
acosentino@apache.org.

[camel] 01/02: CAMEL-12547 - Manage labels the right way

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit a50f44fc729dccc293ce6ac1aa8f35a783e49b87
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Jun 7 08:36:23 2018 +0200

    CAMEL-12547 - Manage labels the right way
---
 .../mail/stream/GoogleMailStreamConsumer.java      | 16 +++++---------
 .../mail/stream/GoogleMailStreamEndpoint.java      | 25 ++++++++++++++++++++--
 2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/stream/GoogleMailStreamConsumer.java b/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/stream/GoogleMailStreamConsumer.java
index d44f28d..d344193 100644
--- a/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/stream/GoogleMailStreamConsumer.java
+++ b/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/stream/GoogleMailStreamConsumer.java
@@ -23,13 +23,10 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Queue;
 
-import javax.mail.internet.AddressException;
-
 import com.google.api.services.gmail.Gmail;
 import com.google.api.services.gmail.model.ListMessagesResponse;
 import com.google.api.services.gmail.model.Message;
 import com.google.api.services.gmail.model.ModifyMessageRequest;
-import com.google.common.base.Splitter;
 
 import org.apache.camel.AsyncCallback;
 import org.apache.camel.Endpoint;
@@ -49,10 +46,12 @@ public class GoogleMailStreamConsumer extends ScheduledBatchPollingConsumer {
 
     private static final Logger LOG = LoggerFactory.getLogger(GoogleMailStreamConsumer.class);
     private String unreadLabelId;
+    private List labelsIds;
 
-    public GoogleMailStreamConsumer(Endpoint endpoint, Processor processor, String unreadLabelId) {
+    public GoogleMailStreamConsumer(Endpoint endpoint, Processor processor, String unreadLabelId, List labelsIds) {
         super(endpoint, processor);
         this.unreadLabelId = unreadLabelId;
+        this.labelsIds = labelsIds;
     }
 
     protected GoogleMailStreamConfiguration getConfiguration() {
@@ -77,8 +76,8 @@ public class GoogleMailStreamConsumer extends ScheduledBatchPollingConsumer {
         if (ObjectHelper.isNotEmpty(getConfiguration().getMaxResults())) {
             request.setMaxResults(getConfiguration().getMaxResults());
         }
-        if (ObjectHelper.isNotEmpty(getConfiguration().getLabels())) {
-            request.setLabelIds(splitLabels(getConfiguration().getLabels()));
+        if (ObjectHelper.isNotEmpty(labelsIds)) {
+            request.setLabelIds(labelsIds);
         }
 
         Queue<Exchange> answer = new LinkedList<>();
@@ -138,11 +137,6 @@ public class GoogleMailStreamConsumer extends ScheduledBatchPollingConsumer {
         return total;
     }
 
-    private List<String> splitLabels(String labels) throws AddressException {
-        List<String> labelsList = Splitter.on(',').splitToList(getConfiguration().getLabels());
-        return labelsList;
-    }
-
     /**
      * Strategy to delete the message after being processed.
      *
diff --git a/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/stream/GoogleMailStreamEndpoint.java b/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/stream/GoogleMailStreamEndpoint.java
index c2ed119..c695f45 100644
--- a/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/stream/GoogleMailStreamEndpoint.java
+++ b/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/stream/GoogleMailStreamEndpoint.java
@@ -17,13 +17,17 @@
 package org.apache.camel.component.google.mail.stream;
 
 import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
 import java.util.List;
 
+import javax.mail.internet.AddressException;
+
 import com.google.api.client.util.Base64;
 import com.google.api.services.gmail.Gmail;
 import com.google.api.services.gmail.model.Label;
 import com.google.api.services.gmail.model.ListLabelsResponse;
 import com.google.api.services.gmail.model.MessagePartHeader;
+import com.google.common.base.Splitter;
 
 import org.apache.camel.Consumer;
 import org.apache.camel.Exchange;
@@ -35,6 +39,7 @@ import org.apache.camel.component.google.mail.GoogleMailClientFactory;
 import org.apache.camel.impl.ScheduledPollEndpoint;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
+import org.apache.camel.util.ObjectHelper;
 
 /**
  * The google-mail component provides access to Google Mail.
@@ -64,7 +69,7 @@ public class GoogleMailStreamEndpoint extends ScheduledPollEndpoint {
     @Override
     public Consumer createConsumer(Processor processor) throws Exception {
         String unreadLabelId = null;
-        String readLabelId = null;
+        List labelsIds = new ArrayList<>();
         ListLabelsResponse listResponse = getClient().users().labels().list("me").execute();
         for (Label label : listResponse.getLabels()) {
             Label countLabel = getClient().users().labels().get("me", label.getId()).execute();
@@ -72,7 +77,18 @@ public class GoogleMailStreamEndpoint extends ScheduledPollEndpoint {
                 unreadLabelId = countLabel.getId();
             }
         }
-        final GoogleMailStreamConsumer consumer = new GoogleMailStreamConsumer(this, processor, unreadLabelId);
+        if (ObjectHelper.isNotEmpty(getConfiguration().getLabels())) {
+            List<String> plainLabels = splitLabels(getConfiguration().getLabels());
+            for (Label label : listResponse.getLabels()) {
+                Label countLabel = getClient().users().labels().get("me", label.getId()).execute();
+                for (String plainLabel : plainLabels) {
+                    if (countLabel.getName().equalsIgnoreCase(plainLabel)) {
+                        labelsIds.add(countLabel.getId());
+                    }
+                }
+            }
+        }
+        final GoogleMailStreamConsumer consumer = new GoogleMailStreamConsumer(this, processor, unreadLabelId, labelsIds);
         configureConsumer(consumer);
         return consumer;
     }
@@ -134,4 +150,9 @@ public class GoogleMailStreamEndpoint extends ScheduledPollEndpoint {
             }
         }
     }
+    
+    private List<String> splitLabels(String labels) throws AddressException {
+        List<String> labelsList = Splitter.on(',').splitToList(getConfiguration().getLabels());
+        return labelsList;
+    }
 }

-- 
To stop receiving notification emails like this one, please contact
acosentino@apache.org.

[camel] 02/02: CAMEL-12547 - Fixed CS

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 75cb3518a5e03ff7ea5dc7ff92eed8ae59719a70
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Jun 7 08:38:43 2018 +0200

    CAMEL-12547 - Fixed CS
---
 .../component/google/mail/stream/GoogleMailStreamConfiguration.java   | 4 ++--
 .../google/mail/stream/AbstractGoogleMailStreamTestSupport.java       | 2 --
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/stream/GoogleMailStreamConfiguration.java b/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/stream/GoogleMailStreamConfiguration.java
index 1d15831..a69f719 100644
--- a/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/stream/GoogleMailStreamConfiguration.java
+++ b/components/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/stream/GoogleMailStreamConfiguration.java
@@ -54,10 +54,10 @@ public class GoogleMailStreamConfiguration implements Cloneable {
     @UriParam
     private String applicationName;
 
-    @UriParam(defaultValue="is:unread")
+    @UriParam(defaultValue = "is:unread")
     private String query = "is:unread";
 
-    @UriParam(defaultValue="10")
+    @UriParam(defaultValue = "10")
     private long maxResults = 10L;
 
     @UriParam
diff --git a/components/camel-google-mail/src/test/java/org/apache/camel/component/google/mail/stream/AbstractGoogleMailStreamTestSupport.java b/components/camel-google-mail/src/test/java/org/apache/camel/component/google/mail/stream/AbstractGoogleMailStreamTestSupport.java
index 200f95a..0da9cc8 100644
--- a/components/camel-google-mail/src/test/java/org/apache/camel/component/google/mail/stream/AbstractGoogleMailStreamTestSupport.java
+++ b/components/camel-google-mail/src/test/java/org/apache/camel/component/google/mail/stream/AbstractGoogleMailStreamTestSupport.java
@@ -22,8 +22,6 @@ import java.util.Map;
 import java.util.Properties;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.component.google.mail.stream.GoogleMailStreamComponent;
-import org.apache.camel.component.google.mail.stream.GoogleMailStreamConfiguration;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.camel.util.IntrospectionSupport;
 

-- 
To stop receiving notification emails like this one, please contact
acosentino@apache.org.