use of uk.nhs.digital.intranet.model.SearchResultTab in project hippo by NHS-digital-website.
the class SearchPageComponent method searchPeople.
private void searchPeople(HstRequest request, List<SearchResultTab> searchResultTabs) {
final String accessToken = (String) RequestContextProvider.get().getAttribute(Constants.ACCESS_TOKEN_PROPERTY_NAME);
final SearchArea area = getAreaOption(request);
final String searchQuery = getSearchQuery(request, false);
final int peopleLimit = getComponentInfo(request).getPeopleLimit();
int numberOfResults;
if (!StringUtils.hasText(accessToken)) {
numberOfResults = 0;
request.setAttribute(REQUEST_ATTR_ACCESS_TOKEN_REQUIRED, true);
} else if (!StringUtils.hasText(searchQuery)) {
numberOfResults = 0;
request.setAttribute(REQUEST_ATTR_MISSING_TERM_ERROR_MESSAGE, true);
} else {
try {
List<Person> people = graphProvider.getPeople(searchQuery);
int peopleCount = people.size();
if (SearchArea.ALL.equals(area) && peopleCount > peopleLimit) {
people = people.subList(0, peopleLimit);
request.setAttribute(REQUEST_ATTR_MORE_PEOPLE, true);
}
numberOfResults = peopleCount;
request.setAttribute(REQUEST_ATTR_PEOPLE_RESULTS, people);
} catch (ProviderCommunicationException e) {
numberOfResults = 0;
request.setAttribute(REQUEST_ATTR_API_ERROR_MESSAGE, true);
}
}
searchResultTabs.add(new SearchResultTab(SearchArea.PEOPLE, numberOfResults));
}
use of uk.nhs.digital.intranet.model.SearchResultTab in project hippo by NHS-digital-website.
the class SearchPageComponentTest method peopleResultsEmptyIfQueryEmpty.
@Test
public void peopleResultsEmptyIfQueryEmpty() throws ProviderCommunicationException {
MockHstRequest request = new MockHstRequest();
request.setParameterMap("", Collections.emptyMap());
request.addParameter(REQUEST_ATTR_QUERY, "");
mockHstRequestContext.setAttribute(Constants.ACCESS_TOKEN_PROPERTY_NAME, "logged-into-microsoft-access-token");
underTest.doBeforeRender(request, new MockHstResponse());
Mockito.verify(graphProvider, Mockito.never()).getPeople(Mockito.nullable(String.class));
assertNull(request.getAttribute(REQUEST_ATTR_PEOPLE_RESULTS));
assertTrue(((List) request.getAttribute(REQUEST_ATTR_SEARCH_TABS)).contains(new SearchResultTab(SearchArea.PEOPLE, 0)));
}
use of uk.nhs.digital.intranet.model.SearchResultTab in project hippo by NHS-digital-website.
the class SearchPageComponentTest method peopleResultsEmptyIfNotLoggedIn.
@Test
public void peopleResultsEmptyIfNotLoggedIn() throws ProviderCommunicationException {
MockHstRequest request = new MockHstRequest();
request.setParameterMap("", Collections.emptyMap());
request.addParameter(REQUEST_ATTR_QUERY, "queryString is here");
mockHstRequestContext.setAttribute(Constants.ACCESS_TOKEN_PROPERTY_NAME, "");
underTest.doBeforeRender(request, new MockHstResponse());
Mockito.verify(graphProvider, Mockito.never()).getPeople(Mockito.nullable(String.class));
assertNull(request.getAttribute(REQUEST_ATTR_PEOPLE_RESULTS));
assertTrue(((List) request.getAttribute(REQUEST_ATTR_SEARCH_TABS)).contains(new SearchResultTab(SearchArea.PEOPLE, 0)));
}
Aggregations