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