Search in sources :

Example 6 with Resource

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

the class MicrosoftCalendarService method getCalendars.

private CalendarModelWrapper getCalendars(Optional<PaginationInformation> pageInfo) throws IOException {
    URL url = new URL("https://outlook.office.com/api/v2.0/me/calendars");
    HttpRequest getRequest = requestFactory.buildGetRequest(new GenericUrl(url));
    getRequest.setParser(new JsonObjectParser(new JacksonFactory()));
    HttpResponse response;
    try {
        response = getRequest.execute();
    } catch (HttpResponseException e) {
        logger.debug("Error fetching content");
        logger.debug("response status code: {}", e.getStatusCode());
        logger.debug("response status message: {}", e.getStatusMessage());
        logger.debug("response headers: {}", e.getHeaders());
        logger.debug("response content: {}", e.getContent());
        e.printStackTrace();
        throw e;
    }
    int statusCode = response.getStatusCode();
    if (statusCode != 200) {
        throw new IOException("Bad status code: " + statusCode + " error: " + response.getStatusMessage());
    }
    // Parse response into model
    OutlookCalendarList data = response.parseAs(OutlookCalendarList.class);
    List<CalendarModel> calendars = new ArrayList<>(data.list.size());
    List<Resource> resources = new ArrayList<>(data.list.size());
    for (OutlookCalendar calendar : data.list) {
        calendars.add(new CalendarModel(calendar.id, calendar.name, null));
        resources.add(new IdOnlyResource(calendar.id));
    }
    return new CalendarModelWrapper(calendars, null, new ContinuationInformation(resources, null));
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) ArrayList(java.util.ArrayList) Resource(org.dataportabilityproject.dataModels.Resource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) HttpResponse(com.google.api.client.http.HttpResponse) CalendarModel(org.dataportabilityproject.dataModels.calendar.CalendarModel) HttpResponseException(com.google.api.client.http.HttpResponseException) GenericUrl(com.google.api.client.http.GenericUrl) IOException(java.io.IOException) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) URL(java.net.URL) CalendarModelWrapper(org.dataportabilityproject.dataModels.calendar.CalendarModelWrapper) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) JsonObjectParser(com.google.api.client.json.JsonObjectParser)

Example 7 with Resource

use of org.dataportabilityproject.dataModels.Resource 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);
    }
}
Also used : MessagingException(javax.mail.MessagingException) Resource(org.dataportabilityproject.dataModels.Resource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) IOException(java.io.IOException) ImapMailHelper(org.dataportabilityproject.serviceProviders.common.mail.ImapMailHelper)

Example 8 with Resource

use of org.dataportabilityproject.dataModels.Resource 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));
}
Also used : ArrayList(java.util.ArrayList) Resource(org.dataportabilityproject.dataModels.Resource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) IOException(java.io.IOException) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) URL(java.net.URL) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) ServiceException(com.google.gdata.util.ServiceException) UserFeed(com.google.gdata.data.photos.UserFeed) PhotoAlbum(org.dataportabilityproject.dataModels.photos.PhotoAlbum) GphotoEntry(com.google.gdata.data.photos.GphotoEntry)

Example 9 with Resource

use of org.dataportabilityproject.dataModels.Resource 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)

Example 10 with Resource

use of org.dataportabilityproject.dataModels.Resource 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));
}
Also used : TaskModelWrapper(org.dataportabilityproject.dataModels.tasks.TaskModelWrapper) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) ListInfo(org.dataportabilityproject.serviceProviders.rememberTheMilk.model.ListInfo) ArrayList(java.util.ArrayList) Resource(org.dataportabilityproject.dataModels.Resource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) TaskListModel(org.dataportabilityproject.dataModels.tasks.TaskListModel)

Aggregations

Resource (org.dataportabilityproject.dataModels.Resource)12 IdOnlyResource (org.dataportabilityproject.shared.IdOnlyResource)11 ContinuationInformation (org.dataportabilityproject.dataModels.ContinuationInformation)8 ArrayList (java.util.ArrayList)6 StringPaginationToken (org.dataportabilityproject.shared.StringPaginationToken)6 PaginationInformation (org.dataportabilityproject.dataModels.PaginationInformation)5 CalendarModelWrapper (org.dataportabilityproject.dataModels.calendar.CalendarModelWrapper)5 IOException (java.io.IOException)4 ExportInformation (org.dataportabilityproject.dataModels.ExportInformation)4 CalendarModel (org.dataportabilityproject.dataModels.calendar.CalendarModel)3 CalendarList (com.google.api.services.calendar.model.CalendarList)2 CalendarListEntry (com.google.api.services.calendar.model.CalendarListEntry)2 URL (java.net.URL)2 CalendarEventModel (org.dataportabilityproject.dataModels.calendar.CalendarEventModel)2 PhotoAlbum (org.dataportabilityproject.dataModels.photos.PhotoAlbum)2 PhotosModelWrapper (org.dataportabilityproject.dataModels.photos.PhotosModelWrapper)2 TaskListModel (org.dataportabilityproject.dataModels.tasks.TaskListModel)2 TaskModelWrapper (org.dataportabilityproject.dataModels.tasks.TaskModelWrapper)2 Test (org.junit.Test)2 GenericUrl (com.google.api.client.http.GenericUrl)1