use of org.datatransferproject.types.common.StringPaginationToken in project data-transfer-project by google.
the class GooglePlusExporter method export.
@Override
public ExportResult<SocialActivityContainerResource> export(UUID jobId, TokensAndUrlAuthData authData, Optional<ExportInformation> exportInformation) throws IOException {
Plus plus = getOrCreatePeopleService(authData);
Plus.Activities.List listActivities = plus.activities().list("me", "public");
if (exportInformation.isPresent()) {
StringPaginationToken pageToken = (StringPaginationToken) exportInformation.get().getPaginationData();
listActivities.setPageToken(pageToken.getToken());
}
ActivityFeed activityFeed = listActivities.execute();
List<Activity> activities = activityFeed.getItems();
ContinuationData continuationData = null;
SocialActivityContainerResource results = null;
if (activities != null && !activities.isEmpty()) {
List<SocialActivityModel> activityModels = new ArrayList<>();
Activity.Actor actor = activities.get(0).getActor();
SocialActivityActor parsedActor = new SocialActivityActor(actor.getUrl(), actor.getDisplayName(), actor.getUrl());
if (!Strings.isNullOrEmpty(activityFeed.getNextPageToken())) {
continuationData = new ContinuationData(new StringPaginationToken(activityFeed.getNextPageToken()));
}
for (Activity activity : activities) {
try {
activityModels.add(postToActivityModel(activity));
} catch (RuntimeException e) {
throw new IOException("Problem exporting: " + activity, e);
}
}
results = new SocialActivityContainerResource(jobId.toString(), parsedActor, activityModels);
}
return new ExportResult<>(continuationData == null ? ResultType.END : ResultType.CONTINUE, results, continuationData);
}
use of org.datatransferproject.types.common.StringPaginationToken in project data-transfer-project by google.
the class GoogleMailExporterTest method exportMessagesSubsequentSet.
@Test
public void exportMessagesSubsequentSet() throws IOException {
setUpSingleMessageResponse();
// Looking at subsequent page, with no page after it
PaginationData paginationData = new StringPaginationToken(NEXT_TOKEN);
ExportInformation exportInformation = new ExportInformation(paginationData, null);
messageListResponse.setNextPageToken(null);
// Run test
ExportResult<MailContainerResource> result = googleMailExporter.export(JOB_ID, null, Optional.of(exportInformation));
// Check results
// Verify correct calls were made (i.e., token was set before execution)
InOrder inOrder = Mockito.inOrder(messageListRequest);
inOrder.verify(messageListRequest).setPageToken(NEXT_TOKEN);
inOrder.verify(messageListRequest).execute();
// Check pagination token (should be null)
ContinuationData continuationData = (ContinuationData) result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken).isNull();
}
use of org.datatransferproject.types.common.StringPaginationToken in project data-transfer-project by google.
the class GooglePhotosExporterTest method exportAlbumFirstSet.
@Test
public void exportAlbumFirstSet() throws IOException, InvalidTokenException, PermissionDeniedException {
setUpSingleAlbum();
when(albumListResponse.getNextPageToken()).thenReturn(ALBUM_TOKEN);
// Run test
ExportResult<PhotosContainerResource> result = googlePhotosExporter.exportAlbums(null, Optional.empty(), uuid);
// Check results
// Verify correct methods were called
verify(photosInterface).listAlbums(Optional.empty());
verify(albumListResponse).getAlbums();
// Check pagination token
ContinuationData continuationData = result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken.getToken()).isEqualTo(ALBUM_TOKEN_PREFIX + ALBUM_TOKEN);
// Check albums field of container
Collection<PhotoAlbum> actualAlbums = result.getExportedData().getAlbums();
assertThat(actualAlbums.stream().map(PhotoAlbum::getId).collect(Collectors.toList())).containsExactly(ALBUM_ID);
// Check photos field of container (should be empty, even though there is a photo in the
// original album)
Collection<PhotoModel> actualPhotos = result.getExportedData().getPhotos();
assertThat(actualPhotos).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(ALBUM_ID);
}
use of org.datatransferproject.types.common.StringPaginationToken in project data-transfer-project by google.
the class MastodonActivityExport method export.
@Override
public ExportResult<SocialActivityContainerResource> export(UUID jobId, CookiesAndUrlAuthData authData, Optional<ExportInformation> exportInformation) throws Exception {
checkState(authData.getCookies().size() == 1, "Exactly 1 cookie expected: %s", authData.getCookies());
String maxId = null;
if (exportInformation.isPresent()) {
StringPaginationToken pageData = (StringPaginationToken) exportInformation.get().getPaginationData();
if (!Strings.isNullOrEmpty(pageData.getToken())) {
maxId = pageData.getToken();
}
}
MastodonHttpUtilities utilities = new MastodonHttpUtilities(authData.getCookies().get(0), authData.getUrl());
Account account = utilities.getAccount();
Status[] statuses = utilities.getStatuses(maxId);
List<SocialActivityModel> activityList = new ArrayList<>(statuses.length);
SocialActivityActor actor = new SocialActivityActor("acct:" + account.getUsername() + "@" + utilities.getHostName(), account.getDisplayName(), account.getUrl());
ContinuationData continuationData = null;
if (statuses.length > 0) {
String lastId = null;
for (Status status : statuses) {
activityList.add(statusToActivity(account, status, utilities));
lastId = status.getId();
}
continuationData = new ContinuationData(new StringPaginationToken(lastId));
}
return new ExportResult<>(continuationData == null ? ResultType.END : ResultType.CONTINUE, new SocialActivityContainerResource(account.getId() + maxId, actor, activityList), continuationData);
}
use of org.datatransferproject.types.common.StringPaginationToken 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);
}
Aggregations