Search in sources :

Example 41 with Lang

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

the class DataObjectListHelper method buildCacheKey.

protected static String buildCacheKey(String listName, Collection<String> userGroupCodes, RequestContext reqCtx) {
    IPage page = (null != reqCtx) ? (IPage) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE) : null;
    StringBuilder cacheKey = (null != page) ? new StringBuilder(page.getCode()) : new StringBuilder("NOTFOUND");
    Widget currentWidget = (null != reqCtx) ? (Widget) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_WIDGET) : null;
    if (null != currentWidget && null != currentWidget.getType()) {
        cacheKey.append("_").append(currentWidget.getType().getCode());
    }
    if (null != reqCtx) {
        Integer frame = (Integer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_FRAME);
        if (null != frame) {
            cacheKey.append("_").append(frame.intValue());
        }
        Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
        if (null != currentLang) {
            cacheKey.append("_LANG").append(currentLang.getCode()).append("_");
        }
    }
    List<String> groupCodes = new ArrayList<String>(userGroupCodes);
    if (!groupCodes.contains(Group.FREE_GROUP_NAME)) {
        groupCodes.add(Group.FREE_GROUP_NAME);
    }
    Collections.sort(groupCodes);
    for (int i = 0; i < groupCodes.size(); i++) {
        String code = (String) groupCodes.get(i);
        cacheKey.append("_").append(code);
    }
    if (null != currentWidget && null != currentWidget.getConfig()) {
        List<String> paramKeys = new ArrayList(currentWidget.getConfig().keySet());
        Collections.sort(paramKeys);
        for (int i = 0; i < paramKeys.size(); i++) {
            if (i == 0) {
                cacheKey.append("_WIDGETPARAM");
            } else {
                cacheKey.append(",");
            }
            String paramkey = (String) paramKeys.get(i);
            cacheKey.append(paramkey).append("=").append(currentWidget.getConfig().getProperty(paramkey));
        }
    }
    if (null != listName) {
        cacheKey.append("_LISTNAME").append(listName);
    }
    return cacheKey.toString();
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) Widget(com.agiletec.aps.system.services.page.Widget) ArrayList(java.util.ArrayList) Lang(com.agiletec.aps.system.services.lang.Lang)

Example 42 with Lang

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

the class WidgetTypeDOM method createParameters.

protected void createParameters(List<WidgetTypeParameter> parameters, Element parameterElement) {
    String name = parameterElement.getAttributeValue("name");
    String description = parameterElement.getText();
    if (name.indexOf("{lang}") > 0) {
        for (int i = 0; i < this.getLangs().size(); i++) {
            Lang lang = this.getLangs().get(i);
            String newName = name.replace("{lang}", lang.getCode());
            String newDescription = description;
            if (null != description && description.indexOf("{lang}") > 0) {
                newDescription = description.replace("{lang}", lang.getCode());
            }
            this.addParameter(parameters, newName, newDescription);
        }
    } else {
        this.addParameter(parameters, name, description);
    }
}
Also used : Lang(com.agiletec.aps.system.services.lang.Lang)

Example 43 with Lang

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

the class FilterUtils method getUserFilter.

public UserFilterOptionBean getUserFilter(String dataObjectType, IEntityFilterBean bean, IDataObjectManager dataObjectManager, String dateFormat, RequestContext reqCtx) {
    UserFilterOptionBean filter = null;
    try {
        IApsEntity prototype = dataObjectManager.createDataObject(dataObjectType);
        Properties props = new Properties();
        props.setProperty(UserFilterOptionBean.PARAM_KEY, bean.getKey());
        props.setProperty(UserFilterOptionBean.PARAM_IS_ATTRIBUTE_FILTER, String.valueOf(bean.isAttributeFilter()));
        Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
        Integer currentFrame = (Integer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_FRAME);
        filter = new UserFilterOptionBean(props, prototype, currentFrame, currentLang, dateFormat, reqCtx.getRequest());
    } catch (Throwable t) {
        _logger.error("Error creating user filter", t);
    // ApsSystemUtils.logThrowable(t, FilterUtils.class, "getUserFilter", "Error creating user filter");
    }
    return filter;
}
Also used : UserFilterOptionBean(org.entando.entando.aps.system.services.dataobject.widget.UserFilterOptionBean) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) Lang(com.agiletec.aps.system.services.lang.Lang) Properties(java.util.Properties)

Example 44 with Lang

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

the class IndexerDAO method createDocument.

/**
 * Crea un oggetto Document pronto per l'indicizzazione da un oggetto
 * Content.
 *
 * @param entity Il dataobject dal quale ricavare il Document.
 * @return L'oggetto Document ricavato dal dataobject.
 * @throws ApsSystemException In caso di errore
 */
