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;
}
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());
}
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());
}
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;
}
}
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;
}
}
Aggregations