use of org.dataportabilityproject.spi.transfer.types.PaginationData in project data-transfer-project by google.
the class GoogleCalendarExporter method exportCalendars.
private ExportResult<CalendarContainerResource> exportCalendars(AuthData authData, Optional<PaginationData> pageData) {
Calendar.CalendarList.List listRequest;
CalendarList listResult;
// Get calendar information
try {
listRequest = getOrCreateCalendarInterface(authData).calendarList().list();
if (pageData.isPresent()) {
StringPaginationToken paginationToken = (StringPaginationToken) pageData.get();
Preconditions.checkState(paginationToken.getToken().startsWith(CALENDAR_TOKEN_PREFIX), "Token is not applicable");
listRequest.setPageToken(((StringPaginationToken) pageData.get()).getToken().substring(CALENDAR_TOKEN_PREFIX.length()));
}
listResult = listRequest.execute();
} catch (IOException e) {
return new ExportResult<CalendarContainerResource>(ResultType.ERROR, e.getMessage());
}
// Set up continuation data
PaginationData nextPageData = null;
if (listResult.getNextPageToken() != null) {
nextPageData = new StringPaginationToken(CALENDAR_TOKEN_PREFIX + listResult.getNextPageToken());
}
ContinuationData continuationData = new ContinuationData(nextPageData);
// Process calendar list
List<CalendarModel> calendarModels = new ArrayList<>(listResult.getItems().size());
for (CalendarListEntry calendarData : listResult.getItems()) {
CalendarModel model = convertToCalendarModel(calendarData);
continuationData.addContainerResource(new IdOnlyContainerResource(calendarData.getId()));
calendarModels.add(model);
}
CalendarContainerResource calendarContainerResource = new CalendarContainerResource(calendarModels, null);
// Get result type
ExportResult.ResultType resultType = ResultType.CONTINUE;
if (calendarModels.isEmpty()) {
resultType = ResultType.END;
}
return new ExportResult<CalendarContainerResource>(resultType, calendarContainerResource, continuationData);
}
use of org.dataportabilityproject.spi.transfer.types.PaginationData in project data-transfer-project by google.
the class GoogleCalendarExporter method export.
@Override
public ExportResult<CalendarContainerResource> export(UUID jobId, AuthData authData, ExportInformation exportInformation) {
StringPaginationToken paginationToken = (StringPaginationToken) exportInformation.getPaginationData();
if (paginationToken != null && paginationToken.getToken().startsWith(CALENDAR_TOKEN_PREFIX)) {
// Next thing to export is more calendars
return exportCalendars(authData, Optional.of(paginationToken));
} else {
// Next thing to export is events
IdOnlyContainerResource idOnlyContainerResource = (IdOnlyContainerResource) exportInformation.getContainerResource();
Optional<PaginationData> pageData = paginationToken != null ? Optional.of(paginationToken) : Optional.empty();
return getCalendarEvents(authData, idOnlyContainerResource.getId(), pageData);
}
}
use of org.dataportabilityproject.spi.transfer.types.PaginationData in project data-transfer-project by google.
the class GoogleContactsExporter method export.
@Override
public ExportResult<ContactsModelWrapper> export(UUID jobId, TokensAndUrlAuthData authData, ExportInformation exportInformation) {
StringPaginationToken stringPaginationToken = (StringPaginationToken) exportInformation.getPaginationData();
Optional<PaginationData> paginationData = Optional.ofNullable(stringPaginationToken);
return exportContacts(authData, paginationData);
}
use of org.dataportabilityproject.spi.transfer.types.PaginationData in project data-transfer-project by google.
the class GoogleContactsExporter method exportContacts.
private ExportResult<ContactsModelWrapper> exportContacts(TokensAndUrlAuthData authData, Optional<PaginationData> pageData) {
try {
// Set up connection
Connections.List connectionsListRequest = getOrCreatePeopleService(authData).people().connections().list(SELF_RESOURCE);
// Get next page, if we have a page token
if (pageData.isPresent()) {
StringPaginationToken paginationToken = (StringPaginationToken) pageData.get();
connectionsListRequest.setPageToken(paginationToken.getToken());
}
// Get list of connections (nb: not a list containing full info of each Person)
ListConnectionsResponse response = connectionsListRequest.setPersonFields(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 = getOrCreatePeopleService(authData).people().getBatchGet().setResourceNames(resourceNames).setPersonFields(PERSON_FIELDS).execute();
List<PersonResponse> personResponseList = batchResponse.getResponses();
// Convert Persons to VCards
List<VCard> vCards = personResponseList.stream().map(a -> convert(a.getPerson())).collect(Collectors.toList());
// Determine if there's a next page
StringPaginationToken nextPageData = null;
if (response.getNextPageToken() != null) {
nextPageData = new StringPaginationToken(response.getNextPageToken());
}
ContinuationData continuationData = new ContinuationData(nextPageData);
ContactsModelWrapper wrapper = new ContactsModelWrapper(makeVCardString(vCards));
// Get result type
ResultType resultType = ResultType.CONTINUE;
if (nextPageData == null) {
resultType = ResultType.END;
}
return new ExportResult<ContactsModelWrapper>(resultType, wrapper, continuationData);
} catch (IOException e) {
return new ExportResult<ContactsModelWrapper>(ResultType.ERROR, e.getMessage());
}
}
use of org.dataportabilityproject.spi.transfer.types.PaginationData in project data-transfer-project by google.
the class GooglePhotosExporter method export.
@Override
public ExportResult<PhotosContainerResource> export(UUID jobId, TokensAndUrlAuthData authData, ExportInformation exportInformation) {
StringPaginationToken paginationToken = (StringPaginationToken) exportInformation.getPaginationData();
if (paginationToken != null && paginationToken.getToken().startsWith(ALBUM_TOKEN_PREFIX)) {
// Next thing to export is more albums
return exportAlbums(authData, Optional.of(paginationToken));
} else {
// Next thing to export is photos
IdOnlyContainerResource idOnlyContainerResource = (IdOnlyContainerResource) exportInformation.getContainerResource();
Optional<PaginationData> pageData = paginationToken != null ? Optional.of(paginationToken) : Optional.empty();
return exportPhotos(authData, idOnlyContainerResource.getId(), pageData);
}
}
Aggregations