Search in sources :

Example 1 with BatchGoogleCalendarClientFactory

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();
}
Also used : BatchGoogleCalendarClientFactory(org.apache.camel.component.google.calendar.BatchGoogleCalendarClientFactory) GoogleCalendarClientFactory(org.apache.camel.component.google.calendar.GoogleCalendarClientFactory) ResultBuilder(org.apache.camel.component.extension.verifier.ResultBuilder) BatchGoogleCalendarClientFactory(org.apache.camel.component.google.calendar.BatchGoogleCalendarClientFactory) Calendar(com.google.api.services.calendar.Calendar) ResultErrorBuilder(org.apache.camel.component.extension.verifier.ResultErrorBuilder) GoogleCalendarStreamConfiguration(org.apache.camel.component.google.calendar.stream.GoogleCalendarStreamConfiguration)

Example 2 with BatchGoogleCalendarClientFactory

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());
}
Also used : CalendarListEntry(com.google.api.services.calendar.model.CalendarListEntry) BatchGoogleCalendarClientFactory(org.apache.camel.component.google.calendar.BatchGoogleCalendarClientFactory) Calendar(com.google.api.services.calendar.Calendar) IOException(java.io.IOException) CalendarList(com.google.api.services.calendar.model.CalendarList) HashSet(java.util.HashSet)

Aggregations

Calendar (com.google.api.services.calendar.Calendar)2 BatchGoogleCalendarClientFactory (org.apache.camel.component.google.calendar.BatchGoogleCalendarClientFactory)2 CalendarList (com.google.api.services.calendar.model.CalendarList)1 CalendarListEntry (com.google.api.services.calendar.model.CalendarListEntry)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 ResultBuilder (org.apache.camel.component.extension.verifier.ResultBuilder)1 ResultErrorBuilder (org.apache.camel.component.extension.verifier.ResultErrorBuilder)1 GoogleCalendarClientFactory (org.apache.camel.component.google.calendar.GoogleCalendarClientFactory)1 GoogleCalendarStreamConfiguration (org.apache.camel.component.google.calendar.stream.GoogleCalendarStreamConfiguration)1