use of org.datatransferproject.types.common.models.photos.PhotoAlbum in project data-transfer-project by google.
the class MicrosoftPhotosExporter method tryConvertDriveItemToPhotoAlbum.
private PhotoAlbum tryConvertDriveItemToPhotoAlbum(MicrosoftDriveItem driveItem, UUID jobId) {
if (driveItem.folder != null) {
PhotoAlbum photoAlbum = new PhotoAlbum(driveItem.id, driveItem.name, driveItem.description);
monitor.debug(() -> String.format("%s: Microsoft OneDrive exporting album: %s", jobId, photoAlbum));
return photoAlbum;
}
return null;
}
use of org.datatransferproject.types.common.models.photos.PhotoAlbum in project data-transfer-project by google.
the class MicrosoftPhotosExporter method exportOneDrivePhotos.
@VisibleForTesting
ExportResult<PhotosContainerResource> exportOneDrivePhotos(TokensAndUrlAuthData authData, Optional<IdOnlyContainerResource> albumData, Optional<PaginationData> paginationData, UUID jobId) throws IOException {
Optional<String> albumId = Optional.empty();
if (albumData.isPresent()) {
albumId = Optional.of(albumData.get().getId());
}
Optional<String> paginationUrl = getDrivePaginationToken(paginationData);
MicrosoftDriveItemsResponse driveItemsResponse;
if (paginationData.isPresent() || albumData.isPresent()) {
driveItemsResponse = getOrCreatePhotosInterface(authData).getDriveItems(albumId, paginationUrl);
} else {
driveItemsResponse = getOrCreatePhotosInterface(authData).getDriveItemsFromSpecialFolder(MicrosoftSpecialFolder.FolderType.photos);
}
PaginationData nextPageData = SetNextPageToken(driveItemsResponse);
ContinuationData continuationData = new ContinuationData(nextPageData);
PhotosContainerResource containerResource;
MicrosoftDriveItem[] driveItems = driveItemsResponse.getDriveItems();
List<PhotoAlbum> albums = new ArrayList<>();
List<PhotoModel> photos = new ArrayList<>();
if (driveItems != null && driveItems.length > 0) {
for (MicrosoftDriveItem driveItem : driveItems) {
PhotoAlbum album = tryConvertDriveItemToPhotoAlbum(driveItem, jobId);
if (album != null) {
albums.add(album);
continuationData.addContainerResource(new IdOnlyContainerResource(driveItem.id));
}
PhotoModel photo = tryConvertDriveItemToPhotoModel(albumId, driveItem, jobId);
if (photo != null) {
photos.add(photo);
}
}
}
ExportResult.ResultType result = nextPageData == null ? ExportResult.ResultType.END : ExportResult.ResultType.CONTINUE;
containerResource = new PhotosContainerResource(albums, photos);
return new ExportResult<>(result, containerResource, continuationData);
}
use of org.datatransferproject.types.common.models.photos.PhotoAlbum in project data-transfer-project by google.
the class PortabilityJobTest method verifySerializeDeserializeWithAlbum.
@Test
public void verifySerializeDeserializeWithAlbum() throws IOException {
ObjectMapper objectMapper = ObjectMapperFactory.createObjectMapper();
Instant date = Instant.now();
JobAuthorization jobAuthorization = JobAuthorization.builder().setState(JobAuthorization.State.INITIAL).setSessionSecretKey("foo").build();
PortabilityJob job = PortabilityJob.builder().setState(State.NEW).setExportService("fooService").setImportService("barService").setTransferDataType("PHOTOS").setExportInformation(objectMapper.writeValueAsString(new ExportInformation(null, new PhotosContainerResource(Lists.newArrayList(new PhotoAlbum("album_id", "album name", "album description")), null)))).setCreatedTimestamp(date).setLastUpdateTimestamp(date.plusSeconds(120)).setJobAuthorization(jobAuthorization).build();
String serializedJobAuthorization = objectMapper.writeValueAsString(jobAuthorization);
JobAuthorization deserializedJobAuthorization = objectMapper.readValue(serializedJobAuthorization, JobAuthorization.class);
assertThat(deserializedJobAuthorization).isEqualTo(jobAuthorization);
String serializedJob = objectMapper.writeValueAsString(job);
PortabilityJob deserializedJob = objectMapper.readValue(serializedJob, PortabilityJob.class);
assertThat(deserializedJob).isEqualTo(job);
}
use of org.datatransferproject.types.common.models.photos.PhotoAlbum 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.types.common.models.photos.PhotoAlbum 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);
}
Aggregations