use of org.datatransferproject.datatransfer.google.mediaModels.GoogleAlbum in project data-transfer-project by google.
the class GooglePhotosImporterTest method retrieveAlbumStringOnlyOnce.
@Test
public void retrieveAlbumStringOnlyOnce() throws PermissionDeniedException, InvalidTokenException, IOException {
String albumId = "Album Id";
String albumName = "Album Name";
String albumDescription = "Album Description";
PhotoAlbum albumModel = new PhotoAlbum(albumId, albumName, albumDescription);
PortabilityJob portabilityJob = Mockito.mock(PortabilityJob.class);
Mockito.when(portabilityJob.userLocale()).thenReturn("it");
JobStore jobStore = Mockito.mock(JobStore.class);
Mockito.when(jobStore.findJob(uuid)).thenReturn(portabilityJob);
GoogleAlbum responseAlbum = new GoogleAlbum();
responseAlbum.setId(NEW_ALBUM_ID);
Mockito.when(googlePhotosInterface.createAlbum(any(GoogleAlbum.class))).thenReturn(responseAlbum);
GooglePhotosImporter sut = new GooglePhotosImporter(null, jobStore, null, null, googlePhotosInterface, imageStreamProvider, monitor, 1.0);
sut.importSingleAlbum(uuid, null, albumModel);
sut.importSingleAlbum(uuid, null, albumModel);
Mockito.verify(jobStore, atMostOnce()).findJob(uuid);
}
use of org.datatransferproject.datatransfer.google.mediaModels.GoogleAlbum in project data-transfer-project by google.
the class GooglePhotosImporterTest method importAlbumWithITString.
@Test
public void importAlbumWithITString() throws PermissionDeniedException, InvalidTokenException, IOException {
String albumId = "Album Id";
String albumName = "Album Name";
String albumDescription = "Album Description";
PhotoAlbum albumModel = new PhotoAlbum(albumId, albumName, albumDescription);
PortabilityJob portabilityJob = Mockito.mock(PortabilityJob.class);
Mockito.when(portabilityJob.userLocale()).thenReturn("it");
JobStore jobStore = Mockito.mock(JobStore.class);
Mockito.when(jobStore.findJob(uuid)).thenReturn(portabilityJob);
GoogleAlbum responseAlbum = new GoogleAlbum();
responseAlbum.setId(NEW_ALBUM_ID);
Mockito.when(googlePhotosInterface.createAlbum(any(GoogleAlbum.class))).thenReturn(responseAlbum);
GooglePhotosImporter sut = new GooglePhotosImporter(null, jobStore, null, null, googlePhotosInterface, imageStreamProvider, monitor, 1.0);
sut.importSingleAlbum(uuid, null, albumModel);
ArgumentCaptor<GoogleAlbum> albumArgumentCaptor = ArgumentCaptor.forClass(GoogleAlbum.class);
Mockito.verify(googlePhotosInterface).createAlbum(albumArgumentCaptor.capture());
assertEquals(albumArgumentCaptor.getValue().getTitle(), albumName);
}
use of org.datatransferproject.datatransfer.google.mediaModels.GoogleAlbum in project data-transfer-project by google.
the class GooglePhotosExporter method exportAlbums.
/**
* Note: not all accounts have albums to return. In that case, we just return an empty list of
* albums instead of trying to iterate through a null list.
*/
@VisibleForTesting
ExportResult<PhotosContainerResource> exportAlbums(TokensAndUrlAuthData authData, Optional<PaginationData> paginationData, UUID jobId) throws IOException, InvalidTokenException, PermissionDeniedException {
Optional<String> paginationToken = Optional.empty();
if (paginationData.isPresent()) {
String token = ((StringPaginationToken) paginationData.get()).getToken();
Preconditions.checkArgument(token.startsWith(ALBUM_TOKEN_PREFIX), "Invalid pagination token " + token);
paginationToken = Optional.of(token.substring(ALBUM_TOKEN_PREFIX.length()));
}
AlbumListResponse albumListResponse;
albumListResponse = getOrCreatePhotosInterface(authData).listAlbums(paginationToken);
PaginationData nextPageData;
String token = albumListResponse.getNextPageToken();
List<PhotoAlbum> albums = new ArrayList<>();
GoogleAlbum[] googleAlbums = albumListResponse.getAlbums();
if (Strings.isNullOrEmpty(token)) {
nextPageData = new StringPaginationToken(PHOTO_TOKEN_PREFIX);
} else {
nextPageData = new StringPaginationToken(ALBUM_TOKEN_PREFIX + token);
}
ContinuationData continuationData = new ContinuationData(nextPageData);
if (googleAlbums != null && googleAlbums.length > 0) {
for (GoogleAlbum googleAlbum : googleAlbums) {
// Add album info to list so album can be recreated later
PhotoAlbum photoAlbum = new PhotoAlbum(googleAlbum.getId(), googleAlbum.getTitle(), null);
albums.add(photoAlbum);
monitor.debug(() -> String.format("%s: Google Photos exporting album: %s", jobId, photoAlbum.getId()));
// Add album id to continuation data
continuationData.addContainerResource(new IdOnlyContainerResource(googleAlbum.getId()));
}
}
ResultType resultType = ResultType.CONTINUE;
PhotosContainerResource containerResource = new PhotosContainerResource(albums, null);
return new ExportResult<>(resultType, containerResource, continuationData);
}
use of org.datatransferproject.datatransfer.google.mediaModels.GoogleAlbum in project data-transfer-project by google.
the class GooglePhotosImporter method importSingleAlbum.
@VisibleForTesting
String importSingleAlbum(UUID jobId, TokensAndUrlAuthData authData, PhotoAlbum inputAlbum) throws IOException, InvalidTokenException, PermissionDeniedException {
// Set up album
GoogleAlbum googleAlbum = new GoogleAlbum();
String title = Strings.nullToEmpty(inputAlbum.getName());
// https://developers.google.com/photos/library/guides/manage-albums#creating-new-album
if (title.length() > 500) {
title = title.substring(0, 497) + "...";
}
googleAlbum.setTitle(title);
GoogleAlbum responseAlbum = getOrCreatePhotosInterface(jobId, authData).createAlbum(googleAlbum);
return responseAlbum.getId();
}
use of org.datatransferproject.datatransfer.google.mediaModels.GoogleAlbum in project data-transfer-project by google.
the class GooglePhotosExporterTest method setUpSingleAlbum.
/**
* Sets up a response with a single album, containing a single photo
*/
private void setUpSingleAlbum() {
GoogleAlbum albumEntry = new GoogleAlbum();
albumEntry.setId(ALBUM_ID);
albumEntry.setTitle("Title");
when(albumListResponse.getAlbums()).thenReturn(new GoogleAlbum[] { albumEntry });
}
Aggregations