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/09/14 08:30:54 UTC

[camel] 01/02: CAMEL-12784 - Create a Camel-google-calendar-stream component, use calendarId instead of CalendarSummary

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 0b70f646ed4506a31b10fd72f9a84314bf02a0dc
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Sep 14 10:23:40 2018 +0200

    CAMEL-12784 - Create a Camel-google-calendar-stream component, use calendarId instead of CalendarSummary
---
 .../docs/google-calendar-stream-component.adoc     |  2 +-
 .../stream/GoogleCalendarStreamConfiguration.java  | 22 +++++++++++-----------
 .../stream/GoogleCalendarStreamConsumer.java       |  6 ++----
 .../stream/GoogleCalendarStreamEndpoint.java       | 20 +-------------------
 ...GoogleCalendarStreamComponentConfiguration.java | 12 ++++++------
 5 files changed, 21 insertions(+), 41 deletions(-)

diff --git a/components/camel-google-calendar/src/main/docs/google-calendar-stream-component.adoc b/components/camel-google-calendar/src/main/docs/google-calendar-stream-component.adoc
index 84ecdb4..e74f4f5 100644
--- a/components/camel-google-calendar/src/main/docs/google-calendar-stream-component.adoc
+++ b/components/camel-google-calendar/src/main/docs/google-calendar-stream-component.adoc
@@ -87,7 +87,7 @@ with the following path and query parameters:
 | *accessToken* (consumer) | OAuth 2 access token. This typically expires after an hour so refreshToken is recommended for long term usage. |  | String
 | *applicationName* (consumer) | Google Calendar application name. Example would be camel-google-calendar/1.0 |  | String
 | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean
-| *calendarSummaryName* (consumer) | Calendar Summary Name to use | primary | String
+| *calendarId* (consumer) | The calendarId to be used | primary | String
 | *clientId* (consumer) | Client ID of the mail application |  | String
 | *clientSecret* (consumer) | Client secret of the mail application |  | String
 | *considerLastUpdate* (consumer) | Take into account the lastUpdate of the last event polled as start date for the next poll | false | boolean
