Search in sources :

Example 1 with ExportInformation

use of org.dataportabilityproject.spi.transfer.types.ExportInformation in project data-transfer-project by google.

the class GoogleCalendarExporterTest method exportEventFirstSet.

@Test
public void exportEventFirstSet() throws IOException {
    setUpSingleEventResponse();
    // Looking at first page, with at least one page after it
    ContainerResource containerResource = new IdOnlyContainerResource(CALENDAR_ID);
    ExportInformation exportInformation = new ExportInformation(null, containerResource);
    eventListResponse.setNextPageToken(NEXT_TOKEN);
    // Run test
    ExportResult<CalendarContainerResource> result = googleCalendarExporter.export(UUID.randomUUID(), null, exportInformation);
    // Check results
    // Verify correct methods were called
    verify(calendarEvents).list(CALENDAR_ID);
    verify(eventListRequest).setMaxAttendees(MAX_ATTENDEES);
    verify(eventListRequest).execute();
    // Check events
    Collection<CalendarEventModel> actualEvents = result.getExportedData().getEvents();
    assertThat(actualEvents.stream().map(CalendarEventModel::getCalendarId).collect(Collectors.toList())).containsExactly(CALENDAR_ID);
    assertThat(actualEvents.stream().map(CalendarEventModel::getTitle).collect(Collectors.toList())).containsExactly(EVENT_DESCRIPTION);
    // Check pagination token
    ContinuationData continuationData = (ContinuationData) result.getContinuationData();
    StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
    assertThat(paginationToken.getToken()).isEqualTo(EVENT_TOKEN_PREFIX + NEXT_TOKEN);
}
Also used : ExportInformation(org.dataportabilityproject.spi.transfer.types.ExportInformation) IdOnlyContainerResource(org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource) CalendarContainerResource(org.dataportabilityproject.types.transfer.models.calendar.CalendarContainerResource) ContainerResource(org.dataportabilityproject.types.transfer.models.ContainerResource) IdOnlyContainerResource(org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource) ContinuationData(org.dataportabilityproject.spi.transfer.types.ContinuationData) CalendarEventModel(org.dataportabilityproject.types.transfer.models.calendar.CalendarEventModel) CalendarContainerResource(org.dataportabilityproject.types.transfer.models.calendar.CalendarContainerResource) StringPaginationToken(org.dataportabilityproject.spi.transfer.types.StringPaginationToken) Test(org.junit.Test)

Example 2 with ExportInformation

use of org.dataportabilityproject.spi.transfer.types.ExportInformation in project data-transfer-project by google.

the class PortabilityInMemoryDataCopier method copyHelper.

/**
 * Transfers data from the given {@code exporter} optionally starting at the point specified in
 * the provided {@code exportInformation}. Imports the data using the provided {@code importer}.
 * If there is more data to required to be exported, recursively copies using the specific {@link
 * ExportInformation} to continue the process.
 *
 * @param exportAuthData The auth data for the export
 * @param importAuthData The auth data for the import
 * @param exportInformation Any pagination or resource information to use for subsequent calls.
 */
private void copyHelper(UUID jobId, AuthData exportAuthData, AuthData importAuthData, ExportInformation exportInformation) {
    logger.debug("copy iteration: {}", COPY_ITERATION_COUNTER.incrementAndGet());
    // NOTE: order is important below, do the import of all the items, then do continuation
    // then do sub resources, this ensures all parents are populated before children get
    // processed.
    logger.debug("Starting export, ExportInformation: {}", exportInformation);
    ExportResult<?> exportResult = exporter.get().export(jobId, exportAuthData, exportInformation);
    logger.debug("Finished export, results: {}", exportResult);
    logger.debug("Starting import");
    importer.get().importItem(jobId, importAuthData, exportResult.getExportedData());
    logger.debug("Finished import");
    ContinuationData continuationData = (ContinuationData) exportResult.getContinuationData();
    if (null != continuationData) {
        // Process the next page of items for the resource
        if (null != continuationData.getPaginationData()) {
            logger.debug("start off a new copy iteration with pagination info");
            copyHelper(jobId, exportAuthData, importAuthData, new ExportInformation(continuationData.getPaginationData(), exportInformation.getContainerResource()));
        }
        // Start processing sub-resources
        if (continuationData.getContainerResources() != null && !continuationData.getContainerResources().isEmpty()) {
            for (ContainerResource resource : continuationData.getContainerResources()) {
                copyHelper(jobId, exportAuthData, importAuthData, new ExportInformation(null, resource));
            }
        }
    }
}
Also used : ExportInformation(org.dataportabilityproject.spi.transfer.types.ExportInformation) ContainerResource(org.dataportabilityproject.types.transfer.models.ContainerResource) ContinuationData(org.dataportabilityproject.spi.transfer.types.ContinuationData)

