Search in sources :

Example 26 with ITextAttribute

use of com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute in project entando-core by entando.

the class BaseEntityRenderer method convertSpecialCharacters.

protected List<TextAttributeCharReplaceInfo> convertSpecialCharacters(IApsEntity entity, String langCode) {
    List<TextAttributeCharReplaceInfo> conversions = new ArrayList<TextAttributeCharReplaceInfo>();
    Lang defaultLang = this.getLangManager().getDefaultLang();
    EntityAttributeIterator attributeIter = new EntityAttributeIterator(entity);
    while (attributeIter.hasNext()) {
        AttributeInterface currAttribute = (AttributeInterface) attributeIter.next();
        if (currAttribute instanceof ITextAttribute) {
            String attributeLangCode = langCode;
            ITextAttribute renderizable = (ITextAttribute) currAttribute;
            if (renderizable.needToConvertSpecialCharacter()) {
                String textToConvert = renderizable.getTextForLang(attributeLangCode);
                if (null == textToConvert || textToConvert.trim().length() == 0) {
                    attributeLangCode = defaultLang.getCode();
                    textToConvert = renderizable.getTextForLang(attributeLangCode);
                }
                if (null != textToConvert && textToConvert.trim().length() > 0) {
                    conversions.add(new TextAttributeCharReplaceInfo(renderizable, textToConvert, attributeLangCode));
                    String convertedText = StringEscapeUtils.escapeHtml(textToConvert);
                    renderizable.setText(convertedText, attributeLangCode);
                }
            }
        }
    }
    return conversions;
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) ArrayList(java.util.ArrayList) Lang(com.agiletec.aps.system.services.lang.Lang) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) EntityAttributeIterator(com.agiletec.aps.system.common.util.EntityAttributeIterator)

Example 27 with ITextAttribute

use of com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute in project entando-core by entando.

the class EntitySearchFilter method getInstance.

public static EntitySearchFilter getInstance(IApsEntity prototype, Properties props) {
    EntitySearchFilter filter = null;
    try {
        String key = props.getProperty(KEY_PARAM);
        String roleName = props.getProperty(ROLE_PARAM);
        if (null == key && null == roleName) {
            return null;
        }
        boolean isAttributeFilter = Boolean.parseBoolean(props.getProperty(FILTER_TYPE_PARAM));
        filter = new EntitySearchFilter();
        boolean isDateAttribute = false;
        if (!isAttributeFilter) {
            filter.setKey(key);
            String dataType = props.getProperty(DATA_TYPE_PARAM);
            if (null == dataType) {
                dataType = DATA_TYPE_STRING;
            }
            setValues(filter, props, dataType);
        } else {
            AttributeInterface attr = null;
            if (null != key) {
                attr = (AttributeInterface) prototype.getAttribute(key);
                filter.setKey(key);
            } else {
                attr = (AttributeInterface) prototype.getAttributeByRole(roleName);
                filter.setRoleName(roleName);
            }
            filter.setAttributeFilter(true);
            if (null != attr) {
                String dataType = null;
                if (attr instanceof DateAttribute) {
                    dataType = DATA_TYPE_DATE;
                    isDateAttribute = true;
                } else if (attr instanceof ITextAttribute || attr instanceof BooleanAttribute) {
                    dataType = DATA_TYPE_STRING;
                } else if (attr instanceof NumberAttribute) {
                    dataType = DATA_TYPE_NUMBER;
                }
                setValues(filter, props, dataType);
            } else
                throw new ApsSystemException("ERROR: Entity type '" + prototype.getTypeCode() + "' and attribute '" + key + "' not recognized");
        }
        if (isDateAttribute) {
            String valueDateDelay = props.getProperty(EntitySearchFilter.VALUE_DATE_DELAY_PARAM);
            filter.setValueDateDelay(null != valueDateDelay ? Integer.valueOf(valueDateDelay) : null);
            String endDateDelay = props.getProperty(EntitySearchFilter.END_DATE_DELAY_PARAM);
            filter.setEndDateDelay(null != endDateDelay ? Integer.valueOf(endDateDelay) : null);
            String startDateDelay = props.getProperty(EntitySearchFilter.START_DATE_DELAY_PARAM);
            filter.setStartDateDelay(null != startDateDelay ? Integer.valueOf(startDateDelay) : null);
        }
        String order = props.getProperty(EntitySearchFilter.ORDER_PARAM);
        filter.setOrder(order);
    } catch (ApsSystemException | NumberFormatException t) {
        _logger.error("Error on creation of filter instance", t);
        throw new RuntimeException("Error on creation of filter instance", t);
    }
    return filter;
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) BooleanAttribute(com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute) NumberAttribute(com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Aggregations

ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)27 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)16 BooleanAttribute (com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute)10 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)10 NumberAttribute (com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute)10 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)9 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)7 BigDecimal (java.math.BigDecimal)5 Date (java.util.Date)5 FieldError (com.agiletec.aps.system.common.entity.model.FieldError)4 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)4 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)3 TextAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules)2 Lang (com.agiletec.aps.system.services.lang.Lang)2 ArrayList (java.util.ArrayList)2 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)2 SearchEngineFilter (org.entando.entando.aps.system.services.searchengine.SearchEngineFilter)2 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)1 AttributeFieldError (com.agiletec.aps.system.common.entity.model.AttributeFieldError)1 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)1