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);
}
}
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);
}
}
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));
}
Aggregations