use of org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource 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.IdOnlyContainerResource 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.IdOnlyContainerResource 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);
}
}
use of org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource in project data-transfer-project by google.
the class GoogleTasksExporter method getTasks.
private ExportResult getTasks(Tasks tasksService, IdOnlyContainerResource resource, PaginationData paginationData) throws IOException {
Tasks.TasksOperations.List query = tasksService.tasks().list(resource.getId()).setMaxResults(PAGE_SIZE);
if (paginationData != null) {
query.setPageToken(((StringPaginationToken) paginationData).getToken());
}
com.google.api.services.tasks.model.Tasks result = query.execute();
List<TaskModel> newTasks = result.getItems().stream().map(t -> new TaskModel(resource.getId(), t.getTitle(), t.getNotes())).collect(Collectors.toList());
PaginationData newPage = null;
ResultType resultType = ResultType.END;
if (result.getNextPageToken() != null) {
newPage = new StringPaginationToken(result.getNextPageToken());
resultType = ResultType.CONTINUE;
}
TaskContainerResource taskContainerResource = new TaskContainerResource(null, newTasks);
return new ExportResult<>(resultType, taskContainerResource, new ContinuationData(newPage));
}
use of org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource in project data-transfer-project by google.
the class GoogleTasksExporter method export.
@Override
public ExportResult<TaskContainerResource> export(UUID jobId, TokensAndUrlAuthData authData, ExportInformation exportInformation) {
// Create a new tasks service for the authorized user
Tasks tasksService = getOrCreateTasksService(authData);
IdOnlyContainerResource resource = (IdOnlyContainerResource) exportInformation.getContainerResource();
try {
if (resource != null) {
return getTasks(tasksService, resource, exportInformation.getPaginationData());
} else {
return getTasksList(tasksService, exportInformation.getPaginationData());
}
} catch (Exception e) {
return new ExportResult<>(ResultType.ERROR, "Error retrieving tasks: " + e.getMessage());
}
}
Aggregations