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);
}
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);
}
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);
}
Aggregations