Search in sources :

Example 1 with EntityTypeAttributeFullDto

use of org.entando.entando.aps.system.services.entity.model.EntityTypeAttributeFullDto in project entando-core by entando.

the class DataTypeController method getDataTypeAttribute.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/dataTypes/{dataTypeCode}/attribute/{attributeCode}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse<EntityTypeAttributeFullDto, Map<String, String>>> getDataTypeAttribute(@PathVariable String dataTypeCode, @PathVariable String attributeCode) throws JsonProcessingException {
    logger.debug("Requested data type {} - attribute {}", dataTypeCode, attributeCode);
    EntityTypeAttributeFullDto dto = this.getDataObjectService().getDataTypeAttribute(dataTypeCode, attributeCode);
    logger.debug("Main Response -> {}", dto);
    Map<String, String> metadata = new HashMap<>();
    metadata.put("dataTypeCode", dataTypeCode);
    return new ResponseEntity<>(new RestResponse<>(dto, metadata), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) EntityTypeAttributeFullDto(org.entando.entando.aps.system.services.entity.model.EntityTypeAttributeFullDto) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl)

Example 2 with EntityTypeAttributeFullDto

use of org.entando.entando.aps.system.services.entity.model.EntityTypeAttributeFullDto in project entando-core by entando.

the class DataTypeController method updateDataTypeAttribute.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/dataTypes/{dataTypeCode}/attribute/{attributeCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse<EntityTypeAttributeFullDto, Map<String, String>>> updateDataTypeAttribute(@PathVariable String dataTypeCode, @PathVariable String attributeCode, @Valid @RequestBody EntityTypeAttributeFullDto bodyRequest, BindingResult bindingResult) throws JsonProcessingException {
    logger.debug("Data type {} - Updating attribute {}", dataTypeCode, bodyRequest);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    } else if (!StringUtils.equals(attributeCode, bodyRequest.getCode())) {
        bindingResult.rejectValue("code", DataTypeValidator.ERRCODE_URINAME_MISMATCH, new String[] { attributeCode, bodyRequest.getCode() }, "entityType.attribute.code.mismatch");
        throw new ValidationConflictException(bindingResult);
    }
    EntityTypeAttributeFullDto result = this.getDataObjectService().updateDataTypeAttribute(dataTypeCode, bodyRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    logger.debug("Main Response -> {}", result);
    Map<String, String> metadata = new HashMap<>();
    metadata.put("dataTypeCode", dataTypeCode);
    return new ResponseEntity<>(new RestResponse<>(result, metadata), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) EntityTypeAttributeFullDto(org.entando.entando.aps.system.services.entity.model.EntityTypeAttributeFullDto) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl)

Example 3 with EntityTypeAttributeFullDto

use of org.entando.entando.aps.system.services.entity.model.EntityTypeAttributeFullDto in project entando-core by entando.

the class DataTypeController method addDataTypeAttribute.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/dataTypes/{dataTypeCode}/attribute", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse<EntityTypeAttributeFullDto, Map<String, String>>> addDataTypeAttribute(@PathVariable String dataTypeCode, @Valid @RequestBody EntityTypeAttributeFullDto bodyRequest, BindingResult bindingResult) throws JsonProcessingException {
    logger.debug("Data type {} - Adding attribute {}", dataTypeCode, bodyRequest);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    EntityTypeAttributeFullDto result = this.getDataObjectService().addDataTypeAttribute(dataTypeCode, bodyRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    logger.debug("Main Response -> {}", result);
    Map<String, String> metadata = new HashMap<>();
    metadata.put("dataTypeCode", dataTypeCode);
    return new ResponseEntity<>(new RestResponse<>(result, metadata), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) EntityTypeAttributeFullDto(org.entando.entando.aps.system.services.entity.model.EntityTypeAttributeFullDto) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl)

Aggregations

HashMap (java.util.HashMap)3 EntityTypeAttributeFullDto (org.entando.entando.aps.system.services.entity.model.EntityTypeAttributeFullDto)3 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)3 ResponseEntity (org.springframework.http.ResponseEntity)3 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)2 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)1