Search in sources :

Example 6 with IdOnlyResource

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);
    }
}
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 7 with IdOnlyResource

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));
}
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 8 with IdOnlyResource

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));
}
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 9 with IdOnlyResource

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);
    }
}
Also used : FlickrException(com.flickr4java.flickr.FlickrException) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) IOException(java.io.IOException) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) Photoset(com.flickr4java.flickr.photosets.Photoset) Photosets(com.flickr4java.flickr.photosets.Photosets) PhotoAlbum(org.dataportabilityproject.dataModels.photos.PhotoAlbum)

Example 10 with IdOnlyResource

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));
}
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

IdOnlyResource (org.dataportabilityproject.shared.IdOnlyResource)14 Resource (org.dataportabilityproject.dataModels.Resource)11 ContinuationInformation (org.dataportabilityproject.dataModels.ContinuationInformation)9 ArrayList (java.util.ArrayList)7 StringPaginationToken (org.dataportabilityproject.shared.StringPaginationToken)6 IOException (java.io.IOException)5 ExportInformation (org.dataportabilityproject.dataModels.ExportInformation)5 PaginationInformation (org.dataportabilityproject.dataModels.PaginationInformation)5 CalendarModelWrapper (org.dataportabilityproject.dataModels.calendar.CalendarModelWrapper)5 PhotosModelWrapper (org.dataportabilityproject.dataModels.photos.PhotosModelWrapper)5 PhotoAlbum (org.dataportabilityproject.dataModels.photos.PhotoAlbum)4 Test (org.junit.Test)4 CalendarModel (org.dataportabilityproject.dataModels.calendar.CalendarModel)3 Photoset (com.flickr4java.flickr.photosets.Photoset)2 Photosets (com.flickr4java.flickr.photosets.Photosets)2 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 TaskListModel (org.dataportabilityproject.dataModels.tasks.TaskListModel)2