use of org.datatransferproject.types.common.models.photos.PhotoModel 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.PhotoModel in project data-transfer-project by google.
the class KoofrMediaExport method getPhotos.
public List<PhotoModel> getPhotos() throws IOException, InvalidTokenException {
ArrayList<PhotoModel> exportPhotos = new ArrayList<>();
for (PhotoModelContainer photoContainer : photos) {
PhotoModel photo = photoContainer.photoModel;
String fetchableUrl = getFetchableUrl(photoContainer.fullPath);
if (fetchableUrl == null) {
continue;
}
exportPhotos.add(new PhotoModel(photo.getTitle(), fetchableUrl, photo.getDescription(), photo.getMediaType(), photo.getDataId(), photo.getAlbumId(), photo.isInTempStore(), photo.getUploadedTime()));
}
return exportPhotos;
}
use of org.datatransferproject.types.common.models.photos.PhotoModel 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());
}
use of org.datatransferproject.types.common.models.photos.PhotoModel in project data-transfer-project by google.
the class InstagramPhotoExporter method exportPhotos.
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, photoId, 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));
}
use of org.datatransferproject.types.common.models.photos.PhotoModel in project data-transfer-project by google.
the class MediaContainerResource method ensureRootAlbum.
// Ensures that the model obeys the restrictions of the destination service, grouping all
// un-nested photos into their own root album if allowRootPhotos is true, noop otherwise
void ensureRootAlbum(boolean allowRootPhotos) {
if (allowRootPhotos) {
return;
}
MediaAlbum rootAlbum = new MediaAlbum(ROOT_ALBUM, ROOT_ALBUM, "A copy of your transferred media that were not in any album");
boolean usedRootAlbum = false;
for (PhotoModel photo : photos) {
if (photo.getAlbumId() == null) {
photo.reassignToAlbum(rootAlbum.getId());
usedRootAlbum = true;
}
}
for (VideoModel video : videos) {
if (video.getAlbumId() == null) {
video.reassignToAlbum(rootAlbum.getId());
usedRootAlbum = true;
}
}
if (usedRootAlbum) {
albums.add(rootAlbum);
}
}
Aggregations