Search in sources :

Example 1 with DataModelDto

use of org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto 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 DataModelDto

use of org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto in project entando-core by entando.

the class DataObjectModelController method getDataObjectModels.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getDataObjectModels(RestListRequest requestList) {
    this.getDataObjectModelValidator().validateRestListRequest(requestList);
    PagedMetadata<DataModelDto> result = this.getDataObjectModelService().getDataObjectModels(requestList);
    this.getDataObjectModelValidator().validateRestListResult(requestList, result);
    logger.debug("Main Response -> {}", result);
    return new ResponseEntity<>(new RestResponse(result.getBody(), null, result), HttpStatus.OK);
}
Also used : DataModelDto(org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto) ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with DataModelDto

use of org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto 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 4 with DataModelDto

use of org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto in project entando-core by entando.

the class DataObjectModelService method removeDataObjectModel.

@Override
public void removeDataObjectModel(Long dataModelId) {
    try {
        DataObjectModel dataObjectModel = this.getDataObjectModelManager().getDataObjectModel(dataModelId);
        if (null == dataObjectModel) {
            return;
        }
        DataModelDto dto = this.getDtoBuilder().convert(dataObjectModel);
        BeanPropertyBindingResult validationResult = this.checkDataObjectModelForDelete(dataObjectModel, dto);
        if (validationResult.hasErrors()) {
            throw new ValidationConflictException(validationResult);
        }
        this.getDataObjectModelManager().removeDataObjectModel(dataObjectModel);
    } catch (ApsSystemException e) {
        logger.error("Error in delete DataObjectModel {}", dataModelId, e);
        throw new RestServerError("error in delete DataObjectModel", e);
    }
}
Also used : DataModelDto(org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException)

Example 5 with DataModelDto

use of org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto in project entando-core by entando.

the class DataObjectModelService method getDataObjectModels.

@Override
public PagedMetadata<DataModelDto> getDataObjectModels(RestListRequest restListReq) {
    PagedMetadata<DataModelDto> pagedMetadata = null;
    try {
        List<FieldSearchFilter> filters = new ArrayList<>(restListReq.buildFieldSearchFilters());
        // transforms the filters by overriding the key specified in the request with the correct one known by the dto
        filters.stream().filter(searchFilter -> searchFilter.getKey() != null).forEach(searchFilter -> {
            searchFilter.setKey(DataModelDto.getEntityFieldName(searchFilter.getKey()));
            if (searchFilter.getKey().equals("modelid") && null != searchFilter.getValue()) {
                String stringValue = searchFilter.getValue().toString();
                Long value = Long.parseLong(stringValue);
                searchFilter = new FieldSearchFilter("modelid", value, true);
            }
        });
        SearcherDaoPaginatedResult<DataObjectModel> models = this.getDataObjectModelManager().getDataObjectModels(filters);
        List<DataModelDto> dtoList = this.getDtoBuilder().convert(models.getList());
        pagedMetadata = new PagedMetadata<>(restListReq, models);
        pagedMetadata.setBody(dtoList);
    } catch (Throwable t) {
        logger.error("error in search data models", t);
        throw new RestServerError("error in search data models", t);
    }
    return pagedMetadata;
}
Also used : Logger(org.slf4j.Logger) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ArrayList(java.util.ArrayList) IPage(com.agiletec.aps.system.services.page.IPage) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) List(java.util.List) RestListRequest(org.entando.entando.web.common.model.RestListRequest) RestServerError(org.entando.entando.aps.system.exception.RestServerError) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) GuiFragmentValidator(org.entando.entando.web.guifragment.validator.GuiFragmentValidator) DataModelDto(org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto) Map(java.util.Map) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) DataObjectModelRequest(org.entando.entando.web.dataobjectmodel.model.DataObjectModelRequest) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) DataModelDto(org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto) ArrayList(java.util.ArrayList) RestServerError(org.entando.entando.aps.system.exception.RestServerError) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter)

Aggregations

DataModelDto (org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto)9 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)4 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)4 RestResponse (org.entando.entando.web.common.model.RestResponse)4 ResponseEntity (org.springframework.http.ResponseEntity)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)3 RestListRequest (org.entando.entando.web.common.model.RestListRequest)3 Test (org.junit.Test)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 IPage (com.agiletec.aps.system.services.page.IPage)2 UserDetails (com.agiletec.aps.system.services.user.UserDetails)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 RestServerError (org.entando.entando.aps.system.exception.RestServerError)2 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)2 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)2 ResultActions (org.springframework.test.web.servlet.ResultActions)2 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)2 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)1