details: https://code.openbravo.com/erp/devel/pi/rev/bbb998610a90
changeset: 24057:bbb998610a90
user: Shankar Balachandran <shankar.balachandran <at> openbravo.com>
date: Thu Jul 17 14:42:48 2014 +0530
summary: Fixes Issue 26696: Filtering of records works in all cases
Fixes filtering of records in all cases whether the field is primitive or a
composite reference.
diffstat:
modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
| 32 +++++++--
1 files changed, 24 insertions(+), 8 deletions(-)
diffs (73 lines):
diff -r c563d84563da -r bbb998610a90
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 Jul 15 11:02:51 2014 +0200
+++
b/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
Thu Jul 17 14:42:48 2014 +0530
@@ -600,7 +600,14 @@
useProperty = property.getEntity().getPropertyByColumnName(
referencedTable.getDisplayedColumn().getDBColumnName());
final int index = useFieldName.lastIndexOf(DalUtil.DOT);
- useFieldName = useFieldName.substring(0, index + 1) +
useProperty.getName();
+ if (useProperty.isPrimitive()) {
+ useFieldName = useFieldName.substring(0, index + 1) +
useProperty.getName();
+ } else {
+ // adding _identifier so that the identifier properties will
be formed properly in
+ // computeLeftWhereClauseForIdentifier.
+ useFieldName = useFieldName.substring(0, index + 1) +
useProperty.getName()
+ + DalUtil.DOT + JsonConstants.IDENTIFIER;
+ }
break;
}
}
@@ -630,14 +637,16 @@
clause = getMainAlias() + DalUtil.DOT
+ useFieldName.replace(DalUtil.DOT + JsonConstants.IDENTIFIER, "");
} else {
- clause = computeLeftWhereClauseForIdentifier(useProperty,
useFieldName, clause);
+ clause = computeLeftWhereClauseForIdentifier(useProperty,
useFieldName, clause,
+ tableReference);
}
} else if (!useProperty.isPrimitive()) {
clause = clause + ".id";
} else if (tableReference && useProperty.isTranslatable()
&& OBContext.hasTranslationInstalled()) {
// filtering by table reference translatable field: use translation table
- clause = computeLeftWhereClauseForIdentifier(useProperty, useFieldName,
clause);
+ clause = computeLeftWhereClauseForIdentifier(useProperty, useFieldName,
clause,
+ tableReference);
}
if (ignoreCase(properties, operator)) {
@@ -852,14 +861,20 @@
}
private String computeLeftWhereClauseForIdentifier(Property property, String
key,
- String leftWherePart) {
+ String leftWherePart, boolean isTableReference) {
// the identifierProperties are read from the owning entity of the
// property, that should work fine, as this last property is always part
of the
// identifier
- final List<Property> identifierProperties =
property.getEntity().getIdentifierProperties();
- Check.isTrue(identifierProperties.contains(property), "Property " +
property
- + " not part of identifier of " + property.getEntity());
+ List<Property> identifierProperties = null;
+ if (!isTableReference) {
+ identifierProperties = property.getEntity().getIdentifierProperties();
+ Check.isTrue(identifierProperties.contains(property), "Property " +
property
+ + " not part of identifier of " + property.getEntity());
+ } else {
+ // for table references, the display column identifier properties should
be used in the joins
+ identifierProperties =
property.getTargetEntity().getIdentifierProperties();
+ }
String prefix;
final int index = leftWherePart.lastIndexOf(DalUtil.DOT);
if (key.equals(JsonConstants.IDENTIFIER)) {
@@ -867,7 +882,8 @@
} else if (key.endsWith(JsonConstants.IDENTIFIER)) {
final String propPath = key.substring(0,
key.indexOf(JsonConstants.IDENTIFIER) - 1);
boolean fromCriteria = true;
- final String join =
resolveJoins(getPropertyForTableReference(JsonUtils.getPropertiesOnPath(getEntity(),
propPath)),
+ final String join = resolveJoins(
+
getPropertyForTableReference(JsonUtils.getPropertiesOnPath(getEntity(),
propPath)),
propPath, fromCriteria);
prefix = join + DalUtil.DOT;
} else if (index == -1) {
------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits