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
The following commit(s) were added to refs/heads/master by this push: new d32da42 CAMEL-12784 - Create a Camel-google-calendar-stream component, option to consume from now or to start from the beginning d32da42 is described below commit d32da425d3acecfd24ef58a08dfed8020be20faf Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Mon Sep 10 12:00:49 2018 +0200 CAMEL-12784 - Create a Camel-google-calendar-stream component, option to consume from now or to start from the beginning --- .../src/main/docs/google-calendar-stream-component.adoc | 5 +++-- .../stream/GoogleCalendarStreamConfiguration.java | 16 +++++++++++++++- .../calendar/stream/GoogleCalendarStreamConsumer.java | 7 +++++-- .../GoogleCalendarStreamComponentConfiguration.java | 14 +++++++++++++- 4 files changed, 36 insertions(+), 6 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 8cc4f5a..fdf04a8 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 (28 parameters): +==== Query Parameters (29 parameters): [width="100%",cols="2,5,^1,2",options="header"] @@ -87,9 +87,10 @@ 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 +| *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 +| *consumeFromNow* (consumer) | Consume events in the selected calendar from now on | true | boolean | *maxResults* (consumer) | Max results to be returned | 10 | int | *query* (consumer) | The query to execute on calendar | | String | *refreshToken* (consumer) | OAuth 2 refresh token. Using this, the Google Calendar component can obtain a new accessToken whenever the current one expires - a necessity if the application is long-lived. | | String 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 da8a307..bdb3b26 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 @@ -62,6 +62,9 @@ public class GoogleCalendarStreamConfiguration implements Cloneable { @UriParam(defaultValue = "primary") private String calendarSummaryName = "primary"; + + @UriParam(defaultValue = "true") + private boolean consumeFromNow = true; public String getClientId() { return clientId; @@ -172,11 +175,22 @@ public class GoogleCalendarStreamConfiguration implements Cloneable { } /** - * Calendar Summary name to use + * Calendar Summary Name to use */ public void setCalendarSummaryName(String calendarSummaryName) { this.calendarSummaryName = calendarSummaryName; } + + public boolean isConsumeFromNow() { + return consumeFromNow; + } + + /** + * Consume events in the selected calendar from now on + */ + public void setConsumeFromNow(boolean consumeFromNow) { + this.consumeFromNow = 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 097c0d7..4a74b77 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 @@ -64,14 +64,17 @@ 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(calendarId).setOrderBy("updated").setTimeMin(new DateTime(date)); + com.google.api.services.calendar.Calendar.Events.List request = getClient().events().list(calendarId).setOrderBy("updated"); if (ObjectHelper.isNotEmpty(getConfiguration().getQuery())) { request.setQ(getConfiguration().getQuery()); } if (ObjectHelper.isNotEmpty(getConfiguration().getMaxResults())) { request.setMaxResults(getConfiguration().getMaxResults()); } + if (getConfiguration().isConsumeFromNow()) { + Date date = new Date(); + request.setTimeMin(new DateTime(date)); + } Queue<Exchange> answer = new LinkedList<>(); 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 91b7429..39cafad 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,13 @@ public class GoogleCalendarStreamComponentConfiguration */ private Integer maxResults = 10; /** - * Calendar Summary name to use + * Calendar Summary Name to use */ private String calendarSummaryName = "primary"; + /** + * Consume events in the selected calendar from now on + */ + private Boolean consumeFromNow = true; public String getClientId() { return clientId; @@ -209,5 +213,13 @@ public class GoogleCalendarStreamComponentConfiguration public void setCalendarSummaryName(String calendarSummaryName) { this.calendarSummaryName = calendarSummaryName; } + + public Boolean getConsumeFromNow() { + return consumeFromNow; + } + + public void setConsumeFromNow(Boolean consumeFromNow) { + this.consumeFromNow = consumeFromNow; + } } } \ No newline at end of file