diff --git a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamConfiguration.java b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamConfiguration.java
index 3f5110e..6e95908 100644
--- a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamConfiguration.java
+++ b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamConfiguration.java
@@ -61,7 +61,7 @@ public class GoogleCalendarStreamConfiguration implements Cloneable {
     private int maxResults = 10;
     
     @UriParam(defaultValue = "primary")
-    private String calendarSummaryName = "primary";
+    private String calendarId = "primary";
     
     @UriParam(defaultValue = "true")
     private boolean consumeFromNow = true;
@@ -172,19 +172,19 @@ public class GoogleCalendarStreamConfiguration implements Cloneable {
     public void setMaxResults(int maxResults) {
         this.maxResults = maxResults;
     }
-
-    public String getCalendarSummaryName() {
-        return calendarSummaryName;
-    }
+    
+    public String getCalendarId() {
+		return calendarId;
+	}
 
     /**
-     * Calendar Summary Name to use
+     * The calendarId to be used
      */
-    public void setCalendarSummaryName(String calendarSummaryName) {
-        this.calendarSummaryName = calendarSummaryName;
-    } 
-    
-    public boolean isConsumeFromNow() {
+	public void setCalendarId(String calendarId) {
+		this.calendarId = calendarId;
+	}
+
+	public boolean isConsumeFromNow() {
         return consumeFromNow;
     }
     
diff --git a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamConsumer.java b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamConsumer.java
index b2f976e..460de6b 100644
--- a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamConsumer.java
+++ b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamConsumer.java
@@ -42,12 +42,10 @@ import org.slf4j.LoggerFactory;
 public class GoogleCalendarStreamConsumer extends ScheduledBatchPollingConsumer {
 
     private static final Logger LOG = LoggerFactory.getLogger(GoogleCalendarStreamConsumer.class);
-    private String calendarId;
     private DateTime lastUpdate;
 
-    public GoogleCalendarStreamConsumer(Endpoint endpoint, Processor processor, String calendarId) {
+    public GoogleCalendarStreamConsumer(Endpoint endpoint, Processor processor) {
         super(endpoint, processor);
-        this.calendarId = calendarId;
     }
 
     protected GoogleCalendarStreamConfiguration getConfiguration() {
@@ -65,7 +63,7 @@ public class GoogleCalendarStreamConsumer extends ScheduledBatchPollingConsumer
 
     @Override
     protected int poll() throws Exception {
-        com.google.api.services.calendar.Calendar.Events.List request = getClient().events().list(calendarId).setOrderBy("updated");
+        com.google.api.services.calendar.Calendar.Events.List request = getClient().events().list(getConfiguration().getCalendarId()).setOrderBy("updated");
         if (ObjectHelper.isNotEmpty(getConfiguration().getQuery())) {
             request.setQ(getConfiguration().getQuery());
         }
diff --git a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamEndpoint.java b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamEndpoint.java
index 85033fa..eab297b 100644
--- a/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamEndpoint.java
+++ b/components/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamEndpoint.java
@@ -65,25 +65,7 @@ public class GoogleCalendarStreamEndpoint extends ScheduledPollEndpoint {
 
     @Override
     public Consumer createConsumer(Processor processor) throws Exception {
-        String calendarId = null;
-        if (getConfiguration().getCalendarSummaryName().equals("primary")) {
-            com.google.api.services.calendar.model.CalendarList calendars = getClient().calendarList().list().execute();
-            if (calendars.getItems() != null) {
-                for (CalendarListEntry entry : calendars.getItems()) {
-                    if (getConfiguration().getCalendarSummaryName().equals(entry.getSummary())) {
-                        calendarId = entry.getId();
-                    }
-                }
-            }
-            if (ObjectHelper.isEmpty(calendarId)) {
-                LOG.warn("The calendar {} doesn't exists fallback to primary calendar", getConfiguration().getCalendarSummaryName());
-                calendarId = "primary";
-            }
-        } else {
-            LOG.debug("Setting calendarId as primary", getConfiguration().getCalendarSummaryName());
-            calendarId = "primary";
-        }
-        final GoogleCalendarStreamConsumer consumer = new GoogleCalendarStreamConsumer(this, processor, calendarId);
+        final GoogleCalendarStreamConsumer consumer = new GoogleCalendarStreamConsumer(this, processor);
         configureConsumer(consumer);
         return consumer;
     }
diff --git a/platforms/spring-boot/components-starter/camel-google-calendar-starter/src/main/java/org/apache/camel/component/google/calendar/stream/springboot/GoogleCalendarStreamComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-google-calendar-starter/src/main/java/org/apache/camel/component/google/calendar/stream/springboot/GoogleCalendarStreamComponentConfiguration.java
index 36b10e7..5acded1 100644
--- a/platforms/spring-boot/components-starter/camel-google-calendar-starter/src/main/java/org/apache/camel/component/google/calendar/stream/springboot/GoogleCalendarStreamComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-google-calendar-starter/src/main/java/org/apache/camel/component/google/calendar/stream/springboot/GoogleCalendarStreamComponentConfiguration.java
@@ -126,9 +126,9 @@ public class GoogleCalendarStreamComponentConfiguration
          */
         private Integer maxResults = 10;
         /**
-         * Calendar Summary Name to use
+         * The calendarId to be used
          */
-        private String calendarSummaryName = "primary";
+        private String calendarId = "primary";
         /**
          * Consume events in the selected calendar from now on
          */
@@ -211,12 +211,12 @@ public class GoogleCalendarStreamComponentConfiguration
             this.maxResults = maxResults;
         }
 
-        public String getCalendarSummaryName() {
-            return calendarSummaryName;
+        public String getCalendarId() {
+            return calendarId;
         }
 
-        public void setCalendarSummaryName(String calendarSummaryName) {
-            this.calendarSummaryName = calendarSummaryName;
+        public void setCalendarId(String calendarId) {
+            this.calendarId = calendarId;
         }
 
         public Boolean getConsumeFromNow() {