use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.
the class WidgetService method updateWidget.
@Override
public WidgetDto updateWidget(String widgetCode, WidgetRequest widgetRequest) {
WidgetType type = this.getWidgetManager().getWidgetType(widgetCode);
if (type == null) {
throw new RestRourceNotFoundException(WidgetValidator.ERRCODE_WIDGET_DOES_NOT_EXISTS, "widget", widgetCode);
} else if (null == this.getGroupManager().getGroup(widgetRequest.getGroup())) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(type, "widget");
bindingResult.reject(WidgetValidator.ERRCODE_WIDGET_GROUP_INVALID, new String[] { widgetRequest.getGroup() }, "widgettype.group.invalid");
throw new ValidationGenericException(bindingResult);
}
this.processWidgetType(type, widgetRequest);
WidgetDto widgetDto = dtoBuilder.convert(type);
try {
this.getWidgetManager().updateWidgetType(widgetCode, type.getTitles(), type.getConfig(), type.getMainGroup());
if (!StringUtils.isEmpty(widgetCode)) {
GuiFragment guiFragment = this.getGuiFragmentManager().getUniqueGuiFragmentByWidgetType(widgetCode);
if (null == guiFragment) {
this.createAndAddFragment(type, widgetRequest);
} else {
guiFragment.setGui(widgetRequest.getCustomUi());
this.getGuiFragmentManager().updateGuiFragment(guiFragment);
}
}
this.addFragments(widgetDto);
} catch (Throwable e) {
logger.error("failed to update widget type", e);
throw new RestServerError("Failed to update widget", e);
}
return widgetDto;
}
use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.
the class CategoryService method addCategory.
@Override
public CategoryDto addCategory(CategoryDto categoryDto) {
Category parentCategory = this.getCategoryManager().getCategory(categoryDto.getParentCode());
if (null == parentCategory) {
throw new RestRourceNotFoundException(CategoryValidator.ERRCODE_PARENT_CATEGORY_NOT_FOUND, "parent category", categoryDto.getParentCode());
}
Category category = this.getCategoryManager().getCategory(categoryDto.getCode());
if (null != category) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(category, "category");
bindingResult.reject(CategoryValidator.ERRCODE_CATEGORY_ALREADY_EXISTS, new String[] { category.getCode() }, "category.exists");
throw new ValidationGenericException(bindingResult);
}
CategoryDto dto = null;
try {
Category categoryToAdd = new Category();
categoryToAdd.setCode(categoryDto.getCode());
categoryToAdd.setParentCode(categoryDto.getParentCode());
categoryToAdd.getTitles().putAll(categoryDto.getTitles());
this.getCategoryManager().addCategory(categoryToAdd);
dto = this.getDtoBuilder().convert(this.getCategoryManager().getCategory(categoryDto.getCode()));
} catch (Exception e) {
logger.error("error adding category " + categoryDto.getCode(), e);
throw new RestServerError("error adding category " + categoryDto.getCode(), e);
}
return dto;
}
use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.
the class CategoryService method deleteCategory.
@Override
public void deleteCategory(String categoryCode) {
Category category = this.getCategoryManager().getCategory(categoryCode);
if (null == category) {
return;
}
try {
for (CategoryUtilizer categoryUtilizer : this.getCategoryUtilizers()) {
List references = categoryUtilizer.getCategoryUtilizers(categoryCode);
if (null != references && !references.isEmpty()) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(category, "category");
bindingResult.reject(CategoryValidator.ERRCODE_CATEGORY_REFERENCES, new String[] { categoryCode }, "category.cannot.delete.references");
throw new ValidationGenericException(bindingResult);
}
}
this.getCategoryManager().deleteCategory(categoryCode);
} catch (ValidationGenericException e) {
throw e;
} catch (Exception e) {
logger.error("error deleting category " + categoryCode, e);
throw new RestServerError("error deleting category " + categoryCode, e);
}
}
use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.
the class DataTypeController method addDataTypes.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> addDataTypes(@Valid @RequestBody DataTypeDtoRequest bodyRequest, BindingResult bindingResult) throws JsonProcessingException {
// field validations
this.getDataTypeValidator().validate(bodyRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
// business validations
if (this.getDataTypeValidator().existType(bodyRequest.getCode())) {
bindingResult.reject(DataTypeValidator.ERRCODE_ENTITY_TYPE_ALREADY_EXISTS, new String[] { bodyRequest.getCode() }, "entityType.exists");
}
if (bindingResult.hasErrors()) {
throw new ValidationConflictException(bindingResult);
}
DataTypeDto result = this.getDataObjectService().addDataType(bodyRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
logger.debug("Main Response -> {}", result);
return new ResponseEntity<>(new RestResponse(result), HttpStatus.OK);
}
use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.
the class DataObjectModelController method getDataObjectModel.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{dataModelId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getDataObjectModel(@PathVariable String dataModelId) {
logger.debug("Requested data object model -> {}", dataModelId);
MapBindingResult bindingResult = new MapBindingResult(new HashMap<>(), "dataModels");
int result = this.getDataObjectModelValidator().checkModelId(dataModelId, bindingResult);
if (bindingResult.hasErrors()) {
if (404 == result) {
throw new RestRourceNotFoundException(DataObjectModelValidator.ERRCODE_DATAOBJECTMODEL_DOES_NOT_EXIST, "dataObjectModel", dataModelId);
} else {
throw new ValidationGenericException(bindingResult);
}
}
DataModelDto dataModelDto = this.getDataObjectModelService().getDataObjectModel(Long.parseLong(dataModelId));
return new ResponseEntity<>(new RestResponse(dataModelDto), HttpStatus.OK);
}
Aggregations