Search in sources :

Example 41 with ValidationGenericException

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");
    }
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) Category(com.agiletec.aps.system.services.category.Category) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Example 42 with ValidationGenericException

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);
    }
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) GuiFragmentDto(org.entando.entando.aps.system.services.guifragment.model.GuiFragmentDto)

Example 43 with ValidationGenericException

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;
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Example 44 with ValidationGenericException

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;
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto)

Aggregations

ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)44 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)34 RestResponse (org.entando.entando.web.common.model.RestResponse)34 ResponseEntity (org.springframework.http.ResponseEntity)34 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)34 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)12 ArrayList (java.util.ArrayList)9 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)9 HashMap (java.util.HashMap)8 RestServerError (org.entando.entando.aps.system.exception.RestServerError)8 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)5 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)5 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)5 WidgetDto (org.entando.entando.aps.system.services.widgettype.model.WidgetDto)4 Category (com.agiletec.aps.system.services.category.Category)3 CategoryDto (org.entando.entando.aps.system.services.category.model.CategoryDto)3 DataModelDto (org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto)3 GuiFragmentDto (org.entando.entando.aps.system.services.guifragment.model.GuiFragmentDto)3 UserDto (org.entando.entando.aps.system.services.user.model.UserDto)3 ApsProperties (com.agiletec.aps.util.ApsProperties)2