protected Document createDocument(IApsEntity entity) throws ApsSystemException {
    Document document = new Document();
    document.add(new StringField(DATAOBJECT_ID_FIELD_NAME, entity.getId(), Field.Store.YES));
    document.add(new TextField(DATAOBJECT_TYPE_FIELD_NAME, entity.getTypeCode(), Field.Store.YES));
    document.add(new StringField(DATAOBJECT_GROUP_FIELD_NAME, entity.getMainGroup(), Field.Store.YES));
    Iterator<String> iterGroups = entity.getGroups().iterator();
    while (iterGroups.hasNext()) {
        String groupName = (String) iterGroups.next();
        document.add(new StringField(DATAOBJECT_GROUP_FIELD_NAME, groupName, Field.Store.YES));
    }
    try {
        EntityAttributeIterator attributesIter = new EntityAttributeIterator(entity);
        while (attributesIter.hasNext()) {
            AttributeInterface currentAttribute = (AttributeInterface) attributesIter.next();
            List<Lang> langs = this.getLangManager().getLangs();
            for (int i = 0; i < langs.size(); i++) {
                Lang currentLang = (Lang) langs.get(i);
                this.indexAttribute(document, currentAttribute, currentLang);
            }
        }
        List<Category> categories = entity.getCategories();
        if (null != categories && !categories.isEmpty()) {
            for (int i = 0; i < categories.size(); i++) {
                Category category = categories.get(i);
                this.indexCategory(document, category);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error creating document", t);
        throw new ApsSystemException("Error creating document", t);
    }
    return document;
}
Also used : Category(com.agiletec.aps.system.services.category.Category) Lang(com.agiletec.aps.system.services.lang.Lang) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) Document(org.apache.lucene.document.Document) StringField(org.apache.lucene.document.StringField) TextField(org.apache.lucene.document.TextField) IndexableAttributeInterface(com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) EntityAttributeIterator(com.agiletec.aps.system.common.util.EntityAttributeIterator)

Example 45 with Lang

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

the class IndexerDAO method indexAttribute.

private void indexAttribute(Document document, AttributeInterface attribute, Lang lang) throws ApsSystemException {
    attribute.setRenderingLang(lang.getCode());
    if (attribute instanceof IndexableAttributeInterface) {
        String valueToIndex = ((IndexableAttributeInterface) attribute).getIndexeableFieldValue();
        String indexingType = attribute.getIndexingType();
        String fieldName = lang.getCode();
        if (null != indexingType && IndexableAttributeInterface.INDEXING_TYPE_UNSTORED.equalsIgnoreCase(indexingType)) {
            document.add(new TextField(fieldName, valueToIndex, Field.Store.NO));
        }
        if (null != indexingType && IndexableAttributeInterface.INDEXING_TYPE_TEXT.equalsIgnoreCase(indexingType)) {
            document.add(new TextField(fieldName, valueToIndex, Field.Store.YES));
        }
    }
    if (attribute.isSearchable()) {
        List<Lang> langs = new ArrayList<Lang>();
        langs.add(lang);
        AttributeTracer tracer = new AttributeTracer();
        tracer.setLang(lang);
        String name = tracer.getFormFieldName(attribute);
        List<AttributeSearchInfo> searchInfos = attribute.getSearchInfos(langs);
        if (null != searchInfos) {
            for (int i = 0; i < searchInfos.size(); i++) {
                AttributeSearchInfo info = searchInfos.get(i);
                Field field = null;
                if (null != info.getDate()) {
                    field = new TextField(name, DateTools.timeToString(info.getDate().getTime(), DateTools.Resolution.MINUTE), Field.Store.YES);
                } else if (null != info.getBigDecimal()) {
                    field = new IntField(name, info.getBigDecimal().intValue(), Field.Store.YES);
                } else {
                    field = new TextField(name, info.getString(), Field.Store.YES);
                }
                document.add(field);
            }
        }
    }
}
Also used : StringField(org.apache.lucene.document.StringField) Field(org.apache.lucene.document.Field) TextField(org.apache.lucene.document.TextField) IntField(org.apache.lucene.document.IntField) AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) ArrayList(java.util.ArrayList) TextField(org.apache.lucene.document.TextField) Lang(com.agiletec.aps.system.services.lang.Lang) IntField(org.apache.lucene.document.IntField) AttributeSearchInfo(com.agiletec.aps.system.common.entity.model.AttributeSearchInfo) IndexableAttributeInterface(com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface)

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