Search in sources :

Example 36 with ValidationGenericException

use of org.entando.entando.web.common.exceptions.ValidationGenericException 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 37 with ValidationGenericException

use of org.entando.entando.web.common.exceptions.ValidationGenericException 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)

Example 38 with ValidationGenericException

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

the class ProfileTypeController method addUserProfileTypes.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> addUserProfileTypes(@Valid @RequestBody ProfileTypeDtoRequest bodyRequest, BindingResult bindingResult) throws JsonProcessingException {
    // field validations
    this.getProfileTypeValidator().validate(bodyRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    // business validations
    if (this.getProfileTypeValidator().existType(bodyRequest.getCode())) {
        bindingResult.reject(DataTypeValidator.ERRCODE_ENTITY_TYPE_ALREADY_EXISTS, new String[] { bodyRequest.getCode() }, "entityType.exists");
    }
    if (bindingResult.hasErrors()) {
        throw new ValidationConflictException(bindingResult);
    }
    UserProfileTypeDto result = this.getUserProfileTypeService().addUserProfileType(bodyRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    logger.debug("Main Response -> {}", result);
    return new ResponseEntity<>(new RestResponse(result), HttpStatus.OK);
}
Also used : 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) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 39 with ValidationGenericException

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

the class UserSettingsController method updateUserSettings.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> updateUserSettings(@Valid @RequestBody UserSettingsRequest request, BindingResult bindingResult) {
    logger.debug("updatinug user settings");
    // params validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    UserSettingsDto settings = this.getUserSettingsService().updateUserSettings(request);
    return new ResponseEntity<>(new RestResponse(settings), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) UserSettingsDto(org.entando.entando.aps.system.services.usersettings.model.UserSettingsDto) 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)

Example 40 with ValidationGenericException

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

the class CategoryController method updateCategory.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{categoryCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> updateCategory(@PathVariable String categoryCode, @Valid @RequestBody CategoryDto categoryRequest, BindingResult bindingResult) {
    logger.debug("updating category {} with request {}", categoryCode, categoryRequest);
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getCategoryValidator().validatePutReferences(categoryCode, categoryRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    CategoryDto category = this.getCategoryService().updateCategory(categoryRequest);
    Map<String, String> metadata = new HashMap<>();
    return new ResponseEntity<>(new RestResponse(category, new ArrayList<>(), metadata), HttpStatus.OK);
}
Also used : CategoryDto(org.entando.entando.aps.system.services.category.model.CategoryDto) ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) RestResponse(org.entando.entando.web.common.model.RestResponse) ArrayList(java.util.ArrayList) 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