use of org.dataportabilityproject.dataModels.ContinuationInformation 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));
}
use of org.dataportabilityproject.dataModels.ContinuationInformation in project data-transfer-project by google.
the class SmugMugPhotoService method getAlbums.
private PhotosModelWrapper getAlbums(Optional<PaginationInformation> paginationInformation) throws IOException {
String albumUri;
if (paginationInformation.isPresent()) {
albumUri = ((StringPaginationToken) paginationInformation.get()).getId();
} else {
SmugMugResponse<SmugMugUserResponse> userResponse = makeUserRequest(USER_URL);
albumUri = userResponse.getResponse().getUser().getUris().get("UserAlbums").getUri();
}
List<PhotoAlbum> albums = new ArrayList<>();
List<Resource> resources = new ArrayList<>();
SmugMugResponse<SmugmugAlbumsResponse> albumResponse = makeAlbumRequest(albumUri);
for (SmugMugAlbum album : albumResponse.getResponse().getAlbums()) {
albums.add(new PhotoAlbum(album.getAlbumKey(), album.getTitle(), album.getDescription()));
resources.add(new IdOnlyResource(album.getAlbumKey()));
}
StringPaginationToken pageToken = null;
if (albumResponse.getResponse().getPageInfo() != null && albumResponse.getResponse().getPageInfo().getNextPage() != null) {
pageToken = new StringPaginationToken(albumResponse.getResponse().getPageInfo().getNextPage());
}
return new PhotosModelWrapper(albums, null, new ContinuationInformation(resources, pageToken));
}
use of org.dataportabilityproject.dataModels.ContinuationInformation 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.ContinuationInformation in project data-transfer-project by google.
the class GoogleContactsService method export.
public ContactsModelWrapper export(ExportInformation continuationInformation) throws IOException {
// Set up connection
Connections.List connectionsList = peopleService.people().connections().list(GoogleContactsConstants.SELF_RESOURCE);
// Get next page, if we have a page token
if (continuationInformation.getPaginationInformation().isPresent()) {
String pageToken = ((StringPaginationToken) continuationInformation.getPaginationInformation().get()).getId();
connectionsList.setPageToken(pageToken);
}
// Get list of connections (nb: not a list containing full info of each Person)
ListConnectionsResponse response = connectionsList.setPersonFields(GoogleContactsConstants.PERSON_FIELDS).execute();
List<Person> peopleList = response.getConnections();
// Get list of resource names, then get list of Persons
List<String> resourceNames = peopleList.stream().map(Person::getResourceName).collect(Collectors.toList());
GetPeopleResponse batchResponse = peopleService.people().getBatchGet().setResourceNames(resourceNames).setPersonFields(GoogleContactsConstants.PERSON_FIELDS).execute();
List<PersonResponse> personResponseList = batchResponse.getResponses();
// Convert Persons to VCards
List<VCard> vCards = personResponseList.stream().map(a -> GoogleContactToVCardConverter.convert(a.getPerson())).collect(Collectors.toList());
// Determine if there's a next page
StringPaginationToken newPage = null;
if (response.getNextPageToken() != null) {
newPage = new StringPaginationToken(response.getNextPageToken());
}
ContinuationInformation newContinuationInformation = null;
if (newPage != null) {
newContinuationInformation = new ContinuationInformation(null, newPage);
}
return new ContactsModelWrapper(vCards, newContinuationInformation);
}
use of org.dataportabilityproject.dataModels.ContinuationInformation 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));
}
Aggregations