Search in sources :

Example 11 with CalendarList

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);
}
Also used : MAX_ATTENDEES(org.datatransferproject.datatransfer.google.common.GoogleStaticObjects.MAX_ATTENDEES) CalendarContainerResource(org.datatransferproject.types.common.models.calendar.CalendarContainerResource) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult) CalendarEventModel(org.datatransferproject.types.common.models.calendar.CalendarEventModel) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) EVENT_TOKEN_PREFIX(org.datatransferproject.datatransfer.google.common.GoogleStaticObjects.EVENT_TOKEN_PREFIX) ExportInformation(org.datatransferproject.types.common.ExportInformation) Events(com.google.api.services.calendar.model.Events) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) Calendar(com.google.api.services.calendar.Calendar) GoogleCredentialFactory(org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory) Before(org.junit.Before) Event(com.google.api.services.calendar.model.Event) InOrder(org.mockito.InOrder) CalendarList(com.google.api.services.calendar.model.CalendarList) Collection(java.util.Collection) IOException(java.io.IOException) ContainerResource(org.datatransferproject.types.common.models.ContainerResource) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) PaginationData(org.datatransferproject.types.common.PaginationData) Truth.assertThat(com.google.common.truth.Truth.assertThat) CALENDAR_TOKEN_PREFIX(org.datatransferproject.datatransfer.google.common.GoogleStaticObjects.CALENDAR_TOKEN_PREFIX) Collectors(java.util.stream.Collectors) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) Mockito.verify(org.mockito.Mockito.verify) CalendarModel(org.datatransferproject.types.common.models.calendar.CalendarModel) Mockito(org.mockito.Mockito) List(java.util.List) CalendarListEntry(com.google.api.services.calendar.model.CalendarListEntry) Optional(java.util.Optional) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) CalendarContainerResource(org.datatransferproject.types.common.models.calendar.CalendarContainerResource) ContainerResource(org.datatransferproject.types.common.models.ContainerResource) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) CalendarModel(org.datatransferproject.types.common.models.calendar.CalendarModel) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) CalendarEventModel(org.datatransferproject.types.common.models.calendar.CalendarEventModel) CalendarContainerResource(org.datatransferproject.types.common.models.calendar.CalendarContainerResource) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) Test(org.junit.Test)

Example 12 with CalendarList

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;
}
Also used : CalendarListEntry(com.google.api.services.calendar.model.CalendarListEntry) CalendarList(com.google.api.services.calendar.model.CalendarList)

Example 13 with CalendarList

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());
    }
}
Also used : CalendarList(com.google.api.services.calendar.model.CalendarList) WorkItemHandlerRuntimeException(org.jbpm.bpmn2.handler.WorkItemHandlerRuntimeException) Before(org.junit.Before)

Example 14 with CalendarList

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());
}
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

CalendarList (com.google.api.services.calendar.model.CalendarList)14 CalendarListEntry (com.google.api.services.calendar.model.CalendarListEntry)13 IOException (java.io.IOException)7 Calendar (com.google.api.services.calendar.Calendar)5 Event (com.google.api.services.calendar.model.Event)4 Events (com.google.api.services.calendar.model.Events)4 ArrayList (java.util.ArrayList)4 Before (org.junit.Before)4 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 Collectors (java.util.stream.Collectors)3 Test (org.junit.Test)3 InOrder (org.mockito.InOrder)3 Mockito (org.mockito.Mockito)3 Mockito.mock (org.mockito.Mockito.mock)3 Mockito.verify (org.mockito.Mockito.verify)3 Mockito.when (org.mockito.Mockito.when)3 List (java.util.List)2 Optional (java.util.Optional)2