use of org.dataportabilityproject.transfer.microsoft.types.GraphPagination in project data-transfer-project by google.
the class MicrosoftContactsExporter method doExport.
@SuppressWarnings("unchecked")
private ExportResult<ContactsModelWrapper> doExport(TokenAuthData authData, String url) {
Request.Builder graphReqBuilder = new Request.Builder().url(url);
graphReqBuilder.header("Authorization", "Bearer " + authData.getToken());
try (Response graphResponse = client.newCall(graphReqBuilder.build()).execute()) {
ResponseBody body = graphResponse.body();
if (body == null) {
return new ExportResult<>(ExportResult.ResultType.ERROR, "Error retrieving contacts: response body was null");
}
String graphBody = new String(body.bytes());
Map graphMap = objectMapper.reader().forType(Map.class).readValue(graphBody);
String nextLink = (String) graphMap.get(ODATA_NEXT);
ContinuationData continuationData = nextLink == null ? null : new ContinuationData(new GraphPagination(nextLink));
List<Map<String, Object>> rawContacts = (List<Map<String, Object>>) graphMap.get("value");
if (rawContacts == null) {
return new ExportResult<>(ExportResult.ResultType.END);
}
ContactsModelWrapper wrapper = transform(rawContacts);
return new ExportResult<>(ExportResult.ResultType.CONTINUE, wrapper, continuationData);
} catch (IOException e) {
// FIXME log error
e.printStackTrace();
return new ExportResult<>(ExportResult.ResultType.ERROR, "Error retrieving contacts: " + e.getMessage());
}
}
Aggregations