use of org.datatransferproject.types.common.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 exportInfo}. 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 exportInfo Any pagination or resource information to use for subsequent calls.
*/
private Collection<ErrorDetail> copyHelper(AuthData exportAuthData, AuthData importAuthData, UUID jobId, Optional<ExportInformation> exportInfo) throws CopyException {
String jobIdPrefix = "Job " + jobId + ": ";
final int copyIteration = 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.
ExportResult<?> exportResult = copyIteration(jobId, exportAuthData, importAuthData, exportInfo, jobIdPrefix, copyIteration);
// Import and Export were successful, determine what to do next
ContinuationData continuationData = exportResult.getContinuationData();
if (null != continuationData) {
// Process the next page of items for the resource
if (null != continuationData.getPaginationData()) {
monitor.debug(() -> jobIdPrefix + "Starting off a new copy iteration with pagination info, copy iteration: " + copyIteration);
copyHelper(exportAuthData, importAuthData, jobId, Optional.of(new ExportInformation(continuationData.getPaginationData(), exportInfo.isPresent() ? exportInfo.get().getContainerResource() : null)));
}
// Start processing sub-resources
if (continuationData.getContainerResources() != null && !continuationData.getContainerResources().isEmpty()) {
for (ContainerResource resource : continuationData.getContainerResources()) {
monitor.debug(() -> jobIdPrefix + "Starting off a new copy iteration with a new container resource, copy iteration: " + copyIteration);
copyHelper(exportAuthData, importAuthData, jobId, Optional.of(new ExportInformation(null, resource)));
}
}
}
return idempotentImportExecutor.getErrors();
}
use of org.datatransferproject.types.common.ExportInformation in project data-transfer-project by google.
the class PortabilityJobTest method verifySerializeDeserializeWithAlbum.
@Test
public void verifySerializeDeserializeWithAlbum() throws IOException {
ObjectMapper objectMapper = ObjectMapperFactory.createObjectMapper();
Instant date = Instant.now();
JobAuthorization jobAuthorization = JobAuthorization.builder().setState(JobAuthorization.State.INITIAL).setSessionSecretKey("foo").build();
PortabilityJob job = PortabilityJob.builder().setState(State.NEW).setExportService("fooService").setImportService("barService").setTransferDataType("PHOTOS").setExportInformation(objectMapper.writeValueAsString(new ExportInformation(null, new PhotosContainerResource(Lists.newArrayList(new PhotoAlbum("album_id", "album name", "album description")), null)))).setCreatedTimestamp(date).setLastUpdateTimestamp(date.plusSeconds(120)).setJobAuthorization(jobAuthorization).build();
String serializedJobAuthorization = objectMapper.writeValueAsString(jobAuthorization);
JobAuthorization deserializedJobAuthorization = objectMapper.readValue(serializedJobAuthorization, JobAuthorization.class);
assertThat(deserializedJobAuthorization).isEqualTo(jobAuthorization);
String serializedJob = objectMapper.writeValueAsString(job);
PortabilityJob deserializedJob = objectMapper.readValue(serializedJob, PortabilityJob.class);
assertThat(deserializedJob).isEqualTo(job);
}
use of org.datatransferproject.types.common.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, Optional.of(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);
}
use of org.datatransferproject.types.common.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, Optional.of(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();
}
use of org.datatransferproject.types.common.ExportInformation in project data-transfer-project by google.
the class GoogleContactsExporterTest method exportSubsequentPage.
@Test
public void exportSubsequentPage() throws IOException {
setUpSinglePersonResponse();
// Looking at a subsequent page, with no pages after it
PaginationData paginationData = new StringPaginationToken(NEXT_PAGE_TOKEN);
ExportInformation exportInformation = new ExportInformation(paginationData, null);
listConnectionsResponse.setNextPageToken(null);
when(listConnectionsRequest.setPageToken(NEXT_PAGE_TOKEN)).thenReturn(listConnectionsRequest);
// Run test
ExportResult<ContactsModelWrapper> result = contactsService.export(UUID.randomUUID(), null, Optional.of(exportInformation));
// 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 data
ContinuationData continuationData = (ContinuationData) result.getContinuationData();
assertThat(continuationData.getContainerResources()).isEmpty();
assertThat(continuationData.getPaginationData()).isNull();
}
Aggregations