camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [camel] 01/02: CAMEL-12784 - Create a Camel-google-calendar-stream component, option to set a Calendar to consume from with its summary name
Date Fri, 07 Sep 2018 11:45:23 GMT
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 1d290bdf3a99acf7b029378e27bd1b54e902111c
Author: Andrea Cosentino <ancosen@gmail.com>
AuthorDate: Fri Sep 7 13:21:29 2018 +0200

    CAMEL-12784 - Create a Camel-google-calendar-stream component, option to set a Calendar
to consume from with its summary name
---
 .../docs/google-calendar-stream-component.adoc     |  3 +-
 .../stream/GoogleCalendarStreamConfiguration.java  | 15 +++++++++-
 .../stream/GoogleCalendarStreamConsumer.java       |  6 ++--
 .../stream/GoogleCalendarStreamEndpoint.java       | 32 +++++++++++++++++++---
 ...GoogleCalendarStreamComponentConfiguration.java | 12 ++++++++
 5 files changed, 60 insertions(+), 8 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 4530424..a6fdec4 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
@@ -78,7 +78,7 @@ with the following path and query parameters:
 |===
 
 
-==== Query Parameters (27 parameters):
+==== Query Parameters (28 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
@@ -87,6 +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
 | *clientId* (consumer) | Client ID of the mail application |  | String
 | *clientSecret* (consumer) | Client secret of the mail application |  | String
 | *maxResults* (consumer) | Max results to be returned | 10 | int
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 a7d654a..da8a307 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
@@ -59,6 +59,9 @@ public class GoogleCalendarStreamConfiguration implements Cloneable {
 
     @UriParam(defaultValue = "10")
     private int maxResults = 10;
+    
+    @UriParam(defaultValue = "primary")
+    private String calendarSummaryName = "primary";
 
     public String getClientId() {
         return clientId;
@@ -164,10 +167,20 @@ public class GoogleCalendarStreamConfiguration implements Cloneable
{
         this.maxResults = maxResults;
     }
 
+    public String getCalendarSummaryName() {
+        return calendarSummaryName;
+    }
+
+    /**
+     * Calendar Summary name to use
+     */
+    public void setCalendarSummaryName(String calendarSummaryName) {
+        this.calendarSummaryName = calendarSummaryName;
+    } 
+
     // *************************************************
     //
     // *************************************************
-
     public GoogleCalendarStreamConfiguration copy() {
         try {
             return (GoogleCalendarStreamConfiguration)super.clone();
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 c177f9f..097c0d7 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,9 +42,11 @@ import org.slf4j.LoggerFactory;
 public class GoogleCalendarStreamConsumer extends ScheduledBatchPollingConsumer {
 
     private static final Logger LOG = LoggerFactory.getLogger(GoogleCalendarStreamConsumer.class);
+    private String calendarId;
 
-    public GoogleCalendarStreamConsumer(Endpoint endpoint, Processor processor) {
+    public GoogleCalendarStreamConsumer(Endpoint endpoint, Processor processor, String calendarId)
{
         super(endpoint, processor);
+        this.calendarId = calendarId;
     }
 
     protected GoogleCalendarStreamConfiguration getConfiguration() {
@@ -63,7 +65,7 @@ public class GoogleCalendarStreamConsumer extends ScheduledBatchPollingConsumer
     @Override
     protected int poll() throws Exception {
         Date date = new Date();
-        com.google.api.services.calendar.Calendar.Events.List request = getClient().events().list("primary").setOrderBy("updated").setTimeMin(new
DateTime(date));
+        com.google.api.services.calendar.Calendar.Events.List request = getClient().events().list(calendarId).setOrderBy("updated").setTimeMin(new
DateTime(date));
         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 5331601..1b60db5 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
@@ -18,9 +18,6 @@ package org.apache.camel.component.google.calendar.stream;
 
 import java.io.UnsupportedEncodingException;
 
-import com.google.api.services.calendar.Calendar;
-import com.google.api.services.calendar.model.Event;
-
 import org.apache.camel.Consumer;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
@@ -31,6 +28,13 @@ import org.apache.camel.component.google.calendar.GoogleCalendarClientFactory;
 import org.apache.camel.impl.ScheduledPollEndpoint;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.api.services.calendar.Calendar;
+import com.google.api.services.calendar.model.CalendarListEntry;
+import com.google.api.services.calendar.model.Event;
 
 /**
  * The google-calendar component provides access to Google Calendar in a streaming mod.
@@ -43,6 +47,8 @@ import org.apache.camel.spi.UriParam;
              consumerOnly = true,
              label = "api,cloud")
 public class GoogleCalendarStreamEndpoint extends ScheduledPollEndpoint {
+    
+    private static final Logger LOG = LoggerFactory.getLogger(GoogleCalendarStreamEndpoint.class);
 
     @UriParam
     private GoogleCalendarStreamConfiguration configuration;
@@ -59,7 +65,25 @@ public class GoogleCalendarStreamEndpoint extends ScheduledPollEndpoint
{
 
     @Override
     public Consumer createConsumer(Processor processor) throws Exception {
-        final GoogleCalendarStreamConsumer consumer = new GoogleCalendarStreamConsumer(this,
processor);
+        String calendarId = null;
+        if (getConfiguration().getCalendarSummaryName() != "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);
         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 598fc40..91b7429 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
@@ -125,6 +125,10 @@ public class GoogleCalendarStreamComponentConfiguration
          * Max results to be returned
          */
         private Integer maxResults = 10;
+        /**
+         * Calendar Summary name to use
+         */
+        private String calendarSummaryName = "primary";
 
         public String getClientId() {
             return clientId;
@@ -197,5 +201,13 @@ public class GoogleCalendarStreamComponentConfiguration
         public void setMaxResults(Integer maxResults) {
             this.maxResults = maxResults;
         }
+
+        public String getCalendarSummaryName() {
+            return calendarSummaryName;
+        }
+
+        public void setCalendarSummaryName(String calendarSummaryName) {
+            this.calendarSummaryName = calendarSummaryName;
+        }
     }
 }
\ No newline at end of file


Mime
View raw message