Search in sources :

Example 11 with RestAccessControl

use of org.entando.entando.web.common.annotation.RestAccessControl 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 12 with RestAccessControl

use of org.entando.entando.web.common.annotation.RestAccessControl 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 13 with RestAccessControl

use of org.entando.entando.web.common.annotation.RestAccessControl 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 14 with RestAccessControl

use of org.entando.entando.web.common.annotation.RestAccessControl in project entando-core by entando.

the class EntityManagerController method getEntityManagers.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getEntityManagers(RestListRequest requestList) throws JsonProcessingException {
    PagedMetadata<String> result = this.getEntityManagerService().getEntityManagers(requestList);
    logger.debug("Main Response -> {}", result);
    return new ResponseEntity<>(new RestResponse(result.getBody(), null, result), HttpStatus.OK);
}
Also used : 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 15 with RestAccessControl

use of org.entando.entando.web.common.annotation.RestAccessControl in project entando-core by entando.

the class EntityManagerController method getEntityManager.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{entityManagerCode}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getEntityManager(@PathVariable String entityManagerCode) throws JsonProcessingException {
    logger.debug("Requested manager -> {}", entityManagerCode);
    EntityManagerDto dto = this.getEntityManagerService().getEntityManager(entityManagerCode);
    logger.debug("Main Response -> {}", dto);
    return new ResponseEntity<>(new RestResponse(dto), HttpStatus.OK);
}
Also used : EntityManagerDto(org.entando.entando.aps.system.services.entity.model.EntityManagerDto) 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)

Aggregations

RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)87 RestResponse (org.entando.entando.web.common.model.RestResponse)86 ResponseEntity (org.springframework.http.ResponseEntity)86 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)86 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)34 HashMap (java.util.HashMap)33 ArrayList (java.util.ArrayList)14 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)8 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)7 UserDto (org.entando.entando.aps.system.services.user.model.UserDto)6 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)5 CategoryDto (org.entando.entando.aps.system.services.category.model.CategoryDto)4 DataModelDto (org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto)4 LabelDto (org.entando.entando.aps.system.services.label.model.LabelDto)4 RoleDto (org.entando.entando.aps.system.services.role.model.RoleDto)4 WidgetDto (org.entando.entando.aps.system.services.widgettype.model.WidgetDto)4 DataTypeDto (org.entando.entando.aps.system.services.dataobject.model.DataTypeDto)3 GroupDto (org.entando.entando.aps.system.services.group.model.GroupDto)3 LanguageDto (org.entando.entando.aps.system.services.language.LanguageDto)3 PageModelDto (org.entando.entando.aps.system.services.pagemodel.model.PageModelDto)3