use of org.dataportabilityproject.dataModels.ContinuationInformation in project data-transfer-project by google.
the class GoogleCalendarService method exportCalendars.
private CalendarModelWrapper exportCalendars(Optional<PaginationInformation> pageInfo) throws IOException {
Calendar.CalendarList.List listRequest = calendarClient.calendarList().list();
if (pageInfo.isPresent()) {
listRequest.setPageToken(((StringPaginationToken) pageInfo.get()).getId());
}
CalendarList listResult = listRequest.execute();
List<CalendarModel> calendarModels = new ArrayList<>(listResult.getItems().size());
List<Resource> resources = new ArrayList<>(listResult.getItems().size());
for (CalendarListEntry calendarData : listResult.getItems()) {
CalendarModel model = GoogleCalendarToModelConverter.convertToCalendarModel(calendarData);
resources.add(new IdOnlyResource(calendarData.getId()));
calendarModels.add(model);
}
PaginationInformation newPageInfo = null;
if (listResult.getNextPageToken() != null) {
newPageInfo = new StringPaginationToken(listResult.getNextPageToken());
}
return new CalendarModelWrapper(calendarModels, null, new ContinuationInformation(resources, newPageInfo));
}
use of org.dataportabilityproject.dataModels.ContinuationInformation in project data-transfer-project by google.
the class ImapMailHelper method getMessages.
/**
* Get all messages in an account.
*/
private MailModelWrapper getMessages(String host, String account, String password, Folder parentFolder, boolean fetchMessages, PaginationInformation paginationInformation) throws MessagingException, IOException {
int foldersSize = 0;
// Find containers to and be imported
ImmutableCollection.Builder<MailContainerModel> folders = ImmutableList.builder();
ImmutableCollection.Builder<Resource> folderIds = ImmutableList.builder();
log("Calling list for folder: %s", parentFolder.getName());
Folder[] subFolders = parentFolder.list();
log("Folder: %s, subFolders: %d", parentFolder.getName(), subFolders.length);
for (Folder folder : subFolders) {
// This will tell the framework to create this folder on import
folders.add(new MailContainerModel(folder.getName(), folder.getFullName()));
// Content for these resources will be 'fetched' by the framework
folderIds.add(new IdOnlyResource(folder.getName()));
foldersSize++;
}
log("foldersSize: %d", foldersSize);
// Get messages in the folder
ImmutableCollection.Builder<MailMessageModel> resources = ImmutableList.builder();
log("fetchMessages: %b", fetchMessages);
PaginationInformation nextPaginationInformation = null;
if (fetchMessages) {
parentFolder.open(Folder.READ_ONLY);
int start = getStart(paginationInformation);
int end = getEnd(start, parentFolder.getMessageCount());
if (end < parentFolder.getMessageCount()) {
// Indicates page to be fetched on next request
nextPaginationInformation = new IntPaginationToken(end + 1);
}
log("Fetching messages for foder: %s, start: %d, end: %d", parentFolder.getFullName(), start, end);
Message[] messages = parentFolder.getMessages(start, end);
log("Fetched message for folder: %s, messages: %s", parentFolder.getFullName(), messages.length);
for (Message message : messages) {
log("Message, contentType: %s ,size: %s", message.getContentType(), message.getSize());
ImmutableList<String> folderId = ImmutableList.of(parentFolder.getName());
resources.add(new MailMessageModel(createRawMessage(message), folderId));
}
parentFolder.close(false);
}
// TODO: add pagination below
return new MailModelWrapper(folders.build(), resources.build(), new ContinuationInformation(folderIds.build(), nextPaginationInformation));
}
use of org.dataportabilityproject.dataModels.ContinuationInformation in project data-transfer-project by google.
the class PortabilityCopier method copy.
private static <T extends DataModel> void copy(Exporter<T> exporter, Importer<T> importer, ExportInformation exportInformation) throws IOException {
logger.debug("copy iteration: {}", COPY_ITERATION_COUNTER.incrementAndGet());
// NOTE: order is important below, do the import of all the items, then do continuation
// then do sub resources, this ensures all parents are populated before children get
// processed.
logger.debug("Starting export, exportInformation: {}", exportInformation);
T items = exporter.export(exportInformation);
logger.debug("Finished export, results: {}", items);
logger.debug("Starting import");
// The collection of items can be both containers and items
importer.importItem(items);
logger.debug("Finished import");
ContinuationInformation continuationInfo = items.getContinuationInformation();
if (null != continuationInfo) {
// Process the next page of items for the resource
if (null != continuationInfo.getPaginationInformation()) {
logger.debug("Start off a new copy iteration with pagination info");
copy(exporter, importer, new ExportInformation(// Resource with additional pages to fetch
exportInformation.getResource(), Optional.of(continuationInfo.getPaginationInformation())));
}
// Start processing sub-resources
if (continuationInfo.getSubResources() != null && !continuationInfo.getSubResources().isEmpty()) {
logger.debug("Start off a new copy iteration with a sub resource, size: {}", continuationInfo.getSubResources().size());
for (Resource resource : continuationInfo.getSubResources()) {
copy(exporter, importer, new ExportInformation(Optional.of(resource), Optional.empty()));
}
}
}
}
use of org.dataportabilityproject.dataModels.ContinuationInformation in project data-transfer-project by google.
the class GoogleMailService method export.
// This currently exports each message with associated labels
@Override
public MailModelWrapper export(ExportInformation exportInformation) throws IOException {
Messages.List request = gmail.users().messages().list(USER).setMaxResults(MAX_RESULTS_PER_REQUEST);
if (exportInformation.getPaginationInformation().isPresent()) {
request.setPageToken(((StringPaginationToken) exportInformation.getPaginationInformation().get()).getId());
}
ListMessagesResponse response = request.execute();
List<MailMessageModel> results = new ArrayList<>(response.getMessages().size());
// as we can't store all the mail messagess in memory at once.
for (Message listMessage : response.getMessages()) {
Message getResponse = gmail.users().messages().get(USER, listMessage.getId()).setFormat("raw").execute();
// TODO: note this doesn't transfer things like labels
results.add(new MailMessageModel(getResponse.getRaw(), getResponse.getLabelIds()));
}
PaginationInformation pageInfo = null;
if (response.getNextPageToken() != null) {
pageInfo = new StringPaginationToken(response.getNextPageToken());
}
// TODO: export by label or by message?
return new MailModelWrapper(null, results, new ContinuationInformation(null, pageInfo));
}
use of org.dataportabilityproject.dataModels.ContinuationInformation in project data-transfer-project by google.
the class GooglePhotosService method exportPhotos.
private PhotosModelWrapper exportPhotos(String albumId, Optional<PaginationInformation> pageInfo) throws IOException {
// imgmax=d gets the original immage as per:
// https://developers.google.com/picasa-web/docs/2.0/reference
URL photosUrl = new URL("https://picasaweb.google.com/data/feed/api/user/default/albumid/" + albumId + "?imgmax=d");
AlbumFeed photoFeed;
try {
photoFeed = service.getFeed(photosUrl, AlbumFeed.class);
} catch (ServiceException e) {
throw new IOException("Problem making request to: " + photosUrl, e);
}
List<PhotoModel> photos = new ArrayList<>(photoFeed.getEntries().size());
for (GphotoEntry photo : photoFeed.getEntries()) {
MediaContent mediaContent = (MediaContent) photo.getContent();
photos.add(new PhotoModel(photo.getTitle().getPlainText(), mediaContent.getUri(), photo.getDescription().getPlainText(), mediaContent.getMimeType().getMediaType(), albumId));
}
return new PhotosModelWrapper(null, photos, new ContinuationInformation(null, null));
}
Aggregations