Search in sources :

Example 1 with NumberAttribute

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

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

the class UserFilterOptionBean method extractFormParameters.

protected void extractFormParameters(HttpServletRequest request) throws Throwable {
    String[] formFieldNames = null;
    try {
        String frameIdSuffix = (null != this.getCurrentFrame()) ? "_frame" + this.getCurrentFrame().toString() : "";
        if (!this.isAttributeFilter()) {
            if (this.getKey().equals(KEY_FULLTEXT)) {
                String fieldName = TYPE_METADATA + "_fulltext" + frameIdSuffix;
                String[] fieldsSuffix = { "", "_option", "_attachSearch" };
                formFieldNames = this.extractParams(fieldName, fieldsSuffix, frameIdSuffix, request);
            } else if (this.getKey().equals(KEY_CATEGORY)) {
                formFieldNames = new String[1];
                formFieldNames[0] = TYPE_METADATA + "_category" + frameIdSuffix;
                String value = request.getParameter(formFieldNames[0]);
                this.addFormValue(formFieldNames[0], value, formFieldNames.length);
            }
        } else {
            AttributeInterface attribute = this.getAttribute();
            if (attribute instanceof ITextAttribute) {
                String[] fieldsSuffix = { "_textFieldName" };
                formFieldNames = this.extractAttributeParams(fieldsSuffix, frameIdSuffix, request);
            } else if (attribute instanceof DateAttribute) {
                String[] fieldsSuffix = { "_dateStartFieldName", "_dateEndFieldName" };
                formFieldNames = this.extractAttributeParams(fieldsSuffix, frameIdSuffix, request);
                this.checkRange(formFieldNames);
            } else if (attribute instanceof BooleanAttribute) {
                String[] fieldsSuffix = { "_booleanFieldName", "_booleanFieldName_ignore", "_booleanFieldName_control" };
                formFieldNames = this.extractAttributeParams(fieldsSuffix, frameIdSuffix, request);
            } else if (attribute instanceof NumberAttribute) {
                String[] fieldsSuffix = { "_numberStartFieldName", "_numberEndFieldName" };
                formFieldNames = this.extractAttributeParams(fieldsSuffix, frameIdSuffix, request);
                this.checkRange(formFieldNames);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error extracting form parameters", t);
        throw new ApsSystemException("Error extracting form parameters", t);
    }
    this.setFormFieldNames(formFieldNames);
}
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)

Example 3 with NumberAttribute

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

the class NumberAttributeValidationRules method validate.

@Override
public List<AttributeFieldError> validate(AttributeInterface attribute, AttributeTracer tracer, ILangManager langManager) {
    List<AttributeFieldError> errors = super.validate(attribute, tracer, langManager);
    if (this.isEmpty()) {
        return errors;
    }
    try {
        NumberAttribute numberAttribute = (NumberAttribute) attribute;
        if (null == numberAttribute.getValue()) {
            return errors;
        }
        int attributeValue = numberAttribute.getValue().intValue();
        Integer startValue = (this.getRangeStart() != null) ? (Integer) this.getRangeStart() : this.getOtherAttributeValue(attribute, this.getRangeStartAttribute());
        if (null != startValue && attributeValue < startValue) {
            AttributeFieldError error = new AttributeFieldError(attribute, FieldError.LESS_THAN_ALLOWED, tracer);
            error.setMessage("Number less than " + startValue);
            errors.add(error);
        }
        Integer endValue = (this.getRangeEnd() != null) ? (Integer) this.getRangeEnd() : this.getOtherAttributeValue(attribute, this.getRangeEndAttribute());
        if (null != endValue && attributeValue > endValue) {
            AttributeFieldError error = new AttributeFieldError(attribute, FieldError.GREATER_THAN_ALLOWED, tracer);
            error.setMessage("Number greater than " + endValue);
            errors.add(error);
        }
        Integer value = (this.getValue() != null) ? (Integer) this.getValue() : this.getOtherAttributeValue(attribute, this.getValueAttribute());
        if (null != value && attributeValue != value) {
            AttributeFieldError error = new AttributeFieldError(attribute, FieldError.INVALID, tracer);
            error.setMessage("Number not equals than " + value);
            errors.add(error);
        }
    } catch (Throwable t) {
        _logger.error("Error validating number attribute", t);
        throw new RuntimeException("Error validating number attribute", t);
    }
    return errors;
}
Also used : NumberAttribute(com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError)

Example 4 with NumberAttribute

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

the class EntityActionHelper method getAttributeFilters.

@Override
public EntitySearchFilter[] getAttributeFilters(AbstractApsEntityFinderAction entityFinderAction, IApsEntity prototype) {
    EntitySearchFilter[] filters = new EntitySearchFilter[0];
    if (null == prototype) {
        return filters;
    }
    List<AttributeInterface> contentAttributes = prototype.getAttributeList();
    for (int i = 0; i < contentAttributes.size(); i++) {
        AttributeInterface attribute = contentAttributes.get(i);
        if (attribute.isActive() && attribute.isSearcheable()) {
            if (attribute instanceof ITextAttribute) {
                String insertedText = entityFinderAction.getSearchFormFieldValue(attribute.getName() + "_textFieldName");
                if (null != insertedText && insertedText.trim().length() > 0) {
                    EntitySearchFilter filterToAdd = new EntitySearchFilter(attribute.getName(), true, insertedText.trim(), true);
                    filters = this.addFilter(filters, filterToAdd);
                }
            } else if (attribute instanceof DateAttribute) {
                Date dateStart = this.getDateSearchFormValue(entityFinderAction, attribute.getName(), "_dateStartFieldName", true);
                Date dateEnd = this.getDateSearchFormValue(entityFinderAction, attribute.getName(), "_dateEndFieldName", false);
                if (null != dateStart || null != dateEnd) {
                    EntitySearchFilter filterToAdd = new EntitySearchFilter(attribute.getName(), true, dateStart, dateEnd);
                    filters = this.addFilter(filters, filterToAdd);
                }
            } else if (attribute instanceof BooleanAttribute) {
                String booleanValue = entityFinderAction.getSearchFormFieldValue(attribute.getName() + "_booleanFieldName");
                if (null != booleanValue && booleanValue.trim().length() > 0) {
                    EntitySearchFilter filterToAdd = new EntitySearchFilter(attribute.getName(), true, booleanValue, false);
                    filters = this.addFilter(filters, filterToAdd);
                }
            } else if (attribute instanceof NumberAttribute) {
                BigDecimal numberStart = this.getNumberSearchFormValue(entityFinderAction, attribute.getName(), "_numberStartFieldName", true);
                BigDecimal numberEnd = this.getNumberSearchFormValue(entityFinderAction, attribute.getName(), "_numberEndFieldName", false);
                if (null != numberStart || null != numberEnd) {
                    EntitySearchFilter filterToAdd = new EntitySearchFilter(attribute.getName(), true, numberStart, numberEnd);
                    filters = this.addFilter(filters, filterToAdd);
                }
            }
        }
    }
    return filters;
}
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) 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 5 with NumberAttribute

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

