Search in sources :

Example 1 with MicrosoftDriveItem

use of org.datatransferproject.transfer.microsoft.driveModels.MicrosoftDriveItem in project data-transfer-project by google.

the class MicrosoftPhotosExporter method exportOneDrivePhotos.

@VisibleForTesting
ExportResult<PhotosContainerResource> exportOneDrivePhotos(TokensAndUrlAuthData authData, Optional<IdOnlyContainerResource> albumData, Optional<PaginationData> paginationData, UUID jobId) throws IOException {
    Optional<String> albumId = Optional.empty();
    if (albumData.isPresent()) {
        albumId = Optional.of(albumData.get().getId());
    }
    Optional<String> paginationUrl = getDrivePaginationToken(paginationData);
    MicrosoftDriveItemsResponse driveItemsResponse;
    if (paginationData.isPresent() || albumData.isPresent()) {
        driveItemsResponse = getOrCreatePhotosInterface(authData).getDriveItems(albumId, paginationUrl);
    } else {
        driveItemsResponse = getOrCreatePhotosInterface(authData).getDriveItemsFromSpecialFolder(MicrosoftSpecialFolder.FolderType.photos);
    }
    PaginationData nextPageData = SetNextPageToken(driveItemsResponse);
    ContinuationData continuationData = new ContinuationData(nextPageData);
    PhotosContainerResource containerResource;
    MicrosoftDriveItem[] driveItems = driveItemsResponse.getDriveItems();
    List<PhotoAlbum> albums = new ArrayList<>();
    List<PhotoModel> photos = new ArrayList<>();
    if (driveItems != null && driveItems.length > 0) {
        for (MicrosoftDriveItem driveItem : driveItems) {
            PhotoAlbum album = tryConvertDriveItemToPhotoAlbum(driveItem, jobId);
            if (album != null) {
                albums.add(album);
                continuationData.addContainerResource(new IdOnlyContainerResource(driveItem.id));
            }
            PhotoModel photo = tryConvertDriveItemToPhotoModel(albumId, driveItem, jobId);
            if (photo != null) {
                photos.add(photo);
            }
        }
    }
    ExportResult.ResultType result = nextPageData == null ? ExportResult.ResultType.END : ExportResult.ResultType.CONTINUE;
    containerResource = new PhotosContainerResource(albums, photos);
    return new ExportResult<>(result, containerResource, continuationData);
}
Also used : MicrosoftDriveItem(org.datatransferproject.transfer.microsoft.driveModels.MicrosoftDriveItem) PaginationData(org.datatransferproject.types.common.PaginationData) MicrosoftDriveItemsResponse(org.datatransferproject.transfer.microsoft.driveModels.MicrosoftDriveItemsResponse) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) ArrayList(java.util.ArrayList) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ArrayList (java.util.ArrayList)1 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)1 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)1 MicrosoftDriveItem (org.datatransferproject.transfer.microsoft.driveModels.MicrosoftDriveItem)1 MicrosoftDriveItemsResponse (org.datatransferproject.transfer.microsoft.driveModels.MicrosoftDriveItemsResponse)1 PaginationData (org.datatransferproject.types.common.PaginationData)1 IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)1 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)1 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)1 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)1