You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2015/10/13 13:24:17 UTC
svn commit: r1708341 - in /ofbiz/trunk:
applications/party/entitydef/entitymodel.xml
framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java
framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java
Author: jleroux
Date: Tue Oct 13 11:24:17 2015
New Revision: 1708341
URL: http://svn.apache.org/viewvc?rev=1708341&view=rev
Log:
A patch from Wei for "The filter-by-date="true" of <entity-condition></entity> in view entity PartyExport does not work" https://issues.apache.org/jira/browse/OFBIZ-6495
I changed ViewEntityCondition.getWhereCondition(), ViewConditionExpr.createCondition() and ViewConditionList.createCondition() which will add additional condition of filtering by date to where clause.
Please test by following steps.
1. Change the code below in GenericDAO
if (queryTotalTime > 150) {
Debug.logTiming("Ran query in " + queryTotalTime + " milli-seconds: " + " EntityName: " + modelEntity.getEntityName() + " Sql: " + sql + " where clause:" + whereEntityConditionParams, module);
}
to
{code:title=GenericDAO.java|borderStyle=solid}
if (queryTotalTime > 0) {
Debug.logTiming("Ran query in " + queryTotalTime + " milli-seconds: " + " EntityName: " + modelEntity.getEntityName() + " Sql: " + sql + " where clause:" + whereEntityConditionParams, module);
}
It will always log the sql to the log file.
2. Open https://localhost:8443/partymgr/control/ImportExport
2. Enter a valid partyId for export and click SUBMIT
3. Check ofbiz.log file under runtime folder. You should able to see the query below which contains filter data condition
SELECT
PRT.PARTY_ID,
PRT.STATUS_ID,
PRT.PREFERRED_CURRENCY_UOM_ID,
GRP.GROUP_NAME,
PER.FIRST_NAME,
PER.MIDDLE_NAME,
PER.LAST_NAME,
PR.PARTY_ID_FROM,
CGRP.GROUP_NAME,
PRL.ROLE_TYPE_ID,
CM.CONTACT_MECH_TYPE_ID,
PCP.CONTACT_MECH_PURPOSE_TYPE_ID,
CM.INFO_STRING,
TN.COUNTRY_CODE,
TN.AREA_CODE,
TN.CONTACT_NUMBER,
PA.ADDRESS1,
PA.ADDRESS2,
PA.CITY,
PA.STATE_PROVINCE_GEO_ID,
PA.POSTAL_CODE,
PA.COUNTRY_GEO_ID,
PCM.FROM_DATE,
PCM.THRU_DATE
FROM (((((((((public.PARTY PRT
LEFT OUTER JOIN public.PARTY_GROUP GRP
ON PRT.PARTY_ID = GRP.PARTY_ID)
LEFT OUTER JOIN public.PERSON PER
ON PRT.PARTY_ID = PER.PARTY_ID)
LEFT OUTER JOIN public.PARTY_RELATIONSHIP PR
ON PRT.PARTY_ID = PR.PARTY_ID_TO
AND ((PR.ROLE_TYPE_ID_FROM = 'ACCOUNT'
AND PR.PARTY_RELATIONSHIP_TYPE_ID = 'EMPLOYMENT')))
LEFT OUTER JOIN public.PARTY_GROUP CGRP
ON PR.PARTY_ID_FROM = CGRP.PARTY_ID)
LEFT OUTER JOIN public.PARTY_ROLE PRL
ON PRT.PARTY_ID = PRL.PARTY_ID)
LEFT OUTER JOIN public.PARTY_CONTACT_MECH PCM
ON PRT.PARTY_ID = PCM.PARTY_ID
AND (((PCM.THRU_DATE IS NULL
OR PCM.THRU_DATE > '2015-06-15 13:21:30.157')
AND (PCM.FROM_DATE IS NULL
OR PCM.FROM_DATE <= '2015-06-15 13:21:30.157'))))
LEFT OUTER JOIN public.POSTAL_ADDRESS PA
ON PCM.CONTACT_MECH_ID = PA.CONTACT_MECH_ID)
LEFT OUTER JOIN public.CONTACT_MECH CM
ON PCM.CONTACT_MECH_ID = CM.CONTACT_MECH_ID)
LEFT OUTER JOIN public.TELECOM_NUMBER TN
ON PCM.CONTACT_MECH_ID = TN.CONTACT_MECH_ID)
LEFT OUTER JOIN public.PARTY_CONTACT_MECH_PURPOSE PCP
ON PCM.CONTACT_MECH_ID = PCP.CONTACT_MECH_ID
AND (((PCM.THRU_DATE IS NULL
OR PCM.THRU_DATE > '2015-06-15 13:21:30.157')
AND (PCM.FROM_DATE IS NULL
OR PCM.FROM_DATE <= '2015-06-15 13:21:30.157')))
AND PCM.PARTY_ID = PCP.PARTY_ID
AND (((PCM.THRU_DATE IS NULL
OR PCM.THRU_DATE > '2015-06-15 13:21:30.236')
AND (PCM.FROM_DATE IS NULL
OR PCM.FROM_DATE <= '2015-06-15 13:21:30.236')))
WHERE (((PRL.ROLE_TYPE_ID = ?
OR PRL.ROLE_TYPE_ID = ?
OR PRL.ROLE_TYPE_ID = ?)
AND (PRT.STATUS_ID <> ?
OR PRT.STATUS_ID IS NULL)
AND PRT.PARTY_ID = ?))
ORDER BY PRT.PARTY_ID ASC
Modified:
ofbiz/trunk/applications/party/entitydef/entitymodel.xml
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java
Modified: ofbiz/trunk/applications/party/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/party/entitydef/entitymodel.xml?rev=1708341&r1=1708340&r2=1708341&view=diff
==============================================================================
--- ofbiz/trunk/applications/party/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/applications/party/entitydef/entitymodel.xml Tue Oct 13 11:24:17 2015
@@ -2965,6 +2965,8 @@ under the License.
<alias entity-alias="PA" name="stateProvinceGeoId"/>
<alias entity-alias="PA" name="postalCode"/>
<alias entity-alias="PA" name="countryGeoId"/>
+ <alias entity-alias="PCM" name="fromDate"/>
+ <alias entity-alias="PCM" name="thruDate"/>
<view-link entity-alias="PRT" rel-entity-alias="GRP" rel-optional="true">
<key-map field-name="partyId"/>
</view-link>
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java?rev=1708341&r1=1708340&r2=1708341&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java Tue Oct 13 11:24:17 2015
@@ -47,7 +47,8 @@ import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.condition.EntityCondition;
import org.ofbiz.entity.condition.EntityConditionParam;
import org.ofbiz.entity.condition.EntityOperator;
-import org.ofbiz.entity.config.model.*;
+import org.ofbiz.entity.config.model.Datasource;
+import org.ofbiz.entity.config.model.EntityConfig;
import org.ofbiz.entity.jdbc.DatabaseUtil;
import org.ofbiz.entity.jdbc.SQLProcessor;
import org.ofbiz.entity.jdbc.SqlJdbcUtil;
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java?rev=1708341&r1=1708340&r2=1708341&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java Tue Oct 13 11:24:17 2015
@@ -45,6 +45,7 @@ import org.ofbiz.entity.condition.Entity
import org.ofbiz.entity.condition.EntityJoinOperator;
import org.ofbiz.entity.condition.EntityOperator;
import org.ofbiz.entity.jdbc.SqlJdbcUtil;
+import org.ofbiz.entity.util.EntityUtil;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@@ -1297,11 +1298,16 @@ public class ModelViewEntity extends Mod
}
public EntityCondition getWhereCondition(ModelFieldTypeReader modelFieldTypeReader, List<String> entityAliasStack) {
+
+ List<EntityCondition> conditionList = new LinkedList<EntityCondition>();
+ if(this.filterByDate) {
+ conditionList.add(EntityUtil.getFilterByDateExpr());
+ }
if (this.whereCondition != null) {
- return this.whereCondition.createCondition(modelFieldTypeReader, entityAliasStack);
- } else {
- return null;
+ conditionList.add(whereCondition.createCondition(modelFieldTypeReader, entityAliasStack));
}
+
+ return EntityCondition.makeCondition(conditionList, EntityOperator.AND);
}
public EntityCondition getHavingCondition(ModelFieldTypeReader modelFieldTypeReader, List<String> entityAliasStack) {
@@ -1405,30 +1411,42 @@ public class ModelViewEntity extends Mod
rhs = EntityFieldValue.makeFieldValue(this.relFieldName, this.relEntityAlias, entityAliasStack, this.viewEntityCondition.modelViewEntity);
}
+ EntityCondition entityCondition;
+
if (this.operator == EntityOperator.NOT_EQUAL && value != null) {
// since some databases don't consider nulls in != comparisons, explicitly include them
// this makes more sense logically, but if anyone ever needs it to not behave this way we should add an "or-null" attribute that is true by default
if (ignoreCase) {
- return EntityCondition.makeCondition(
+ entityCondition = EntityCondition.makeCondition(
EntityCondition.makeCondition(EntityFunction.UPPER(lhs), this.operator, EntityFunction.UPPER(rhs)),
EntityOperator.OR,
EntityCondition.makeCondition(lhs, EntityOperator.EQUALS, null));
} else {
- return EntityCondition.makeCondition(
+ entityCondition = EntityCondition.makeCondition(
EntityCondition.makeCondition(lhs, this.operator, rhs),
EntityOperator.OR,
EntityCondition.makeCondition(lhs, EntityOperator.EQUALS, null));
}
} else if ( value == null && this.relFieldName == null && (this.operator == EntityOperator.EQUALS || this.operator == EntityOperator.NOT_EQUAL)) {
- return EntityCondition.makeCondition(lhs, this.operator, null);
+ entityCondition = EntityCondition.makeCondition(lhs, this.operator, null);
} else {
if (ignoreCase) {
// use the stuff to upper case both sides
- return EntityCondition.makeCondition(EntityFunction.UPPER(lhs), this.operator, EntityFunction.UPPER(rhs));
+ entityCondition = EntityCondition.makeCondition(EntityFunction.UPPER(lhs), this.operator, EntityFunction.UPPER(rhs));
} else {
- return EntityCondition.makeCondition(lhs, this.operator, rhs);
+ entityCondition = EntityCondition.makeCondition(lhs, this.operator, rhs);
}
}
+
+ if(this.viewEntityCondition.filterByDate) {
+ List<EntityCondition> conditionList = new LinkedList<EntityCondition>();
+ conditionList.add(entityCondition);
+ conditionList.add(EntityUtil.getFilterByDateExpr());
+ return EntityCondition.makeCondition(conditionList, EntityOperator.AND);
+ } else {
+ return entityCondition;
+ }
+
}
}
@@ -1487,6 +1505,14 @@ public class ModelViewEntity extends Mod
}
}
+ if(this.viewEntityCondition.filterByDate) {
+ entityConditionList.add(EntityUtil.getFilterByDateExpr());
+ }
+
+ if(this.viewEntityCondition.filterByDate) {
+ entityConditionList.add(EntityUtil.getFilterByDateExpr());
+ }
+
return EntityCondition.makeCondition(entityConditionList, this.operator);
}
}