Search in sources :

Example 21 with DateAttribute

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

the class AbstractBaseEntityAttributeConfigAction method valueFormFields.

/**
 * Fill form fields.
 * @param attribute
 */
protected void valueFormFields(AttributeInterface attribute) {
    this.setAttributeName(attribute.getName());
    if (null != attribute.getDescription() && attribute.getDescription().trim().length() > 0) {
        this.setAttributeDescription(attribute.getDescription());
    }
    this.setAttributeTypeCode(attribute.getType());
    if (null != attribute.getRoles()) {
        this.setAttributeRoles(Arrays.asList(attribute.getRoles()));
    }
    if (null != attribute.getDisablingCodes()) {
        this.setDisablingCodes(Arrays.asList(attribute.getDisablingCodes()));
    }
    IAttributeValidationRules valRule = attribute.getValidationRules();
    this.setRequired(valRule.isRequired());
    this.setOgnlValidationRule(valRule.getOgnlValidationRule());
    this.setSearchable(attribute.isSearchable());
    String indexingType = attribute.getIndexingType();
    if (null != indexingType) {
        this.setIndexable(indexingType.equalsIgnoreCase(IndexableAttributeInterface.INDEXING_TYPE_TEXT));
    }
    if (attribute.isTextAttribute()) {
        TextAttributeValidationRules textValRule = (TextAttributeValidationRules) valRule;
        if (null != textValRule.getMaxLength() && textValRule.getMaxLength() > -1) {
            this.setMaxLength(textValRule.getMaxLength());
        }
        if (null != textValRule.getMinLength() && textValRule.getMinLength() > -1) {
            this.setMinLength(textValRule.getMinLength());
        }
        this.setRegexp(textValRule.getRegexp());
        this.setRangeEndString((String) textValRule.getRangeEnd());
        this.setRangeStartString((String) textValRule.getRangeStart());
        this.setEqualString((String) textValRule.getValue());
        this.setRangeEndStringAttribute(textValRule.getRangeEndAttribute());
        this.setRangeStartStringAttribute(textValRule.getRangeStartAttribute());
        this.setEqualStringAttribute(textValRule.getValueAttribute());
        if (attribute instanceof EnumeratorAttribute) {
            EnumeratorAttribute enumeratorAttribute = (EnumeratorAttribute) attribute;
            this.setEnumeratorStaticItems(enumeratorAttribute.getStaticItems());
            this.setEnumeratorStaticItemsSeparator(enumeratorAttribute.getCustomSeparator());
            this.setEnumeratorExtractorBean(enumeratorAttribute.getExtractorBeanName());
        }
    }
    if (attribute instanceof DateAttribute) {
        DateAttributeValidationRules dateValRule = (DateAttributeValidationRules) valRule;
        this.setRangeEndDate((Date) dateValRule.getRangeEnd());
        this.setRangeStartDate((Date) dateValRule.getRangeStart());
        this.setEqualDate((Date) dateValRule.getValue());
        this.setRangeEndDateAttribute(dateValRule.getRangeEndAttribute());
        this.setRangeStartDateAttribute(dateValRule.getRangeStartAttribute());
        this.setEqualDateAttribute(dateValRule.getValueAttribute());
    }
    if (attribute instanceof NumberAttribute) {
        NumberAttributeValidationRules nulValRule = (NumberAttributeValidationRules) valRule;
        this.setRangeEndNumber((Integer) nulValRule.getRangeEnd());
        this.setRangeStartNumber((Integer) nulValRule.getRangeStart());
        this.setEqualNumber((Integer) nulValRule.getValue());
        this.setRangeEndNumberAttribute(nulValRule.getRangeEndAttribute());
        this.setRangeStartNumberAttribute(nulValRule.getRangeStartAttribute());
        this.setEqualNumberAttribute(nulValRule.getValueAttribute());
    }
}
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)

Example 22 with DateAttribute

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

the class UserFilterOptionBean method extractFilter.

