Search in sources :

Example 1 with IdOnlyContainerResource

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);
}
Also used : PaginationData(org.dataportabilityproject.spi.transfer.types.PaginationData) ArrayList(java.util.ArrayList) ResultType(org.dataportabilityproject.spi.transfer.provider.ExportResult.ResultType) CalendarModel(org.dataportabilityproject.types.transfer.models.calendar.CalendarModel) ContinuationData(org.dataportabilityproject.spi.transfer.types.ContinuationData) IOException(java.io.IOException) CalendarContainerResource(org.dataportabilityproject.types.transfer.models.calendar.CalendarContainerResource) CalendarListEntry(com.google.api.services.calendar.model.CalendarListEntry) IdOnlyContainerResource(org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource) CalendarList(com.google.api.services.calendar.model.CalendarList) StringPaginationToken(org.dataportabilityproject.spi.transfer.types.StringPaginationToken) ExportResult(org.dataportabilityproject.spi.transfer.provider.ExportResult)

Example 2 with IdOnlyContainerResource

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);
    }
}
Also used : PaginationData(org.dataportabilityproject.spi.transfer.types.PaginationData) IdOnlyContainerResource(org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource) StringPaginationToken(org.dataportabilityproject.spi.transfer.types.StringPaginationToken)

Example 3 with IdOnlyContainerResource

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);
    }
}
Also used : PaginationData(org.dataportabilityproject.spi.transfer.types.PaginationData) IdOnlyContainerResource(org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource) StringPaginationToken(org.dataportabilityproject.spi.transfer.types.StringPaginationToken)

Example 4 with IdOnlyContainerResource

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));
}
Also used : ExportInformation(org.dataportabilityproject.spi.transfer.types.ExportInformation) IdOnlyContainerResource(org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource) Exporter(org.dataportabilityproject.spi.transfer.provider.Exporter) StringPaginationToken(org.dataportabilityproject.spi.transfer.types.StringPaginationToken) TaskModel(org.dataportabilityproject.types.transfer.models.tasks.TaskModel) BearerToken(com.google.api.client.auth.oauth2.BearerToken) ExportResult(org.dataportabilityproject.spi.transfer.provider.ExportResult) ResultType(org.dataportabilityproject.spi.transfer.provider.ExportResult.ResultType) TaskContainerResource(org.dataportabilityproject.types.transfer.models.tasks.TaskContainerResource) IOException(java.io.IOException) Tasks(com.google.api.services.tasks.Tasks) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) TokensAndUrlAuthData(org.dataportabilityproject.types.transfer.auth.TokensAndUrlAuthData) TaskListModel(org.dataportabilityproject.types.transfer.models.tasks.TaskListModel) List(java.util.List) TaskList(com.google.api.services.tasks.model.TaskList) ImmutableList(com.google.common.collect.ImmutableList) ContinuationData(org.dataportabilityproject.spi.transfer.types.ContinuationData) Credential(com.google.api.client.auth.oauth2.Credential) VisibleForTesting(com.google.common.annotations.VisibleForTesting) TaskLists(com.google.api.services.tasks.model.TaskLists) GoogleStaticObjects(org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects) PaginationData(org.dataportabilityproject.spi.transfer.types.PaginationData) PaginationData(org.dataportabilityproject.spi.transfer.types.PaginationData) ContinuationData(org.dataportabilityproject.spi.transfer.types.ContinuationData) ResultType(org.dataportabilityproject.spi.transfer.provider.ExportResult.ResultType) TaskContainerResource(org.dataportabilityproject.types.transfer.models.tasks.TaskContainerResource) TaskModel(org.dataportabilityproject.types.transfer.models.tasks.TaskModel) StringPaginationToken(org.dataportabilityproject.spi.transfer.types.StringPaginationToken) ExportResult(org.dataportabilityproject.spi.transfer.provider.ExportResult)

Example 5 with IdOnlyContainerResource

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());
    }
}
Also used : Tasks(com.google.api.services.tasks.Tasks) IdOnlyContainerResource(org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource) IOException(java.io.IOException)

Aggregations

IdOnlyContainerResource (org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource)17 ContinuationData (org.dataportabilityproject.spi.transfer.types.ContinuationData)12 PaginationData (org.dataportabilityproject.spi.transfer.types.PaginationData)12 StringPaginationToken (org.dataportabilityproject.spi.transfer.types.StringPaginationToken)11 ExportResult (org.dataportabilityproject.spi.transfer.provider.ExportResult)8 ResultType (org.dataportabilityproject.spi.transfer.provider.ExportResult.ResultType)7 IOException (java.io.IOException)6 ExportInformation (org.dataportabilityproject.spi.transfer.types.ExportInformation)6 ArrayList (java.util.ArrayList)5 PhotosContainerResource (org.dataportabilityproject.types.transfer.models.photos.PhotosContainerResource)5 Test (org.junit.Test)5 ImmutableList (com.google.common.collect.ImmutableList)4 PhotoAlbum (org.dataportabilityproject.types.transfer.models.photos.PhotoAlbum)4 FlickrException (com.flickr4java.flickr.FlickrException)3 Photoset (com.flickr4java.flickr.photosets.Photoset)3 Photosets (com.flickr4java.flickr.photosets.Photosets)3 List (java.util.List)3 UUID (java.util.UUID)3 Collectors (java.util.stream.Collectors)3 IntPaginationToken (org.dataportabilityproject.spi.transfer.types.IntPaginationToken)3