use of org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem in project data-transfer-project by google.
the class GooglePhotosExporter method convertPhotosList.
private List<PhotoModel> convertPhotosList(Optional<String> albumId, GoogleMediaItem[] mediaItems, UUID jobId) throws IOException {
List<PhotoModel> photos = new ArrayList<>(mediaItems.length);
TempPhotosData tempPhotosData = null;
InputStream stream = jobStore.getStream(jobId, createCacheKey()).getStream();
if (stream != null) {
tempPhotosData = new ObjectMapper().readValue(stream, TempPhotosData.class);
stream.close();
}
for (GoogleMediaItem mediaItem : mediaItems) {
if (mediaItem.getMediaMetadata().getPhoto() != null) {
// TODO: address videos
boolean shouldUpload = albumId.isPresent();
if (tempPhotosData != null) {
shouldUpload = shouldUpload || !tempPhotosData.isContainedPhotoId(mediaItem.getId());
}
if (shouldUpload) {
PhotoModel photoModel = convertToPhotoModel(albumId, mediaItem);
photos.add(photoModel);
monitor.debug(() -> String.format("%s: Google exporting photo: %s", jobId, photoModel.getDataId()));
}
}
}
return photos;
}
use of org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem in project data-transfer-project by google.
the class GooglePhotosExporterTest method populateContainedPhotosList.
@Test
public void populateContainedPhotosList() throws IOException, InvalidTokenException, PermissionDeniedException {
// Set up an album with two photos
setUpSingleAlbum();
when(albumListResponse.getNextPageToken()).thenReturn(null);
MediaItemSearchResponse albumMediaResponse = mock(MediaItemSearchResponse.class);
GoogleMediaItem firstPhoto = setUpSinglePhoto(IMG_URI, PHOTO_ID);
String secondUri = "second uri";
String secondId = "second id";
GoogleMediaItem secondPhoto = setUpSinglePhoto(secondUri, secondId);
when(photosInterface.listMediaItems(eq(Optional.of(ALBUM_ID)), any(Optional.class))).thenReturn(albumMediaResponse);
when(albumMediaResponse.getMediaItems()).thenReturn(new GoogleMediaItem[] { firstPhoto, secondPhoto });
when(albumMediaResponse.getNextPageToken()).thenReturn(null);
// Run test
googlePhotosExporter.populateContainedPhotosList(uuid, null);
// Check contents of job store
ArgumentCaptor<InputStream> inputStreamArgumentCaptor = ArgumentCaptor.forClass(InputStream.class);
verify(jobStore).create(eq(uuid), eq("tempPhotosData"), inputStreamArgumentCaptor.capture());
TempPhotosData tempPhotosData = new ObjectMapper().readValue(inputStreamArgumentCaptor.getValue(), TempPhotosData.class);
assertThat(tempPhotosData.lookupContainedPhotoIds()).containsExactly(PHOTO_ID, secondId);
}
use of org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem in project data-transfer-project by google.
the class GoogleVideosExporterTest method exportSingleVideo.
@Test
public void exportSingleVideo() throws IOException {
when(albumListResponse.getNextPageToken()).thenReturn(null);
GoogleMediaItem mediaItem = setUpSingleVideo(VIDEO_URI, VIDEO_ID);
when(mediaItemSearchResponse.getMediaItems()).thenReturn(new GoogleMediaItem[] { mediaItem });
when(mediaItemSearchResponse.getNextPageToken()).thenReturn(VIDEO_TOKEN);
// Run test
ExportResult<VideosContainerResource> result = googleVideosExporter.exportVideos(null, Optional.empty());
// Verify correct methods were called
verify(videosInterface).listVideoItems(Optional.empty());
verify(mediaItemSearchResponse).getMediaItems();
// Check pagination
ContinuationData continuationData = result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken.getToken()).isEqualTo(VIDEO_TOKEN);
// Check videos field of container
Collection<VideoModel> actualVideos = result.getExportedData().getVideos();
URI video_uri_object = null;
try {
video_uri_object = new URI(VIDEO_URI + "=dv");
} catch (URISyntaxException e) {
e.printStackTrace();
}
assertThat(actualVideos.stream().map(VideoModel::getContentUrl).collect(Collectors.toList())).containsExactly(video_uri_object);
// Since albums are not supported atm, this should be null
assertThat(actualVideos.stream().map(VideoModel::getAlbumId).collect(Collectors.toList())).containsExactly((Object) null);
}
use of org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem 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.datatransfer.google.mediaModels.GoogleMediaItem in project data-transfer-project by google.
the class GooglePhotosExporterTest method exportPhotoSubsequentSet.
@Test
public void exportPhotoSubsequentSet() throws IOException, InvalidTokenException, PermissionDeniedException {
setUpSingleAlbum();
when(albumListResponse.getNextPageToken()).thenReturn(null);
GoogleMediaItem mediaItem = setUpSinglePhoto(IMG_URI, PHOTO_ID);
when(mediaItemSearchResponse.getMediaItems()).thenReturn(new GoogleMediaItem[] { mediaItem });
when(mediaItemSearchResponse.getNextPageToken()).thenReturn(null);
StringPaginationToken inputPaginationToken = new StringPaginationToken(PHOTO_TOKEN_PREFIX + PHOTO_TOKEN);
IdOnlyContainerResource idOnlyContainerResource = new IdOnlyContainerResource(ALBUM_ID);
// Run test
ExportResult<PhotosContainerResource> result = googlePhotosExporter.exportPhotos(null, Optional.of(idOnlyContainerResource), Optional.of(inputPaginationToken), uuid);
// Check results
// Verify correct methods were called
verify(photosInterface).listMediaItems(Optional.of(ALBUM_ID), Optional.of(PHOTO_TOKEN));
verify(mediaItemSearchResponse).getMediaItems();
// Check pagination token
ContinuationData continuationData = result.getContinuationData();
PaginationData paginationToken = continuationData.getPaginationData();
assertNull(paginationToken);
}
Aggregations