Search in sources :

Example 6 with ITextAttribute

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

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

the class MonoTextAttributeManager method getCustomAttributeErrorMessage.

@Override
protected String getCustomAttributeErrorMessage(AttributeFieldError attributeFieldError, ActionSupport action) {
    AttributeInterface attribute = attributeFieldError.getAttribute();
    TextAttributeValidationRules valRules = (TextAttributeValidationRules) attribute.getValidationRules();
    if (null != valRules) {
        ITextAttribute textAttribute = (ITextAttribute) attribute;
        String text = textAttribute.getTextForLang(null);
        String errorCode = attributeFieldError.getErrorCode();
        if (errorCode.equals(FieldError.INVALID_MIN_LENGTH)) {
            String[] args = { String.valueOf(text.length()), String.valueOf(valRules.getMinLength()) };
            return action.getText("MonotextAttribute.fieldError.invalidMinLength", args);
        } else if (errorCode.equals(FieldError.INVALID_MAX_LENGTH)) {
            String[] args = { String.valueOf(text.length()), String.valueOf(valRules.getMaxLength()) };
            return action.getText("MonotextAttribute.fieldError.invalidMaxLength", args);
        } else if (errorCode.equals(FieldError.INVALID_FORMAT)) {
            return action.getText("MonotextAttribute.fieldError.invalidInsertedText");
        }
    }
    return action.getText(this.getInvalidAttributeMessage());
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) TextAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules)

Example 8 with ITextAttribute

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

the class TextAttributeManager method getCustomAttributeErrorMessage.

@Override
protected String getCustomAttributeErrorMessage(AttributeFieldError attributeFieldError, ActionSupport action) {
    AttributeInterface attribute = attributeFieldError.getAttribute();
    TextAttributeValidationRules valRules = (TextAttributeValidationRules) attribute.getValidationRules();
    if (null != valRules) {
        ITextAttribute textAttribute = (ITextAttribute) attribute;
        Lang lang = attributeFieldError.getTracer().getLang();
        String langCode = (null != lang) ? lang.getCode() : null;
        String text = textAttribute.getTextForLang(langCode);
        String errorCode = attributeFieldError.getErrorCode();
        if (errorCode.equals(FieldError.INVALID_MIN_LENGTH)) {
            String[] args = { String.valueOf(text.length()), String.valueOf(valRules.getMinLength()), lang.getDescr() };
            return action.getText("TextAttribute.fieldError.invalidMinLength", args);
        } else if (errorCode.equals(FieldError.INVALID_MAX_LENGTH)) {
            String[] args = { String.valueOf(text.length()), String.valueOf(valRules.getMaxLength()), lang.getDescr() };
            return action.getText("TextAttribute.fieldError.invalidMaxLength", args);
        } else if (errorCode.equals(FieldError.INVALID_FORMAT)) {
            String[] args = { lang.getDescr() };
            return action.getText("TextAttribute.fieldError.invalidInsertedText", args);
        }
    }
    return action.getText(this.getInvalidAttributeMessage());
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) Lang(com.agiletec.aps.system.services.lang.Lang) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) TextAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules)

Example 9 with ITextAttribute

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

the class TestValidateDataObject method testValidate_2.

public void testValidate_2() throws Throwable {
    try {
        DataObject content = this.createNewVoid("RAH", "descr", DataObject.STATUS_DRAFT, Group.FREE_GROUP_NAME, "admin");
        ITextAttribute emailAttribute = (ITextAttribute) content.getAttribute("email");
        emailAttribute.setText("wrongEmailAddress", null);
        List<FieldError> errors = content.validate(this._groupManager);
        assertEquals(1, errors.size());
        FieldError error = errors.get(0);
        assertEquals("Monotext:email", error.getFieldCode());
        assertEquals(FieldError.INVALID_FORMAT, error.getErrorCode());
    } catch (Throwable t) {
        throw t;
    }
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) FieldError(com.agiletec.aps.system.common.entity.model.FieldError)

Example 10 with ITextAttribute

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

the class TestValidateDataObject method testValidate_4.

public void testValidate_4() throws Throwable {
    String shortTitle = "short";
    String longTitle = "Titolo che supera la lunghezza massima di cento caratteri; " + "Ripeto, Titolo che supera la lunghezza massima di cento caratteri";
    try {
        DataObject content = this.createNewVoid("RAH", "descr", DataObject.STATUS_DRAFT, Group.FREE_GROUP_NAME, "admin");
        ITextAttribute textAttribute = (ITextAttribute) content.getAttribute("Titolo");
        textAttribute.setText(shortTitle, "it");
        List<FieldError> errors = content.validate(this._groupManager);
        assertEquals(1, errors.size());
        FieldError error = errors.get(0);
        assertEquals("Text:it_Titolo", error.getFieldCode());
        assertEquals(FieldError.INVALID_MIN_LENGTH, error.getErrorCode());
        textAttribute.setText(longTitle, "it");
        errors = content.validate(this._groupManager);
        assertEquals(1, errors.size());
        error = errors.get(0);
        assertEquals("Text:it_Titolo", error.getFieldCode());
        assertEquals(FieldError.INVALID_MAX_LENGTH, error.getErrorCode());
        textAttribute.setText(shortTitle, "en");
        errors = content.validate(this._groupManager);
        assertEquals(2, errors.size());
        error = errors.get(0);
        assertEquals("Text:it_Titolo", error.getFieldCode());
        assertEquals(FieldError.INVALID_MAX_LENGTH, error.getErrorCode());
        error = errors.get(1);
        assertEquals("Text:en_Titolo", error.getFieldCode());
        assertEquals(FieldError.INVALID_MIN_LENGTH, error.getErrorCode());
    } catch (Throwable t) {
        throw t;
    }
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) FieldError(com.agiletec.aps.system.common.entity.model.FieldError)

Aggregations

ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)27 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)16 BooleanAttribute (com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute)10 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)10 NumberAttribute (com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute)10 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)9 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)7 BigDecimal (java.math.BigDecimal)5 Date (java.util.Date)5 FieldError (com.agiletec.aps.system.common.entity.model.FieldError)4 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)4 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)3 TextAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules)2 Lang (com.agiletec.aps.system.services.lang.Lang)2 ArrayList (java.util.ArrayList)2 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)2 SearchEngineFilter (org.entando.entando.aps.system.services.searchengine.SearchEngineFilter)2 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)1 AttributeFieldError (com.agiletec.aps.system.common.entity.model.AttributeFieldError)1 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)1