use of uk.nhs.digital.intranet.json.UserResponse in project hippo by NHS-digital-website.
the class GraphProviderImpl method getPeople.
@Override
public List<Person> getPeople(final String searchTerm) throws ProviderCommunicationException {
final HttpEntity<String> httpRequest = getHttpRequest(MediaType.APPLICATION_JSON);
final String cleanSearchTerm = searchTerm.trim();
final String filter = String.format("startsWith(displayName, '%s')", cleanSearchTerm) + " or " + String.format("startsWith(givenName, '%s')", cleanSearchTerm) + " or " + String.format("startsWith(surname, '%s')", cleanSearchTerm) + " or " + String.format("startsWith(mail, '%s')", cleanSearchTerm);
final URI uri = UriComponentsBuilder.fromUriString(BASE_URL_V1).pathSegment("users").queryParam("$filter", filter).queryParam("$select", SELECTED_FIELDS_SHORT).build().toUri();
try {
final ResponseEntity<UserResponse> responseEntity = restTemplate.exchange(uri, HttpMethod.GET, httpRequest, UserResponse.class);
Assert.notNull(responseEntity.getBody(), "Received null response from Microsoft Graph API.");
return personFactory.createPersons(responseEntity.getBody().getValue());
} catch (final HttpStatusCodeException e) {
LOGGER.error("Received exception with status {} from Microsoft Graph API.", e.getStatusCode(), e);
throw new ProviderCommunicationException();
}
}
Aggregations