Search in sources :

Example 6 with PhotoModel

use of org.dataportabilityproject.dataModels.photos.PhotoModel 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 PhotoModel

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

the class FlickrPhotoService method getPhotos.

private PhotosModelWrapper getPhotos(String photosetId, Optional<PaginationInformation> paginationInformation) throws IOException {
    try {
        int page = getPage(paginationInformation);
        PhotoList<Photo> photoSetList;
        if (null == photosetId) {
            RequestContext.getRequestContext().setExtras(EXTRAS);
            photoSetList = photosInterface.getNotInSet(PHOTO_PER_PAGE, page);
            RequestContext.getRequestContext().setExtras(ImmutableList.of());
        } else {
            photoSetList = photosetsInterface.getPhotos(photosetId, ImmutableSet.copyOf(EXTRAS), 0, PHOTO_PER_PAGE, page);
        }
        boolean hasMore = photoSetList.getPage() != photoSetList.getPages() && !photoSetList.isEmpty();
        Collection<PhotoModel> photos = photoSetList.stream().map(p -> toCommonPhoto(p, photosetId)).collect(Collectors.toList());
        FlickrPaginationInformation newPage = null;
        if (hasMore) {
            newPage = new FlickrPaginationInformation(page + 1);
        }
        return new PhotosModelWrapper(null, photos, new ContinuationInformation(null, newPage));
    } catch (FlickrException e) {
        throw new IOException("Couldn't fetch photos in album: " + photosetId, e);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) Importer(org.dataportabilityproject.dataModels.Importer) FlickrException(com.flickr4java.flickr.FlickrException) AppCredentials(org.dataportabilityproject.shared.AppCredentials) LoggerFactory(org.slf4j.LoggerFactory) Photoset(com.flickr4java.flickr.photosets.Photoset) REST(com.flickr4java.flickr.REST) PhotoAlbum(org.dataportabilityproject.dataModels.photos.PhotoAlbum) ArrayList(java.util.ArrayList) Photo(com.flickr4java.flickr.photos.Photo) Strings(com.google.api.client.repackaged.com.google.common.base.Strings) ImmutableList(com.google.common.collect.ImmutableList) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) PhotoModel(org.dataportabilityproject.dataModels.photos.PhotoModel) JobDataCache(org.dataportabilityproject.cloud.interfaces.JobDataCache) Uploader(com.flickr4java.flickr.uploader.Uploader) Flickr(com.flickr4java.flickr.Flickr) PhotoList(com.flickr4java.flickr.photos.PhotoList) Auth(com.flickr4java.flickr.auth.Auth) ImageStreamProvider(org.dataportabilityproject.shared.ImageStreamProvider) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) PhotosInterface(com.flickr4java.flickr.photos.PhotosInterface) Resource(org.dataportabilityproject.dataModels.Resource) ExportInformation(org.dataportabilityproject.dataModels.ExportInformation) Collection(java.util.Collection) IOException(java.io.IOException) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) UploadMetaData(com.flickr4java.flickr.uploader.UploadMetaData) Exporter(org.dataportabilityproject.dataModels.Exporter) Photosets(com.flickr4java.flickr.photosets.Photosets) List(java.util.List) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) RequestContext(com.flickr4java.flickr.RequestContext) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) PhotosetsInterface(com.flickr4java.flickr.photosets.PhotosetsInterface) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) FlickrException(com.flickr4java.flickr.FlickrException) PhotoModel(org.dataportabilityproject.dataModels.photos.PhotoModel) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) Photo(com.flickr4java.flickr.photos.Photo) IOException(java.io.IOException)

Example 8 with PhotoModel

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

the class SmugMugPhotoService method getImages.

private PhotosModelWrapper getImages(IdOnlyResource resource, Optional<PaginationInformation> paginationInformation) throws IOException {
    List<PhotoModel> photos = new ArrayList<>();
    String url;
    if (paginationInformation.isPresent()) {
        url = ((StringPaginationToken) paginationInformation.get()).getId();
    } else {
        String id = resource.getId();
        url = "/api/v2/album/" + id + "!images";
    }
    StringPaginationToken pageToken = null;
    SmugMugResponse<SmugMugAlbumInfoResponse> albumInfoResponse = makeAlbumInfoRequest(url);
    if (albumInfoResponse.getResponse().getImages() != null) {
        for (SmugMugAlbumImage image : albumInfoResponse.getResponse().getImages()) {
            String title = image.getTitle();
            if (Strings.isNullOrEmpty(title)) {
                title = image.getFileName();
            }
            try {
                photos.add(new PhotoModel(title, this.authConsumer.sign(image.getArchivedUri()), image.getCaption(), image.getFormat(), resource.getId()));
            } catch (OAuthException e) {
                throw new IOException("Couldn't sign: " + image.getArchivedUri(), e);
            }
        }
        if (albumInfoResponse.getResponse().getPageInfo().getNextPage() != null) {
            pageToken = new StringPaginationToken(albumInfoResponse.getResponse().getPageInfo().getNextPage());
        }
    }
    return new PhotosModelWrapper(null, photos, new ContinuationInformation(null, pageToken));
}
Also used : ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) PhotoModel(org.dataportabilityproject.dataModels.photos.PhotoModel) SmugMugAlbumImage(org.dataportabilityproject.serviceProviders.smugmug.model.SmugMugAlbumImage) OAuthException(oauth.signpost.exception.OAuthException) ArrayList(java.util.ArrayList) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) IOException(java.io.IOException) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken) SmugMugAlbumInfoResponse(org.dataportabilityproject.serviceProviders.smugmug.model.SmugMugAlbumInfoResponse)

Aggregations

PhotoModel (org.dataportabilityproject.dataModels.photos.PhotoModel)8 IOException (java.io.IOException)5 PhotoAlbum (org.dataportabilityproject.dataModels.photos.PhotoAlbum)5 ArrayList (java.util.ArrayList)4 PhotosModelWrapper (org.dataportabilityproject.dataModels.photos.PhotosModelWrapper)4 ContinuationInformation (org.dataportabilityproject.dataModels.ContinuationInformation)3 FlickrException (com.flickr4java.flickr.FlickrException)2 Photo (com.flickr4java.flickr.photos.Photo)2 Photoset (com.flickr4java.flickr.photosets.Photoset)2 ServiceException (com.google.gdata.util.ServiceException)2 URL (java.net.URL)2 Flickr (com.flickr4java.flickr.Flickr)1 REST (com.flickr4java.flickr.REST)1 RequestContext (com.flickr4java.flickr.RequestContext)1 Auth (com.flickr4java.flickr.auth.Auth)1 PhotoList (com.flickr4java.flickr.photos.PhotoList)1 PhotosInterface (com.flickr4java.flickr.photos.PhotosInterface)1 Photosets (com.flickr4java.flickr.photosets.Photosets)1 PhotosetsInterface (com.flickr4java.flickr.photosets.PhotosetsInterface)1 UploadMetaData (com.flickr4java.flickr.uploader.UploadMetaData)1