use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.
the class DataTypeController method getDataTypes.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getDataTypes(@Valid RestListRequest requestList) throws JsonProcessingException {
this.getDataTypeValidator().validateRestListRequest(requestList);
PagedMetadata<EntityTypeShortDto> result = this.getDataObjectService().getShortDataTypes(requestList);
this.getDataTypeValidator().validateRestListResult(requestList, result);
logger.debug("Main Response -> {}", result);
return new ResponseEntity<>(new RestResponse(result.getBody(), null, result), HttpStatus.OK);
}
use of org.entando.entando.web.common.model.RestResponse 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.web.common.model.RestResponse 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);
}
use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.
the class DataObjectModelController method getDataObjectModel.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{dataModelId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getDataObjectModel(@PathVariable String dataModelId) {
logger.debug("Requested data object model -> {}", dataModelId);
MapBindingResult bindingResult = new MapBindingResult(new HashMap<>(), "dataModels");
int result = this.getDataObjectModelValidator().checkModelId(dataModelId, bindingResult);
if (bindingResult.hasErrors()) {
if (404 == result) {
throw new RestRourceNotFoundException(DataObjectModelValidator.ERRCODE_DATAOBJECTMODEL_DOES_NOT_EXIST, "dataObjectModel", dataModelId);
} else {
throw new ValidationGenericException(bindingResult);
}
}
DataModelDto dataModelDto = this.getDataObjectModelService().getDataObjectModel(Long.parseLong(dataModelId));
return new ResponseEntity<>(new RestResponse(dataModelDto), HttpStatus.OK);
}
use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.
the class DataObjectModelController method deleteGroup.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{dataModelId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> deleteGroup(@PathVariable String dataModelId) throws ApsSystemException {
logger.info("deleting data object model -> {}", dataModelId);
MapBindingResult bindingResult = new MapBindingResult(new HashMap<>(), "dataModels");
Long dataId = this.getDataObjectModelValidator().checkValidModelId(dataModelId, bindingResult);
if (null == dataId) {
throw new ValidationGenericException(bindingResult);
}
this.getDataObjectModelService().removeDataObjectModel(Long.parseLong(dataModelId));
Map<String, String> payload = new HashMap<>();
payload.put("modelId", dataModelId);
return new ResponseEntity<>(new RestResponse(payload), HttpStatus.OK);
}
Aggregations