use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.
the class SmugMugPhotosImporterTest method importEmptyAlbumName.
@Test
public void importEmptyAlbumName() throws Exception {
UUID jobId = UUID.randomUUID();
PhotoAlbum photoAlbum = new PhotoAlbum("albumid", "", "albumDescription");
PhotosContainerResource photosContainerResource = new PhotosContainerResource(Collections.singletonList(photoAlbum), ImmutableList.of());
SmugMugAlbum smugMugAlbum = new SmugMugAlbum("date", photoAlbum.getDescription(), "Untitled Album", "privacy", "albumUri1", "urlname", "weburi");
SmugMugAlbumResponse mockAlbumResponse = new SmugMugAlbumResponse(smugMugAlbum.getUri(), "Locator", "LocatorType", smugMugAlbum);
when(smugMugInterface.createAlbum(eq(smugMugAlbum.getName()))).thenReturn(mockAlbumResponse);
// Run test
SmugMugPhotosImporter importer = new SmugMugPhotosImporter(smugMugInterface, config, jobStore, new AppCredentials("key", "secret"), mock(ObjectMapper.class), monitor);
ImportResult result = importer.importItem(jobId, EXECUTOR, new TokenSecretAuthData("token", "secret"), photosContainerResource);
// Verify
verify(smugMugInterface, atLeastOnce()).createAlbum(ArgumentCaptor.forClass(String.class).capture());
}
use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.
the class SmugMugPhotosImporterTest method importStoresAlbumInJobStore.
@Test
public void importStoresAlbumInJobStore() throws Exception {
// setup test objects
UUID jobId = UUID.randomUUID();
PhotoAlbum photoAlbum1 = new PhotoAlbum("albumId1", "albumName1", "albumDescription1");
PhotoModel photoModel1 = new PhotoModel("PHOTO_TITLE", "FETCHABLE_URL", "PHOTO_DESCRIPTION", "MEDIA_TYPE", "photoId1", photoAlbum1.getId(), false);
PhotoModel photoModel2 = new PhotoModel("PHOTO_TITLE", "FETCHABLE_URL", "PHOTO_DESCRIPTION", "MEDIA_TYPE", "photoId2", photoAlbum1.getId(), false);
PhotoModel photoModel3 = new PhotoModel("PHOTO_TITLE", "FETCHABLE_URL", "PHOTO_DESCRIPTION", "MEDIA_TYPE", "photoId3", photoAlbum1.getId(), false);
PhotosContainerResource photosContainerResource1 = new PhotosContainerResource(Collections.singletonList(photoAlbum1), ImmutableList.of());
PhotosContainerResource photosContainerResource2 = new PhotosContainerResource(ImmutableList.of(), ImmutableList.of(photoModel1, photoModel2, photoModel3));
SmugMugAlbum smugMugAlbum1 = new SmugMugAlbum("date", photoAlbum1.getDescription(), photoAlbum1.getName(), "privacy", "albumUri1", "urlname", "weburi");
String overflowAlbumName = smugMugAlbum1.getName() + " (1)";
SmugMugAlbum smugMugAlbum2 = new SmugMugAlbum("date", photoAlbum1.getDescription(), overflowAlbumName, "privacy", "albumUri2", "urlname", "weburi");
SmugMugAlbumResponse mockAlbumResponse1 = new SmugMugAlbumResponse(smugMugAlbum1.getUri(), "Locator", "LocatorType", smugMugAlbum1);
SmugMugAlbumResponse mockAlbumResponse2 = new SmugMugAlbumResponse(smugMugAlbum2.getUri(), "Locator", "LocatorType", smugMugAlbum2);
when(smugMugInterface.createAlbum(eq(smugMugAlbum1.getName()))).thenReturn(mockAlbumResponse1);
when(smugMugInterface.createAlbum(eq(smugMugAlbum2.getName()))).thenReturn(mockAlbumResponse2);
SmugMugImageUploadResponse smugMugUploadImageResponse = new SmugMugImageUploadResponse("imageUri", "albumImageUri", new ImageInfo("imageUri", "albumImageUri", "statusImageReplaceUri", "url"));
when(smugMugInterface.uploadImage(any(), any(), any())).thenReturn(smugMugUploadImageResponse);
when(smugMugInterface.getImageAsStream(any())).thenReturn(bufferedInputStream);
// Run test
SmugMugPhotosImporter importer = new SmugMugPhotosImporter(smugMugInterface, config, jobStore, new AppCredentials("key", "secret"), mock(ObjectMapper.class), monitor);
ImportResult result = importer.importItem(jobId, EXECUTOR, new TokenSecretAuthData("token", "secret"), photosContainerResource1);
result = importer.importItem(jobId, EXECUTOR, new TokenSecretAuthData("token", "secret"), photosContainerResource2);
// Verify
ArgumentCaptor<String> photoUrlsCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> albumNamesCaptor = ArgumentCaptor.forClass(String.class);
verify(smugMugInterface, atLeastOnce()).createAlbum(albumNamesCaptor.capture());
verify(smugMugInterface, atLeastOnce()).getImageAsStream(photoUrlsCaptor.capture());
List<String> capturedAlbumNames = albumNamesCaptor.getAllValues();
assertTrue(capturedAlbumNames.contains(smugMugAlbum1.getName()));
assertTrue(capturedAlbumNames.contains(smugMugAlbum2.getName()));
List<String> capturedPhotoUrls = photoUrlsCaptor.getAllValues();
assertTrue(capturedPhotoUrls.contains(photoModel1.getFetchableUrl()));
assertTrue(capturedPhotoUrls.contains(photoModel2.getFetchableUrl()));
assertTrue(capturedPhotoUrls.contains(photoModel3.getFetchableUrl()));
String overflowAlbumId = photoAlbum1.getId() + "-overflow-1";
assertThat((String) EXECUTOR.getCachedValue(photoAlbum1.getId())).isEqualTo(smugMugAlbum1.getUri());
assertThat((String) EXECUTOR.getCachedValue(overflowAlbumId)).isEqualTo(smugMugAlbum2.getUri());
SmugMugPhotoTempData tempData1 = new SmugMugPhotoTempData(photoAlbum1.getId(), smugMugAlbum1.getName(), smugMugAlbum1.getDescription(), smugMugAlbum1.getUri(), 2, overflowAlbumId);
SmugMugPhotoTempData tempData2 = new SmugMugPhotoTempData(overflowAlbumId, smugMugAlbum2.getName(), smugMugAlbum2.getDescription(), smugMugAlbum2.getUri(), 1, null);
assertThat(jobStore.findData(jobId, String.format(TEMP_DATA_FORMAT, photoAlbum1.getId()), SmugMugPhotoTempData.class).toString()).isEqualTo(tempData1.toString());
assertThat(jobStore.findData(jobId, String.format(TEMP_DATA_FORMAT, overflowAlbumId), SmugMugPhotoTempData.class).toString()).isEqualTo(tempData2.toString());
}
use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.
the class SmugMugPhotosExporter method exportAlbums.
private ExportResult<PhotosContainerResource> exportAlbums(StringPaginationToken paginationData, SmugMugInterface smugMugInterface) throws IOException {
SmugMugAlbumsResponse albumsResponse;
try {
// Make request to SmugMug
String albumInfoUri = "";
if (paginationData != null) {
String pageToken = paginationData.getToken();
Preconditions.checkState(pageToken.startsWith(ALBUM_TOKEN_PREFIX), "Invalid pagination token " + pageToken);
albumInfoUri = pageToken.substring(ALBUM_TOKEN_PREFIX.length());
}
albumsResponse = smugMugInterface.getAlbums(albumInfoUri);
} catch (IOException e) {
monitor.severe(() -> "Unable to get AlbumsResponse: ", e);
throw e;
}
// Set up continuation data
StringPaginationToken paginationToken = null;
if (albumsResponse.getPageInfo() != null && albumsResponse.getPageInfo().getNextPage() != null) {
paginationToken = new StringPaginationToken(ALBUM_TOKEN_PREFIX + albumsResponse.getPageInfo().getNextPage());
}
ContinuationData continuationData = new ContinuationData(paginationToken);
// Build album list
List<PhotoAlbum> albumsList = new ArrayList<>();
if (albumsResponse.getAlbums() != null) {
for (SmugMugAlbum album : albumsResponse.getAlbums()) {
albumsList.add(new PhotoAlbum(album.getUri(), album.getName(), album.getDescription()));
continuationData.addContainerResource(new IdOnlyContainerResource(album.getUri()));
}
}
PhotosContainerResource resource = new PhotosContainerResource(albumsList, null);
// Get result type
ResultType resultType = ResultType.CONTINUE;
if (paginationToken == null) {
resultType = ResultType.END;
}
return new ExportResult<>(resultType, resource, continuationData);
}
use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.
the class SmugMugPhotosExporter method exportPhotos.
private ExportResult<PhotosContainerResource> exportPhotos(IdOnlyContainerResource containerResource, StringPaginationToken paginationData, SmugMugInterface smugMugInterface, UUID jobId) throws IOException {
List<PhotoModel> photoList = new ArrayList<>();
// Make request to SmugMug
String photoInfoUri;
if (paginationData != null) {
String token = paginationData.getToken();
Preconditions.checkState(token.startsWith(PHOTO_TOKEN_PREFIX), "Invalid pagination token " + token);
photoInfoUri = token.substring(PHOTO_TOKEN_PREFIX.length());
} else {
photoInfoUri = containerResource.getId();
}
SmugMugAlbumImageResponse albumImageList;
try {
albumImageList = smugMugInterface.getListOfAlbumImages(photoInfoUri + "!images");
} catch (IOException e) {
monitor.severe(() -> "Unable to get SmugMugAlbumImageResponse");
throw e;
}
// Set up continuation data
StringPaginationToken pageToken = null;
if (albumImageList.getPageInfo().getNextPage() != null) {
pageToken = new StringPaginationToken(PHOTO_TOKEN_PREFIX + albumImageList.getPageInfo().getNextPage());
}
ContinuationData continuationData = new ContinuationData(pageToken);
// Make list of photos - images may be empty if the album provided is empty
List<SmugMugImage> images = albumImageList.getAlbumImages() == null ? ImmutableList.of() : albumImageList.getAlbumImages();
for (SmugMugImage albumImage : images) {
if (!albumImage.isPhoto()) {
continue;
}
String title = albumImage.getTitle();
if (Strings.isNullOrEmpty(title)) {
title = albumImage.getFileName();
}
PhotoModel model = new PhotoModel(title, albumImage.getArchivedUri(), albumImage.getCaption(), getMimeType(albumImage.getFormat()), albumImage.getArchivedUri(), containerResource.getId(), true);
InputStream inputStream = smugMugInterface.getImageAsStream(model.getFetchableUrl());
jobStore.create(jobId, model.getFetchableUrl(), inputStream);
photoList.add(model);
}
PhotosContainerResource resource = new PhotosContainerResource(null, photoList);
// Get result type
ResultType resultType = ResultType.CONTINUE;
if (pageToken == null) {
resultType = ResultType.END;
}
return new ExportResult<>(resultType, resource, continuationData);
}
use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.
the class FlickrPhotosExporterTest method exportAlbumInitial.
@Test
public void exportAlbumInitial() 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);
// setup photoset
Photoset photoset = FlickrTestUtils.initializePhotoset("photosetId", "title", "description");
// setup photoset list (aka album view)
int page = 1;
Photosets photosetsList = new Photosets();
photosetsList.setPage(page);
photosetsList.setPages(page + 1);
photosetsList.setPhotosets(Collections.singletonList(photoset));
when(photosetsInterface.getList(anyString(), anyInt(), anyInt(), anyString())).thenReturn(photosetsList);
// run test
FlickrPhotosExporter exporter = new FlickrPhotosExporter(flickr, TransferServiceConfig.getDefaultInstance());
AuthData authData = new TokenSecretAuthData("token", "secret");
ExportResult<PhotosContainerResource> result = exporter.export(UUID.randomUUID(), authData, Optional.empty());
// make sure album and photo information is correct
assertThat(result.getExportedData().getPhotos()).isEmpty();
Collection<PhotoAlbum> albums = result.getExportedData().getAlbums();
assertThat(albums.size()).isEqualTo(1);
assertThat(albums).containsExactly(new PhotoAlbum("photosetId", "title", "description"));
// check continuation information
ContinuationData continuationData = (ContinuationData) result.getContinuationData();
assertThat(continuationData.getPaginationData()).isInstanceOf(IntPaginationToken.class);
assertThat(((IntPaginationToken) continuationData.getPaginationData()).getStart()).isEqualTo(page + 1);
Collection<? extends ContainerResource> subResources = continuationData.getContainerResources();
assertThat(subResources.size()).isEqualTo(1);
assertThat(subResources).containsExactly(new IdOnlyContainerResource("photosetId"));
}
Aggregations