Search in sources :

Example 1 with DataTypeDto

use of org.entando.entando.aps.system.services.dataobject.model.DataTypeDto 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 2 with DataTypeDto

use of org.entando.entando.aps.system.services.dataobject.model.DataTypeDto 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 3 with DataTypeDto

use of org.entando.entando.aps.system.services.dataobject.model.DataTypeDto in project entando-core by entando.

the class DataTypeController method getDataType.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{dataTypeCode}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getDataType(@PathVariable String dataTypeCode) throws JsonProcessingException {
    logger.debug("Requested data type -> {}", dataTypeCode);
    if (!this.getDataTypeValidator().existType(dataTypeCode)) {
        throw new RestRourceNotFoundException(DataTypeValidator.ERRCODE_ENTITY_TYPE_DOES_NOT_EXIST, "Data Type", dataTypeCode);
    }
    DataTypeDto dto = this.getDataObjectService().getDataType(dataTypeCode);
    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) 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)

Aggregations

DataTypeDto (org.entando.entando.aps.system.services.dataobject.model.DataTypeDto)3 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)3 RestResponse (org.entando.entando.web.common.model.RestResponse)3 ResponseEntity (org.springframework.http.ResponseEntity)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)2 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)2 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)1