use of com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute 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());
}
use of com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute 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);
}
}
use of com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute 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;
}
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);
}
use of com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute in project entando-core by entando.
the class EntityAttributeValidationDto method buildAttributeValidation.
public void buildAttributeValidation(String typeCode, AttributeInterface attribute, BindingResult bindingResult) {
EntityAttributeOgnlValidationDto ognlValidationDto = this.getOgnlValidation();
if (null != ognlValidationDto) {
ognlValidationDto.buildAttributeOgnlValidation(typeCode, attribute, bindingResult);
}
IAttributeValidationRules validationRules = attribute.getValidationRules();
if (attribute.isTextAttribute()) {
TextAttributeValidationRules textValRule = (TextAttributeValidationRules) validationRules;
if (StringUtils.isEmpty(this.getRegex())) {
textValRule.setRegexp(this.getRegex());
}
if (null != this.getMinLength() && null != this.getMaxLength() && (this.getMinLength() > this.getMaxLength())) {
this.addError(EntityTypeValidator.ERRCODE_INVALID_TEXT_RANGE, bindingResult, new String[] { typeCode, attribute.getName() }, "entityType.attribute.text.invalidRange");
} else {
if (null != this.getMinLength()) {
textValRule.setMinLength(this.getMinLength());
}
if (null != this.getMinLength()) {
textValRule.setMaxLength(this.getMaxLength());
}
}
if (StringUtils.isEmpty(this.getRangeStartString()) || StringUtils.isEmpty(this.getRangeEndString()) || StringUtils.isEmpty(this.getRangeStartStringAttribute()) || StringUtils.isEmpty(this.getRangeEndStringAttribute())) {
textValRule.setRangeEnd(this.getRangeEndString());
textValRule.setRangeStart(this.getRangeStartString());
textValRule.setRangeEndAttribute(this.getRangeEndStringAttribute());
textValRule.setRangeStartAttribute(this.getRangeStartStringAttribute());
} else {
textValRule.setValue(this.getEqualString());
textValRule.setValueAttribute(this.getEqualStringAttribute());
}
} else if (attribute instanceof DateAttribute) {
DateAttributeValidationRules dateValRule = (DateAttributeValidationRules) validationRules;
dateValRule.setRangeStart(this.extractDate(this.getRangeStartDate(), typeCode, attribute.getName(), EntityTypeValidator.ERRCODE_INVALID_DATE_RANGE_START, "entityType.attribute.date.invalidRangeStart", bindingResult));
dateValRule.setRangeEnd(this.extractDate(this.getRangeEndDate(), typeCode, attribute.getName(), EntityTypeValidator.ERRCODE_INVALID_DATE_RANGE_END, "entityType.attribute.date.invalidRangeEnd", bindingResult));
dateValRule.setValue(this.extractDate(this.getEqualDate(), typeCode, attribute.getName(), EntityTypeValidator.ERRCODE_INVALID_DATE_VALUE, "entityType.attribute.date.invalidValue", bindingResult));
dateValRule.setRangeStartAttribute(this.getRangeStartDateAttribute());
dateValRule.setRangeEndAttribute(this.getRangeEndDateAttribute());
dateValRule.setValueAttribute(this.getEqualDateAttribute());
} else if (attribute instanceof NumberAttribute) {
NumberAttributeValidationRules nulValRule = (NumberAttributeValidationRules) validationRules;
nulValRule.setRangeEnd(this.getRangeEndNumber());
nulValRule.setRangeStart(this.getRangeStartNumber());
if (null != this.getRangeStartNumber() && null != this.getRangeEndNumber() && (this.getRangeEndNumber() < this.getRangeStartNumber())) {
this.addError(EntityTypeValidator.ERRCODE_INVALID_NUMBER_RANGE, bindingResult, new String[] { typeCode, attribute.getName() }, "entityType.attribute.number.invalidRange");
}
nulValRule.setValue(this.getEqualNumber());
nulValRule.setRangeEndAttribute(this.getRangeEndNumberAttribute());
nulValRule.setRangeStartAttribute(this.getRangeStartNumberAttribute());
nulValRule.setValueAttribute(nulValRule.getValueAttribute());
}
}
Aggregations