the class AbstractBaseEntityAttributeConfigAction method fillAttributeFields.

/**
 * Fill attribute fields.
 * @param attribute The attribute to edit with the form values.
 * @return A customized return code in the attribute needs a extra configuration, else null.
 */
protected String fillAttributeFields(AttributeInterface attribute) {
    if (null != this.getAttributeDescription() && this.getAttributeDescription().trim().length() > 0) {
        attribute.setDescription(this.getAttributeDescription().trim());
    } else {
        attribute.setDescription(null);
    }
    attribute.setRoles(this.createStringArray(this.getAttributeRoles()));
    attribute.setDisablingCodes(this.createStringArray(this.getDisablingCodes()));
    attribute.setSearchable(null != this.getSearchable() && this.getSearchable());
    String indexingType = IndexableAttributeInterface.INDEXING_TYPE_NONE;
    if (null != this.getIndexable()) {
        indexingType = IndexableAttributeInterface.INDEXING_TYPE_TEXT;
    }
    attribute.setIndexingType(indexingType);
    IAttributeValidationRules valCond = attribute.getValidationRules();
    valCond.setRequired(null != this.getRequired() && this.getRequired());
    valCond.setOgnlValidationRule(this.getOgnlValidationRule());
    if (attribute.isTextAttribute()) {
        TextAttributeValidationRules valRule = (TextAttributeValidationRules) valCond;
        valRule.setMaxLength(this.getMaxLength());
        valRule.setMinLength(this.getMinLength());
        valRule.setRegexp(this.getRegexp());
        valRule.setRangeEnd(this.getRangeEndString());
        valRule.setRangeStart(this.getRangeStartString());
        valRule.setValue(this.getEqualString());
        valRule.setRangeEndAttribute(this.getRangeEndStringAttribute());
        valRule.setRangeStartAttribute(this.getRangeStartStringAttribute());
        valRule.setValueAttribute(this.getEqualStringAttribute());
        if (attribute instanceof EnumeratorAttribute) {
            EnumeratorAttribute enumeratorAttribute = (EnumeratorAttribute) attribute;
            enumeratorAttribute.setStaticItems(this.getEnumeratorStaticItems());
            if (null != this.getEnumeratorStaticItemsSeparator() && this.getEnumeratorStaticItemsSeparator().length() > 0) {
                enumeratorAttribute.setCustomSeparator(this.getEnumeratorStaticItemsSeparator());
            }
            if (null != this.getEnumeratorExtractorBean() && this.getEnumeratorExtractorBean().trim().length() > 0) {
                enumeratorAttribute.setExtractorBeanName(this.getEnumeratorExtractorBean());
            } else {
                enumeratorAttribute.setExtractorBeanName(null);
            }
        }
    }
    if (attribute instanceof DateAttribute) {
        DateAttributeValidationRules dateValRule = (DateAttributeValidationRules) valCond;
        dateValRule.setRangeEnd(this.getRangeEndDate());
        dateValRule.setRangeStart(this.getRangeStartDate());
        dateValRule.setValue(this.getEqualDate());
        dateValRule.setRangeEndAttribute(this.getRangeEndDateAttribute());
        dateValRule.setRangeStartAttribute(this.getRangeStartDateAttribute());
        dateValRule.setValueAttribute(this.getEqualDateAttribute());
    }
    if (attribute instanceof NumberAttribute) {
        NumberAttributeValidationRules nulValRule = (NumberAttributeValidationRules) valCond;
        nulValRule.setRangeEnd(this.getRangeEndNumber());
        nulValRule.setRangeStart(this.getRangeStartNumber());
        nulValRule.setValue(this.getEqualNumber());
        nulValRule.setRangeEndAttribute(this.getRangeEndNumberAttribute());
        nulValRule.setRangeStartAttribute(this.getRangeStartNumberAttribute());
        nulValRule.setValueAttribute(this.getEqualNumberAttribute());
    }
    return null;
}
Also used : EnumeratorAttribute(com.agiletec.aps.system.common.entity.model.attribute.EnumeratorAttribute) DateAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.DateAttributeValidationRules) IAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.IAttributeValidationRules) NumberAttribute(com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute) TextAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules) NumberAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.NumberAttributeValidationRules) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Aggregations

NumberAttribute (com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute)20 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)17 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)12 BooleanAttribute (com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute)10 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)10 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)7 BigDecimal (java.math.BigDecimal)7 Date (java.util.Date)7 EnumeratorAttribute (com.agiletec.aps.system.common.entity.model.attribute.EnumeratorAttribute)4 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)3 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 CheckBoxAttribute (com.agiletec.aps.system.common.entity.model.attribute.CheckBoxAttribute)2 CompositeAttribute (com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute)2 HypertextAttribute (com.agiletec.aps.system.common.entity.model.attribute.HypertextAttribute)2 ListAttribute (com.agiletec.aps.system.common.entity.model.attribute.ListAttribute)2 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)2 MonoTextAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute)2