Search in sources :

Example 6 with DateAttribute

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

the class DateAttributeValidationRules 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 {
        Date attributeValue = ((DateAttribute) attribute).getDate();
        if (null == attributeValue) {
            return errors;
        }
        Date startValue = (this.getRangeStart() != null) ? (Date) this.getRangeStart() : this.getOtherAttributeValue(attribute, this.getRangeStartAttribute());
        if (null != startValue && attributeValue.before(startValue)) {
            AttributeFieldError error = new AttributeFieldError(attribute, FieldError.LESS_THAN_ALLOWED, tracer);
            String allowedDate = DateConverter.getFormattedDate(startValue, DATE_PATTERN);
            error.setMessage("Date less than " + allowedDate);
            errors.add(error);
        }
        Date endValue = (this.getRangeEnd() != null) ? (Date) this.getRangeEnd() : this.getOtherAttributeValue(attribute, this.getRangeEndAttribute());
        if (null != endValue && attributeValue.after(endValue)) {
            AttributeFieldError error = new AttributeFieldError(attribute, FieldError.GREATER_THAN_ALLOWED, tracer);
            String allowedDate = DateConverter.getFormattedDate(endValue, DATE_PATTERN);
            error.setMessage("Date greater than " + allowedDate);
            errors.add(error);
        }
        Date value = (this.getValue() != null) ? (Date) this.getValue() : this.getOtherAttributeValue(attribute, this.getValueAttribute());
        if (null != value && !attributeValue.equals(value)) {
            AttributeFieldError error = new AttributeFieldError(attribute, FieldError.NOT_EQUALS_THAN_ALLOWED, tracer);
            String allowedDate = DateConverter.getFormattedDate(value, DATE_PATTERN);
            error.setMessage("Date not equals than " + allowedDate);
            errors.add(error);
        }
    } catch (Throwable t) {
        _logger.error("Error validating Attribute '{}'", attribute.getName(), t);
        throw new RuntimeException("Error validating Attribute '" + attribute.getName() + "'", t);
    }
    return errors;
}
Also used : AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) Date(java.util.Date) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 7 with DateAttribute

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

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

the class DateAttributeManager method setValue.

@Override
protected void setValue(AttributeInterface attribute, String value) {
    DateAttribute dateAttribute = (DateAttribute) attribute;
    Date data = null;
    if (value != null) {
        value = value.trim();
    }
    if (CheckFormatUtil.isValidDate(value)) {
        try {
            SimpleDateFormat dataF = new SimpleDateFormat("dd/MM/yyyy");
            data = dataF.parse(value);
            dateAttribute.setFailedDateString(null);
        } catch (ParseException ex) {
            throw new RuntimeException("Error while parsing the date submitted - " + value + " -", ex);
        }
    } else {
        dateAttribute.setFailedDateString(value);
    }
    dateAttribute.setDate(data);
}
Also used : ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 9 with DateAttribute

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

Example 10 with DateAttribute

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

the class TestDataObjectManager method testLoadFullDataObject.

