Search in sources :

Example 1 with UserResponse

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();
    }
}
Also used : UserResponse(uk.nhs.digital.intranet.json.UserResponse) ProviderCommunicationException(uk.nhs.digital.intranet.model.exception.ProviderCommunicationException) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException) URI(java.net.URI)

Aggregations

URI (java.net.URI)1 HttpStatusCodeException (org.springframework.web.client.HttpStatusCodeException)1 UserResponse (uk.nhs.digital.intranet.json.UserResponse)1 ProviderCommunicationException (uk.nhs.digital.intranet.model.exception.ProviderCommunicationException)1