use of org.dataportabilityproject.shared.IdOnlyResource in project data-transfer-project by google.
the class MicrosoftMailService method export.
@Override
public MailModelWrapper export(ExportInformation exportInformation) throws IOException {
ImapMailHelper helper = new ImapMailHelper();
Optional<Resource> resource = exportInformation.getResource();
try {
if (resource.isPresent()) {
IdOnlyResource folder = (IdOnlyResource) resource.get();
return helper.getFolderContents(HOST, account, password, folder.getId(), getPaginationInformation(exportInformation));
} else {
return helper.getFolderContents(HOST, account, password, null, getPaginationInformation(exportInformation));
}
} catch (MessagingException e) {
throw new IOException(e);
}
}
use of org.dataportabilityproject.shared.IdOnlyResource in project data-transfer-project by google.
the class GooglePhotosService method exportAlbums.
private PhotosModelWrapper exportAlbums(Optional<PaginationInformation> pageInfo) throws IOException {
URL albumUrl = new URL("https://picasaweb.google.com/data/feed/api/user/default?kind=album");
UserFeed albumFeed;
try {
albumFeed = service.getFeed(albumUrl, UserFeed.class);
} catch (ServiceException e) {
throw new IOException("Problem making request to: " + albumUrl, e);
}
List<PhotoAlbum> albums = new ArrayList<>(albumFeed.getEntries().size());
List<Resource> resources = new ArrayList<>(albumFeed.getEntries().size());
for (GphotoEntry myAlbum : albumFeed.getEntries()) {
// Adding sub-resources tells the framework to re-call
// export to get all the photos.
resources.add(new IdOnlyResource(myAlbum.getGphotoId()));
// Saving data to the album allows the target service
// to recreate the album structure.
albums.add(new PhotoAlbum(myAlbum.getGphotoId(), myAlbum.getTitle().getPlainText(), myAlbum.getDescription().getPlainText()));
}
return new PhotosModelWrapper(albums, null, new ContinuationInformation(resources, null));
}
use of org.dataportabilityproject.shared.IdOnlyResource in project data-transfer-project by google.
the class GoogleTaskService method getTaskLists.
private TaskModelWrapper getTaskLists(Optional<PaginationInformation> pageInfo) throws IOException {
Tasks.Tasklists.List query = taskClient.tasklists().list().setMaxResults(PAGE_SIZE);
if (pageInfo.isPresent()) {
query.setPageToken(((StringPaginationToken) pageInfo.get()).getId());
}
TaskLists result = query.execute();
List<TaskListModel> newTaskLists = new ArrayList<>(result.getItems().size());
List<Resource> newResources = new ArrayList<>(result.getItems().size());
for (TaskList taskList : result.getItems()) {
newTaskLists.add(new TaskListModel(taskList.getId(), taskList.getTitle()));
newResources.add(new IdOnlyResource(taskList.getId()));
}
PaginationInformation newPageInfo = null;
if (result.getNextPageToken() != null) {
newPageInfo = new StringPaginationToken(result.getNextPageToken());
}
return new TaskModelWrapper(newTaskLists, null, new ContinuationInformation(newResources, newPageInfo));
}
use of org.dataportabilityproject.shared.IdOnlyResource in project data-transfer-project by google.
the class FlickrPhotoService method getAlbums.
private PhotosModelWrapper getAlbums(Optional<PaginationInformation> paginationInformation) throws IOException {
try {
ImmutableList.Builder<PhotoAlbum> results = ImmutableList.builder();
List<IdOnlyResource> subResources = new ArrayList<>();
int page = getPage(paginationInformation);
Photosets photoSetList = photosetsInterface.getList(auth.getUser().getId(), PHOTO_SETS_PER_PAGE, page, PHOTOSET_EXTRAS);
for (Photoset photoset : photoSetList.getPhotosets()) {
// Saving data to the album allows the target service
// to recreate the album structure.
results.add(new PhotoAlbum(photoset.getId(), photoset.getTitle(), photoset.getDescription()));
// Adding sub-resources tells the framework to re-call
// export to get all the photos.
subResources.add(new IdOnlyResource(photoset.getId()));
}
FlickrPaginationInformation newPage = null;
boolean hasMore = photoSetList.getPage() != photoSetList.getPages() && !photoSetList.getPhotosets().isEmpty();
if (hasMore) {
newPage = new FlickrPaginationInformation(page + 1);
}
return new PhotosModelWrapper(results.build(), null, new ContinuationInformation(subResources, newPage));
} catch (FlickrException e) {
throw new IOException("Couldn't fetch albums", e);
}
}
use of org.dataportabilityproject.shared.IdOnlyResource in project data-transfer-project by google.
the class RememberTheMilkTaskService method exportTaskLists.
private TaskModelWrapper exportTaskLists(Optional<PaginationInformation> paginationInformation) throws IOException {
List<TaskListModel> lists = new ArrayList<>();
List<Resource> subResources = new ArrayList<>();
for (ListInfo oldListInfo : getLists().listInfoList.lists) {
if (oldListInfo.name.equals("All Tasks")) {
// don't copy that over.
continue;
}
lists.add(new TaskListModel(Integer.toString(oldListInfo.id), oldListInfo.name));
subResources.add(new IdOnlyResource(Integer.toString(oldListInfo.id)));
}
return new TaskModelWrapper(lists, null, new ContinuationInformation(subResources, null));
}
Aggregations