Search in sources :

Example 1 with CalendarEventModel

use of org.dataportabilityproject.dataModels.calendar.CalendarEventModel in project data-transfer-project by google.

the class GoogleCalendarServiceTest method testExportCalendarFirstSet.

@Test
public void testExportCalendarFirstSet() throws IOException {
    setUpSingleCalendarResponse();
    // Looking at first page, with at least one page after it
    ExportInformation emptyExportInformation = new ExportInformation(Optional.empty(), Optional.empty());
    calendarListResponse.setNextPageToken(NEXT_TOKEN);
    // Run test
    CalendarModelWrapper wrapper = calendarService.export(emptyExportInformation);
    // Check results
    // Verify correct methods were called
    verify(calendarClient).calendarList();
    verify(calendarCalendarList).list();
    verify(calendarListRequest).execute();
    // Check pagination token
    StringPaginationToken paginationToken = (StringPaginationToken) wrapper.getContinuationInformation().getPaginationInformation();
    assertThat(paginationToken.getId()).isEqualTo(NEXT_TOKEN);
    // Check calendars
    Collection<CalendarModel> calendars = wrapper.getCalendars();
    assertThat(calendars.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> events = wrapper.getEvents();
    assertThat(events).isEmpty();
    // Should be one event in the resource list
    Collection<? extends Resource> subResources = wrapper.getContinuationInformation().getSubResources();
    assertThat(subResources.stream().map(a -> ((IdOnlyResource) a).getId()).collect(Collectors.toList())).containsExactly(CALENDAR_ID);
}
Also used : CalendarModelWrapper(org.dataportabilityproject.dataModels.calendar.CalendarModelWrapper) Events(com.google.api.services.calendar.model.Events) InMemoryJobDataCache(org.dataportabilityproject.cloud.local.InMemoryJobDataCache) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) JobDataCache(org.dataportabilityproject.cloud.interfaces.JobDataCache) Calendar(com.google.api.services.calendar.Calendar) GoogleStaticObjects(org.dataportabilityproject.serviceProviders.google.GoogleStaticObjects) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken) Before(org.junit.Before) Event(com.google.api.services.calendar.model.Event) InOrder(org.mockito.InOrder) Resource(org.dataportabilityproject.dataModels.Resource) ExportInformation(org.dataportabilityproject.dataModels.ExportInformation) CalendarList(com.google.api.services.calendar.model.CalendarList) Collection(java.util.Collection) CalendarModelWrapper(org.dataportabilityproject.dataModels.calendar.CalendarModelWrapper) IOException(java.io.IOException) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) CalendarEventModel(org.dataportabilityproject.dataModels.calendar.CalendarEventModel) CalendarModel(org.dataportabilityproject.dataModels.calendar.CalendarModel) Mockito(org.mockito.Mockito) CalendarListEntry(com.google.api.services.calendar.model.CalendarListEntry) Optional(java.util.Optional) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) ExportInformation(org.dataportabilityproject.dataModels.ExportInformation) CalendarModel(org.dataportabilityproject.dataModels.calendar.CalendarModel) CalendarEventModel(org.dataportabilityproject.dataModels.calendar.CalendarEventModel) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken) Test(org.junit.Test)

Example 2 with CalendarEventModel

use of org.dataportabilityproject.dataModels.calendar.CalendarEventModel in project data-transfer-project by google.

the class GoogleCalendarServiceTest method importCalendarAndEvent.

@Test
public void importCalendarAndEvent() throws IOException {
    String modelCalendarId = "modelCalendarId";
    String googleCalendarId = "googleCalendarId";
    // Set up calendar, events, and mocks
    CalendarModel calendarModel = new CalendarModel(modelCalendarId, null, null);
    com.google.api.services.calendar.model.Calendar calendarToInsert = ModelToGoogleCalendarConverter.convertToGoogleCalendar(calendarModel);
    com.google.api.services.calendar.model.Calendar responseCalendar = new com.google.api.services.calendar.model.Calendar().setId(googleCalendarId);
    CalendarEventModel eventModel = new CalendarEventModel(modelCalendarId, null, null, null, null, null, null);
    Event eventToInsert = ModelToGoogleCalendarConverter.convertToGoogleCalendarEvent(eventModel);
    Event responseEvent = new Event();
    when(calendarInsertRequest.execute()).thenReturn(responseCalendar);
    when(calendarCalendars.insert(calendarToInsert)).thenReturn(calendarInsertRequest);
    when(eventInsertRequest.execute()).thenReturn(responseEvent);
    when(calendarEvents.insert(googleCalendarId, eventToInsert)).thenReturn(eventInsertRequest);
    CalendarModelWrapper wrapper = new CalendarModelWrapper(Collections.singleton(calendarModel), Collections.singleton(eventModel), null);
    // Run test
    calendarService.importItem(wrapper);
    // Check the right methods were called
    verify(calendarCalendars).insert(calendarToInsert);
    verify(calendarInsertRequest).execute();
    verify(calendarEvents).insert(googleCalendarId, eventToInsert);
    verify(eventInsertRequest).execute();
    // Check jobDataCache contents
    assertThat(jobDataCache.getData(modelCalendarId, String.class)).isEqualTo(googleCalendarId);
}
Also used : CalendarModelWrapper(org.dataportabilityproject.dataModels.calendar.CalendarModelWrapper) CalendarModel(org.dataportabilityproject.dataModels.calendar.CalendarModel) Event(com.google.api.services.calendar.model.Event) CalendarEventModel(org.dataportabilityproject.dataModels.calendar.CalendarEventModel) Test(org.junit.Test)

