Search in sources :

Example 1 with ValidationConflictException

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

the class RoleController method addRole.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> addRole(@Valid @RequestBody RoleRequest roleRequest, BindingResult bindingResult) throws ApsSystemException {
    logger.debug("adding role");
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    // business validations
    getRoleValidator().validate(roleRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationConflictException(bindingResult);
    }
    RoleDto dto = this.getRoleService().addRole(roleRequest);
    return new ResponseEntity<>(new RestResponse(dto), 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) 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 2 with ValidationConflictException

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

the class PageModelService method removePageModel.

@Override
public void removePageModel(String code) {
    try {
        PageModel pageModel = this.getPageModelManager().getPageModel(code);
        if (null == pageModel) {
            return;
        }
        BeanPropertyBindingResult validationResult = this.validateDelete(pageModel);
        if (validationResult.hasErrors()) {
            throw new ValidationConflictException(validationResult);
        }
        this.getPageModelManager().deletePageModel(code);
    } catch (ApsSystemException e) {
        logger.error("Error in delete pagemodel {}", code, e);
        throw new RestServerError("error in delete pagemodel", e);
    }
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException)

Example 3 with ValidationConflictException

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

the class RoleService method addRole.

@Override
public RoleDto addRole(RoleRequest roleRequest) {
    try {
        Role role = this.createRole(roleRequest);
        BeanPropertyBindingResult validationResult = this.validateRoleForAdd(role);
        if (validationResult.hasErrors()) {
            throw new ValidationConflictException(validationResult);
        }
        this.getRoleManager().addRole(role);
        RoleDto dto = this.getDtoBuilder().toDto(role, this.getRoleManager().getPermissionsCodes());
        return dto;
    } catch (ApsSystemException e) {
        logger.error("Error adding a role", e);
        throw new RestServerError("error in add role", e);
    }
}
Also used : Role(com.agiletec.aps.system.services.role.Role) RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException)

Example 4 with ValidationConflictException

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

the class RoleService method removeRole.

@Override
public void removeRole(String roleCode) {
    try {
        Role role = this.getRoleManager().getRole(roleCode);
        if (null == role) {
            logger.info("role {} does not exists", roleCode);
            return;
        }
        BeanPropertyBindingResult validationResult = this.validateRoleForDelete(role);
        if (validationResult.hasErrors()) {
            throw new ValidationConflictException(validationResult);
        }
        this.getRoleManager().removeRole(role);
    } catch (ApsSystemException e) {
        logger.error("Error in delete role {}", roleCode, e);
        throw new RestServerError("error in delete role", e);
    }
}
Also used : Role(com.agiletec.aps.system.services.role.Role) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException)

Example 5 with ValidationConflictException

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

the class DataObjectModelService method removeDataObjectModel.

@Override
public void removeDataObjectModel(Long dataModelId) {
    try {
        DataObjectModel dataObjectModel = this.getDataObjectModelManager().getDataObjectModel(dataModelId);
        if (null == dataObjectModel) {
            return;
        }
        DataModelDto dto = this.getDtoBuilder().convert(dataObjectModel);
        BeanPropertyBindingResult validationResult = this.checkDataObjectModelForDelete(dataObjectModel, dto);
        if (validationResult.hasErrors()) {
            throw new ValidationConflictException(validationResult);
        }
        this.getDataObjectModelManager().removeDataObjectModel(dataObjectModel);
    } catch (ApsSystemException e) {
        logger.error("Error in delete DataObjectModel {}", dataModelId, e);
        throw new RestServerError("error in delete DataObjectModel", e);
    }
}
Also used : DataModelDto(org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException)

Aggregations

ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)16 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)11 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)10 RestServerError (org.entando.entando.aps.system.exception.RestServerError)10 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)5 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)5 RestResponse (org.entando.entando.web.common.model.RestResponse)5 ResponseEntity (org.springframework.http.ResponseEntity)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Role (com.agiletec.aps.system.services.role.Role)3 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)3 RoleDto (org.entando.entando.aps.system.services.role.model.RoleDto)3 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)2 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)1 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)1 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)1 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)1 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)1 IAuthorizationService (com.agiletec.aps.system.services.authorization.IAuthorizationService)1 Group (com.agiletec.aps.system.services.group.Group)1