use of org.datatransferproject.types.common.models.photos.PhotoModel in project data-transfer-project by google.
the class GooglePhotosExporterTest method exportPhotoFirstSet.
@Test
public void exportPhotoFirstSet() throws IOException, InvalidTokenException, PermissionDeniedException {
setUpSingleAlbum();
when(albumListResponse.getNextPageToken()).thenReturn(null);
GoogleMediaItem mediaItem = setUpSinglePhoto(IMG_URI, PHOTO_ID);
when(mediaItemSearchResponse.getMediaItems()).thenReturn(new GoogleMediaItem[] { mediaItem });
when(mediaItemSearchResponse.getNextPageToken()).thenReturn(PHOTO_TOKEN);
IdOnlyContainerResource idOnlyContainerResource = new IdOnlyContainerResource(ALBUM_ID);
ExportResult<PhotosContainerResource> result = googlePhotosExporter.exportPhotos(null, Optional.of(idOnlyContainerResource), Optional.empty(), uuid);
// Check results
// Verify correct methods were called
verify(photosInterface).listMediaItems(Optional.of(ALBUM_ID), Optional.empty());
verify(mediaItemSearchResponse).getMediaItems();
// Check pagination
ContinuationData continuationData = result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken.getToken()).isEqualTo(PHOTO_TOKEN_PREFIX + PHOTO_TOKEN);
// Check albums field of container (should be empty)
Collection<PhotoAlbum> actualAlbums = result.getExportedData().getAlbums();
assertThat(actualAlbums).isEmpty();
// Check photos field of container
Collection<PhotoModel> actualPhotos = result.getExportedData().getPhotos();
assertThat(actualPhotos.stream().map(PhotoModel::getFetchableUrl).collect(Collectors.toList())).containsExactly(// for download
IMG_URI + "=d");
assertThat(actualPhotos.stream().map(PhotoModel::getAlbumId).collect(Collectors.toList())).containsExactly(ALBUM_ID);
assertThat(actualPhotos.stream().map(PhotoModel::getTitle).collect(Collectors.toList())).containsExactly(FILENAME);
}
use of org.datatransferproject.types.common.models.photos.PhotoModel in project data-transfer-project by google.
the class ImgurPhotosExporter method requestNonAlbumPhotos.
/**
* Queries all photos for the account. Chooses photos which are not included to the collection of
* photos from albums.
*
* @param authData authentication information
* @param paginationData pagination information to use for subsequent calls.
*/
private ExportResult<PhotosContainerResource> requestNonAlbumPhotos(TokensAndUrlAuthData authData, PaginationData paginationData, UUID jobId) throws IOException {
int page = paginationData == null ? 0 : ((IntPaginationToken) paginationData).getStart();
String url = format(ALL_PHOTOS_URL_TEMPLATE, page);
Set<PhotoAlbum> albums = new HashSet<>();
List<PhotoModel> photos = new ArrayList<>();
List<Map<String, Object>> items = requestData(authData, url);
boolean hasMore = (items != null && items.size() != 0);
for (Map<String, Object> item : items) {
String photoId = (String) item.get("id");
// Select photos which are not included to the collection of retrieved album photos
if (!albumPhotos.contains(photoId)) {
PhotoModel photoModel = new PhotoModel((String) item.get("name"), (String) item.get("link"), (String) item.get("description"), (String) item.get("type"), (String) item.get("id"), DEFAULT_ALBUM_ID, true);
photos.add(photoModel);
InputStream inputStream = getImageAsStream(photoModel.getFetchableUrl());
jobStore.create(jobId, photoModel.getFetchableUrl(), inputStream);
}
}
if (!containsNonAlbumPhotos && photos.size() > 0) {
// Add album for non-album photos
albums.add(new PhotoAlbum(DEFAULT_ALBUM_ID, "Non-album photos", "Contains non-album photos"));
// Make sure album will not be added multiply times on subsequent calls
containsNonAlbumPhotos = true;
}
PaginationData newPage = null;
if (hasMore) {
newPage = new IntPaginationToken(page + 1);
monitor.info(() -> format("added non-album photos, size: %s", photos.size()));
}
PhotosContainerResource photosContainerResource = new PhotosContainerResource(albums, photos);
ContinuationData continuationData = new ContinuationData(newPage);
ExportResult.ResultType resultType = ExportResult.ResultType.CONTINUE;
if (newPage == null) {
resultType = ExportResult.ResultType.END;
}
return new ExportResult<>(resultType, photosContainerResource, continuationData);
}
use of org.datatransferproject.types.common.models.photos.PhotoModel in project data-transfer-project by google.
the class ImgurPhotosExporter method requestPhotos.
/**
* Exports photos from album.
*
* <p>This request doesn't support pages so it retrieves all photos at once for each album.
*
* @param authData authentication information
* @param resource contains album id
* @param paginationData pagination information to use for subsequent calls.
*/
private ExportResult<PhotosContainerResource> requestPhotos(TokensAndUrlAuthData authData, IdOnlyContainerResource resource, PaginationData paginationData, UUID jobId) throws IOException {
String albumId = resource.getId();
// Means all other albums with photos are imported, so non-album photos can be determined
if (albumId.equals(DEFAULT_ALBUM_ID)) {
return requestNonAlbumPhotos(authData, paginationData, jobId);
}
String url = format(ALBUM_PHOTOS_URL_TEMPLATE, albumId);
List<PhotoModel> photos = new ArrayList<>();
List<Map<String, Object>> items = requestData(authData, url);
for (Map<String, Object> item : items) {
PhotoModel photoModel = new PhotoModel((String) item.get("name"), (String) item.get("link"), (String) item.get("description"), (String) item.get("type"), (String) item.get("id"), albumId, true);
photos.add(photoModel);
InputStream inputStream = getImageAsStream(photoModel.getFetchableUrl());
jobStore.create(jobId, photoModel.getFetchableUrl(), inputStream);
// Save id of each album photo for finding non-album photos later
albumPhotos.add((String) item.get("id"));
}
// This request doesn't support pages
ExportResult.ResultType resultType = ExportResult.ResultType.END;
if (photos.size() > 0) {
monitor.info(() -> format("added albumPhotos, size: %s", photos.size()));
}
PhotosContainerResource photosContainerResource = new PhotosContainerResource(null, photos);
return new ExportResult<>(resultType, photosContainerResource, new ContinuationData(null));
}
use of org.datatransferproject.types.common.models.photos.PhotoModel in project data-transfer-project by google.
the class GooglePhotosImporterTest method importPhotoInTempStoreFailure.
@Test
public void importPhotoInTempStoreFailure() throws Exception {
PhotoModel photoModel = new PhotoModel(PHOTO_TITLE, IMG_URI, PHOTO_DESCRIPTION, JPEG_MEDIA_TYPE, "oldPhotoID1", OLD_ALBUM_ID, true);
Mockito.when(googlePhotosInterface.uploadPhotoContent(any())).thenThrow(new IOException("Unit Testing"));
JobStore jobStore = Mockito.mock(LocalJobStore.class);
Mockito.when(jobStore.getStream(any(), any())).thenReturn(new TemporaryPerJobDataStore.InputStreamWrapper(new ByteArrayInputStream("TestingBytes".getBytes())));
Mockito.doNothing().when(jobStore).removeData(any(), anyString());
GooglePhotosImporter googlePhotosImporter = new GooglePhotosImporter(null, jobStore, null, null, googlePhotosInterface, null, null, 1.0);
BatchMediaItemResponse batchMediaItemResponse = new BatchMediaItemResponse(new NewMediaItemResult[] { buildMediaItemResult("token1", Code.OK_VALUE) });
Mockito.when(googlePhotosInterface.createPhotos(any(NewMediaItemUpload.class))).thenReturn(batchMediaItemResponse);
UUID jobId = UUID.randomUUID();
googlePhotosImporter.importPhotoBatch(jobId, Mockito.mock(TokensAndUrlAuthData.class), Lists.newArrayList(photoModel), executor, NEW_ALBUM_ID);
Mockito.verify(jobStore, Mockito.times(0)).removeData(any(), anyString());
Mockito.verify(jobStore, Mockito.times(1)).getStream(any(), anyString());
}
use of org.datatransferproject.types.common.models.photos.PhotoModel in project data-transfer-project by google.
the class KoofrMediaExport method processPhoto.
protected void processPhoto(FilesFile file, String path, String albumId) {
String photoId = path;
String name = getFileName(file);
String description = getFileDescription(file);
String contentType = file.getContentType();
Date uploadedTime = new Date(file.getModified());
String fullPath = rootPath + path;
albumsWithPhotos.add(albumId);
PhotoModelContainer container = new PhotoModelContainer();
container.photoModel = new PhotoModel(name, "", description, contentType, photoId, albumId, false, uploadedTime);
container.fullPath = fullPath;
photos.add(container);
}
Aggregations