public void testLoadFullDataObject() throws Throwable {
    DataObject dataObject = this._dataObjectManager.loadDataObject("ALL4", false);
    assertEquals(DataObject.STATUS_PUBLIC, dataObject.getStatus());
    assertEquals(Group.FREE_GROUP_NAME, dataObject.getMainGroup());
    assertEquals(0, dataObject.getGroups().size());
    Map<String, AttributeInterface> attributes = dataObject.getAttributeMap();
    assertEquals(37, attributes.size());
    CheckBoxAttribute checkBoxAttribute = (CheckBoxAttribute) attributes.get("CheckBox");
    assertNotNull(checkBoxAttribute);
    assertNull(checkBoxAttribute.getBooleanValue());
    DateAttribute dateAttribute = (DateAttribute) attributes.get("Date");
    assertNotNull(dateAttribute);
    assertEquals("20100321", DateConverter.getFormattedDate(dateAttribute.getDate(), "yyyyMMdd"));
    DateAttribute dateAttribute2 = (DateAttribute) attributes.get("Date2");
    assertNotNull(dateAttribute2);
    assertEquals("20120321", DateConverter.getFormattedDate(dateAttribute2.getDate(), "yyyyMMdd"));
    EnumeratorAttribute enumeratorAttribute = (EnumeratorAttribute) attributes.get("Enumerator");
    assertNotNull(enumeratorAttribute);
    assertEquals("a", enumeratorAttribute.getText());
    EnumeratorMapAttribute enumeratorMapAttribute = (EnumeratorMapAttribute) attributes.get("EnumeratorMap");
    assertNotNull(enumeratorMapAttribute);
    assertEquals("02", enumeratorMapAttribute.getMapKey());
    assertEquals("Value 2", enumeratorMapAttribute.getMapValue());
    HypertextAttribute hypertextAttribute = (HypertextAttribute) attributes.get("Hypertext");
    assertNotNull(hypertextAttribute);
    assertEquals("<p>text Hypertext</p>", hypertextAttribute.getTextForLang("it"));
    TextAttribute longtextAttribute = (TextAttribute) attributes.get("Longtext");
    assertNotNull(longtextAttribute);
    assertEquals("text Longtext", longtextAttribute.getTextForLang("it"));
    MonoTextAttribute monoTextAttribute = (MonoTextAttribute) attributes.get("Monotext");
    assertNotNull(monoTextAttribute);
    assertEquals("text Monotext", monoTextAttribute.getText());
    MonoTextAttribute monoTextAttribute2 = (MonoTextAttribute) attributes.get("Monotext2");
    assertNotNull(monoTextAttribute2);
    assertEquals("aaaa@entando.com", monoTextAttribute2.getText());
    NumberAttribute numberAttribute = (NumberAttribute) attributes.get("Number");
    assertNotNull(numberAttribute);
    assertEquals(25, numberAttribute.getValue().intValue());
    NumberAttribute numberAttribute2 = (NumberAttribute) attributes.get("Number2");
    assertNotNull(numberAttribute2);
    assertEquals(85, numberAttribute2.getValue().intValue());
    TextAttribute textAttribute = (TextAttribute) attributes.get("Text");
    assertNotNull(textAttribute);
    assertEquals("text Text", textAttribute.getTextForLang("it"));
    TextAttribute textAttribute2 = (TextAttribute) attributes.get("Text2");
    assertNotNull(textAttribute2);
    assertEquals("bbbb@entando.com", textAttribute2.getTextForLang("it"));
    ThreeStateAttribute threeStateAttribute = (ThreeStateAttribute) attributes.get("ThreeState");
    assertNotNull(threeStateAttribute);
    assertEquals(Boolean.FALSE, threeStateAttribute.getBooleanValue());
    CompositeAttribute compositeAttribute = (CompositeAttribute) attributes.get("Composite");
    assertNotNull(compositeAttribute);
    assertEquals(10, compositeAttribute.getAttributeMap().size());
    ListAttribute listAttribute1 = (ListAttribute) attributes.get("ListBoolea");
    assertNotNull(listAttribute1);
    assertEquals(2, listAttribute1.getAttributeList("it").size());
    ListAttribute listAttribute2 = (ListAttribute) attributes.get("ListCheck");
    assertNotNull(listAttribute2);
    assertEquals(2, listAttribute2.getAttributeList("it").size());
    ListAttribute listAttribute3 = (ListAttribute) attributes.get("ListDate");
    assertNotNull(listAttribute3);
    assertEquals(2, listAttribute3.getAttributeList("it").size());
    ListAttribute listAttribute4 = (ListAttribute) attributes.get("ListEnum");
    assertNotNull(listAttribute4);
    assertEquals(2, listAttribute4.getAttributeList("it").size());
    ListAttribute listAttribute5 = (ListAttribute) attributes.get("ListMonot");
    assertNotNull(listAttribute5);
    assertEquals(2, listAttribute5.getAttributeList("it").size());
    ListAttribute listAttribute6 = (ListAttribute) attributes.get("ListNumber");
    assertNotNull(listAttribute6);
    assertEquals(2, listAttribute6.getAttributeList("it").size());
    ListAttribute listAttribute7 = (ListAttribute) attributes.get("List3Stat");
    assertNotNull(listAttribute7);
    assertEquals(3, listAttribute7.getAttributeList("it").size());
    MonoListAttribute monoListAttribute2 = (MonoListAttribute) attributes.get("MonoLBool");
    assertNotNull(monoListAttribute2);
    assertEquals(2, monoListAttribute2.getAttributes().size());
    MonoListAttribute monoListAttribute3 = (MonoListAttribute) attributes.get("MonoLChec");
    assertNotNull(monoListAttribute3);
    assertEquals(2, monoListAttribute3.getAttributes().size());
    MonoListAttribute monoListAttribute4 = (MonoListAttribute) attributes.get("MonoLCom");
    assertNotNull(monoListAttribute4);
    assertEquals(1, monoListAttribute4.getAttributes().size());
    MonoListAttribute monoListAttribute5 = (MonoListAttribute) attributes.get("MonoLCom2");
    assertNotNull(monoListAttribute5);
    assertEquals(2, monoListAttribute5.getAttributes().size());
    MonoListAttribute monoListAttribute6 = (MonoListAttribute) attributes.get("MonoLDate");
    assertNotNull(monoListAttribute6);
    assertEquals(2, monoListAttribute6.getAttributes().size());
    MonoListAttribute monoListAttribute7 = (MonoListAttribute) attributes.get("MonoLEnum");
    assertNotNull(monoListAttribute7);
    assertEquals(2, monoListAttribute7.getAttributes().size());
    MonoListAttribute monoListAttribute8 = (MonoListAttribute) attributes.get("MonoLHyper");
    assertNotNull(monoListAttribute8);
    assertEquals(2, monoListAttribute8.getAttributes().size());
    MonoListAttribute monoListAttribute11 = (MonoListAttribute) attributes.get("MonoLLong");
    assertNotNull(monoListAttribute11);
    assertEquals(1, monoListAttribute11.getAttributes().size());
    MonoListAttribute monoListAttribute12 = (MonoListAttribute) attributes.get("MonoLMonot");
    assertNotNull(monoListAttribute12);
    assertEquals(2, monoListAttribute12.getAttributes().size());
    MonoListAttribute monoListAttribute13 = (MonoListAttribute) attributes.get("MonoLNumb");
    assertNotNull(monoListAttribute13);
    assertEquals(2, monoListAttribute13.getAttributes().size());
    MonoListAttribute monoListAttribute14 = (MonoListAttribute) attributes.get("MonoLText");
    assertNotNull(monoListAttribute14);
    assertEquals(2, monoListAttribute14.getAttributes().size());
    MonoListAttribute monoListAttribute15 = (MonoListAttribute) attributes.get("MonoL3stat");
    assertNotNull(monoListAttribute15);
    assertEquals(3, monoListAttribute15.getAttributes().size());
    EnumeratorMapAttribute enumeratorMapAttribute2 = (EnumeratorMapAttribute) attributes.get("EnumeratorMapBis");
    assertNotNull(enumeratorMapAttribute2);
    assertEquals("01", enumeratorMapAttribute2.getMapKey());
    assertEquals("Value 1 Bis", enumeratorMapAttribute2.getMapValue());
}
Also used : HypertextAttribute(com.agiletec.aps.system.common.entity.model.attribute.HypertextAttribute) EnumeratorMapAttribute(org.entando.entando.aps.system.common.entity.model.attribute.EnumeratorMapAttribute) TextAttribute(com.agiletec.aps.system.common.entity.model.attribute.TextAttribute) MonoTextAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute) ThreeStateAttribute(com.agiletec.aps.system.common.entity.model.attribute.ThreeStateAttribute) EnumeratorAttribute(com.agiletec.aps.system.common.entity.model.attribute.EnumeratorAttribute) MonoListAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) CompositeAttribute(com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute) CheckBoxAttribute(com.agiletec.aps.system.common.entity.model.attribute.CheckBoxAttribute) NumberAttribute(com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) MonoTextAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute) MonoListAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute) ListAttribute(com.agiletec.aps.system.common.entity.model.attribute.ListAttribute) 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