Search in sources :

Example 26 with DateAttribute

use of com.agiletec.aps.system.common.entity.model.attribute.DateAttribute 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

DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)26 NumberAttribute (com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute)17 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)14 BooleanAttribute (com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute)10 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)10 Date (java.util.Date)10 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)7 MonoTextAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute)6 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)5 BigDecimal (java.math.BigDecimal)5 EnumeratorAttribute (com.agiletec.aps.system.common.entity.model.attribute.EnumeratorAttribute)4 HypertextAttribute (com.agiletec.aps.system.common.entity.model.attribute.HypertextAttribute)4 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)4 TextAttribute (com.agiletec.aps.system.common.entity.model.attribute.TextAttribute)4 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)4 DateAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.DateAttributeValidationRules)3 IAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.IAttributeValidationRules)3 NumberAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.NumberAttributeValidationRules)3 TextAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules)3 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)3