use of org.datatransferproject.types.common.models.photos.PhotoAlbum 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.PhotoAlbum 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());
}
use of org.datatransferproject.types.common.models.photos.PhotoAlbum in project data-transfer-project by google.
the class KoofrPhotosImporterTest method testImportItemFromJobStore.
@Test
public void testImportItemFromJobStore() throws Exception {
ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4 });
when(client.ensureRootFolder()).thenReturn("/root");
when(jobStore.getStream(any(), any())).thenReturn(new InputStreamWrapper(inputStream, 5L));
doNothing().when(jobStore).removeData(any(), anyString());
when(executor.getCachedValue(eq("id1"))).thenReturn("/root/Album 1");
UUID jobId = UUID.randomUUID();
Collection<PhotoAlbum> albums = ImmutableList.of(new PhotoAlbum("id1", "Album 1", "This is a fake album"));
Collection<PhotoModel> photos = ImmutableList.of(new PhotoModel("pic1.jpg", "http://fake.com/1.jpg", "A pic", "image/jpeg", "p1", "id1", true), new PhotoModel("pic2.png", "https://fake.com/2.png", "fine art", "image/png", "p2", "id1", true));
PhotosContainerResource resource = spy(new PhotosContainerResource(albums, photos));
importer.importItem(jobId, executor, authData, resource);
InOrder clientInOrder = Mockito.inOrder(client);
verify(resource).transmogrify(any(KoofrTransmogrificationConfig.class));
clientInOrder.verify(client).ensureRootFolder();
clientInOrder.verify(client).ensureFolder("/root", "Album 1");
clientInOrder.verify(client).uploadFile(eq("/root/Album 1"), eq("pic1.jpg"), any(), eq("image/jpeg"), isNull(), eq("A pic"));
clientInOrder.verify(client).uploadFile(eq("/root/Album 1"), eq("pic2.png"), any(), eq("image/png"), isNull(), eq("fine art"));
verify(jobStore, Mockito.times(2)).removeData(any(), anyString());
}
use of org.datatransferproject.types.common.models.photos.PhotoAlbum in project data-transfer-project by google.
the class KoofrMediaExport method processAlbum.
protected void processAlbum(FilesFile file, String path) {
String albumId = path;
String albumName = getFileName(file);
String description = getFileDescription(file);
albums.add(new PhotoAlbum(albumId, albumName, description));
}
use of org.datatransferproject.types.common.models.photos.PhotoAlbum in project data-transfer-project by google.
the class KoofrTransmogrificationConfigTest method testPhotoTitleName.
@Test
public void testPhotoTitleName() {
Collection<PhotoAlbum> albums = ImmutableList.of(new PhotoAlbum("id1", "Album ~\"#%&*:<>?/\\{|}1", "This is a fake album"));
Collection<PhotoModel> photos = ImmutableList.of(new PhotoModel("pic1~\"#%&*:<>?/\\{|}.jpg", "http://fake.com/1.jpg", "A pic", "image/jpg", "p1", "id1", true), new PhotoModel("pic2~\"#%&*:<>?/\\{|}.jpg", "https://fake.com/2.png", "fine art", "image/png", "p2", "id1", true));
PhotosContainerResource container = new PhotosContainerResource(albums, photos);
KoofrTransmogrificationConfig config = new KoofrTransmogrificationConfig();
container.transmogrify(config);
PhotoAlbum[] albumsArray = container.getAlbums().toArray(new PhotoAlbum[0]);
PhotoModel[] photosArray = container.getPhotos().toArray(new PhotoModel[0]);
Assert.assertEquals(1, albumsArray.length);
Assert.assertEquals("Album _______________1", albumsArray[0].getName());
Assert.assertEquals(2, photosArray.length);
Assert.assertEquals("pic1_______________.jpg", photosArray[0].getTitle());
Assert.assertEquals("pic2_______________.jpg", photosArray[1].getTitle());
}
Aggregations