Search in sources :

Example 11 with FlickrException

use of com.flickr4java.flickr.FlickrException 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 12 with FlickrException

use of com.flickr4java.flickr.FlickrException in project osm-contributor by jawg.

the class GetFlickrPhotos method doInBackground.

@Override
protected List<List<Size>> doInBackground(Void... params) {
    // Create search tags list
    ArrayList<String> searchTags = new ArrayList<String>(TAGS);
    searchTags.add(new StringBuilder("osm:").append((featurePoi.getWay()) ? "way" : "node").append("=").append(featurePoi.getBackendId()).toString());
    SearchParameters parameters = new SearchParameters();
    parameters.setLatitude(String.valueOf(latitude));
    parameters.setLongitude(String.valueOf(longitude));
    parameters.setRadius(RADIUS);
    parameters.setTags(searchTags.toArray(new String[searchTags.size()]));
    parameters.setSort(SearchParameters.INTERESTINGNESS_DESC);
    if (!isCancelled()) {
        try {
            PhotoList<Photo> photos = flickr.getPhotosInterface().search(parameters, limitPerPage, nbPage);
            List<List<Size>> photosList = new ArrayList<>();
            for (Photo photo : photos) {
                photosList.add((List<Size>) flickr.getPhotosInterface().getSizes(photo.getId()));
            }
            return photosList;
        } catch (FlickrException e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : SearchParameters(com.flickr4java.flickr.photos.SearchParameters) FlickrException(com.flickr4java.flickr.FlickrException) Size(com.flickr4java.flickr.photos.Size) ArrayList(java.util.ArrayList) Photo(com.flickr4java.flickr.photos.Photo) ArrayList(java.util.ArrayList) List(java.util.List) PhotoList(com.flickr4java.flickr.photos.PhotoList)

Aggregations

FlickrException (com.flickr4java.flickr.FlickrException)12 IOException (java.io.IOException)7 Auth (com.flickr4java.flickr.auth.Auth)6 Photoset (com.flickr4java.flickr.photosets.Photoset)6 ArrayList (java.util.ArrayList)5 Photosets (com.flickr4java.flickr.photosets.Photosets)4 ImmutableList (com.google.common.collect.ImmutableList)4 AuthInterface (com.flickr4java.flickr.auth.AuthInterface)3 Photo (com.flickr4java.flickr.photos.Photo)3 PhotoList (com.flickr4java.flickr.photos.PhotoList)3 List (java.util.List)3 PhotoAlbum (org.dataportabilityproject.dataModels.photos.PhotoAlbum)3 IdOnlyContainerResource (org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource)3 PaginationData (org.dataportabilityproject.spi.transfer.types.PaginationData)3 PhotoAlbum (org.dataportabilityproject.types.transfer.models.photos.PhotoAlbum)3 Token (org.scribe.model.Token)3 Flickr (com.flickr4java.flickr.Flickr)2 REST (com.flickr4java.flickr.REST)2 RequestContext (com.flickr4java.flickr.RequestContext)2 PhotosInterface (com.flickr4java.flickr.photos.PhotosInterface)2