use of com.google.api.services.calendar.model.CalendarList in project data-transfer-project by google.
the class GoogleCalendarExporterTest method exportCalendarFirstSet.
@Test
public void exportCalendarFirstSet() throws IOException {
setUpSingleCalendarResponse();
// Looking at first page, with at least one page after it
calendarListResponse.setNextPageToken(NEXT_TOKEN);
// Run test
ExportResult<CalendarContainerResource> result = googleCalendarExporter.export(JOB_ID, null, Optional.empty());
// Check results
// Verify correct methods were called
verify(calendarClient).calendarList();
verify(calendarCalendarList).list();
verify(calendarListRequest).execute();
// Check pagination token
ContinuationData continuationData = (ContinuationData) result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken.getToken()).isEqualTo(CALENDAR_TOKEN_PREFIX + NEXT_TOKEN);
// Check calendars
Collection<CalendarModel> actualCalendars = result.getExportedData().getCalendars();
assertThat(actualCalendars.stream().map(CalendarModel::getId).collect(Collectors.toList())).containsExactly(CALENDAR_ID);
// Check events (should be empty, even though there is an event in the calendar)
Collection<CalendarEventModel> actualEvents = result.getExportedData().getEvents();
assertThat(actualEvents).isEmpty();
// Should be one container in the resource list
List<ContainerResource> actualResources = continuationData.getContainerResources();
assertThat(actualResources.stream().map(a -> ((IdOnlyContainerResource) a).getId()).collect(Collectors.toList())).containsExactly(CALENDAR_ID);
}
use of com.google.api.services.calendar.model.CalendarList in project jbpm-work-items by kiegroup.
the class AddEventWorkitemHandler method getCalendarIdBySummary.
public String getCalendarIdBySummary(com.google.api.services.calendar.Calendar client, String summary) {
String resultId = null;
try {
CalendarList calendarList = getAllCalendars(client);
List<CalendarListEntry> entryList = calendarList.getItems();
for (CalendarListEntry entry : entryList) {
if (entry.getSummary().equalsIgnoreCase(summary)) {
resultId = entry.getId();
}
}
} catch (Exception e) {
logger.error(MessageFormat.format("Error retrieveing calendars: {0}", e.getMessage()));
}
return resultId;
}
use of com.google.api.services.calendar.model.CalendarList in project jbpm-work-items by kiegroup.
the class GoogleCalendarWorkitemHandlerTest method setUp.
@Before
public void setUp() {
try {
CalendarList calendarListModel = new com.google.api.services.calendar.model.CalendarList();
when(client.calendars()).thenReturn(calendars);
when(calendars.insert(anyObject())).thenReturn(calendarsInsert);
when(calendarsInsert.execute()).thenReturn(new com.google.api.services.calendar.model.Calendar());
when(client.calendarList()).thenReturn(calendarsList);
when(calendarsList.list()).thenReturn(calendarsListList);
when(calendarsListList.execute()).thenReturn(calendarListModel);
when(auth.getAuthorizedCalendar(anyString(), anyString())).thenReturn(client);
when(client.events()).thenReturn(clientEvents);
when(clientEvents.insert(any(), any())).thenReturn(calendarEventsInsert);
when(calendarEventsInsert.execute()).thenReturn(new com.google.api.services.calendar.model.Event());
when(clientEvents.list(any())).thenReturn(calendarEventsList);
when(calendarEventsList.execute()).thenReturn(new com.google.api.services.calendar.model.Events());
} catch (Exception e) {
fail(e.getMessage());
}
}
use of com.google.api.services.calendar.model.CalendarList 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