Search in sources :

Example 1 with FilterTooShortException

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);
}
Also used : FilterTooShortException(org.hisp.dhis.webapi.controller.exception.FilterTooShortException) User(org.hisp.dhis.user.User) NotAuthenticatedException(org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException) Recipients(org.hisp.dhis.webapi.webdomain.user.Recipients) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

User (org.hisp.dhis.user.User)1 FilterTooShortException (org.hisp.dhis.webapi.controller.exception.FilterTooShortException)1 NotAuthenticatedException (org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException)1 Recipients (org.hisp.dhis.webapi.webdomain.user.Recipients)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1