use of org.apache.camel.component.google.calendar.BatchGoogleCalendarClientFactory in project syndesis by syndesisio.
the class GoogleCalendarVerifierExtension method verifyConnectivity.
// *********************************
// Connectivity validation
// *********************************
@Override
protected Result verifyConnectivity(Map<String, Object> parameters) {
ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.CONNECTIVITY);
try {
GoogleCalendarStreamConfiguration configuration = setProperties(new GoogleCalendarStreamConfiguration(), parameters);
GoogleCalendarClientFactory clientFactory = new BatchGoogleCalendarClientFactory();
Calendar client = clientFactory.makeClient(configuration.getClientId(), configuration.getClientSecret(), configuration.getScopes(), configuration.getApplicationName(), configuration.getRefreshToken(), configuration.getAccessToken(), null, null, "me");
client.calendarList().list().execute();
} catch (Exception e) {
ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION, e.getMessage()).detail("google_calendar_exception", e.getMessage()).detail(VerificationError.ExceptionAttribute.EXCEPTION_CLASS, e.getClass().getName()).detail(VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE, e);
builder.error(errorBuilder.build());
}
return builder.build();
}
use of org.apache.camel.component.google.calendar.BatchGoogleCalendarClientFactory in project syndesis by syndesisio.
the class GoogleCalendarMetaDataExtension method meta.
@Override
public Optional<MetaData> meta(Map<String, Object> parameters) {
String clientId = ConnectorOptions.extractOption(parameters, "clientId");
if (clientId == null) {
return Optional.empty();
}
LOG.debug("Retrieving calendars for connection to google calendar");
String clientSecret = ConnectorOptions.extractOption(parameters, "clientSecret");
String googleScopes = "https://www.googleapis.com/auth/calendar";
String applicationName = ConnectorOptions.extractOption(parameters, "applicationName");
String accessToken = ConnectorOptions.extractOption(parameters, "accessToken");
String refreshToken = ConnectorOptions.extractOption(parameters, "refreshToken");
Calendar client = new BatchGoogleCalendarClientFactory().makeClient(clientId, clientSecret, getScopes(googleScopes), applicationName, refreshToken, accessToken, null, null, "me");
final CalendarList calendars;
try {
calendars = client.calendarList().list().execute();
} catch (IOException e) {
throw new IllegalStateException("Unable to fetch the list of calendars", e);
}
Set<CalendarListEntry> setCalendars = new HashSet<CalendarListEntry>();
if (calendars.getItems() != null) {
for (CalendarListEntry entry : calendars.getItems()) {
setCalendars.add(entry);
}
}
return Optional.of(MetaDataBuilder.on(getCamelContext()).withAttribute(MetaData.CONTENT_TYPE, "text/plain").withAttribute(MetaData.JAVA_TYPE, String.class).withPayload(setCalendars).build());
}
Aggregations