use of org.datatransferproject.spi.transfer.provider.ExportResult in project data-transfer-project by google.
the class MicrosoftPhotosExporterTest method exportOneAlbumWithNextPage.
@Test
public void exportOneAlbumWithNextPage() throws IOException {
// Setup
MicrosoftDriveItem folderItem = setUpSingleAlbum();
when(driveItemsResponse.getDriveItems()).thenReturn(new MicrosoftDriveItem[] { folderItem });
when(driveItemsResponse.getNextPageLink()).thenReturn(DRIVE_PAGE_URL);
// Run
ExportResult<PhotosContainerResource> result = microsoftPhotosExporter.exportOneDrivePhotos(null, Optional.empty(), Optional.empty(), uuid);
// Verify method calls
verify(photosInterface).getDriveItemsFromSpecialFolder(MicrosoftSpecialFolder.FolderType.photos);
verify(driveItemsResponse).getDriveItems();
// Verify pagination token is set
ContinuationData continuationData = result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken.getToken()).isEqualTo(DRIVE_TOKEN_PREFIX + DRIVE_PAGE_URL);
// Verify one album is ready for import
Collection<PhotoAlbum> actualAlbums = result.getExportedData().getAlbums();
assertThat(actualAlbums.stream().map(PhotoAlbum::getId).collect(Collectors.toList())).containsExactly(FOLDER_ID);
// Verify photos should be empty (in the root)
Collection<PhotoModel> actualPhotos = result.getExportedData().getPhotos();
assertThat(actualPhotos).isEmpty();
// Verify there is one container ready for sub-processing
List<ContainerResource> actualResources = continuationData.getContainerResources();
assertThat(actualResources.stream().map(a -> ((IdOnlyContainerResource) a).getId()).collect(Collectors.toList())).containsExactly(FOLDER_ID);
}
use of org.datatransferproject.spi.transfer.provider.ExportResult in project data-transfer-project by google.
the class MicrosoftPhotosExporterTest method exportAlbumWithoutNextPage.
@Test
public void exportAlbumWithoutNextPage() throws IOException {
// Setup
MicrosoftDriveItem folderItem = setUpSingleAlbum();
when(driveItemsResponse.getDriveItems()).thenReturn(new MicrosoftDriveItem[] { folderItem });
when(driveItemsResponse.getNextPageLink()).thenReturn(null);
StringPaginationToken inputPaginationToken = new StringPaginationToken(DRIVE_TOKEN_PREFIX + DRIVE_PAGE_URL);
// Run
ExportResult<PhotosContainerResource> result = microsoftPhotosExporter.exportOneDrivePhotos(null, Optional.empty(), Optional.of(inputPaginationToken), uuid);
// Verify method calls
verify(photosInterface).getDriveItems(Optional.empty(), 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 one album is ready for import
Collection<PhotoAlbum> actualAlbums = result.getExportedData().getAlbums();
assertThat(actualAlbums.stream().map(PhotoAlbum::getId).collect(Collectors.toList())).containsExactly(FOLDER_ID);
// Verify photos should be empty (in the root)
Collection<PhotoModel> actualPhotos = result.getExportedData().getPhotos();
assertThat(actualPhotos).isEmpty();
// Verify there is one container ready for sub-processing
List<ContainerResource> actualResources = continuationData.getContainerResources();
assertThat(actualResources.stream().map(a -> ((IdOnlyContainerResource) a).getId()).collect(Collectors.toList())).containsExactly(FOLDER_ID);
}
use of org.datatransferproject.spi.transfer.provider.ExportResult 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.spi.transfer.provider.ExportResult in project data-transfer-project by google.
the class MicrosoftCalendarExportTest method testExport.
@Test
public void testExport() throws Exception {
server.enqueue(new MockResponse().setBody(CALENDARS_RESPONSE));
server.enqueue(new MockResponse().setBody(CALENDAR1_EVENTS_RESPONSE));
server.enqueue(new MockResponse().setBody(CALENDAR2_EVENTS_RESPONSE));
server.start();
HttpUrl baseUrl = server.url("");
MicrosoftCalendarExporter exporter = new MicrosoftCalendarExporter(baseUrl.toString(), client, mapper, transformerService);
ExportResult<CalendarContainerResource> resource = exporter.export(UUID.randomUUID(), token, Optional.empty());
CalendarContainerResource calendarResource = resource.getExportedData();
Assert.assertEquals(2, calendarResource.getCalendars().size());
Assert.assertFalse(calendarResource.getCalendars().stream().anyMatch(c -> "Calendar1".equals(c.getId()) && "Calendar2".equals(c.getId())));
Assert.assertEquals(2, calendarResource.getEvents().size());
Assert.assertFalse(calendarResource.getEvents().stream().anyMatch(e -> "Test Appointment 1".equals(e.getTitle()) && "Test Appointment 2".equals(e.getTitle())));
}
use of org.datatransferproject.spi.transfer.provider.ExportResult 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);
}
Aggregations