use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.
the class CategoryValidator method validatePutReferences.
public void validatePutReferences(String categoryCode, CategoryDto request, BindingResult bindingResult) {
if (!StringUtils.equals(categoryCode, request.getCode())) {
bindingResult.rejectValue("code", ERRCODE_URINAME_MISMATCH, new String[] { categoryCode, request.getCode() }, "category.code.mismatch");
throw new ValidationGenericException(bindingResult);
}
Category category = this.getCategoryManager().getCategory(request.getCode());
if (null == category) {
bindingResult.reject(ERRCODE_CATEGORY_NOT_FOUND, new String[] { request.getCode() }, "category.notexists");
throw new RestRourceNotFoundException(bindingResult);
}
Category parent = this.getCategoryManager().getCategory(request.getParentCode());
if (null == parent) {
bindingResult.reject(ERRCODE_PARENT_CATEGORY_NOT_FOUND, new String[] { request.getCode() }, "category.parent.notexists");
throw new RestRourceNotFoundException(bindingResult);
} else if (!parent.getCode().equals(category.getParentCode())) {
bindingResult.reject(ERRCODE_PARENT_CATEGORY_CANNOT_BE_CHANGED, new String[] {}, "category.parent.cannotBeChanged");
}
}
use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.
the class GuiFragmentService method removeGuiFragment.
@Override
public void removeGuiFragment(String guiFragmentCode) {
try {
GuiFragment fragment = this.getGuiFragmentManager().getGuiFragment(guiFragmentCode);
if (null == fragment) {
return;
}
GuiFragmentDto dto = this.getDtoBuilder().convert(fragment);
BeanPropertyBindingResult validationResult = this.checkFragmentForDelete(fragment, dto);
if (validationResult.hasErrors()) {
throw new ValidationGenericException(validationResult);
}
this.getGuiFragmentManager().deleteGuiFragment(guiFragmentCode);
} catch (ApsSystemException e) {
logger.error("Error in delete guiFragmentCode {}", guiFragmentCode, e);
throw new RestServerError("error in delete guiFragmentCode", e);
}
}
use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.
the class PageService method loadPage.
private IPage loadPage(String pageCode, String status) {
IPage page = null;
switch(status) {
case STATUS_DRAFT:
page = this.getPageManager().getDraftPage(pageCode);
break;
case STATUS_ONLINE:
page = this.getPageManager().getOnlinePage(pageCode);
break;
default:
break;
}
if (status.equals(STATUS_ONLINE) && null == page && null != this.getPageManager().getDraftPage(pageCode)) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(page, "page");
bindingResult.reject(ERRCODE_PAGE_ONLY_DRAFT, new Object[] { pageCode }, "page.status.draftOnly");
throw new ValidationGenericException(bindingResult);
}
return page;
}
use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.
the class WidgetService method addWidget.
@Override
public WidgetDto addWidget(WidgetRequest widgetRequest) {
WidgetType widgetType = new WidgetType();
this.processWidgetType(widgetType, widgetRequest);
WidgetType oldWidgetType = this.getWidgetManager().getWidgetType(widgetType.getCode());
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(widgetType, "widget");
if (null != oldWidgetType) {
bindingResult.reject(WidgetValidator.ERRCODE_WIDGET_ALREADY_EXISTS, new String[] { widgetType.getCode() }, "widgettype.exists");
throw new ValidationGenericException(bindingResult);
} else if (null == this.getGroupManager().getGroup(widgetRequest.getGroup())) {
bindingResult.reject(WidgetValidator.ERRCODE_WIDGET_GROUP_INVALID, new String[] { widgetRequest.getGroup() }, "widgettype.group.invalid");
throw new ValidationGenericException(bindingResult);
}
WidgetDto widgetDto = null;
try {
this.getWidgetManager().addWidgetType(widgetType);
this.createAndAddFragment(widgetType, widgetRequest);
widgetDto = this.dtoBuilder.convert(widgetType);
this.addFragments(widgetDto);
} catch (Exception e) {
logger.error("Failed to add widget type for request {} ", widgetRequest);
throw new RestServerError("error in add widget", e);
}
return widgetDto;
}
Aggregations