Search in sources :

Example 76 with RestResponse

use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.

the class RoleController method getRoles.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getRoles(RestListRequest requestList) throws JsonProcessingException {
    this.getRoleValidator().validateRestListRequest(requestList);
    PagedMetadata<RoleDto> result = this.getRoleService().getRoles(requestList);
    this.getRoleValidator().validateRestListResult(requestList, result);
    logger.debug("loading role list -> {}", result);
    return new ResponseEntity<>(new RestResponse(result.getBody(), null, result), HttpStatus.OK);
}
Also used : RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto) ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 77 with RestResponse

use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.

the class UserController method deleteUser.

@RestAccessControl(permission = Permission.MANAGE_USERS)
@RequestMapping(value = "/{username}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> deleteUser(@PathVariable String username) throws ApsSystemException {
    logger.debug("deleting {}", username);
    this.getUserService().removeUser(username);
    Map<String, String> result = new HashMap<>();
    result.put("code", username);
    return new ResponseEntity<>(new RestResponse(result), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) RestResponse(org.entando.entando.web.common.model.RestResponse) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 78 with RestResponse

use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.

the class UserController method getUsers.

@RestAccessControl(permission = Permission.MANAGE_USERS)
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getUsers(RestListRequest requestList) {
    logger.debug("getting users details with request {}", requestList);
    PagedMetadata<UserDto> result = this.getUserService().getUsers(requestList);
    return new ResponseEntity<>(new RestResponse(result.getBody(), null, result), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) UserDto(org.entando.entando.aps.system.services.user.model.UserDto) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 79 with RestResponse

use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.

the class UserController method addUserAuthorities.

@RestAccessControl(permission = Permission.MANAGE_USERS)
@RequestMapping(value = "/{target}/authorities", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> addUserAuthorities(@ModelAttribute("user") UserDetails user, @PathVariable String target, @Valid @RequestBody UserAuthoritiesRequest authRequest, BindingResult bindingResult) throws ApsSystemException {
    logger.debug("user {} requesting add authorities for username {} with req {}", user.getUsername(), target, authRequest);
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    // business validations
    getUserValidator().validate(authRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    getUserValidator().validateUpdateSelf(target, user.getUsername(), bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    List<UserAuthorityDto> authorities = this.getUserService().addUserAuthorities(target, authRequest);
    return new ResponseEntity<>(new RestResponse(authorities), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) UserAuthorityDto(org.entando.entando.aps.system.services.user.model.UserAuthorityDto) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 80 with RestResponse

use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.

the class UserController method updateUserAuthorities.

@RestAccessControl(permission = Permission.MANAGE_USERS)
@RequestMapping(value = "/{target}/authorities", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> updateUserAuthorities(@ModelAttribute("user") UserDetails user, @PathVariable String target, @Valid @RequestBody UserAuthoritiesRequest authRequest, BindingResult bindingResult) {
    logger.debug("user {} requesting update authorities for username {} with req {}", user.getUsername(), target, authRequest);
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    // business validations
    getUserValidator().validate(authRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    getUserValidator().validateUpdateSelf(target, user.getUsername(), bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    List<UserAuthorityDto> authorities = this.getUserService().addUserAuthorities(target, authRequest);
    return new ResponseEntity<>(new RestResponse(authorities), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) UserAuthorityDto(org.entando.entando.aps.system.services.user.model.UserAuthorityDto) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RestResponse (org.entando.entando.web.common.model.RestResponse)95 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)86 ResponseEntity (org.springframework.http.ResponseEntity)86 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)86 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)34 HashMap (java.util.HashMap)33 ArrayList (java.util.ArrayList)18 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)8 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)8 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)8 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)8 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)7 BindingResult (org.springframework.validation.BindingResult)7 UserDto (org.entando.entando.aps.system.services.user.model.UserDto)6 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)5 CategoryDto (org.entando.entando.aps.system.services.category.model.CategoryDto)4 DataModelDto (org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto)4 LabelDto (org.entando.entando.aps.system.services.label.model.LabelDto)4 RoleDto (org.entando.entando.aps.system.services.role.model.RoleDto)4 WidgetDto (org.entando.entando.aps.system.services.widgettype.model.WidgetDto)4