Search in sources :

Example 11 with BooleanAttribute

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

the class UserFilterOptionBean method getEntityFilter.

public EntitySearchFilter getEntityFilter() throws ApsSystemException {
    EntitySearchFilter filter = null;
    try {
        if (!this.isAttributeFilter() || null == this.getFormFieldValues()) {
            return null;
        }
        AttributeInterface attribute = this.getAttribute();
        if (attribute instanceof ITextAttribute) {
            String text = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
            filter = new EntitySearchFilter(attribute.getName(), true, text, true);
            if (attribute.isMultilingual()) {
                filter.setLangCode(this.getCurrentLang().getCode());
            }
        } else if (attribute instanceof DateAttribute) {
            String start = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
            String end = this.getFormFieldValues().get(this.getFormFieldNames()[1]);
            Date startDate = DateConverter.parseDate(start, this.getDateFormat());
            Date endDate = DateConverter.parseDate(end, this.getDateFormat());
            filter = new EntitySearchFilter(attribute.getName(), true, startDate, endDate);
        } else if (attribute instanceof BooleanAttribute) {
            String value = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
            String ignore = this.getFormFieldValues().get(this.getFormFieldNames()[1]);
            if (null != ignore) {
                return null;
            } else if (null == value || value.equals("both")) {
                // special option for three state Attribute
                filter = new EntitySearchFilter(attribute.getName(), true);
                filter.setNullOption(true);
            } else {
                filter = new EntitySearchFilter(attribute.getName(), true, value, false);
            }
        } else if (attribute instanceof NumberAttribute) {
            String start = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
            String end = this.getFormFieldValues().get(this.getFormFieldNames()[1]);
            BigDecimal startNumber = null;
            try {
                Integer startNumberInt = Integer.parseInt(start);
                startNumber = new BigDecimal(startNumberInt);
            } catch (Throwable t) {
            }
            BigDecimal endNumber = null;
            try {
                Integer endNumberInt = Integer.parseInt(end);
                endNumber = new BigDecimal(endNumberInt);
            } catch (Throwable t) {
            }
            filter = new EntitySearchFilter(attribute.getName(), true, startNumber, endNumber);
        }
    } catch (Throwable t) {
        _logger.error("Error extracting entity search filters", t);
        throw new ApsSystemException("Error extracting entity search filters", 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) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) Date(java.util.Date) BigDecimal(java.math.BigDecimal) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 12 with BooleanAttribute

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

BooleanAttribute (com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute)12 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)10 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)10 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)10 NumberAttribute (com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute)10 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)7 BigDecimal (java.math.BigDecimal)5 Date (java.util.Date)5 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)3 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)3 SearchEngineFilter (org.entando.entando.aps.system.services.searchengine.SearchEngineFilter)2 AbstractComplexAttribute (com.agiletec.aps.system.common.entity.model.attribute.AbstractComplexAttribute)1 ActionSupport (com.opensymphony.xwork2.ActionSupport)1 List (java.util.List)1