use of org.dataportabilityproject.dataModels.ExportInformation in project data-transfer-project by google.
the class PortabilityCopier method copy.
private static <T extends DataModel> void copy(Exporter<T> exporter, Importer<T> importer, ExportInformation exportInformation) throws IOException {
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);
T items = exporter.export(exportInformation);
logger.debug("Finished export, results: {}", items);
logger.debug("Starting import");
// The collection of items can be both containers and items
importer.importItem(items);
logger.debug("Finished import");
ContinuationInformation continuationInfo = items.getContinuationInformation();
if (null != continuationInfo) {
// Process the next page of items for the resource
if (null != continuationInfo.getPaginationInformation()) {
logger.debug("Start off a new copy iteration with pagination info");
copy(exporter, importer, new ExportInformation(// Resource with additional pages to fetch
exportInformation.getResource(), Optional.of(continuationInfo.getPaginationInformation())));
}
// Start processing sub-resources
if (continuationInfo.getSubResources() != null && !continuationInfo.getSubResources().isEmpty()) {
logger.debug("Start off a new copy iteration with a sub resource, size: {}", continuationInfo.getSubResources().size());
for (Resource resource : continuationInfo.getSubResources()) {
copy(exporter, importer, new ExportInformation(Optional.of(resource), Optional.empty()));
}
}
}
}
use of org.dataportabilityproject.dataModels.ExportInformation 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);
}
use of org.dataportabilityproject.dataModels.ExportInformation 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();
}
use of org.dataportabilityproject.dataModels.ExportInformation in project data-transfer-project by google.
the class GoogleContactsService method export.
public ContactsModelWrapper export(ExportInformation continuationInformation) throws IOException {
// Set up connection
Connections.List connectionsList = peopleService.people().connections().list(GoogleContactsConstants.SELF_RESOURCE);
// Get next page, if we have a page token
if (continuationInformation.getPaginationInformation().isPresent()) {
String pageToken = ((StringPaginationToken) continuationInformation.getPaginationInformation().get()).getId();
connectionsList.setPageToken(pageToken);
}
// Get list of connections (nb: not a list containing full info of each Person)
ListConnectionsResponse response = connectionsList.setPersonFields(GoogleContactsConstants.PERSON_FIELDS).execute();
List<Person> peopleList = response.getConnections();
// Get list of resource names, then get list of Persons
List<String> resourceNames = peopleList.stream().map(Person::getResourceName).collect(Collectors.toList());
GetPeopleResponse batchResponse = peopleService.people().getBatchGet().setResourceNames(resourceNames).setPersonFields(GoogleContactsConstants.PERSON_FIELDS).execute();
List<PersonResponse> personResponseList = batchResponse.getResponses();
// Convert Persons to VCards
List<VCard> vCards = personResponseList.stream().map(a -> GoogleContactToVCardConverter.convert(a.getPerson())).collect(Collectors.toList());
// Determine if there's a next page
StringPaginationToken newPage = null;
if (response.getNextPageToken() != null) {
newPage = new StringPaginationToken(response.getNextPageToken());
}
ContinuationInformation newContinuationInformation = null;
if (newPage != null) {
newContinuationInformation = new ContinuationInformation(null, newPage);
}
return new ContactsModelWrapper(vCards, newContinuationInformation);
}
use of org.dataportabilityproject.dataModels.ExportInformation in project data-transfer-project by google.
the class PortabilityCopier method copyDataType.
// Start the copy data process
public static <T extends DataModel> void copyDataType(ServiceProviderRegistry registry, PortableDataType dataType, String exportService, AuthData exportAuthData, String importService, AuthData importAuthData, UUID jobId) throws IOException {
Exporter<T> exporter = registry.getExporter(exportService, dataType, jobId, exportAuthData);
Importer<T> importer = registry.getImporter(importService, dataType, jobId, importAuthData);
ExportInformation emptyExportInfo = new ExportInformation(Optional.empty(), Optional.empty());
logger.debug("Starting copy job, id: {}, source: {}, destination: {}", jobId, exportService, importService);
copy(exporter, importer, emptyExportInfo);
}
Aggregations