Search in sources :

Example 1 with ValidationGenericException

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

the class CategoryController method addCategory.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> addCategory(@Valid @RequestBody CategoryDto categoryRequest, BindingResult bindingResult) throws ApsSystemException {
    // field validations
    this.getCategoryValidator().validate(categoryRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    // business validations
    this.getCategoryValidator().validatePostReferences(categoryRequest, bindingResult);
    CategoryDto category = this.getCategoryService().addCategory(categoryRequest);
    return new ResponseEntity<>(new RestResponse(category, new ArrayList<>(), new HashMap<>()), 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)

Example 2 with ValidationGenericException

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

the class DataTypeController method updateDataType.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{dataTypeCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> updateDataType(@PathVariable String dataTypeCode, @Valid @RequestBody DataTypeDtoRequest request, BindingResult bindingResult) throws JsonProcessingException {
    int result = this.getDataTypeValidator().validateBodyName(dataTypeCode, request, bindingResult);
    if (bindingResult.hasErrors()) {
        if (result == 404) {
            throw new RestRourceNotFoundException(DataTypeValidator.ERRCODE_ENTITY_TYPE_DOES_NOT_EXIST, "data type", dataTypeCode);
        } else {
            throw new ValidationGenericException(bindingResult);
        }
    }
    DataTypeDto dto = this.getDataObjectService().updateDataType(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) 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) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ValidationGenericException

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

the class DataObjectModelController method updateGroup.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{dataModelId}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> updateGroup(@PathVariable String dataModelId, @Valid @RequestBody DataObjectModelRequest dataObjectModelRequest, BindingResult bindingResult) throws JsonProcessingException {
    logger.debug("Updating data object model -> {}", dataObjectModelRequest.getModelId());
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getDataObjectModelValidator().validateBodyName(dataModelId, dataObjectModelRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    int result = this.getDataObjectModelValidator().validateBody(dataObjectModelRequest, true, bindingResult);
    if (bindingResult.hasErrors()) {
        if (404 == result) {
            if (1 == bindingResult.getFieldErrorCount("type")) {
                throw new RestRourceNotFoundException(DataObjectModelValidator.ERRCODE_PUT_DATAOBJECTTYPE_DOES_NOT_EXIST, "type", dataObjectModelRequest.getType());
            } else {
                throw new RestRourceNotFoundException(DataObjectModelValidator.ERRCODE_DATAOBJECTMODEL_ALREADY_EXISTS, "modelId", dataObjectModelRequest.getModelId());
            }
        } else {
            throw new ValidationGenericException(bindingResult);
        }
    }
    DataModelDto dataModelDto = this.getDataObjectModelService().updateDataObjectModel(dataObjectModelRequest);
    logger.debug("Main Response -> {}", dataModelDto);
    return new ResponseEntity<>(new RestResponse(dataModelDto), HttpStatus.OK);
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) DataModelDto(org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto) ResponseEntity(org.springframework.http.ResponseEntity) 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 4 with ValidationGenericException

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

the class DataObjectModelController method addDataObjectModel.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> addDataObjectModel(@Valid @RequestBody DataObjectModelRequest dataObjectModelRequest, BindingResult bindingResult) throws JsonProcessingException {
    logger.debug("Adding data object model -> {}", dataObjectModelRequest.getModelId());
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    // business validations
    this.getDataObjectModelValidator().validate(dataObjectModelRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    int result = this.getDataObjectModelValidator().validateBody(dataObjectModelRequest, false, bindingResult);
    if (bindingResult.hasErrors()) {
        if (404 == result) {
            throw new RestRourceNotFoundException(DataObjectModelValidator.ERRCODE_POST_DATAOBJECTTYPE_DOES_NOT_EXIST, "type", dataObjectModelRequest.getType());
        } else {
            throw new ValidationGenericException(bindingResult);
        }
    }
    DataModelDto dataModelDto = this.getDataObjectModelService().addDataObjectModel(dataObjectModelRequest);
    logger.debug("Main Response -> {}", dataModelDto);
    return new ResponseEntity<>(new RestResponse(dataModelDto), HttpStatus.OK);
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) DataModelDto(org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto) ResponseEntity(org.springframework.http.ResponseEntity) 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 5 with ValidationGenericException

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

the class GroupController method updateGroup.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{groupCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> updateGroup(@PathVariable String groupCode, @Valid @RequestBody GroupRequest groupRequest, BindingResult bindingResult) {
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getGroupValidator().validateBodyName(groupCode, groupRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    GroupDto group = this.getGroupService().updateGroup(groupCode, groupRequest.getName());
    return new ResponseEntity<>(new RestResponse(group), 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) 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