return new PhotosContainerResource(albums, photoModels);
if (Strings.isNullOrEmpty(token)) { return new ExportResult<>( ExportResult.ResultType.END, new PhotosContainerResource(null, exportPhotos)); } else { PaginationData nextPageData = new StringPaginationToken(PHOTO_TOKEN_PREFIX + token); return new ExportResult<>( ExportResult.ResultType.CONTINUE, new PhotosContainerResource(null, exportPhotos), continuationData);
private ExportResult<PhotosContainerResource> exportPhotos(TokensAndUrlAuthData authData, Optional<PaginationData> pageData) { Preconditions.checkNotNull(authData); MediaResponse response; try { response = makeRequest(MEDIA_URL, MediaResponse.class, authData); } catch (IOException e) { return new ExportResult<>(e); } List<PhotoModel> photos = new ArrayList<>(); // TODO: check out paging. for (MediaFeedData photo : response.getData()) { // TODO json mapping is broken. String photoId = photo.getId(); String url = photo.getImages().getStandardResolution().getUrl(); String text = (photo.getCaption() != null) ? photo.getCaption().getText() : null; photos.add(new PhotoModel("Instagram photo: " + photoId, url, text, null, null, FAKE_ALBUM_ID, false)); } List<PhotoAlbum> albums = new ArrayList<>(); if (!photos.isEmpty() && !pageData.isPresent()) { albums.add( new PhotoAlbum( FAKE_ALBUM_ID, "Imported Instagram Photos", "Photos imported from instagram")); } return new ExportResult<>(ResultType.END, new PhotosContainerResource(albums, photos)); }
PhotosContainerResource containerResource = new PhotosContainerResource(albums, null); ExportResult<PhotosContainerResource> exportResult = new ExportResult<>(resultType, containerResource, continuationData);
@VisibleForTesting ExportResult<PhotosContainerResource> exportPhotos(TokensAndUrlAuthData authData, Optional<IdOnlyContainerResource> albumData, Optional<PaginationData> paginationData, UUID jobId) throws IOException { Optional<String> albumId = Optional.empty(); if (albumData.isPresent()) { albumId = Optional.of(albumData.get().getId()); } Optional<String> paginationToken = getPhotosPaginationToken(paginationData); MediaItemSearchResponse mediaItemSearchResponse = getOrCreatePhotosInterface(authData) .listMediaItems(albumId, paginationToken); PaginationData nextPageData = null; if (!Strings.isNullOrEmpty(mediaItemSearchResponse.getNextPageToken())) { nextPageData = new StringPaginationToken( PHOTO_TOKEN_PREFIX + mediaItemSearchResponse.getNextPageToken()); } ContinuationData continuationData = new ContinuationData(nextPageData); PhotosContainerResource containerResource = null; GoogleMediaItem[] mediaItems = mediaItemSearchResponse.getMediaItems(); if (mediaItems != null && mediaItems.length > 0) { List<PhotoModel> photos = convertPhotosList(albumId, mediaItems, jobId); containerResource = new PhotosContainerResource(null, photos); } ResultType resultType = ResultType.CONTINUE; if (nextPageData == null) { resultType = ResultType.END; } return new ExportResult<>(resultType, containerResource, continuationData); }
private ExportResult<PhotosContainerResource> exportAlbums( TokensAndUrlAuthData authData, Optional<StringPaginationToken> paginationData) { Optional<String> paginationToken = stripTokenPrefix(paginationData, ALBUM_TOKEN_PREFIX); ArrayList<PhotoAlbum> exportAlbums = new ArrayList<>(); // Get albums Connection<Album> connection = getOrCreatePhotosInterface(authData).getAlbums(paginationToken); PaginationData nextPageData = null; String token = connection.getAfterCursor(); if (!Strings.isNullOrEmpty(token)) { nextPageData = new StringPaginationToken(ALBUM_TOKEN_PREFIX + token); } ContinuationData continuationData = new ContinuationData(nextPageData); List<Album> albums = connection.getData(); for (Album album : albums) { exportAlbums.add(new PhotoAlbum(album.getId(), album.getName(), album.getDescription())); continuationData.addContainerResource(new IdOnlyContainerResource(album.getId())); } return new ExportResult<>( ExportResult.ResultType.CONTINUE, new PhotosContainerResource(exportAlbums, null), continuationData); }
new PhotosContainerResource(albumBuilder.build(), null); ContinuationData continuationData = new ContinuationData(newPage); subResources.forEach(resource -> continuationData.addContainerResource(resource));
PhotosContainerResource resource = new PhotosContainerResource(albumsList, null);
PhotosContainerResource photosContainerResource = new PhotosContainerResource(null, photos); return new ExportResult<>(resultType, photosContainerResource, new ContinuationData(newPage));
return new ExportResult<>( moreData ? ResultType.CONTINUE : ResultType.END, new PhotosContainerResource(null, photos), moreData ? new ContinuationData(new IntPaginationToken(pageNumber + 1)) : null); } catch (TwitterException e) {
@Test public void verifySerializeDeserialize() throws Exception { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerSubtypes(PhotosContainerResource.class); List<PhotoAlbum> albums = ImmutableList.of(new PhotoAlbum("id1", "albumb1", "This is a fake albumb")); List<PhotoModel> photos = ImmutableList.of( new PhotoModel("Pic1", "http://fake.com/1.jpg", "A pic", "image/jpg", "p1", "id1", false), new PhotoModel( "Pic2", "https://fake.com/pic.png", "fine art", "image/png", "p2", "id1", false)); ContainerResource data = new PhotosContainerResource(albums, photos); String serialized = objectMapper.writeValueAsString(data); ContainerResource deserializedModel = objectMapper.readValue(serialized, ContainerResource.class); Truth.assertThat(deserializedModel).isNotNull(); Truth.assertThat(deserializedModel).isInstanceOf(PhotosContainerResource.class); PhotosContainerResource deserialized = (PhotosContainerResource) deserializedModel; Truth.assertThat(deserialized.getAlbums()).hasSize(1); Truth.assertThat(deserialized.getPhotos()).hasSize(2); } }
new PhotosContainerResource( Collections.singletonList(PHOTO_ALBUM), Collections.singletonList(PHOTO_MODEL));
PhotosContainerResource resource = new PhotosContainerResource(null, photoList);
@Test public void testSpecifiedAlbums() { ExportResult<PhotosContainerResource> result = facebookPhotosExporter.export( uuid, new TokensAndUrlAuthData("accessToken", null, null), Optional.of( new ExportInformation( new StringPaginationToken(PHOTO_TOKEN_PREFIX), new PhotosContainerResource( Lists.newArrayList(new PhotoAlbum(ALBUM_ID, ALBUM_NAME, ALBUM_DESCRIPTION)), new ArrayList<>())))); assertEquals(ExportResult.ResultType.CONTINUE, result.getType()); PhotosContainerResource exportedData = result.getExportedData(); assertEquals(1, exportedData.getAlbums().size()); assertEquals( new PhotoAlbum(ALBUM_ID, ALBUM_NAME, ALBUM_DESCRIPTION), exportedData.getAlbums().toArray()[0]); assertNull((result.getContinuationData().getPaginationData())); assertThat(result.getContinuationData().getContainerResources()) .contains(new IdOnlyContainerResource(ALBUM_ID)); }
new ExportInformation( null, new PhotosContainerResource( Lists.newArrayList( new PhotoAlbum("album_id", "album name", "album description")),