Search in sources :

Example 6 with IdOnlyContainerResource

use of org.datatransferproject.types.common.models.IdOnlyContainerResource in project data-transfer-project by google.

the class MicrosoftPhotosExporterTest method exportPhotoWithoutNextPage.

@Test
public void exportPhotoWithoutNextPage() throws IOException {
    // Setup
    when(driveItemsResponse.getNextPageLink()).thenReturn(null);
    MicrosoftDriveItem photoItem = setUpSinglePhoto(IMAGE_URI, PHOTO_ID);
    when(driveItemsResponse.getDriveItems()).thenReturn(new MicrosoftDriveItem[] { photoItem });
    when(driveItemsResponse.getNextPageLink()).thenReturn(null);
    StringPaginationToken inputPaginationToken = new StringPaginationToken(DRIVE_TOKEN_PREFIX + DRIVE_PAGE_URL);
    IdOnlyContainerResource idOnlyContainerResource = new IdOnlyContainerResource(FOLDER_ID);
    // Run
    ExportResult<PhotosContainerResource> result = microsoftPhotosExporter.exportOneDrivePhotos(null, Optional.of(idOnlyContainerResource), Optional.of(inputPaginationToken), uuid);
    // Verify method calls
    verify(photosInterface).getDriveItems(Optional.of(FOLDER_ID), Optional.of(DRIVE_PAGE_URL));
    verify(driveItemsResponse).getDriveItems();
    // Verify next pagination token is absent
    ContinuationData continuationData = result.getContinuationData();
    StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
    assertThat(paginationToken).isEqualTo(null);
    // Verify no albums are exported
    Collection<PhotoAlbum> actualAlbums = result.getExportedData().getAlbums();
    assertThat(actualAlbums).isEmpty();
    // Verify one photo (in an album) should be exported
    Collection<PhotoModel> actualPhotos = result.getExportedData().getPhotos();
    assertThat(actualPhotos.stream().map(PhotoModel::getFetchableUrl).collect(Collectors.toList())).containsExactly(IMAGE_URI);
    assertThat(actualPhotos.stream().map(PhotoModel::getAlbumId).collect(Collectors.toList())).containsExactly(FOLDER_ID);
    assertThat(actualPhotos.stream().map(PhotoModel::getTitle).collect(Collectors.toList())).containsExactly(FILENAME);
    // Verify there are no containers ready for sub-processing
    List<ContainerResource> actualResources = continuationData.getContainerResources();
    assertThat(actualResources).isEmpty();
}
Also used : PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) ContainerResource(org.datatransferproject.types.common.models.ContainerResource) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) Test(org.junit.Test)

Example 7 with IdOnlyContainerResource

use of org.datatransferproject.types.common.models.IdOnlyContainerResource 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 8 with IdOnlyContainerResource

use of org.datatransferproject.types.common.models.IdOnlyContainerResource in project data-transfer-project by google.

the class RememberTheMilkTasksExporter method exportTaskList.

private ExportResult exportTaskList(RememberTheMilkService service) {
    List<TaskListModel> lists = new ArrayList<>();
    List<IdOnlyContainerResource> subResources = new ArrayList<>();
    List<ListInfo> listInfoList;
    try {
        listInfoList = service.getLists().lists;
    } catch (IOException e) {
        return new ExportResult(e);
    }
    for (ListInfo oldListInfo : listInfoList) {
        if (oldListInfo.name.equals("All Tasks")) {
            // All Tasks is a special list that contains everything, don't copy that over
            continue;
        }
        lists.add(new TaskListModel(Integer.toString(oldListInfo.id), oldListInfo.name));
        subResources.add(new IdOnlyContainerResource(Integer.toString(oldListInfo.id)));
    }
    TaskContainerResource taskContainerResource = new TaskContainerResource(lists, null);
    ContinuationData continuationData = new ContinuationData(null);
    subResources.forEach(continuationData::addContainerResource);
    // TODO: what do we do with pagination data?
    return new ExportResult(ResultType.CONTINUE, taskContainerResource, continuationData);
}
Also used : ListInfo(org.datatransferproject.transfer.rememberthemilk.model.tasks.ListInfo) ArrayList(java.util.ArrayList) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) IOException(java.io.IOException) TaskContainerResource(org.datatransferproject.types.common.models.tasks.TaskContainerResource) TaskListModel(org.datatransferproject.types.common.models.tasks.TaskListModel) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Example 9 with IdOnlyContainerResource

