use of org.hisp.dhis.webapi.controller.exception.FilterTooShortException in project dhis2-core by dhis2.
the class CurrentUserController method recipientsJson.
@RequestMapping(value = "/recipients", produces = { "application/json", "text/*" })
public void recipientsJson(HttpServletResponse response, @RequestParam(value = "filter") String filter) throws IOException, NotAuthenticatedException, FilterTooShortException {
User currentUser = currentUserService.getCurrentUser();
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.CACHE_1_HOUR);
if (currentUser == null) {
throw new NotAuthenticatedException();
}
if (3 > filter.length()) {
throw new FilterTooShortException();
}
Recipients recipients = new Recipients();
recipients.setOrganisationUnits(new HashSet<>(organisationUnitService.getOrganisationUnitsBetweenByName(filter, 0, MAX_OBJECTS)));
recipients.setUsers(new HashSet<>(userService.getAllUsersBetweenByName(filter, 0, MAX_OBJECTS)));
recipients.setUserGroups(new HashSet<>(userGroupService.getUserGroupsBetweenByName(filter, 0, MAX_OBJECTS)));
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
renderService.toJson(response.getOutputStream(), recipients);
}
Aggregations