Search in sources :

Example 51 with RestServerError

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

the class LabelService method validateAddLabelGroup.

protected BeanPropertyBindingResult validateAddLabelGroup(LabelDto labelDto) {
    try {
        BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(labelDto, "labelGroup");
        String code = labelDto.getKey();
        ApsProperties labelGroup = this.getI18nManager().getLabelGroup(code);
        if (null != labelGroup) {
            bindingResult.reject(LabelValidator.ERRCODE_LABELGROUP_EXISTS, new String[] { code }, "labelGroup.code.already.present");
            return bindingResult;
        }
        String defaultLang = this.getLangManager().getDefaultLang().getCode();
        boolean isDefaultLangValid = validateDefaultLang(labelDto, bindingResult, defaultLang);
        if (!isDefaultLangValid) {
            return bindingResult;
        }
        List<String> configuredLangs = this.getLangManager().getLangs().stream().map(i -> i.getCode()).collect(Collectors.toList());
        labelDto.getTitles().entrySet().forEach(i -> validateLangEntry(i, configuredLangs, defaultLang, bindingResult));
        return bindingResult;
    } catch (ApsSystemException t) {
        logger.error("error in validate add label group with code {}", labelDto.getKey(), t);
        throw new RestServerError("error in validate add label group", t);
    }
}
Also used : Logger(org.slf4j.Logger) II18nManager(com.agiletec.aps.system.services.i18n.II18nManager) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) LoggerFactory(org.slf4j.LoggerFactory) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ApsProperties(com.agiletec.aps.util.ApsProperties) LabelValidator(org.entando.entando.web.label.LabelValidator) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) ILangManager(com.agiletec.aps.system.services.lang.ILangManager) List(java.util.List) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) RestListRequest(org.entando.entando.web.common.model.RestListRequest) RestServerError(org.entando.entando.aps.system.exception.RestServerError) Filter(org.entando.entando.web.common.model.Filter) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) Map(java.util.Map) Entry(java.util.Map.Entry) LabelDto(org.entando.entando.aps.system.services.label.model.LabelDto) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) Comparator(java.util.Comparator) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 52 with RestServerError

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

the class LanguageService method getLanguages.

@Override
public PagedMetadata<LanguageDto> getLanguages(RestListRequest requestList) {
    try {
        List<Lang> langs = this.getLangManager().getAssignableLangs();
        Collections.sort(langs, (o1, o2) -> o1.getCode().compareTo(o2.getCode()));
        SearcherDaoPaginatedResult<Lang> langsResult = new SearcherDaoPaginatedResult<>(langs.size(), langs);
        List<LanguageDto> dtoList = this.getLanguageDtoBuilder().convert(langsResult.getList());
        langsResult.setCount(langs.size());
        requestList.setPageSize(langs.size());
        PagedMetadata<LanguageDto> pagedMetadata = new PagedMetadata<>(requestList, langsResult);
        pagedMetadata.setBody(dtoList);
        return pagedMetadata;
    } catch (Throwable t) {
        logger.error("error in search langs", t);
        throw new RestServerError("error in search langs", t);
    }
}
Also used : PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) RestServerError(org.entando.entando.aps.system.exception.RestServerError) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) Lang(com.agiletec.aps.system.services.lang.Lang)

Example 53 with RestServerError

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

the class LanguageService method enableLang.

protected LanguageDto enableLang(String code) {
    try {
        Lang lang = this.getLangManager().getAssignableLangs().stream().filter(i -> i.getCode().equals(code)).findFirst().orElse(null);
        if (null == lang) {
            logger.warn("no lang found with code {}", code);
            throw new RestRourceNotFoundException(LanguageValidator.ERRCODE_LANGUAGE_DOES_NOT_EXISTS, "language", code);
        }
        // idempotent
        if (null == this.getLangManager().getLang(code)) {
            logger.warn("the lang {} is already active", code);
            this.getLangManager().addLang(lang.getCode());
        }
        return this.getLanguageDtoBuilder().convert(lang);
    } catch (ApsSystemException ex) {
        throw new RestServerError("error enabling lang " + code, ex);
    }
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) RestServerError(org.entando.entando.aps.system.exception.RestServerError) Lang(com.agiletec.aps.system.services.lang.Lang) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 54 with RestServerError

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

the class LanguageService method disableLang.

protected LanguageDto disableLang(String code) {
    try {
        Lang sysLang = this.getLangManager().getAssignableLangs().stream().filter(i -> i.getCode().equals(code)).findFirst().orElse(null);
        if (null == sysLang) {
            logger.warn("no lang found with code {}", code);
            throw new RestRourceNotFoundException(LanguageValidator.ERRCODE_LANGUAGE_DOES_NOT_EXISTS, "language", code);
        }
        // idempotent
        Lang lang = this.getLangManager().getLang(code);
        if (null != this.getLangManager().getLang(code)) {
            BeanPropertyBindingResult validations = this.validateDisable(lang);
            if (validations.hasErrors()) {
                throw new ValidationConflictException(validations);
            }
        }
        this.getLangManager().removeLang(code);
        return this.getLanguageDtoBuilder().convert(sysLang);
    } catch (ApsSystemException ex) {
        throw new RestServerError("error disabling language " + code, ex);
    }
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) Lang(com.agiletec.aps.system.services.lang.Lang) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException)

Example 55 with RestServerError

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

the class PageService method updateWidgetConfiguration.

@Override
public WidgetConfigurationDto updateWidgetConfiguration(String pageCode, int frameId, WidgetConfigurationRequest widgetReq) {
    try {
        IPage page = this.loadPage(pageCode, STATUS_DRAFT);
        if (null == page) {
            throw new RestRourceNotFoundException(ERRCODE_PAGE_NOT_FOUND, "page", pageCode);
        }
        if (frameId > page.getWidgets().length) {
            throw new RestRourceNotFoundException(ERRCODE_FRAME_INVALID, "frame", String.valueOf(frameId));
        }
        if (null == this.getWidgetType(widgetReq.getCode())) {
            throw new RestRourceNotFoundException(ERRCODE_WIDGET_INVALID, "widget", String.valueOf(widgetReq.getCode()));
        }
        BeanPropertyBindingResult validation = this.getWidgetValidatorFactory().get(widgetReq.getCode()).validate(widgetReq, page);
        if (null != validation && validation.hasErrors()) {
            throw new ValidationConflictException(validation);
        }
        ApsProperties properties = (ApsProperties) this.getWidgetProcessorFactory().get(widgetReq.getCode()).buildConfiguration(widgetReq);
        WidgetType widgetType = this.getWidgetType(widgetReq.getCode());
        Widget widget = new Widget();
        widget.setType(widgetType);
        widget.setConfig(properties);
        this.getPageManager().joinWidget(pageCode, widget, frameId);
        ApsProperties outProperties = this.getWidgetProcessorFactory().get(widgetReq.getCode()).extractConfiguration(widget.getConfig());
        return new WidgetConfigurationDto(widget.getType().getCode(), outProperties);
    } catch (ApsSystemException e) {
        logger.error("Error in update widget configuration {}", pageCode, e);
        throw new RestServerError("error in update widget configuration", e);
    }
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) IPage(com.agiletec.aps.system.services.page.IPage) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) WidgetConfigurationDto(org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto) RestServerError(org.entando.entando.aps.system.exception.RestServerError) Widget(com.agiletec.aps.system.services.page.Widget) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) ApsProperties(com.agiletec.aps.util.ApsProperties)

Aggregations

RestServerError (org.entando.entando.aps.system.exception.RestServerError)65 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)45 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)28 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)25 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)13 ArrayList (java.util.ArrayList)12 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)12 IPage (com.agiletec.aps.system.services.page.IPage)10 List (java.util.List)10 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)9 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)8 LoggerFactory (org.slf4j.LoggerFactory)8 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)7 RestListRequest (org.entando.entando.web.common.model.RestListRequest)7 Logger (org.slf4j.Logger)7 ApsProperties (com.agiletec.aps.util.ApsProperties)6 Group (com.agiletec.aps.system.services.group.Group)5 GroupUtilizer (com.agiletec.aps.system.services.group.GroupUtilizer)5 IDtoBuilder (org.entando.entando.aps.system.services.IDtoBuilder)5 Category (com.agiletec.aps.system.services.category.Category)4