public SearchEngineFilter extractFilter() {
    if (null == this.getFormFieldValues()) {
        return null;
    }
    SearchEngineFilter filter = null;
    String value0 = this.getFormValue(0);
    String value1 = this.getFormValue(1);
    if (!this.isAttributeFilter()) {
        if (this.getKey().equals(KEY_FULLTEXT) && !StringUtils.isEmpty(value0)) {
            // String[] fieldsSuffix = {"", "_option"};
            filter = new SearchEngineFilter(this.getCurrentLang().getCode(), value0, this.getOption(value1));
            String attachOption = this.getFormValue(2);
            try {
                filter.setIncludeAttachments(Boolean.parseBoolean(attachOption));
            } catch (Exception e) {
            }
        } else if (this.getKey().equals(KEY_CATEGORY) && !StringUtils.isEmpty(value0)) {
            filter = new SearchEngineFilter(IIndexerDAO.CONTENT_CATEGORY_FIELD_NAME, value0, SearchEngineFilter.TextSearchOption.EXACT);
        }
    } else {
        AttributeInterface attribute = this.getAttribute();
        if (attribute instanceof ITextAttribute && !StringUtils.isEmpty(value0)) {
            filter = new SearchEngineFilter(this.getIndexFieldName(), value0, SearchEngineFilter.TextSearchOption.EXACT);
        // String[] fieldsSuffix = {"_textFieldName"};
        } else if (attribute instanceof DateAttribute && (!StringUtils.isEmpty(value0) || !StringUtils.isEmpty(value1))) {
            Date big0 = null;
            try {
                big0 = DateConverter.parseDate(value0, this.getDateFormat());
            } catch (Exception e) {
            }
            Date big1 = null;
            try {
                big1 = DateConverter.parseDate(value1, this.getDateFormat());
            } catch (Exception e) {
            }
            // String[] fieldsSuffix = {"_dateStartFieldName", "_dateEndFieldName"};
            filter = new SearchEngineFilter(this.getIndexFieldName(), big0, big1);
        } else if (attribute instanceof BooleanAttribute && (!StringUtils.isEmpty(value0) && !StringUtils.isEmpty(value1))) {
            filter = new SearchEngineFilter(this.getIndexFieldName(), value0, SearchEngineFilter.TextSearchOption.EXACT);
        // String[] fieldsSuffix = {"_booleanFieldName", "_booleanFieldName_ignore", "_booleanFieldName_control"};
        } else if (attribute instanceof NumberAttribute && (!StringUtils.isEmpty(value0) || !StringUtils.isEmpty(value1))) {
            // String[] fieldsSuffix = {"_numberStartFieldName", "_numberEndFieldName"};
            BigDecimal big0 = null;
            try {
                big0 = new BigDecimal(value0);
            } catch (Exception e) {
            }
            BigDecimal big1 = null;
            try {
                big1 = new BigDecimal(value1);
            } catch (Exception e) {
            }
            filter = new SearchEngineFilter(this.getIndexFieldName(), big0, big1);
        }
    }
    return filter;
}
Also used : SearchEngineFilter(org.entando.entando.aps.system.services.searchengine.SearchEngineFilter) 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) Date(java.util.Date) BigDecimal(java.math.BigDecimal) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 23 with DateAttribute

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

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

the class UserFilterOptionBean method checkRange.

private void checkRange(String[] formFieldNames) {
    if (!this.isAttributeFilter() || null != this.getFormFieldErrors() || null == this.getFormFieldValues() || this.getFormFieldValues().size() < 2)
        return;
    boolean check = false;
    if (this.getAttribute() instanceof DateAttribute) {
        Date start = DateConverter.parseDate(this.getFormFieldValues().get(formFieldNames[0]), this.getDateFormat());
        Date end = DateConverter.parseDate(this.getFormFieldValues().get(formFieldNames[1]), this.getDateFormat());
        check = (!start.equals(end) && start.after(end));
    } else if (this.getAttribute() instanceof NumberAttribute) {
        Integer start = Integer.parseInt(this.getFormFieldValues().get(formFieldNames[0]));
        Integer end = Integer.parseInt(this.getFormFieldValues().get(formFieldNames[1]));
        check = (!start.equals(end) && start.intValue() > end.intValue());
    }
    if (check) {
        this.setFormFieldErrors(new HashMap<String, AttributeFormFieldError>(2));
        AttributeFormFieldError error = new AttributeFormFieldError(this.getAttribute().getName(), formFieldNames[1], AttributeFormFieldError.INVALID_RANGE_KEY, null);
        this.getFormFieldErrors().put(formFieldNames[1], error);
    }
}
Also used : NumberAttribute(com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute) Date(java.util.Date) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 25 with DateAttribute

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

the class DateAttributeHandler method endDate.

private void endDate(StringBuffer textBuffer) {
    if (null != textBuffer && null != this.getCurrentAttr()) {
        Date date = DateConverter.parseDate(textBuffer.toString(), SystemConstants.SYSTEM_DATE_FORMAT);
        ((DateAttribute) this.getCurrentAttr()).setDate(date);
    }
}
Also used : Date(java.util.Date) 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