Search in sources :

Example 11 with PhotoAlbum

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;
}
Also used : PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum)

Example 12 with PhotoAlbum

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);
}
Also used : MicrosoftDriveItem(org.datatransferproject.transfer.microsoft.driveModels.MicrosoftDriveItem) PaginationData(org.datatransferproject.types.common.PaginationData) MicrosoftDriveItemsResponse(org.datatransferproject.transfer.microsoft.driveModels.MicrosoftDriveItemsResponse) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) ArrayList(java.util.ArrayList) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 13 with PhotoAlbum

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);
}
Also used : ExportInformation(org.datatransferproject.types.common.ExportInformation) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) Instant(java.time.Instant) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 14 with PhotoAlbum

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);
}
Also used : PortabilityJob(org.datatransferproject.spi.cloud.types.PortabilityJob) LocalJobStore(org.datatransferproject.cloud.local.LocalJobStore) JobStore(org.datatransferproject.spi.cloud.storage.JobStore) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) GoogleAlbum(org.datatransferproject.datatransfer.google.mediaModels.GoogleAlbum) Test(org.junit.Test)

Example 15 with PhotoAlbum

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);
}
Also used : PortabilityJob(org.datatransferproject.spi.cloud.types.PortabilityJob) LocalJobStore(org.datatransferproject.cloud.local.LocalJobStore) JobStore(org.datatransferproject.spi.cloud.storage.JobStore) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) GoogleAlbum(org.datatransferproject.datatransfer.google.mediaModels.GoogleAlbum) Test(org.junit.Test)

Aggregations

PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)45 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)36 Test (org.junit.Test)27 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)23 IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)19 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)18 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)15 ArrayList (java.util.ArrayList)12 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)12 UUID (java.util.UUID)11 IOException (java.io.IOException)8 PaginationData (org.datatransferproject.types.common.PaginationData)7 GoogleAlbum (org.datatransferproject.datatransfer.google.mediaModels.GoogleAlbum)6 ImportResult (org.datatransferproject.spi.transfer.provider.ImportResult)6 ContainerResource (org.datatransferproject.types.common.models.ContainerResource)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 InputStreamWrapper (org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore.InputStreamWrapper)5 PortabilityJob (org.datatransferproject.spi.cloud.types.PortabilityJob)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)4