Search in sources :

Example 11 with ValidationGenericException

use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.

the class UserController method deleteUserAuthorities.

@RestAccessControl(permission = Permission.MANAGE_USERS)
@RequestMapping(value = "/{target}/authorities", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> deleteUserAuthorities(@ModelAttribute("user") UserDetails user, @PathVariable String target) throws ApsSystemException {
    logger.debug("user {} requesting delete authorities for username {}", user.getUsername(), target);
    DataBinder binder = new DataBinder(target);
    BindingResult bindingResult = binder.getBindingResult();
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    // business validations
    getUserValidator().validateUpdateSelf(target, user.getUsername(), bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getUserService().deleteUserAuthorities(target);
    return new ResponseEntity<>(new RestResponse(new ArrayList<>()), HttpStatus.OK);
}
Also used : BindingResult(org.springframework.validation.BindingResult) ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) ArrayList(java.util.ArrayList) DataBinder(org.springframework.validation.DataBinder) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with ValidationGenericException

use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.

the class UserController method updateUserPassword.

@RestAccessControl(permission = Permission.MANAGE_USERS)
@RequestMapping(value = "/{username}/password", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> updateUserPassword(@PathVariable String username, @Valid @RequestBody UserPasswordRequest passwordRequest, BindingResult bindingResult) {
    logger.debug("changing pasword for user {} with request {}", username, passwordRequest);
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getUserValidator().validateBody(username, passwordRequest.getUsername(), bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getUserValidator().validatePasswords(passwordRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    UserDto user = this.getUserService().updateUserPassword(passwordRequest);
    return new ResponseEntity<>(new RestResponse(user), 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) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with ValidationGenericException

use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.

the class UserController method addUser.

@RestAccessControl(permission = Permission.MANAGE_USERS)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> addUser(@Valid @RequestBody UserRequest userRequest, BindingResult bindingResult) throws ApsSystemException {
    logger.debug("adding user with request {}", userRequest);
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    UserDto dto = this.getUserService().addUser(userRequest);
    return new ResponseEntity<>(new RestResponse(dto), 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) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with ValidationGenericException

use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.

the class UserController method updateUser.

@RestAccessControl(permission = Permission.MANAGE_USERS)
@RequestMapping(value = "/{username}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> updateUser(@PathVariable String username, @Valid @RequestBody UserRequest userRequest, BindingResult bindingResult) {
    logger.debug("updating user {} with request {}", username, userRequest);
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getUserValidator().validateBody(username, userRequest.getUsername(), bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getUserValidator().validatePassword(username, userRequest.getPassword(), bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    UserDto user = this.getUserService().updateUser(userRequest);
    return new ResponseEntity<>(new RestResponse(user), 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) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with ValidationGenericException

use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.

the class ProfileTypeController method updateUserProfileType.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{profileTypeCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> updateUserProfileType(@PathVariable String profileTypeCode, @Valid @RequestBody ProfileTypeDtoRequest request, BindingResult bindingResult) throws JsonProcessingException {
    int result = this.getProfileTypeValidator().validateBodyName(profileTypeCode, request, bindingResult);
    if (bindingResult.hasErrors()) {
        if (result == 404) {
            throw new RestRourceNotFoundException(DataTypeValidator.ERRCODE_ENTITY_TYPE_DOES_NOT_EXIST, "profile type", profileTypeCode);
        } else {
            throw new ValidationGenericException(bindingResult);
        }
    }
    UserProfileTypeDto dto = this.getUserProfileTypeService().updateUserProfileType(request, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    logger.debug("Main Response -> {}", dto);
    return new ResponseEntity<>(new RestResponse(dto), HttpStatus.OK);
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ResponseEntity(org.springframework.http.ResponseEntity) UserProfileTypeDto(org.entando.entando.aps.system.services.userprofile.model.UserProfileTypeDto) RestResponse(org.entando.entando.web.common.model.RestResponse) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)44 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)34 RestResponse (org.entando.entando.web.common.model.RestResponse)34 ResponseEntity (org.springframework.http.ResponseEntity)34 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)34 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)12 ArrayList (java.util.ArrayList)9 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)9 HashMap (java.util.HashMap)8 RestServerError (org.entando.entando.aps.system.exception.RestServerError)8 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)5 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)5 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)5 WidgetDto (org.entando.entando.aps.system.services.widgettype.model.WidgetDto)4 Category (com.agiletec.aps.system.services.category.Category)3 CategoryDto (org.entando.entando.aps.system.services.category.model.CategoryDto)3 DataModelDto (org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto)3 GuiFragmentDto (org.entando.entando.aps.system.services.guifragment.model.GuiFragmentDto)3 UserDto (org.entando.entando.aps.system.services.user.model.UserDto)3 ApsProperties (com.agiletec.aps.util.ApsProperties)2