Search in sources :

Example 46 with Lang

use of com.agiletec.aps.system.services.lang.Lang in project entando-core by entando.

the class TestDataObjectViewerHelper method init.

private void init() throws Exception {
    try {
        _requestContext = this.getRequestContext();
        Lang lang = new Lang();
        lang.setCode("it");
        lang.setDescr("italiano");
        _requestContext.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG, lang);
        Widget widget = new Widget();
        IWidgetTypeManager showletTypeMan = (IWidgetTypeManager) this.getService(SystemConstants.WIDGET_TYPE_MANAGER);
        WidgetType showletType = showletTypeMan.getWidgetType("content_viewer");
        widget.setType(showletType);
        widget.setConfig(new ApsProperties());
        _requestContext.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_WIDGET, widget);
        this._helper = (IDataObjectViewerHelper) this.getApplicationContext().getBean("DataObjectViewerHelper");
    } catch (Throwable t) {
        throw new Exception(t);
    }
}
Also used : IWidgetTypeManager(org.entando.entando.aps.system.services.widgettype.IWidgetTypeManager) Widget(com.agiletec.aps.system.services.page.Widget) Lang(com.agiletec.aps.system.services.lang.Lang) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 47 with Lang

use of com.agiletec.aps.system.services.lang.Lang in project entando-core by entando.

the class ApiI18nLabelInterface method checkLabels.

protected void checkLabels(JAXBI18nLabel jaxbI18nLabel) throws ApiException {
    try {
        String key = jaxbI18nLabel.getKey();
        if (null == key || key.trim().length() == 0) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label key required", Response.Status.CONFLICT);
        }
        ApsProperties labels = jaxbI18nLabel.extractLabels();
        if (null == labels || labels.isEmpty()) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label list can't be empty", Response.Status.CONFLICT);
        }
        Lang defaultLang = this.getLangManager().getDefaultLang();
        Object defaultLangValue = labels.get(defaultLang.getCode());
        if (null == defaultLangValue || defaultLangValue.toString().trim().length() == 0) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label list must contain a label for the default language '" + defaultLang.getCode() + "'", Response.Status.CONFLICT);
        }
        Iterator<Object> labelCodeIter = labels.keySet().iterator();
        while (labelCodeIter.hasNext()) {
            Object langCode = labelCodeIter.next();
            Object value = labels.get(langCode);
            if (null == value || value.toString().trim().length() == 0) {
                throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label for the language '" + langCode + "' is empty", Response.Status.CONFLICT);
            }
        }
    } catch (ApiException ae) {
        throw new ApiException("Error in method checkLabels ", ae);
    }
}
Also used : Lang(com.agiletec.aps.system.services.lang.Lang) ApiException(org.entando.entando.aps.system.services.api.model.ApiException) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 48 with Lang

use of com.agiletec.aps.system.services.lang.Lang 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 49 with Lang

use of com.agiletec.aps.system.services.lang.Lang 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 50 with Lang

use of com.agiletec.aps.system.services.lang.Lang 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)

Aggregations

Lang (com.agiletec.aps.system.services.lang.Lang)90 ArrayList (java.util.ArrayList)15 ApsProperties (com.agiletec.aps.util.ApsProperties)14 IPage (com.agiletec.aps.system.services.page.IPage)12 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)11 RequestContext (com.agiletec.aps.system.RequestContext)10 Widget (com.agiletec.aps.system.services.page.Widget)10 ILangManager (com.agiletec.aps.system.services.lang.ILangManager)8 AttributeTracer (com.agiletec.aps.system.common.entity.model.AttributeTracer)7 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 HashMap (java.util.HashMap)6 ServletRequest (javax.servlet.ServletRequest)6 AttributeFieldError (com.agiletec.aps.system.common.entity.model.AttributeFieldError)4 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)4 IndexableAttributeInterface (com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface)4 Category (com.agiletec.aps.system.services.category.Category)4 Properties (java.util.Properties)4 JspException (javax.servlet.jsp.JspException)4 StringField (org.apache.lucene.document.StringField)4