Example 3 with CalendarEventModel

use of org.dataportabilityproject.dataModels.calendar.CalendarEventModel in project data-transfer-project by google.

the class GoogleCalendarService method importItem.

@Override
public void importItem(CalendarModelWrapper wrapper) throws IOException {
    for (CalendarModel calendar : wrapper.getCalendars()) {
        com.google.api.services.calendar.model.Calendar toInsert = ModelToGoogleCalendarConverter.convertToGoogleCalendar(calendar);
        com.google.api.services.calendar.model.Calendar calendarResult = calendarClient.calendars().insert(toInsert).execute();
        jobDataCache.store(calendar.getId(), calendarResult.getId());
    }
    for (CalendarEventModel eventModel : wrapper.getEvents()) {
        Event event = ModelToGoogleCalendarConverter.convertToGoogleCalendarEvent(eventModel);
        String newCalendarId = jobDataCache.getData(eventModel.getCalendarId(), String.class);
        calendarClient.events().insert(newCalendarId, event).execute();
    }
}
Also used : CalendarModel(org.dataportabilityproject.dataModels.calendar.CalendarModel) Event(com.google.api.services.calendar.model.Event) CalendarEventModel(org.dataportabilityproject.dataModels.calendar.CalendarEventModel)

Example 4 with CalendarEventModel

use of org.dataportabilityproject.dataModels.calendar.CalendarEventModel in project data-transfer-project by google.

the class GoogleCalendarService method getCalendarEvents.

private CalendarModelWrapper getCalendarEvents(String id, Optional<PaginationInformation> pageInfo) throws IOException {
    Calendar.Events.List listRequest = calendarClient.events().list(id).setMaxAttendees(100);
    if (pageInfo.isPresent()) {
        listRequest.setPageToken(((StringPaginationToken) pageInfo.get()).getId());
    }
    Events listResult = listRequest.execute();
    List<CalendarEventModel> results = new ArrayList<>(listResult.getItems().size());
    for (Event eventData : listResult.getItems()) {
        CalendarEventModel model = GoogleCalendarToModelConverter.convertToCalendarEventModel(id, eventData);
        results.add(model);
    }
    PaginationInformation newPageInfo = null;
    if (listResult.getNextPageToken() != null) {
        newPageInfo = new StringPaginationToken(listResult.getNextPageToken());
    }
    return new CalendarModelWrapper(null, results, new ContinuationInformation(null, newPageInfo));
}
Also used : CalendarModelWrapper(org.dataportabilityproject.dataModels.calendar.CalendarModelWrapper) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) Events(com.google.api.services.calendar.model.Events) ArrayList(java.util.ArrayList) Event(com.google.api.services.calendar.model.Event) CalendarEventModel(org.dataportabilityproject.dataModels.calendar.CalendarEventModel) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken)

Example 5 with CalendarEventModel

use of org.dataportabilityproject.dataModels.calendar.CalendarEventModel in project data-transfer-project by google.

the class GoogleCalendarToModelConverter method convertToCalendarEventModel.

static CalendarEventModel convertToCalendarEventModel(String id, Event eventData) {
    List<EventAttendee> attendees = eventData.getAttendees();
    CalendarEventModel model = new CalendarEventModel(id, eventData.getDescription(), eventData.getSummary(), attendees == null ? null : attendees.stream().map(GoogleCalendarToModelConverter::transformToModelAttendee).collect(Collectors.toList()), eventData.getLocation(), getEventTime(eventData.getStart()), getEventTime(eventData.getEnd()));
    return model;
}
Also used : EventAttendee(com.google.api.services.calendar.model.EventAttendee) CalendarEventModel(org.dataportabilityproject.dataModels.calendar.CalendarEventModel)

Aggregations

CalendarEventModel (org.dataportabilityproject.dataModels.calendar.CalendarEventModel)6 Event (com.google.api.services.calendar.model.Event)4 CalendarModelWrapper (org.dataportabilityproject.dataModels.calendar.CalendarModelWrapper)4 CalendarModel (org.dataportabilityproject.dataModels.calendar.CalendarModel)3 StringPaginationToken (org.dataportabilityproject.shared.StringPaginationToken)3 Test (org.junit.Test)3 Events (com.google.api.services.calendar.model.Events)2 ExportInformation (org.dataportabilityproject.dataModels.ExportInformation)2 PaginationInformation (org.dataportabilityproject.dataModels.PaginationInformation)2 Resource (org.dataportabilityproject.dataModels.Resource)2 IdOnlyResource (org.dataportabilityproject.shared.IdOnlyResource)2 Calendar (com.google.api.services.calendar.Calendar)1 CalendarList (com.google.api.services.calendar.model.CalendarList)1 CalendarListEntry (com.google.api.services.calendar.model.CalendarListEntry)1 EventAttendee (com.google.api.services.calendar.model.EventAttendee)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1