details: https://code.openbravo.com/erp/devel/pi/rev/10341843a241
changeset: 24098:10341843a241
user: Shankar Balachandran <shankar.balachandran <at> openbravo.com>
date: Tue Jul 22 15:39:38 2014 +0530
summary: Related to issue 26696 : Fixes filtering and sorting
Filtering and sorting is done using the displayed column of the table reference.
diffstat:
modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
| 70 ++++++++--
1 files changed, 56 insertions(+), 14 deletions(-)
diffs (105 lines):
diff -r 33e4af9b3575 -r 10341843a241
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 22 10:31:55 2014 +0200
+++
b/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
Tue Jul 22 15:39:38 2014 +0530
@@ -674,7 +674,7 @@
tableReference);
} else {
// passing true for last argument to apply filterCriteria
- clause = resolveJoins(properties, useFieldName, true);
+ clause = getMainAlias() + DalUtil.DOT + useFieldName;
}
} else {
clause = computeLeftWhereClauseForIdentifier(useProperty,
useFieldName, clause,
@@ -1390,6 +1390,7 @@
// table.window.identifier as the sort string
boolean isIdentifier = localOrderBy.equals(JsonConstants.IDENTIFIER)
|| localOrderBy.endsWith(DalUtil.DOT + JsonConstants.IDENTIFIER);
+ Property originalProp = null;
if (isIdentifier) {
Entity searchEntity = getEntity();
// a path to an entity, find the last entity
@@ -1403,7 +1404,7 @@
prefix = localOrderBy.substring(0,
localOrderBy.lastIndexOf(DalUtil.DOT) + 1);
String originalPropName = localOrderBy.replace(DalUtil.DOT +
JsonConstants.IDENTIFIER, "");
- Property originalProp = DalUtil.getPropertyFromPath(getEntity(),
originalPropName);
+ originalProp = DalUtil.getPropertyFromPath(getEntity(),
originalPropName);
if (originalProp.isComputedColumn()) {
prefix += Entity.COMPUTED_COLUMNS_PROXY_PROPERTY + DalUtil.DOT +
prefix;
}
@@ -1411,22 +1412,63 @@
} else {
prefix = "";
}
- for (Property prop : searchEntity.getIdentifierProperties()) {
- if (prop.isOneToMany()) {
- // not supported ignoring it
- continue;
+ boolean tableReference = false;
+ if (originalProp == null) {
+ if (distinctProperty != null) {
+ tableReference = true;
+ originalProp = distinctProperty;
}
- if (!prop.isPrimitive()) {
- // get identifier properties from target entity
- // TODO: currently only supports one level, recursive
- // calls have the danger of infinite loops in case of
- // wrong identifier definitions in the AD
- final Entity targetEntity = prop.getTargetEntity();
+ } else {
+ tableReference = originalProp.getDomainType() instanceof
TableDomainType;
+ }
+
+ if (tableReference) {
+ // special case table reference itself
+ final boolean isTable = originalProp.getEntity() ==
ModelProvider.getInstance().getEntity(
+ Table.ENTITY_NAME);
+ Property useProperty = null;
+ if (isTable) {
+ useProperty =
originalProp.getEntity().getProperty(Table.PROPERTY_NAME);
+ } else {
+ // read the reference to get the table reference
+ final Reference reference = OBDal.getInstance().get(Reference.class,
+ originalProp.getDomainType().getReference().getId());
+ for (ReferencedTable referencedTable :
reference.getADReferencedTableList()) {
+ if (referencedTable.isActive() &&
referencedTable.getDisplayedColumn() != null
+ && referencedTable.getDisplayedColumn().isActive()) {
+ useProperty =
originalProp.getTargetEntity().getPropertyByColumnName(
+ referencedTable.getDisplayedColumn().getDBColumnName());
+ break;
+ }
+ }
+ }
+ if (!useProperty.isPrimitive()) {
+ final Entity targetEntity = useProperty.getTargetEntity();
for (Property targetEntityProperty :
targetEntity.getIdentifierProperties()) {
- paths.add(prefix + prop.getName() + DalUtil.DOT +
targetEntityProperty.getName());
+ paths
+ .add(prefix + useProperty.getName() + DalUtil.DOT +
targetEntityProperty.getName());
}
} else {
- paths.add(prefix + prop.getName());
+ paths.add(prefix + useProperty.getName());
+ }
+ } else {
+ for (Property prop : searchEntity.getIdentifierProperties()) {
+ if (prop.isOneToMany()) {
+ // not supported ignoring it
+ continue;
+ }
+ if (!prop.isPrimitive()) {
+ // get identifier properties from target entity
+ // TODO: currently only supports one level, recursive
+ // calls have the danger of infinite loops in case of
+ // wrong identifier definitions in the AD
+ final Entity targetEntity = prop.getTargetEntity();
+ for (Property targetEntityProperty :
targetEntity.getIdentifierProperties()) {
+ paths.add(prefix + prop.getName() + DalUtil.DOT +
targetEntityProperty.getName());
+ }
+ } else {
+ paths.add(prefix + prop.getName());
+ }
}
}
} else {
------------------------------------------------------------------------------
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