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);
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations