Search in sources :

Example 86 with ApsProperties

use of com.agiletec.aps.util.ApsProperties in project entando-core by entando.

the class JAXBI18nLabel method extractLabels.

public ApsProperties extractLabels() {
    ApsProperties properties = new ApsProperties();
    if (null != this.getLabels()) {
        for (int i = 0; i < this.getLabels().size(); i++) {
            JAXBLabel jAXBLabel = this.getLabels().get(i);
            properties.put(jAXBLabel.getLangCode(), jAXBLabel.getValue());
        }
    }
    return properties;
}
Also used : ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 87 with ApsProperties

use of com.agiletec.aps.util.ApsProperties in project entando-core by entando.

the class LabelService method removeLabelGroup.

@Override
public void removeLabelGroup(String code) {
    try {
        ApsProperties labelGroup = this.getI18nManager().getLabelGroup(code);
        if (null == labelGroup) {
            logger.warn("no label found with key {}", code);
            return;
        }
        this.getI18nManager().deleteLabelGroup(code);
    } catch (ApsSystemException t) {
        logger.error("error in delete label group with code {}", code, t);
        throw new RestServerError("error in delete label group", t);
    }
}
Also used : RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 88 with ApsProperties

use of com.agiletec.aps.util.ApsProperties 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 89 with ApsProperties

use of com.agiletec.aps.util.ApsProperties in project entando-core by entando.

the class LabelService method getLabelGroups.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public PagedMetadata<LabelDto> getLabelGroups(RestListRequest restRequest) {
    Map<String, ApsProperties> result = this.i18nManager.getLabelGroups();
    List<LabelDto> dtoList = this.getDtoBuilder().convert(result);
    if (restRequest.getDirection().equals(FieldSearchFilter.DESC_ORDER)) {
        dtoList = dtoList.stream().sorted(Comparator.comparing(LabelDto::getKey).reversed()).collect(Collectors.toList());
    } else {
        dtoList = dtoList.stream().sorted(Comparator.comparing(LabelDto::getKey)).collect(Collectors.toList());
    }
    if (null != restRequest.getFilters()) {
        for (Filter f : restRequest.getFilters()) {
            if (f.getAttributeName().equals(LABEL_KEY_FILTER_KEY)) {
                dtoList = dtoList.stream().filter(i -> i.getKey().toLowerCase().contains(f.getValue().toLowerCase())).collect(Collectors.toList());
            }
            if (f.getAttributeName().equals(LABEL_KEY_FILTER_VALUE)) {
                dtoList = dtoList.stream().filter(i -> i.getTitles().values().stream().filter(k -> k.contains(f.getValue())).collect(Collectors.toList()).size() > 0).collect(Collectors.toList());
            }
        }
    }
    List<?> subList = restRequest.getSublist(dtoList);
    SearcherDaoPaginatedResult<LabelDto> resultx = new SearcherDaoPaginatedResult(dtoList.size(), subList);
    PagedMetadata<LabelDto> pagedMetadata = new PagedMetadata<>(restRequest, resultx);
    pagedMetadata.setBody((List<LabelDto>) subList);
    return pagedMetadata;
}
Also used : FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Filter(org.entando.entando.web.common.model.Filter) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) LabelDto(org.entando.entando.aps.system.services.label.model.LabelDto) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 90 with ApsProperties

use of com.agiletec.aps.util.ApsProperties 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

ApsProperties (com.agiletec.aps.util.ApsProperties)146 Widget (com.agiletec.aps.system.services.page.Widget)62 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)34 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)29 HashMap (java.util.HashMap)17 IPage (com.agiletec.aps.system.services.page.IPage)16 Lang (com.agiletec.aps.system.services.lang.Lang)14 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)10 Properties (java.util.Properties)9 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)9 List (java.util.List)8 RestServerError (org.entando.entando.aps.system.exception.RestServerError)8 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)7 Page (com.agiletec.aps.system.services.page.Page)6 PageMetadata (com.agiletec.aps.system.services.page.PageMetadata)6 NavigatorExpression (com.agiletec.aps.system.services.page.widget.NavigatorExpression)6 ArrayList (java.util.ArrayList)6 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)6 IWidgetTypeManager (org.entando.entando.aps.system.services.widgettype.IWidgetTypeManager)6 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)6