Search in sources :

Example 6 with PhotoAlbum

use of org.dataportabilityproject.dataModels.photos.PhotoAlbum in project data-transfer-project by google.

the class FlickrPhotoService method importItem.

@Override
public void importItem(PhotosModelWrapper modelWrapper) throws IOException {
    // TODO(olsona): what should we do with the continuation information?
    try {
        for (PhotoAlbum album : modelWrapper.getAlbums()) {
            // Store the data in the cache because Flickr only allows you
            // to create an album with a photo in it so we need to wait for
            // the first photo to create the album.
            String key = CACHE_ALBUM_METADATA_PREFIX + album.getId();
            jobDataCache.store(key, album);
        }
        for (PhotoModel photo : modelWrapper.getPhotos()) {
            String photoId = uploadPhoto(photo);
            String oldAlbumId = photo.getAlbumId();
            if (!jobDataCache.hasKey(oldAlbumId)) {
                PhotoAlbum album = jobDataCache.getData(CACHE_ALBUM_METADATA_PREFIX + oldAlbumId, PhotoAlbum.class);
                Photoset photoset = photosetsInterface.create(COPY_PREFIX + album.getName(), album.getDescription(), photoId);
                jobDataCache.store(oldAlbumId, photoset.getId());
            } else {
                String newAlbumId = jobDataCache.getData(oldAlbumId, String.class);
                photosetsInterface.addPhoto(newAlbumId, photoId);
            }
        }
    } catch (FlickrException e) {
        throw new IOException("Problem communicating with serviceProviders.flickr", e);
    }
}
Also used : FlickrException(com.flickr4java.flickr.FlickrException) Photoset(com.flickr4java.flickr.photosets.Photoset) PhotoModel(org.dataportabilityproject.dataModels.photos.PhotoModel) PhotoAlbum(org.dataportabilityproject.dataModels.photos.PhotoAlbum) IOException(java.io.IOException)

Example 7 with PhotoAlbum

use of org.dataportabilityproject.dataModels.photos.PhotoAlbum in project data-transfer-project by google.

the class FlickrPhotoService method getAlbums.

private PhotosModelWrapper getAlbums(Optional<PaginationInformation> paginationInformation) throws IOException {
    try {
        ImmutableList.Builder<PhotoAlbum> results = ImmutableList.builder();
        List<IdOnlyResource> subResources = new ArrayList<>();
        int page = getPage(paginationInformation);
        Photosets photoSetList = photosetsInterface.getList(auth.getUser().getId(), PHOTO_SETS_PER_PAGE, page, PHOTOSET_EXTRAS);
        for (Photoset photoset : photoSetList.getPhotosets()) {
            // Saving data to the album allows the target service
            // to recreate the album structure.
            results.add(new PhotoAlbum(photoset.getId(), photoset.getTitle(), photoset.getDescription()));
            // Adding sub-resources tells the framework to re-call
            // export to get all the photos.
            subResources.add(new IdOnlyResource(photoset.getId()));
        }
        FlickrPaginationInformation newPage = null;
        boolean hasMore = photoSetList.getPage() != photoSetList.getPages() && !photoSetList.getPhotosets().isEmpty();
        if (hasMore) {
            newPage = new FlickrPaginationInformation(page + 1);
        }
        return new PhotosModelWrapper(results.build(), null, new ContinuationInformation(subResources, newPage));
    } catch (FlickrException e) {
        throw new IOException("Couldn't fetch albums", e);
    }
}
Also used : FlickrException(com.flickr4java.flickr.FlickrException) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) IOException(java.io.IOException) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) Photoset(com.flickr4java.flickr.photosets.Photoset) Photosets(com.flickr4java.flickr.photosets.Photosets) PhotoAlbum(org.dataportabilityproject.dataModels.photos.PhotoAlbum)

Example 8 with PhotoAlbum

use of org.dataportabilityproject.dataModels.photos.PhotoAlbum in project data-transfer-project by google.

the class FlickrPhotoServiceTest method exportAlbumInitial.

@Test
public void exportAlbumInitial() throws IOException, FlickrException {
    // Set up initial export information, such as what FlickrPhotoService would see when a transfer
    // is initiated
    ExportInformation emptyExportInfo = new ExportInformation(Optional.empty(), Optional.empty());
    // Set up auth
    when(user.getId()).thenReturn("userId");
    // Set up photoset
    String photosetId = "photosetId";
    String photosetTitle = "title";
    String photosetDescription = "description";
    Photoset photoset = initializePhotoset(photosetId, photosetTitle, photosetDescription);
    // Set up photosets list (aka album view)
    int page = 1;
    Photosets photosetList = new Photosets();
    photosetList.setPage(page);
    photosetList.setPages(page + 1);
    photosetList.setPhotosets(Collections.singletonList(photoset));
    when(photosetsInterface.getList(anyString(), anyInt(), anyInt(), anyString())).thenReturn(photosetList);
    // Run test
    PhotosModelWrapper result = photoService.export(emptyExportInfo);
    // Make sure album/photo information is correct
    assertThat(result.getPhotos()).isEmpty();
    Collection<PhotoAlbum> albums = result.getAlbums();
    assertThat(albums.size()).isEqualTo(1);
    assertThat(albums).containsExactly(new PhotoAlbum(photosetId, photosetTitle, photosetDescription));
    // Make sure continuation information is correct
    ContinuationInformation continuationInformation = result.getContinuationInformation();
    assertThat((FlickrPaginationInformation) continuationInformation.getPaginationInformation()).isEqualTo(new FlickrPaginationInformation(page + 1));
    Collection<? extends Resource> subResources = continuationInformation.getSubResources();
    assertThat(subResources.size()).isEqualTo(1);
    assertThat(subResources).containsExactly(new IdOnlyResource(photosetId));
}
Also used : ExportInformation(org.dataportabilityproject.dataModels.ExportInformation) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) Photoset(com.flickr4java.flickr.photosets.Photoset) Photosets(com.flickr4java.flickr.photosets.Photosets) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) Matchers.anyString(org.mockito.Matchers.anyString) PhotoAlbum(org.dataportabilityproject.dataModels.photos.PhotoAlbum) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) Test(org.junit.Test)

Aggregations

PhotoAlbum (org.dataportabilityproject.dataModels.photos.PhotoAlbum)8 PhotosModelWrapper (org.dataportabilityproject.dataModels.photos.PhotosModelWrapper)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ContinuationInformation (org.dataportabilityproject.dataModels.ContinuationInformation)4 PhotoModel (org.dataportabilityproject.dataModels.photos.PhotoModel)4 IdOnlyResource (org.dataportabilityproject.shared.IdOnlyResource)4 Photoset (com.flickr4java.flickr.photosets.Photoset)3 FlickrException (com.flickr4java.flickr.FlickrException)2 Photosets (com.flickr4java.flickr.photosets.Photosets)2 ServiceException (com.google.gdata.util.ServiceException)2 URL (java.net.URL)2 Resource (org.dataportabilityproject.dataModels.Resource)2 SmugMugUserResponse (org.dataportabilityproject.serviceProviders.smugmug.model.SmugMugUserResponse)2 ImmutableList (com.google.common.collect.ImmutableList)1 PlainTextConstruct (com.google.gdata.data.PlainTextConstruct)1 MediaStreamSource (com.google.gdata.data.media.MediaStreamSource)1 AlbumEntry (com.google.gdata.data.photos.AlbumEntry)1 GphotoEntry (com.google.gdata.data.photos.GphotoEntry)1 PhotoEntry (com.google.gdata.data.photos.PhotoEntry)1