use of org.datatransferproject.spi.transfer.provider.ExportResult in project data-transfer-project by google.
the class MicrosoftPhotosExporterTest method exportAlbumAndPhotoWithNextPage.
@Test
public void exportAlbumAndPhotoWithNextPage() throws IOException {
// Setup
MicrosoftDriveItem folderItem = setUpSingleAlbum();
MicrosoftDriveItem photoItem = setUpSinglePhoto(IMAGE_URI, PHOTO_ID);
when(driveItemsResponse.getDriveItems()).thenReturn(new MicrosoftDriveItem[] { folderItem, photoItem });
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 one photo should be present (in the root Photos special folder)
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(null);
assertThat(actualPhotos.stream().map(PhotoModel::getTitle).collect(Collectors.toList())).containsExactly(FILENAME);
// 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 MicrosoftOfflineDataExporter method export.
@Override
public ExportResult<MicrosoftOfflineData> export(UUID jobId, TokenAuthData authData, Optional<ExportInformation> exportInformation) {
try {
String data = getDataFile(jobId, offlineDataUrl, authData);
MicrosoftOfflineData offlineData = new MicrosoftOfflineData(data);
return new ExportResult<>(ExportResult.ResultType.END, offlineData);
} catch (IOException e) {
// FIXME log error
e.printStackTrace();
return new ExportResult<>(e);
}
}
use of org.datatransferproject.spi.transfer.provider.ExportResult in project data-transfer-project by google.
the class CallableExporter method call.
@Override
public ExportResult call() throws Exception {
boolean success = false;
Stopwatch stopwatch = Stopwatch.createStarted();
try {
ExportResult result = exporterProvider.get().export(jobId, authData, exportInformation);
success = result.getType() != ExportResult.ResultType.ERROR;
return result;
} finally {
metricRecorder.exportPageAttemptFinished(JobMetadata.getDataType(), JobMetadata.getExportService(), success, stopwatch.elapsed());
}
}
use of org.datatransferproject.spi.transfer.provider.ExportResult in project data-transfer-project by google.
the class GoogleVideosExporter method exportVideos.
@VisibleForTesting
ExportResult<VideosContainerResource> exportVideos(TokensAndUrlAuthData authData, Optional<StringPaginationToken> paginationData) throws IOException {
Optional<String> paginationToken = paginationData.map(StringPaginationToken::getToken);
MediaItemSearchResponse mediaItemSearchResponse = getOrCreateVideosInterface(authData).listVideoItems(paginationToken);
PaginationData nextPageData = null;
if (!Strings.isNullOrEmpty(mediaItemSearchResponse.getNextPageToken())) {
nextPageData = new StringPaginationToken(mediaItemSearchResponse.getNextPageToken());
}
ContinuationData continuationData = new ContinuationData(nextPageData);
VideosContainerResource containerResource = null;
GoogleMediaItem[] mediaItems = mediaItemSearchResponse.getMediaItems();
if (mediaItems != null && mediaItems.length > 0) {
List<VideoModel> videos = convertVideosList(mediaItems);
containerResource = new VideosContainerResource(null, videos);
}
ResultType resultType = ResultType.CONTINUE;
if (nextPageData == null) {
resultType = ResultType.END;
}
return new ExportResult<>(resultType, containerResource, continuationData);
}
use of org.datatransferproject.spi.transfer.provider.ExportResult in project data-transfer-project by google.
the class GoogleCalendarExporterTest method exportCalendarFirstSet.
@Test
public void exportCalendarFirstSet() throws IOException {
setUpSingleCalendarResponse();
// Looking at first page, with at least one page after it
calendarListResponse.setNextPageToken(NEXT_TOKEN);
// Run test
ExportResult<CalendarContainerResource> result = googleCalendarExporter.export(JOB_ID, null, Optional.empty());
// Check results
// Verify correct methods were called
verify(calendarClient).calendarList();
verify(calendarCalendarList).list();
verify(calendarListRequest).execute();
// Check pagination token
ContinuationData continuationData = (ContinuationData) result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken.getToken()).isEqualTo(CALENDAR_TOKEN_PREFIX + NEXT_TOKEN);
// Check calendars
Collection<CalendarModel> actualCalendars = result.getExportedData().getCalendars();
assertThat(actualCalendars.stream().map(CalendarModel::getId).collect(Collectors.toList())).containsExactly(CALENDAR_ID);
// Check events (should be empty, even though there is an event in the calendar)
Collection<CalendarEventModel> actualEvents = result.getExportedData().getEvents();
assertThat(actualEvents).isEmpty();
// Should be one container in the resource list
List<ContainerResource> actualResources = continuationData.getContainerResources();
assertThat(actualResources.stream().map(a -> ((IdOnlyContainerResource) a).getId()).collect(Collectors.toList())).containsExactly(CALENDAR_ID);
}
Aggregations