Search in sources :

Example 1 with PaginationInformation

use of org.dataportabilityproject.dataModels.PaginationInformation 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));
}
Also used : ArrayList(java.util.ArrayList) Resource(org.dataportabilityproject.dataModels.Resource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) CalendarModel(org.dataportabilityproject.dataModels.calendar.CalendarModel) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) CalendarModelWrapper(org.dataportabilityproject.dataModels.calendar.CalendarModelWrapper) CalendarListEntry(com.google.api.services.calendar.model.CalendarListEntry) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) CalendarList(com.google.api.services.calendar.model.CalendarList) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken)

Example 2 with PaginationInformation

use of org.dataportabilityproject.dataModels.PaginationInformation 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));
}
Also used : IntPaginationToken(org.dataportabilityproject.shared.IntPaginationToken) ImmutableCollection(com.google.common.collect.ImmutableCollection) Message(javax.mail.Message) Resource(org.dataportabilityproject.dataModels.Resource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) Folder(javax.mail.Folder) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) MailContainerModel(org.dataportabilityproject.dataModels.mail.MailContainerModel) MailModelWrapper(org.dataportabilityproject.dataModels.mail.MailModelWrapper) MailMessageModel(org.dataportabilityproject.dataModels.mail.MailMessageModel) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation)

Example 3 with PaginationInformation

use of org.dataportabilityproject.dataModels.PaginationInformation 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));
}
Also used : ListMessagesResponse(com.google.api.services.gmail.model.ListMessagesResponse) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) Messages(com.google.api.services.gmail.Gmail.Users.Messages) Message(com.google.api.services.gmail.model.Message) ArrayList(java.util.ArrayList) MailModelWrapper(org.dataportabilityproject.dataModels.mail.MailModelWrapper) MailMessageModel(org.dataportabilityproject.dataModels.mail.MailMessageModel) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken)

Example 4 with PaginationInformation

use of org.dataportabilityproject.dataModels.PaginationInformation in project data-transfer-project by google.

the class GoogleTaskService method getTasks.

private TaskModelWrapper getTasks(String taskListId, Optional<PaginationInformation> pageInfo) throws IOException {
    com.google.api.services.tasks.model.Tasks result;
    Tasks.TasksOperations.List query = taskClient.tasks().list(taskListId).setMaxResults(PAGE_SIZE);
    if (pageInfo.isPresent()) {
        query.setPageToken(((StringPaginationToken) pageInfo.get()).getId());
    }
    result = query.execute();
    List<TaskModel> newTasks = result.getItems().stream().map(t -> new TaskModel(taskListId, t.getTitle(), t.getNotes())).collect(Collectors.toList());
    PaginationInformation newPageInfo = null;
    if (result.getNextPageToken() != null) {
        newPageInfo = new StringPaginationToken(result.getNextPageToken());
    }
    return new TaskModelWrapper(null, newTasks, new ContinuationInformation(null, newPageInfo));
}
Also used : Importer(org.dataportabilityproject.dataModels.Importer) Resource(org.dataportabilityproject.dataModels.Resource) ExportInformation(org.dataportabilityproject.dataModels.ExportInformation) IOException(java.io.IOException) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) Tasks(com.google.api.services.tasks.Tasks) TaskModel(org.dataportabilityproject.dataModels.tasks.TaskModel) Collectors(java.util.stream.Collectors) TaskModelWrapper(org.dataportabilityproject.dataModels.tasks.TaskModelWrapper) Task(com.google.api.services.tasks.model.Task) ArrayList(java.util.ArrayList) Exporter(org.dataportabilityproject.dataModels.Exporter) List(java.util.List) TaskList(com.google.api.services.tasks.model.TaskList) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) JobDataCache(org.dataportabilityproject.cloud.interfaces.JobDataCache) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) Optional(java.util.Optional) Credential(com.google.api.client.auth.oauth2.Credential) TaskLists(com.google.api.services.tasks.model.TaskLists) GoogleStaticObjects(org.dataportabilityproject.serviceProviders.google.GoogleStaticObjects) TaskListModel(org.dataportabilityproject.dataModels.tasks.TaskListModel) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken) TaskModelWrapper(org.dataportabilityproject.dataModels.tasks.TaskModelWrapper) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) TaskModel(org.dataportabilityproject.dataModels.tasks.TaskModel) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken)

Example 5 with PaginationInformation

use of org.dataportabilityproject.dataModels.PaginationInformation 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));
}
Also used : TaskList(com.google.api.services.tasks.model.TaskList) ArrayList(java.util.ArrayList) Resource(org.dataportabilityproject.dataModels.Resource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) TaskModelWrapper(org.dataportabilityproject.dataModels.tasks.TaskModelWrapper) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) TaskLists(com.google.api.services.tasks.model.TaskLists) TaskListModel(org.dataportabilityproject.dataModels.tasks.TaskListModel) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken)

Aggregations

PaginationInformation (org.dataportabilityproject.dataModels.PaginationInformation)8 ContinuationInformation (org.dataportabilityproject.dataModels.ContinuationInformation)7 ArrayList (java.util.ArrayList)6 Resource (org.dataportabilityproject.dataModels.Resource)6 IdOnlyResource (org.dataportabilityproject.shared.IdOnlyResource)6 StringPaginationToken (org.dataportabilityproject.shared.StringPaginationToken)6 ExportInformation (org.dataportabilityproject.dataModels.ExportInformation)3 CalendarModelWrapper (org.dataportabilityproject.dataModels.calendar.CalendarModelWrapper)3 TaskList (com.google.api.services.tasks.model.TaskList)2 TaskLists (com.google.api.services.tasks.model.TaskLists)2 IOException (java.io.IOException)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 JobDataCache (org.dataportabilityproject.cloud.interfaces.JobDataCache)2 Exporter (org.dataportabilityproject.dataModels.Exporter)2 Importer (org.dataportabilityproject.dataModels.Importer)2 MailMessageModel (org.dataportabilityproject.dataModels.mail.MailMessageModel)2 MailModelWrapper (org.dataportabilityproject.dataModels.mail.MailModelWrapper)2 Flickr (com.flickr4java.flickr.Flickr)1