Search in sources :

Example 1 with StringPaginationToken

use of org.dataportabilityproject.shared.StringPaginationToken in project data-transfer-project by google.

the class GoogleCalendarService method exportCalendars.

private CalendarModelWrapper exportCalendars(Optional<PaginationInformation> pageInfo) throws IOException {
    Calendar.CalendarList.List listRequest = calendarClient.calendarList().list();
    if (pageInfo.isPresent()) {
        listRequest.setPageToken(((StringPaginationToken) pageInfo.get()).getId());
    }
    CalendarList listResult = listRequest.execute();
    List<CalendarModel> calendarModels = new ArrayList<>(listResult.getItems().size());
    List<Resource> resources = new ArrayList<>(listResult.getItems().size());
    for (CalendarListEntry calendarData : listResult.getItems()) {
        CalendarModel model = GoogleCalendarToModelConverter.convertToCalendarModel(calendarData);
        resources.add(new IdOnlyResource(calendarData.getId()));
        calendarModels.add(model);
    }
    PaginationInformation newPageInfo = null;
    if (listResult.getNextPageToken() != null) {
        newPageInfo = new StringPaginationToken(listResult.getNextPageToken());
    }
    return new CalendarModelWrapper(calendarModels, null, new ContinuationInformation(resources, newPageInfo));
}
Also used : ArrayList(java.util.ArrayList) Resource(org.dataportabilityproject.dataModels.Resource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) CalendarModel(org.dataportabilityproject.dataModels.calendar.CalendarModel) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) CalendarModelWrapper(org.dataportabilityproject.dataModels.calendar.CalendarModelWrapper) CalendarListEntry(com.google.api.services.calendar.model.CalendarListEntry) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) CalendarList(com.google.api.services.calendar.model.CalendarList) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken)

Example 2 with StringPaginationToken

use of org.dataportabilityproject.shared.StringPaginationToken in project data-transfer-project by google.

the class GoogleMailService method export.

// This currently exports each message with associated labels
@Override
public MailModelWrapper export(ExportInformation exportInformation) throws IOException {
    Messages.List request = gmail.users().messages().list(USER).setMaxResults(MAX_RESULTS_PER_REQUEST);
    if (exportInformation.getPaginationInformation().isPresent()) {
        request.setPageToken(((StringPaginationToken) exportInformation.getPaginationInformation().get()).getId());
    }
    ListMessagesResponse response = request.execute();
    List<MailMessageModel> results = new ArrayList<>(response.getMessages().size());
    // as we can't store all the mail messagess in memory at once.
    for (Message listMessage : response.getMessages()) {
        Message getResponse = gmail.users().messages().get(USER, listMessage.getId()).setFormat("raw").execute();
        // TODO: note this doesn't transfer things like labels
        results.add(new MailMessageModel(getResponse.getRaw(), getResponse.getLabelIds()));
    }
    PaginationInformation pageInfo = null;
    if (response.getNextPageToken() != null) {
        pageInfo = new StringPaginationToken(response.getNextPageToken());
    }
    // TODO: export by label or by message?
    return new MailModelWrapper(null, results, new ContinuationInformation(null, pageInfo));
}
Also used : ListMessagesResponse(com.google.api.services.gmail.model.ListMessagesResponse) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) Messages(com.google.api.services.gmail.Gmail.Users.Messages) Message(com.google.api.services.gmail.model.Message) ArrayList(java.util.ArrayList) MailModelWrapper(org.dataportabilityproject.dataModels.mail.MailModelWrapper) MailMessageModel(org.dataportabilityproject.dataModels.mail.MailMessageModel) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken)

Example 3 with StringPaginationToken

use of org.dataportabilityproject.shared.StringPaginationToken in project data-transfer-project by google.

the class GoogleTaskService method getTasks.

