Search in sources :

Example 1 with SmugMugUserResponse

use of org.dataportabilityproject.transfer.smugmug.photos.model.SmugMugUserResponse in project data-transfer-project by google.

the class SmugMugPhotosImporter method importItem.

@Override
public ImportResult importItem(UUID jobId, AuthData authData, PhotosContainerResource data) {
    try {
        String folder = null;
        if (!data.getAlbums().isEmpty()) {
            SmugMugResponse<SmugMugUserResponse> userResponse = smugMugInterface.makeUserRequest(smugMugInterface.USER_URL);
            folder = userResponse.getResponse().getUser().getUris().get("Folder").getUri();
        }
        for (PhotoAlbum album : data.getAlbums()) {
            importSingleAlbum(jobId, folder, album);
        }
        for (PhotoModel photo : data.getPhotos()) {
            importSinglePhoto(jobId, photo);
        }
    } catch (IOException e) {
        // TODO(olsona): we should retry on individual errors
        return new ImportResult(ResultType.ERROR, e.getMessage());
    }
    return ImportResult.OK;
}
Also used : SmugMugUserResponse(org.dataportabilityproject.transfer.smugmug.photos.model.SmugMugUserResponse) ImportResult(org.dataportabilityproject.spi.transfer.provider.ImportResult) PhotoModel(org.dataportabilityproject.types.transfer.models.photos.PhotoModel) PhotoAlbum(org.dataportabilityproject.types.transfer.models.photos.PhotoAlbum) IOException(java.io.IOException)

Example 2 with SmugMugUserResponse

use of org.dataportabilityproject.transfer.smugmug.photos.model.SmugMugUserResponse in project data-transfer-project by google.

the class SmugMugPhotosExporter method exportAlbums.

private ExportResult<PhotosContainerResource> exportAlbums(Optional<PaginationData> paginationData) throws IOException {
    // Make request to SmugMug
    String albumInfoUri;
    if (paginationData.isPresent()) {
        String token = ((StringPaginationToken) paginationData.get()).getToken();
        Preconditions.checkState(token.startsWith(ALBUM_TOKEN_PREFIX), "Invalid pagination token " + token);
        albumInfoUri = token.substring(ALBUM_TOKEN_PREFIX.length());
    } else {
        SmugMugResponse<SmugMugUserResponse> userResponse = smugMugInterface.makeUserRequest(USER_URL);
        albumInfoUri = userResponse.getResponse().getUser().getUris().get(ALBUMS_KEY).getUri();
    }
    SmugMugResponse<SmugMugAlbumsResponse> albumsResponse = smugMugInterface.makeAlbumRequest(albumInfoUri);
    // Set up continuation data
    StringPaginationToken paginationToken = null;
    if (albumsResponse.getResponse().getPageInfo() != null && albumsResponse.getResponse().getPageInfo().getNextPage() != null) {
        paginationToken = new StringPaginationToken(ALBUM_TOKEN_PREFIX + albumsResponse.getResponse().getPageInfo().getNextPage());
    }
    ContinuationData continuationData = new ContinuationData(paginationToken);
    // Build album list
    List<PhotoAlbum> albumsList = new ArrayList<>();
    for (SmugMugAlbum album : albumsResponse.getResponse().getAlbums()) {
        albumsList.add(new PhotoAlbum(album.getAlbumKey(), album.getTitle(), album.getDescription()));
        continuationData.addContainerResource(new IdOnlyContainerResource(album.getAlbumKey()));
    }
    PhotosContainerResource resource = new PhotosContainerResource(albumsList, null);
    // Get result type
    ResultType resultType = ResultType.CONTINUE;
    if (paginationToken == null) {
        resultType = ResultType.END;
    }
    return new ExportResult<>(resultType, resource, continuationData);
}
Also used : SmugMugUserResponse(org.dataportabilityproject.transfer.smugmug.photos.model.SmugMugUserResponse) ArrayList(java.util.ArrayList) ContinuationData(org.dataportabilityproject.spi.transfer.types.ContinuationData) ResultType(org.dataportabilityproject.spi.transfer.provider.ExportResult.ResultType) PhotosContainerResource(org.dataportabilityproject.types.transfer.models.photos.PhotosContainerResource) SmugMugAlbum(org.dataportabilityproject.transfer.smugmug.photos.model.SmugMugAlbum) SmugMugAlbumsResponse(org.dataportabilityproject.transfer.smugmug.photos.model.SmugMugAlbumsResponse) IdOnlyContainerResource(org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource) PhotoAlbum(org.dataportabilityproject.types.transfer.models.photos.PhotoAlbum) StringPaginationToken(org.dataportabilityproject.spi.transfer.types.StringPaginationToken) ExportResult(org.dataportabilityproject.spi.transfer.provider.ExportResult)

Aggregations

SmugMugUserResponse (org.dataportabilityproject.transfer.smugmug.photos.model.SmugMugUserResponse)2 PhotoAlbum (org.dataportabilityproject.types.transfer.models.photos.PhotoAlbum)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ExportResult (org.dataportabilityproject.spi.transfer.provider.ExportResult)1 ResultType (org.dataportabilityproject.spi.transfer.provider.ExportResult.ResultType)1 ImportResult (org.dataportabilityproject.spi.transfer.provider.ImportResult)1 ContinuationData (org.dataportabilityproject.spi.transfer.types.ContinuationData)1 IdOnlyContainerResource (org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource)1 StringPaginationToken (org.dataportabilityproject.spi.transfer.types.StringPaginationToken)1 SmugMugAlbum (org.dataportabilityproject.transfer.smugmug.photos.model.SmugMugAlbum)1 SmugMugAlbumsResponse (org.dataportabilityproject.transfer.smugmug.photos.model.SmugMugAlbumsResponse)1 PhotoModel (org.dataportabilityproject.types.transfer.models.photos.PhotoModel)1 PhotosContainerResource (org.dataportabilityproject.types.transfer.models.photos.PhotosContainerResource)1