Example 3 with ExportInformation

use of org.dataportabilityproject.spi.transfer.types.ExportInformation in project data-transfer-project by google.

the class GoogleCalendarExporterTest method exportCalendarSubsequentSet.

@Test
public void exportCalendarSubsequentSet() throws IOException {
    setUpSingleCalendarResponse();
    // Looking at subsequent page, with no page after it
    PaginationData paginationData = new StringPaginationToken(CALENDAR_TOKEN_PREFIX + NEXT_TOKEN);
    ExportInformation exportInformation = new ExportInformation(paginationData, null);
    calendarListResponse.setNextPageToken(null);
    // Run test
    ExportResult<CalendarContainerResource> result = googleCalendarExporter.export(UUID.randomUUID(), null, exportInformation);
    // Check results
    // Verify correct calls were made
    InOrder inOrder = Mockito.inOrder(calendarListRequest);
    inOrder.verify(calendarListRequest).setPageToken(NEXT_TOKEN);
    inOrder.verify(calendarListRequest).execute();
    // Check pagination token
    ContinuationData continuationData = (ContinuationData) result.getContinuationData();
    StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
    assertThat(paginationToken).isNull();
}
Also used : ExportInformation(org.dataportabilityproject.spi.transfer.types.ExportInformation) PaginationData(org.dataportabilityproject.spi.transfer.types.PaginationData) InOrder(org.mockito.InOrder) ContinuationData(org.dataportabilityproject.spi.transfer.types.ContinuationData) CalendarContainerResource(org.dataportabilityproject.types.transfer.models.calendar.CalendarContainerResource) StringPaginationToken(org.dataportabilityproject.spi.transfer.types.StringPaginationToken) Test(org.junit.Test)

Example 4 with ExportInformation

use of org.dataportabilityproject.spi.transfer.types.ExportInformation in project data-transfer-project by google.

the class GoogleCalendarExporterTest method exportEventSubsequentSet.

@Test
public void exportEventSubsequentSet() throws IOException {
    setUpSingleEventResponse();
    // Looking at subsequent page, with no pages after it
    ContainerResource containerResource = new IdOnlyContainerResource(CALENDAR_ID);
    PaginationData paginationData = new StringPaginationToken(EVENT_TOKEN_PREFIX + NEXT_TOKEN);
    ExportInformation exportInformation = new ExportInformation(paginationData, containerResource);
    eventListResponse.setNextPageToken(null);
    // Run test
    ExportResult<CalendarContainerResource> result = googleCalendarExporter.export(UUID.randomUUID(), null, exportInformation);
    // Check results
    // Verify correct methods were called in order
    InOrder inOrder = Mockito.inOrder(eventListRequest);
    inOrder.verify(eventListRequest).setPageToken(NEXT_TOKEN);
    inOrder.verify(eventListRequest).execute();
    // Check pagination token
    ContinuationData continuationData = (ContinuationData) result.getContinuationData();
    StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
    assertThat(paginationToken).isNull();
}
Also used : ExportInformation(org.dataportabilityproject.spi.transfer.types.ExportInformation) PaginationData(org.dataportabilityproject.spi.transfer.types.PaginationData) InOrder(org.mockito.InOrder) IdOnlyContainerResource(org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource) CalendarContainerResource(org.dataportabilityproject.types.transfer.models.calendar.CalendarContainerResource) ContainerResource(org.dataportabilityproject.types.transfer.models.ContainerResource) IdOnlyContainerResource(org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource) ContinuationData(org.dataportabilityproject.spi.transfer.types.ContinuationData) CalendarContainerResource(org.dataportabilityproject.types.transfer.models.calendar.CalendarContainerResource) StringPaginationToken(org.dataportabilityproject.spi.transfer.types.StringPaginationToken) Test(org.junit.Test)

Example 5 with ExportInformation

use of org.dataportabilityproject.spi.transfer.types.ExportInformation in project data-transfer-project by google.

