Search in sources :

Example 21 with ResourceNotFoundException

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

the class DataTypeController method updateDataType.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/dataTypes/{dataTypeCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<DataTypeDto>> updateDataType(@PathVariable String dataTypeCode, @Valid @RequestBody DataTypeDtoRequest request, BindingResult bindingResult) throws JsonProcessingException {
    int result = this.getDataTypeValidator().validateBodyName(dataTypeCode, request, bindingResult);
    if (bindingResult.hasErrors()) {
        if (result == 404) {
            throw new ResourceNotFoundException(DataTypeValidator.ERRCODE_ENTITY_TYPE_DOES_NOT_EXIST, "data type", dataTypeCode);
        } else {
            throw new ValidationGenericException(bindingResult);
        }
    }
    DataTypeDto dto = this.getDataObjectService().updateDataType(request, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    logger.debug("Main Response -> {}", dto);
    return new ResponseEntity<>(new SimpleRestResponse<>(dto), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) DataTypeDto(org.entando.entando.aps.system.services.dataobject.model.DataTypeDto) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl)

Example 22 with ResourceNotFoundException

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

the class DataObjectModelService method updateDataObjectModel.

@Override
public DataModelDto updateDataObjectModel(DataObjectModelRequest dataObjectModelRequest) {
    String code = dataObjectModelRequest.getModelId();
    try {
        Long modelId = Long.parseLong(code);
        DataObjectModel dataObjectModel = this.getDataObjectModelManager().getDataObjectModel(modelId);
        if (null == dataObjectModel) {
            throw new ResourceNotFoundException("dataObjectModel", code);
        }
        dataObjectModel.setDataType(dataObjectModelRequest.getType());
        dataObjectModel.setDescription(dataObjectModelRequest.getDescr());
        dataObjectModel.setShape(dataObjectModelRequest.getModel());
        dataObjectModel.setStylesheet(dataObjectModelRequest.getStylesheet());
        this.getDataObjectModelManager().updateDataObjectModel(dataObjectModel);
        return this.getDtoBuilder().convert(dataObjectModel);
    } catch (ResourceNotFoundException e) {
        throw e;
    } catch (ApsSystemException e) {
        logger.error("Error updating DataObjectModel {}", code, e);
        throw new RestServerError("error in update DataObjectModel", e);
    }
}
Also used : RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException)

Example 23 with ResourceNotFoundException

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

the class AbstractEntityService method updateEntity.

protected synchronized T updateEntity(String entityManagerCode, EntityDto request, BindingResult bindingResult) {
    IEntityManager entityManager = this.extractEntityManager(entityManagerCode);
    try {
        String id = request.getId();
        I entity = (I) entityManager.getEntity(id);
        if (null == entity) {
            bindingResult.reject(EntityValidator.ERRCODE_ENTITY_DOES_NOT_EXIST, new String[] { id }, "entity.notExists");
            throw new ResourceNotFoundException(bindingResult);
        }
        String typeCode = request.getTypeCode();
        if (!entity.getTypeCode().equals(typeCode)) {
            bindingResult.reject(EntityValidator.ERRCODE_TYPE_MISMATCH, new String[] { entity.getTypeCode(), typeCode }, "entity.type.invalid");
            throw new ValidationConflictException(bindingResult);
        }
        request.fillEntity(entity, this.getCategoryManager(), bindingResult);
        this.scanEntity(entity, bindingResult);
        if (!bindingResult.hasErrors()) {
            I updatedEntity = (I) this.updateEntity(entityManager, entity);
            return this.buildEntityDto(updatedEntity);
        }
    } catch (Exception e) {
        logger.error("Error updating entity", e);
        throw new RestServerError("error updating entity", e);
    }
    return null;
}
Also used : IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException)

Example 24 with ResourceNotFoundException

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

the class AbstractEntityService method extractEntityManager.

protected IEntityManager extractEntityManager(String entityManagerCode) {
    IEntityManager entityManager = null;
    List<IEntityManager> managers = this.getEntityManagers();
    for (IEntityManager manager : managers) {
        if (((IManager) manager).getName().equals(entityManagerCode)) {
            entityManager = manager;
            break;
        }
    }
    if (null == entityManager) {
        logger.warn("no entity manager found with code {}", entityManagerCode);
        throw new ResourceNotFoundException("entityManagerCode", entityManagerCode);
    }
    return entityManager;
}
Also used : IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException)

Example 25 with ResourceNotFoundException

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

the class WidgetService method getWidget.

@Override
public WidgetDto getWidget(String widgetCode) {
    WidgetType widgetType = this.getWidgetManager().getWidgetType(widgetCode);
    if (null == widgetType) {
        logger.warn("no widget type found with code {}", widgetCode);
        throw new ResourceNotFoundException(WidgetValidator.ERRCODE_WIDGET_NOT_FOUND, "widget type", widgetCode);
    }
    WidgetDto widgetDto = dtoBuilder.convert(widgetType);
    try {
        this.addFragments(widgetDto);
    } catch (Exception e) {
        logger.error("Failed to fetch gui fragment for widget type code ", e);
    }
    return widgetDto;
}
Also used : ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto)

Aggregations

ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)53 RestServerError (org.entando.entando.aps.system.exception.RestServerError)27 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)20 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)16 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)15 IPage (com.agiletec.aps.system.services.page.IPage)9 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)9 Category (com.agiletec.aps.system.services.category.Category)7 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)7 ResponseEntity (org.springframework.http.ResponseEntity)7 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)6 List (java.util.List)6 ArrayList (java.util.ArrayList)5 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)5 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 CategoryUtilizer (com.agiletec.aps.system.services.category.CategoryUtilizer)3 Group (com.agiletec.aps.system.services.group.Group)3 Widget (com.agiletec.aps.system.services.page.Widget)3 Role (com.agiletec.aps.system.services.role.Role)3