use of com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute 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.BooleanAttribute in project entando-core by entando.
the class UserProfile method getValue.
private Object getValue(AttributeInterface attribute) {
if (null == attribute)
return "";
if (attribute.isTextAttribute()) {
return ((ITextAttribute) attribute).getText();
} else if (attribute instanceof NumberAttribute) {
return ((NumberAttribute) attribute).getValue();
} else if (attribute instanceof BooleanAttribute) {
return ((BooleanAttribute) attribute).getValue();
} else if (attribute instanceof DateAttribute) {
return ((DateAttribute) attribute).getDate();
} else if (!attribute.isSimple()) {
String text = "";
List<AttributeInterface> attributes = ((AbstractComplexAttribute) attribute).getAttributes();
for (int i = 0; i < attributes.size(); i++) {
if (i > 0)
text += ",";
AttributeInterface attributeElem = attributes.get(i);
text += this.getValue(attributeElem);
}
return text;
}
return null;
}
use of com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute in project entando-core by entando.
the class TestContentAction method testValidate_4.
/*
* We test, among other things the CheckBox attribute
*/
public void testValidate_4() throws Throwable {
String contentTypeCode = "RAH";
String contentOnSessionMarker = this.extractSessionMarker(contentTypeCode, ApsAdminSystemConstants.ADD);
String insertedDescr = "XXX Prova Validazione XXX";
try {
String result = this.executeCreateNewVoid(contentTypeCode, "descr", Content.STATUS_DRAFT, Group.FREE_GROUP_NAME, "admin");
assertEquals(Action.SUCCESS, result);
Content contentOnSession = this.getContentOnEdit(contentOnSessionMarker);
assertNotNull(contentOnSession);
this.initContentAction("/do/jacms/Content", "save", contentOnSessionMarker);
this.setUserOnSession("admin");
this.addParameter("descr", insertedDescr);
this.addParameter("Monotext:email", "wrongEmailAddress");
this.addParameter("Number:Numero", "wrongNumber");
this.addParameter("CheckBox:Checkbox", "true");
result = this.executeAction();
assertEquals(Action.INPUT, result);
ActionSupport action = this.getAction();
Map<String, List<String>> fieldErros = action.getFieldErrors();
assertEquals(2, fieldErros.size());
List<String> emailFieldErrors = fieldErros.get("Monotext:email");
assertEquals(1, emailFieldErrors.size());
List<String> numberFieldErrors = fieldErros.get("Number:Numero");
assertEquals(1, numberFieldErrors.size());
Content content = this.getContentOnEdit(contentOnSessionMarker);
assertNotNull(content);
assertTrue(content.getAttributeMap().containsKey("Checkbox"));
BooleanAttribute attribute = (BooleanAttribute) content.getAttribute("Checkbox");
assertNotNull(attribute);
assertEquals("CheckBox", attribute.getType());
assertEquals(Boolean.TRUE, attribute.getValue());
this.initContentAction("/do/jacms/Content", "save", contentOnSessionMarker);
this.setUserOnSession("admin");
this.addParameter("mainGroup", Group.FREE_GROUP_NAME);
this.addParameter("descr", insertedDescr);
this.addParameter("Monotext:email", "wrongEmailAddress");
this.addParameter("Number:Numero", "wrongNumber");
// LEAVING the Checkbox parameter will result in the checkbox attribute being later evaluated as 'false'
result = this.executeAction();
assertEquals(Action.INPUT, result);
content = this.getContentOnEdit(contentOnSessionMarker);
assertNotNull(content);
assertTrue(content.getAttributeMap().containsKey("Checkbox"));
attribute = (BooleanAttribute) content.getAttribute("Checkbox");
assertNotNull(attribute);
assertEquals("CheckBox", attribute.getType());
assertEquals(Boolean.FALSE, attribute.getValue());
} catch (Throwable t) {
throw t;
} finally {
this.removeTestContent(insertedDescr);
}
}
use of com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute in project entando-core by entando.
the class BaseFilterAction method setFilterType.
@Override
public String setFilterType() {
try {
Content prototype = this.getContentManager().createContentType(this.getContentType());
String key = this.getFilterKey();
int attrFilterType = -1;
AttributeInterface attribute = (AttributeInterface) prototype.getAttribute(key);
if (null != attribute) {
if (attribute instanceof ITextAttribute) {
attrFilterType = TEXT_ATTRIBUTE_FILTER_TYPE;
} else if (attribute instanceof NumberAttribute) {
attrFilterType = NUMBER_ATTRIBUTE_FILTER_TYPE;
} else if (attribute instanceof BooleanAttribute) {
attrFilterType = BOOLEAN_ATTRIBUTE_FILTER_TYPE;
} else if (attribute instanceof DateAttribute) {
attrFilterType = DATE_ATTRIBUTE_FILTER_TYPE;
}
} else if ((METADATA_KEY_PREFIX + IContentManager.CONTENT_CREATION_DATE_FILTER_KEY).equals(key) || (METADATA_KEY_PREFIX + IContentManager.CONTENT_MODIFY_DATE_FILTER_KEY).equals(key)) {
key = key.substring(METADATA_KEY_PREFIX.length());
this.setFilterKey(key);
attrFilterType = METADATA_FILTER_TYPE;
}
this.setFilterTypeId(attrFilterType);
if (this.getFilterTypeId() < 0) {
this.setFilterKey(null);
}
} catch (Throwable t) {
_logger.error("error in setFilterType", t);
// ApsSystemUtils.logThrowable(t, this, "setFilterType");
return FAILURE;
}
return SUCCESS;
}
use of com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute 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;
}
Aggregations