use of com.flickr4java.flickr.photos.PhotoList in project data-transfer-project by google.
the class FlickrPhotosExporter method getPhotos.
private ExportResult<PhotosContainerResource> getPhotos(IdOnlyContainerResource resource, PaginationData paginationData) {
String photoSetId = resource.getId();
int page = paginationData == null ? 1 : ((IntPaginationToken) paginationData).getStart();
PhotoList<Photo> photoSetList;
try {
if (photoSetId == null) {
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);
}
} catch (FlickrException e) {
return new ExportResult<>(ResultType.ERROR, "Error exporting Flickr photo: " + e.getErrorMessage());
}
boolean hasMore = photoSetList.getPage() != photoSetList.getPages() && !photoSetList.isEmpty();
Collection<PhotoModel> photos = photoSetList.stream().map(p -> toCommonPhoto(p, photoSetId)).collect(Collectors.toList());
PaginationData newPage = null;
if (hasMore) {
newPage = new IntPaginationToken(page + 1);
}
// Get result type
ResultType resultType = ResultType.CONTINUE;
if (newPage == null) {
resultType = ResultType.END;
}
PhotosContainerResource photosContainerResource = new PhotosContainerResource(null, photos);
return new ExportResult<>(resultType, photosContainerResource, new ContinuationData(newPage));
}
use of com.flickr4java.flickr.photos.PhotoList in project data-transfer-project by google.
the class FlickrPhotosExporterTest method exportPhotosFromPhotoset.
@Test
public void exportPhotosFromPhotoset() throws FlickrException {
// set up auth, flickr service
when(user.getId()).thenReturn("userId");
when(authInterface.checkToken(any(Token.class))).thenReturn(auth);
when(flickr.getPhotosetsInterface()).thenReturn(photosetsInterface);
when(flickr.getPhotosInterface()).thenReturn(photosInterface);
when(flickr.getAuthInterface()).thenReturn(authInterface);
// getting photos from a set with id photosetsId and page 1
int page = 1;
String photosetsId = "photosetsId";
ExportInformation exportInformation = new ExportInformation(null, new IdOnlyContainerResource(photosetsId));
// make lots of photos and add them to PhotoList (also adding pagination information)
int numPhotos = 4;
PhotoList<Photo> photosList = new PhotoList<>();
for (int i = 0; i < numPhotos; i++) {
photosList.add(FlickrTestUtils.initializePhoto("title" + 1, "url" + i, "description" + i, MEDIA_TYPE));
}
photosList.setPage(page);
photosList.setPages(page + 1);
when(photosetsInterface.getPhotos(anyString(), anySet(), anyInt(), anyInt(), anyInt())).thenReturn(photosList);
// run test
FlickrPhotosExporter exporter = new FlickrPhotosExporter(flickr);
ExportResult<PhotosContainerResource> result = exporter.export(UUID.randomUUID(), new TokenSecretAuthData("token", "secret"), exportInformation);
assertThat(result.getExportedData().getPhotos().size()).isEqualTo(numPhotos);
assertThat(result.getExportedData().getAlbums()).isEmpty();
ContinuationData continuationData = (ContinuationData) result.getContinuationData();
assertThat(continuationData.getContainerResources()).isEmpty();
assertThat(((IntPaginationToken) continuationData.getPaginationData()).getStart()).isEqualTo(page + 1);
}
use of com.flickr4java.flickr.photos.PhotoList 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 com.flickr4java.flickr.photos.PhotoList in project data-transfer-project by google.
the class FlickrPhotoServiceTest method exportPhotosFromPhotoset.
@Test
public void exportPhotosFromPhotoset() throws FlickrException, IOException {
// Situation: getting photos from a set with id photosetsId and page 1
int page = 1;
String photosetsId = "photosetsId";
ExportInformation exportInformation = new ExportInformation(Optional.of(new IdOnlyResource(photosetsId)), Optional.empty());
// Make a bunch of photos, add them to PhotoList, and add pagination information
int numPhotos = 4;
PhotoList<Photo> listOfPhotos = new PhotoList<>();
for (int i = 0; i < numPhotos; i++) {
Photo photo = initializePhoto("title" + i, "url" + i, "description" + i);
listOfPhotos.add(photo);
}
listOfPhotos.setPage(page);
listOfPhotos.setPages(page + 1);
when(photosetsInterface.getPhotos(anyString(), anySet(), anyInt(), anyInt(), anyInt())).thenReturn(listOfPhotos);
// Run test
PhotosModelWrapper result = photoService.export(exportInformation);
assertThat(result.getPhotos().size()).isEqualTo(numPhotos);
assertThat(result.getAlbums()).isEmpty();
assertThat(result.getContinuationInformation().getSubResources()).isEmpty();
assertThat(result.getContinuationInformation().getPaginationInformation()).isEqualTo(new FlickrPaginationInformation(page + 1));
}
use of com.flickr4java.flickr.photos.PhotoList 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;
}
Aggregations