use of com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute in project entando-core by entando.
the class UserFilterOptionBean method getEntityFilter.
public EntitySearchFilter getEntityFilter() throws ApsSystemException {
EntitySearchFilter filter = null;
try {
if (!this.isAttributeFilter() || null == this.getFormFieldValues()) {
return null;
}
AttributeInterface attribute = this.getAttribute();
if (attribute instanceof ITextAttribute) {
String text = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
filter = new EntitySearchFilter(attribute.getName(), true, text, true);
if (attribute.isMultilingual()) {
filter.setLangCode(this.getCurrentLang().getCode());
}
} else if (attribute instanceof DateAttribute) {
String start = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
String end = this.getFormFieldValues().get(this.getFormFieldNames()[1]);
Date startDate = DateConverter.parseDate(start, this.getDateFormat());
Date endDate = DateConverter.parseDate(end, this.getDateFormat());
filter = new EntitySearchFilter(attribute.getName(), true, startDate, endDate);
} else if (attribute instanceof BooleanAttribute) {
String value = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
String ignore = this.getFormFieldValues().get(this.getFormFieldNames()[1]);
if (null != ignore) {
return null;
} else if (null == value || value.equals("both")) {
// special option for three state Attribute
filter = new EntitySearchFilter(attribute.getName(), true);
filter.setNullOption(true);
} else {
filter = new EntitySearchFilter(attribute.getName(), true, value, false);
}
} else if (attribute instanceof NumberAttribute) {
String start = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
String end = this.getFormFieldValues().get(this.getFormFieldNames()[1]);
BigDecimal startNumber = null;
try {
Integer startNumberInt = Integer.parseInt(start);
startNumber = new BigDecimal(startNumberInt);
} catch (Throwable t) {
}
BigDecimal endNumber = null;
try {
Integer endNumberInt = Integer.parseInt(end);
endNumber = new BigDecimal(endNumberInt);
} catch (Throwable t) {
}
filter = new EntitySearchFilter(attribute.getName(), true, startNumber, endNumber);
}
} catch (Throwable t) {
_logger.error("Error extracting entity search filters", t);
throw new ApsSystemException("Error extracting entity search filters", t);
}
return filter;
}
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 TestSaveBooleanAttributes method testSaveBooleanAttribute.
public void testSaveBooleanAttribute() throws Throwable {
try {
String contentOnSessionMarker = this.executeCreateNewContent();
Content content = this.getContentOnEdit(contentOnSessionMarker);
BooleanAttribute attribute = (BooleanAttribute) content.getAttribute("Boolean");
assertNull(attribute.getBooleanValue());
assertFalse(attribute.getValue());
this.initSaveContentAction(contentOnSessionMarker);
contentOnSessionMarker = this.executeSaveAndReloadContent(contentOnSessionMarker);
content = this.getContentOnEdit(contentOnSessionMarker);
attribute = (BooleanAttribute) content.getAttribute("Boolean");
assertNotNull(attribute.getBooleanValue());
assertFalse(attribute.getValue());
this.initSaveContentAction(contentOnSessionMarker);
this.addParameter("Boolean:Boolean", "false");
contentOnSessionMarker = this.executeSaveAndReloadContent(contentOnSessionMarker);
content = this.getContentOnEdit(contentOnSessionMarker);
attribute = (BooleanAttribute) content.getAttribute("Boolean");
assertNotNull(attribute.getBooleanValue());
assertFalse(attribute.getValue());
this.initSaveContentAction(contentOnSessionMarker);
this.addParameter("Boolean:Boolean", "true");
contentOnSessionMarker = this.executeSaveAndReloadContent(contentOnSessionMarker);
content = this.getContentOnEdit(contentOnSessionMarker);
attribute = (BooleanAttribute) content.getAttribute("Boolean");
assertNotNull(attribute.getBooleanValue());
assertTrue(attribute.getValue());
} catch (Throwable t) {
throw t;
} finally {
this.deleteTestContent();
}
}
use of com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute 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.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