details: https://code.openbravo.com/erp/devel/pi/rev/3a1be18988dd
changeset: 16811:3a1be18988dd
user: Guillermo Álvarez de Eulate <guillermo.alvarez <at> openbravo.com>
date: Tue Jun 12 15:42:05 2012 +0200
summary: Fixed issue 20643: Filtering now works fine using hyphens
diffstat:
modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
| 44 ++++++++-
1 files changed, 37 insertions(+), 7 deletions(-)
diffs (82 lines):
diff -r c71e65f4a614 -r 3a1be18988dd
modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
---
a/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
Tue Jun 12 13:49:31 2012 +0200
+++
b/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
Tue Jun 12 15:42:05 2012 +0200
@@ -45,6 +45,7 @@
import org.openbravo.dal.service.OBDal;
import org.openbravo.erpCommon.utility.OBMessageUtils;
import org.openbravo.erpCommon.utility.Utility;
+import org.openbravo.model.ad.datamodel.Column;
import org.openbravo.model.ad.datamodel.Table;
import org.openbravo.model.ad.domain.Reference;
import org.openbravo.model.ad.domain.ReferencedTable;
@@ -490,11 +491,24 @@
throws JSONException {
Object localValue = value;
- // if the value consists of multiple parts then filtering won't work
- // only search on the first part then, is pragmatic but very workable
- if (localValue != null &&
localValue.toString().contains(IdentifierProvider.SEPARATOR)) {
- final int separatorIndex =
localValue.toString().indexOf(IdentifierProvider.SEPARATOR);
- localValue = localValue.toString().substring(0, separatorIndex);
+ // Related to issue 20643: Because multi-identifiers are a concatenation of
+ // values separated by ' - '
+ // With this fix hyphens are supported in the filter when
+ // property is not part of the identifier. Also hyphen is accepted if
+ // the property is the unique property of the identifier
+ if (property.isIdentifier()) {
+ // column associated with the property
+ final Column relatedColumn = OBDal.getInstance().get(Column.class,
property.getColumnId());
+ final Table relatedTable = relatedColumn.getTable();
+
+ if (isTableWithMultipleIdentifierColumns(relatedTable)) {
+ // if the value consists of multiple parts then filtering won't work
+ // only search on the first part then, is pragmatic but very workable
+ if (localValue != null &&
localValue.toString().contains(IdentifierProvider.SEPARATOR)) {
+ final int separatorIndex =
localValue.toString().indexOf(IdentifierProvider.SEPARATOR);
+ localValue = localValue.toString().substring(0, separatorIndex);
+ }
+ }
}
if (ignoreCase(property, operator)) {
@@ -533,6 +547,22 @@
return clause;
}
+ /* Return true if the identifier of the table is composed of more than one
column */
+ private Boolean isTableWithMultipleIdentifierColumns(Table relatedTable) {
+ int identifierCounter = 0;
+ for (Column curColumn : relatedTable.getADColumnList()) {
+ if (curColumn.isIdentifier()) {
+ identifierCounter += 1;
+ if (identifierCounter > 1) {
+ // if there are more than one identifier return true
+ return true;
+ }
+ }
+ }
+ // only one identifier. Is not multiple
+ return false;
+ }
+
private Object getTypeSafeValue(String operator, Property property, Object
value)
throws JSONException {
if (value == null) {
@@ -623,7 +653,7 @@
&& (operator.equals(OPERATOR_GREATERTHAN) ||
operator.equals(OPERATOR_GREATEROREQUAL)
|| operator.equals(OPERATOR_IGREATERTHAN) ||
operator.equals(OPERATOR_IGREATEROREQUAL)
|| operator.equals(OPERATOR_GREATERTHANFIElD) || operator
- .equals(OPERATOR_GREATEROREQUALFIELD));
+ .equals(OPERATOR_GREATEROREQUALFIELD));
}
private boolean isLesserOperator(String operator) {
@@ -631,7 +661,7 @@
&& (operator.equals(OPERATOR_LESSTHAN) ||
operator.equals(OPERATOR_LESSOREQUAL)
|| operator.equals(OPERATOR_ILESSTHAN) ||
operator.equals(OPERATOR_ILESSOREQUAL)
|| operator.equals(OPERATOR_LESSTHANFIELD) || operator
- .equals(OPERATOR_LESSOREQUALFIElD));
+ .equals(OPERATOR_LESSOREQUALFIElD));
}
private String computeLeftWhereClauseForIdentifier(Property property, String
key,
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits