use of org.datatransferproject.types.common.models.photos.PhotoModel in project data-transfer-project by google.
the class FlickrPhotosExporterTest method toCommonPhoto.
@Test
public void toCommonPhoto() {
Photo photo = FlickrTestUtils.initializePhoto(PHOTO_TITLE, FETCHABLE_URL, PHOTO_DESCRIPTION, MEDIA_TYPE);
PhotoModel photoModel = FlickrPhotosExporter.toCommonPhoto(photo, ALBUM_ID);
assertThat(photoModel.getAlbumId()).isEqualTo(ALBUM_ID);
assertThat(photoModel.getFetchableUrl()).isEqualTo(FETCHABLE_URL);
assertThat(photoModel.getTitle()).isEqualTo(PHOTO_TITLE);
assertThat(photoModel.getDescription()).isEqualTo(PHOTO_DESCRIPTION);
assertThat(photoModel.getMediaType()).isEqualTo("image/jpeg");
}
use of org.datatransferproject.types.common.models.photos.PhotoModel in project data-transfer-project by google.
the class GooglePhotosExporter method convertPhotosList.
private List<PhotoModel> convertPhotosList(Optional<String> albumId, GoogleMediaItem[] mediaItems, UUID jobId) throws IOException {
List<PhotoModel> photos = new ArrayList<>(mediaItems.length);
TempPhotosData tempPhotosData = null;
InputStream stream = jobStore.getStream(jobId, createCacheKey()).getStream();
if (stream != null) {
tempPhotosData = new ObjectMapper().readValue(stream, TempPhotosData.class);
stream.close();
}
for (GoogleMediaItem mediaItem : mediaItems) {
if (mediaItem.getMediaMetadata().getPhoto() != null) {
// TODO: address videos
boolean shouldUpload = albumId.isPresent();
if (tempPhotosData != null) {
shouldUpload = shouldUpload || !tempPhotosData.isContainedPhotoId(mediaItem.getId());
}
if (shouldUpload) {
PhotoModel photoModel = convertToPhotoModel(albumId, mediaItem);
photos.add(photoModel);
monitor.debug(() -> String.format("%s: Google exporting photo: %s", jobId, photoModel.getDataId()));
}
}
}
return photos;
}
use of org.datatransferproject.types.common.models.photos.PhotoModel in project data-transfer-project by google.
the class GooglePhotosExporterTest method exportAlbumFirstSet.
@Test
public void exportAlbumFirstSet() throws IOException, InvalidTokenException, PermissionDeniedException {
setUpSingleAlbum();
when(albumListResponse.getNextPageToken()).thenReturn(ALBUM_TOKEN);
// Run test
ExportResult<PhotosContainerResource> result = googlePhotosExporter.exportAlbums(null, Optional.empty(), uuid);
// Check results
// Verify correct methods were called
verify(photosInterface).listAlbums(Optional.empty());
verify(albumListResponse).getAlbums();
// Check pagination token
ContinuationData continuationData = result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken.getToken()).isEqualTo(ALBUM_TOKEN_PREFIX + ALBUM_TOKEN);
// Check albums field of container
Collection<PhotoAlbum> actualAlbums = result.getExportedData().getAlbums();
assertThat(actualAlbums.stream().map(PhotoAlbum::getId).collect(Collectors.toList())).containsExactly(ALBUM_ID);
// Check photos field of container (should be empty, even though there is a photo in the
// original album)
Collection<PhotoModel> actualPhotos = result.getExportedData().getPhotos();
assertThat(actualPhotos).isEmpty();
// Should be one container in the resource list
List<ContainerResource> actualResources = continuationData.getContainerResources();
assertThat(actualResources.stream().map(a -> ((IdOnlyContainerResource) a).getId()).collect(Collectors.toList())).containsExactly(ALBUM_ID);
}
use of org.datatransferproject.types.common.models.photos.PhotoModel in project data-transfer-project by google.
the class KoofrPhotosImporter method importItem.
@Override
public ImportResult importItem(UUID jobId, IdempotentImportExecutor idempotentImportExecutor, TokensAndUrlAuthData authData, PhotosContainerResource resource) throws Exception {
KoofrClient koofrClient = koofrClientFactory.create(authData);
monitor.debug(() -> String.format("%s: Importing %s albums and %s photos before transmogrification", jobId, resource.getAlbums().size(), resource.getPhotos().size()));
// Make the data Koofr compatible
resource.transmogrify(transmogrificationConfig);
monitor.debug(() -> String.format("%s: Importing %s albums and %s photos after transmogrification", jobId, resource.getAlbums().size(), resource.getPhotos().size()));
for (PhotoAlbum album : resource.getAlbums()) {
// Create a Koofr folder and then save the id with the mapping data
idempotentImportExecutor.executeAndSwallowIOExceptions(album.getId(), album.getName(), () -> createAlbumFolder(album, koofrClient));
}
for (PhotoModel photoModel : resource.getPhotos()) {
idempotentImportExecutor.executeAndSwallowIOExceptions(IdempotentImportExecutorHelper.getPhotoIdempotentId(photoModel), photoModel.getTitle(), () -> importSinglePhoto(photoModel, jobId, idempotentImportExecutor, koofrClient));
}
return ImportResult.OK;
}
use of org.datatransferproject.types.common.models.photos.PhotoModel in project data-transfer-project by google.
the class KoofrPhotosExporterTest method testExport.
@Test
public void testExport() throws Exception {
when(client.getRootPath()).thenReturn("/Data transfer");
when(client.listRecursive("/Data transfer")).thenReturn(Fixtures.listRecursiveItems);
when(client.fileLink("/Data transfer/Album 1/Photo 1.jpg")).thenReturn("https://app-1.koofr.net/content/files/get/Photo+1.jpg?base=TESTBASE");
when(client.fileLink("/Data transfer/Album 1/Photo 2.jpg")).thenReturn("https://app-1.koofr.net/content/files/get/Photo+2.jpg?base=TESTBASE");
when(client.fileLink("/Data transfer/Album 2 :heart:/Photo 3.jpg")).thenReturn("https://app-1.koofr.net/content/files/get/Photo+3.jpg?base=TESTBASE");
UUID jobId = UUID.randomUUID();
ExportResult<PhotosContainerResource> result = exporter.export(jobId, authData, Optional.empty());
assertEquals(ExportResult.ResultType.END, result.getType());
assertNull(result.getContinuationData());
PhotosContainerResource exportedData = result.getExportedData();
List<PhotoAlbum> expectedAlbums = ImmutableList.of(new PhotoAlbum("/Album 1", "Album 1", null), new PhotoAlbum("/Album 2 :heart:", "Album 2 ❤️", "Album 2 description ❤️"));
assertEquals(expectedAlbums, exportedData.getAlbums());
List<PhotoModel> expectedPhotos = ImmutableList.of(new PhotoModel("Photo 1.jpg", "https://app-1.koofr.net/content/files/get/Photo+1.jpg?base=TESTBASE", "Photo 1 description", "image/jpeg", "/Album 1/Photo 1.jpg", "/Album 1", false, new Date(1324824491000L)), new PhotoModel("Photo 2.jpg", "https://app-1.koofr.net/content/files/get/Photo+2.jpg?base=TESTBASE", null, "image/jpeg", "/Album 1/Photo 2.jpg", "/Album 1", false, new Date(1368774569000L)), new PhotoModel("Photo 3.jpg", "https://app-1.koofr.net/content/files/get/Photo+3.jpg?base=TESTBASE", "Photo 3 description", "image/jpeg", "/Album 2 :heart:/Photo 3.jpg", "/Album 2 :heart:", false, new Date(1489345497000L)));
assertEquals(expectedPhotos, exportedData.getPhotos());
}
Aggregations