private TaskModelWrapper getTasks(String taskListId, Optional<PaginationInformation> pageInfo) throws IOException {
    com.google.api.services.tasks.model.Tasks result;
    Tasks.TasksOperations.List query = taskClient.tasks().list(taskListId).setMaxResults(PAGE_SIZE);
    if (pageInfo.isPresent()) {
        query.setPageToken(((StringPaginationToken) pageInfo.get()).getId());
    }
    result = query.execute();
    List<TaskModel> newTasks = result.getItems().stream().map(t -> new TaskModel(taskListId, t.getTitle(), t.getNotes())).collect(Collectors.toList());
    PaginationInformation newPageInfo = null;
    if (result.getNextPageToken() != null) {
        newPageInfo = new StringPaginationToken(result.getNextPageToken());
    }
    return new TaskModelWrapper(null, newTasks, new ContinuationInformation(null, newPageInfo));
}
Also used : Importer(org.dataportabilityproject.dataModels.Importer) Resource(org.dataportabilityproject.dataModels.Resource) ExportInformation(org.dataportabilityproject.dataModels.ExportInformation) IOException(java.io.IOException) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) Tasks(com.google.api.services.tasks.Tasks) TaskModel(org.dataportabilityproject.dataModels.tasks.TaskModel) Collectors(java.util.stream.Collectors) TaskModelWrapper(org.dataportabilityproject.dataModels.tasks.TaskModelWrapper) Task(com.google.api.services.tasks.model.Task) ArrayList(java.util.ArrayList) Exporter(org.dataportabilityproject.dataModels.Exporter) List(java.util.List) TaskList(com.google.api.services.tasks.model.TaskList) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) JobDataCache(org.dataportabilityproject.cloud.interfaces.JobDataCache) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) Optional(java.util.Optional) Credential(com.google.api.client.auth.oauth2.Credential) TaskLists(com.google.api.services.tasks.model.TaskLists) GoogleStaticObjects(org.dataportabilityproject.serviceProviders.google.GoogleStaticObjects) TaskListModel(org.dataportabilityproject.dataModels.tasks.TaskListModel) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken) TaskModelWrapper(org.dataportabilityproject.dataModels.tasks.TaskModelWrapper) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) TaskModel(org.dataportabilityproject.dataModels.tasks.TaskModel) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken)

Example 4 with StringPaginationToken

use of org.dataportabilityproject.shared.StringPaginationToken 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 5 with StringPaginationToken

use of org.dataportabilityproject.shared.StringPaginationToken in project data-transfer-project by google.

the class GoogleContactsServiceTest method exportSubsequentPage.

@Test
public void exportSubsequentPage() throws IOException {
    setUpSinglePersonResponse();
    // Looking at a subsequent page, with no pages after it
    ExportInformation nextPageExportInformation = new ExportInformation(Optional.empty(), Optional.of(new StringPaginationToken(NEXT_PAGE_TOKEN)));
    listConnectionsResponse.setNextPageToken(null);
    when(listConnectionsRequest.setPageToken(NEXT_PAGE_TOKEN)).thenReturn(listConnectionsRequest);
    // Run test
    ContactsModelWrapper wrapper = contactsService.export(nextPageExportInformation);
    // Verify correct calls were made - i.e., token was added before execution
    InOrder inOrder = Mockito.inOrder(listConnectionsRequest);
    inOrder.verify(listConnectionsRequest).setPageToken(NEXT_PAGE_TOKEN);
    inOrder.verify(listConnectionsRequest).execute();
    // Check continuation information
    assertThat(wrapper.getContinuationInformation()).isNull();
}
Also used : ExportInformation(org.dataportabilityproject.dataModels.ExportInformation) InOrder(org.mockito.InOrder) ContactsModelWrapper(org.dataportabilityproject.dataModels.contacts.ContactsModelWrapper) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken) Test(org.junit.Test)

Aggregations

StringPaginationToken (org.dataportabilityproject.shared.StringPaginationToken)14 ContinuationInformation (org.dataportabilityproject.dataModels.ContinuationInformation)8 ExportInformation (org.dataportabilityproject.dataModels.ExportInformation)8 ArrayList (java.util.ArrayList)7 PaginationInformation (org.dataportabilityproject.dataModels.PaginationInformation)7 Resource (org.dataportabilityproject.dataModels.Resource)7 IdOnlyResource (org.dataportabilityproject.shared.IdOnlyResource)7 CalendarModelWrapper (org.dataportabilityproject.dataModels.calendar.CalendarModelWrapper)6 Test (org.junit.Test)6 InOrder (org.mockito.InOrder)5 IOException (java.io.IOException)4 Collectors (java.util.stream.Collectors)3 JobDataCache (org.dataportabilityproject.cloud.interfaces.JobDataCache)3 CalendarEventModel (org.dataportabilityproject.dataModels.calendar.CalendarEventModel)3 ContactsModelWrapper (org.dataportabilityproject.dataModels.contacts.ContactsModelWrapper)3 GoogleStaticObjects (org.dataportabilityproject.serviceProviders.google.GoogleStaticObjects)3 Credential (com.google.api.client.auth.oauth2.Credential)2 CalendarList (com.google.api.services.calendar.model.CalendarList)2 CalendarListEntry (com.google.api.services.calendar.model.CalendarListEntry)2 Event (com.google.api.services.calendar.model.Event)2