the class FlickrPhotosExporterTest method exportPhotosFromPhotoset.

@Test
public void exportPhotosFromPhotoset() throws FlickrException {
    // set up auth, flickr service
    when(user.getId()).thenReturn("userId");
    when(authInterface.checkToken(any(Token.class))).thenReturn(auth);
    when(flickr.getPhotosetsInterface()).thenReturn(photosetsInterface);
    when(flickr.getPhotosInterface()).thenReturn(photosInterface);
    when(flickr.getAuthInterface()).thenReturn(authInterface);
    // getting photos from a set with id photosetsId and page 1
    int page = 1;
    String photosetsId = "photosetsId";
    ExportInformation exportInformation = new ExportInformation(null, new IdOnlyContainerResource(photosetsId));
    // make lots of photos and add them to PhotoList (also adding pagination information)
    int numPhotos = 4;
    PhotoList<Photo> photosList = new PhotoList<>();
    for (int i = 0; i < numPhotos; i++) {
        photosList.add(FlickrTestUtils.initializePhoto("title" + 1, "url" + i, "description" + i, MEDIA_TYPE));
    }
    photosList.setPage(page);
    photosList.setPages(page + 1);
    when(photosetsInterface.getPhotos(anyString(), anySet(), anyInt(), anyInt(), anyInt())).thenReturn(photosList);
    // run test
    FlickrPhotosExporter exporter = new FlickrPhotosExporter(flickr);
    ExportResult<PhotosContainerResource> result = exporter.export(UUID.randomUUID(), new TokenSecretAuthData("token", "secret"), exportInformation);
    assertThat(result.getExportedData().getPhotos().size()).isEqualTo(numPhotos);
    assertThat(result.getExportedData().getAlbums()).isEmpty();
    ContinuationData continuationData = (ContinuationData) result.getContinuationData();
    assertThat(continuationData.getContainerResources()).isEmpty();
    assertThat(((IntPaginationToken) continuationData.getPaginationData()).getStart()).isEqualTo(page + 1);
}
Also used : IntPaginationToken(org.dataportabilityproject.spi.transfer.types.IntPaginationToken) IntPaginationToken(org.dataportabilityproject.spi.transfer.types.IntPaginationToken) Token(org.scribe.model.Token) Photo(com.flickr4java.flickr.photos.Photo) ContinuationData(org.dataportabilityproject.spi.transfer.types.ContinuationData) Matchers.anyString(org.mockito.Matchers.anyString) ExportInformation(org.dataportabilityproject.spi.transfer.types.ExportInformation) PhotosContainerResource(org.dataportabilityproject.types.transfer.models.photos.PhotosContainerResource) PhotoList(com.flickr4java.flickr.photos.PhotoList) TokenSecretAuthData(org.dataportabilityproject.types.transfer.auth.TokenSecretAuthData) IdOnlyContainerResource(org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource) Test(org.junit.Test)

Aggregations

ExportInformation (org.dataportabilityproject.spi.transfer.types.ExportInformation)7 ContinuationData (org.dataportabilityproject.spi.transfer.types.ContinuationData)6 Test (org.junit.Test)5 StringPaginationToken (org.dataportabilityproject.spi.transfer.types.StringPaginationToken)4 IdOnlyContainerResource (org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource)3 PaginationData (org.dataportabilityproject.spi.transfer.types.PaginationData)3 ContainerResource (org.dataportabilityproject.types.transfer.models.ContainerResource)3 CalendarContainerResource (org.dataportabilityproject.types.transfer.models.calendar.CalendarContainerResource)3 InOrder (org.mockito.InOrder)3 Photo (com.flickr4java.flickr.photos.Photo)1 PhotoList (com.flickr4java.flickr.photos.PhotoList)1 IntPaginationToken (org.dataportabilityproject.spi.transfer.types.IntPaginationToken)1 TokenSecretAuthData (org.dataportabilityproject.types.transfer.auth.TokenSecretAuthData)1 CalendarEventModel (org.dataportabilityproject.types.transfer.models.calendar.CalendarEventModel)1 ContactsModelWrapper (org.dataportabilityproject.types.transfer.models.contacts.ContactsModelWrapper)1 PhotosContainerResource (org.dataportabilityproject.types.transfer.models.photos.PhotosContainerResource)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Token (org.scribe.model.Token)1