use of org.datatransferproject.types.common.models.IdOnlyContainerResource in project data-transfer-project by google.

the class SmugMugPhotosExporter method export.

@Override
public ExportResult<PhotosContainerResource> export(UUID jobId, TokenSecretAuthData authData, Optional<ExportInformation> exportInformation) throws IOException {
    StringPaginationToken paginationToken = exportInformation.isPresent() ? (StringPaginationToken) exportInformation.get().getPaginationData() : null;
    IdOnlyContainerResource resource = exportInformation.isPresent() ? (IdOnlyContainerResource) exportInformation.get().getContainerResource() : null;
    SmugMugInterface smugMugInterface;
    try {
        smugMugInterface = getOrCreateSmugMugInterface(authData);
    } catch (IOException e) {
        monitor.severe(() -> "Unable to create Smugmug service for user", e);
        throw e;
    }
    if (resource != null) {
        return exportPhotos(resource, paginationToken, smugMugInterface, jobId);
    } else {
        return exportAlbums(paginationToken, smugMugInterface);
    }
}
Also used : IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) IOException(java.io.IOException) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken)

Example 10 with IdOnlyContainerResource

use of org.datatransferproject.types.common.models.IdOnlyContainerResource in project data-transfer-project by google.

the class GoogleCalendarExporterTest method exportEventFirstSet.

@Test
public void exportEventFirstSet() throws IOException {
    setUpSingleEventResponse();
    // Looking at first page, with at least one page after it
    ContainerResource containerResource = new IdOnlyContainerResource(CALENDAR_ID);
    ExportInformation exportInformation = new ExportInformation(null, containerResource);
    eventListResponse.setNextPageToken(NEXT_TOKEN);
    // Run test
    ExportResult<CalendarContainerResource> result = googleCalendarExporter.export(UUID.randomUUID(), null, Optional.of(exportInformation));
    // Check results
    // Verify correct methods were called
    verify(calendarEvents).list(CALENDAR_ID);
    verify(eventListRequest).setMaxAttendees(MAX_ATTENDEES);
    verify(eventListRequest).execute();
    // Check events
    Collection<CalendarEventModel> actualEvents = result.getExportedData().getEvents();
    assertThat(actualEvents.stream().map(CalendarEventModel::getCalendarId).collect(Collectors.toList())).containsExactly(CALENDAR_ID);
    assertThat(actualEvents.stream().map(CalendarEventModel::getTitle).collect(Collectors.toList())).containsExactly(EVENT_DESCRIPTION);
    // Check pagination token
    ContinuationData continuationData = (ContinuationData) result.getContinuationData();
    StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
    assertThat(paginationToken.getToken()).isEqualTo(EVENT_TOKEN_PREFIX + NEXT_TOKEN);
}
Also used : ExportInformation(org.datatransferproject.types.common.ExportInformation) CalendarContainerResource(org.datatransferproject.types.common.models.calendar.CalendarContainerResource) ContainerResource(org.datatransferproject.types.common.models.ContainerResource) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) CalendarEventModel(org.datatransferproject.types.common.models.calendar.CalendarEventModel) CalendarContainerResource(org.datatransferproject.types.common.models.calendar.CalendarContainerResource) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) Test(org.junit.Test)

Aggregations

IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)43 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)29 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)27 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)23 Test (org.junit.Test)21 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)20 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)18 PaginationData (org.datatransferproject.types.common.PaginationData)17 ArrayList (java.util.ArrayList)12 ExportInformation (org.datatransferproject.types.common.ExportInformation)12 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)12 IOException (java.io.IOException)11 ContainerResource (org.datatransferproject.types.common.models.ContainerResource)10 ImmutableList (com.google.common.collect.ImmutableList)7 List (java.util.List)7 Optional (java.util.Optional)7 UUID (java.util.UUID)7 Collectors (java.util.stream.Collectors)7 ResultType (org.datatransferproject.spi.transfer.provider.ExportResult.ResultType)7 IntPaginationToken (org.datatransferproject.types.common.IntPaginationToken)7