Search in sources :

Example 6 with ValidationConflictException

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

the class GroupService method removeGroup.

@Override
public void removeGroup(String groupName) {
    try {
        Group group = this.getGroupManager().getGroup(groupName);
        BeanPropertyBindingResult validationResult = this.checkGroupForDelete(group);
        if (validationResult.hasErrors()) {
            throw new ValidationConflictException(validationResult);
        }
        if (null != group) {
            this.getGroupManager().removeGroup(group);
        }
    } catch (ApsSystemException e) {
        logger.error("Error in delete group {}", groupName, e);
        throw new RestServerError("error in delete group", e);
    }
}
Also used : Group(com.agiletec.aps.system.services.group.Group) 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 7 with ValidationConflictException

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

the class DataTypeController method addDataTypes.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> addDataTypes(@Valid @RequestBody DataTypeDtoRequest bodyRequest, BindingResult bindingResult) throws JsonProcessingException {
    // field validations
    this.getDataTypeValidator().validate(bodyRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    // business validations
    if (this.getDataTypeValidator().existType(bodyRequest.getCode())) {
        bindingResult.reject(DataTypeValidator.ERRCODE_ENTITY_TYPE_ALREADY_EXISTS, new String[] { bodyRequest.getCode() }, "entityType.exists");
    }
    if (bindingResult.hasErrors()) {
        throw new ValidationConflictException(bindingResult);
    }
    DataTypeDto result = this.getDataObjectService().addDataType(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) RestResponse(org.entando.entando.web.common.model.RestResponse) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) DataTypeDto(org.entando.entando.aps.system.services.dataobject.model.DataTypeDto) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with ValidationConflictException

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

the class GroupController method addGroup.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> addGroup(@Valid @RequestBody GroupRequest groupRequest, BindingResult bindingResult) throws ApsSystemException {
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    // business validations
    getGroupValidator().validate(groupRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationConflictException(bindingResult);
    }
    GroupDto dto = this.getGroupService().addGroup(groupRequest);
    return new ResponseEntity<>(new RestResponse(dto), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto) 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 9 with ValidationConflictException

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

the class PageController method addPage.

@RestAccessControl(permission = Permission.MANAGE_PAGES)
@RequestMapping(value = "/pages", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> addPage(@ModelAttribute("user") UserDetails user, @Valid @RequestBody PageRequest pageRequest, BindingResult bindingResult) throws ApsSystemException {
    logger.debug("creating page with request {}", pageRequest);
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    // business validations
    getPageValidator().validate(pageRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationConflictException(bindingResult);
    }
    PageDto dto = this.getPageService().addPage(pageRequest);
    Map<String, String> metadata = new HashMap<>();
    return new ResponseEntity<>(new RestResponse(dto, new ArrayList<>(), metadata), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) HashMap(java.util.HashMap) RestResponse(org.entando.entando.web.common.model.RestResponse) ArrayList(java.util.ArrayList) 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 10 with ValidationConflictException

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

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