Search in sources :

Example 1 with RestRourceNotFoundException

use of org.entando.entando.aps.system.exception.RestRourceNotFoundException 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 2 with RestRourceNotFoundException

use of org.entando.entando.aps.system.exception.RestRourceNotFoundException in project entando-core by entando.

the class AbstractEntityService method getFullEntityType.

protected O getFullEntityType(String entityManagerCode, String entityTypeCode) {
    IEntityManager entityManager = this.extractEntityManager(entityManagerCode);
    I entityType = (I) entityManager.getEntityPrototype(entityTypeCode);
    if (null == entityManager) {
        logger.warn("no entity type found with code {}", entityTypeCode);
        throw new RestRourceNotFoundException("entityTypeCode", entityTypeCode);
    }
    O type = this.convertEntityType(entityManager, entityType);
    type.setStatus(String.valueOf(entityManager.getStatus(entityTypeCode)));
    return type;
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager)

Aggregations

RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)2 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)1 DataModelDto (org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto)1 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)1 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)1 RestResponse (org.entando.entando.web.common.model.RestResponse)1 ResponseEntity (org.springframework.http.ResponseEntity)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1