You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by nm...@apache.org on 2016/07/11 23:05:35 UTC

svn commit: r1752232 - in /ofbiz/trunk: applications/accounting/minilang/finaccount/ applications/accounting/servicedef/ applications/datamodel/entitydef/ framework/service/src/org/ofbiz/service/engine/

Author: nmalin
Date: Mon Jul 11 23:05:34 2016
New Revision: 1752232

URL: http://svn.apache.org/viewvc?rev=1752232&view=rev
Log:
Improve FinAccountStatus entity to manage changeByUserLoginId field with conversion of minilang service to entity-auto. This previous service manage a specific case for the statusEndDate field that set the date when a new entry is stored on statusDate and the same value on previous stored on statusEndDate. This field is also present on ExampleStatus, so extend the EntityAuto engine to manage this case. Thanks Nameet Jain for the OFBIZ-7623

Modified:
    ofbiz/trunk/applications/accounting/minilang/finaccount/FinAccountServices.xml
    ofbiz/trunk/applications/accounting/servicedef/services_finaccount.xml
    ofbiz/trunk/applications/datamodel/entitydef/accounting-entitymodel.xml
    ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java

Modified: ofbiz/trunk/applications/accounting/minilang/finaccount/FinAccountServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/minilang/finaccount/FinAccountServices.xml?rev=1752232&r1=1752231&r2=1752232&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/minilang/finaccount/FinAccountServices.xml (original)
+++ ofbiz/trunk/applications/accounting/minilang/finaccount/FinAccountServices.xml Mon Jul 11 23:05:34 2016
@@ -152,27 +152,6 @@ under the License.
         <remove-value value-field="finAccount"/>
     </simple-method>
 
-    <simple-method method-name="createFinAccountStatus" short-description="Create FinAccountStatus">
-        <now-timestamp field="nowTimestamp"/>
-
-        <!-- find the most recent status record and set the statusEndDate -->
-        <entity-and entity-name="FinAccountStatus" list="oldFinAccountStatusList">
-            <field-map field-name="finAccountId" from-field="parameters.finAccountId"/>
-            <order-by field-name="-statusDate"/>
-        </entity-and>
-        <first-from-list entry="oldFinAccountStatus" list="oldFinAccountStatusList"/>
-        <if-not-empty field="oldFinAccountStatus">
-            <set field="oldFinAccountStatus.statusEndDate" from-field="nowTimestamp"/>
-            <store-value value-field="oldFinAccountStatus"/>
-        </if-not-empty>
-
-        <make-value entity-name="FinAccountStatus" value-field="newEntity"/>
-        <set-pk-fields map="parameters" value-field="newEntity"/>
-        <set-nonpk-fields map="parameters" value-field="newEntity"/>
-        <set field="newEntity.statusDate" from-field="nowTimestamp"/>
-        <create-value value-field="newEntity"/>
-    </simple-method>
-
     <!-- FinAccountTrans Services -->
     <simple-method method-name="createFinAccountTrans" short-description="Create a Financial Account Transaction">
         <entity-one entity-name="FinAccount" value-field="finAccount"/>

Modified: ofbiz/trunk/applications/accounting/servicedef/services_finaccount.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/services_finaccount.xml?rev=1752232&r1=1752231&r2=1752232&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/servicedef/services_finaccount.xml (original)
+++ ofbiz/trunk/applications/accounting/servicedef/services_finaccount.xml Mon Jul 11 23:05:34 2016
@@ -63,13 +63,13 @@ under the License.
         <description>Update FinAccount.availableBalance based on a new FinAccountAuth; meant to be called as an EECA as it is for data maintenance</description>
         <attribute name="finAccountAuthId" type="String" mode="IN" optional="false"/>
     </service>
-    <service name="createFinAccountStatus" default-entity-name="FinAccountStatus" engine="simple"
-        location="component://accounting/minilang/finaccount/FinAccountServices.xml" invoke="createFinAccountStatus" auth="true">
+    <service name="createFinAccountStatus" default-entity-name="FinAccountStatus" engine="entity-auto" invoke="create" auth="true">
         <description>Create a FinAccountStatus</description>
         <auto-attributes include="all" mode="IN" optional="false">
-            <exclude field-name="statusDate"/>
             <exclude field-name="statusEndDate"/>
+            <exclude field-name="changeByUserLoginId"/>
         </auto-attributes>
+        <override name="statusDate" optional="true" mode="IN"/>
     </service>
 
     <!-- Financial Account Transaction -->

Modified: ofbiz/trunk/applications/datamodel/entitydef/accounting-entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/datamodel/entitydef/accounting-entitymodel.xml?rev=1752232&r1=1752231&r2=1752232&view=diff
==============================================================================
--- ofbiz/trunk/applications/datamodel/entitydef/accounting-entitymodel.xml (original)
+++ ofbiz/trunk/applications/datamodel/entitydef/accounting-entitymodel.xml Mon Jul 11 23:05:34 2016
@@ -441,6 +441,7 @@ under the License.
         <field name="statusId" type="id"></field>
         <field name="statusDate" type="date-time"></field>
         <field name="statusEndDate" type="date-time"></field>
+        <field name="changeByUserLoginId" type="id-vlong"/>
         <prim-key field="finAccountId"/>
         <prim-key field="statusId"/>
         <prim-key field="statusDate"/>
@@ -450,6 +451,9 @@ under the License.
         <relation type="one" fk-name="FINACT_STTS_STI" rel-entity-name="StatusItem">
             <key-map field-name="statusId"/>
         </relation>
+        <relation type="one" fk-name="FINACT_STTS_USER" rel-entity-name="UserLogin">
+            <key-map field-name="changeByUserLoginId" rel-field-name="userLoginId"/>
+        </relation>
     </entity>
     <entity entity-name="FinAccountTrans" package-name="org.ofbiz.accounting.finaccount" title="Financial Account Transaction Entity">
         <field name="finAccountTransId" type="id-ne"></field>

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java?rev=1752232&r1=1752231&r2=1752232&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java Mon Jul 11 23:05:34 2016
@@ -35,6 +35,7 @@ import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.finder.PrimaryKeyFinder;
 import org.ofbiz.entity.model.ModelEntity;
 import org.ofbiz.entity.model.ModelField;
+import org.ofbiz.entity.util.EntityQuery;
 import org.ofbiz.service.DispatchContext;
 import org.ofbiz.service.GenericServiceException;
 import org.ofbiz.service.ModelParam;
@@ -321,6 +322,7 @@ public final class EntityAutoEngine exte
                 newEntity.set("changedDate", UtilDateTime.nowTimestamp());
             }
         }
+
         if (modelEntity.getField("changeByUserLoginId") != null) {
             GenericValue userLogin = (GenericValue) parameters.get("userLogin");
             if (userLogin != null) {
@@ -328,10 +330,28 @@ public final class EntityAutoEngine exte
             } else {
                 throw new GenericServiceException("You call a creation on entity that require the userLogin to track the activity, please controle that your service definition has auth='true'");
             }
+
             //Oh changeByUserLoginId detected, check if an EntityStatus concept
             if (modelEntity.getEntityName().endsWith("Status")) {
                 if (modelEntity.getField("statusDate") != null && parameters.get("statusDate") == null) {
                     newEntity.set("statusDate", UtilDateTime.nowTimestamp());
+
+                    //if a statusEndDate is present, resolve the last EntityStatus to store this value on the previous element
+                    if (modelEntity.getField("statusEndDate") != null) {
+                        ModelEntity relatedEntity = dctx.getDelegator().getModelEntity(modelEntity.getEntityName().replaceFirst("Status", ""));
+                        if (relatedEntity != null) {
+                            Map<String, Object> conditionRelatedPkFieldMap = new HashMap<String, Object>();
+                            for (String pkRelatedField : relatedEntity.getPkFieldNames()) {
+                                conditionRelatedPkFieldMap.put(pkRelatedField, parameters.get(pkRelatedField));
+                            }
+                            GenericValue previousStatus = EntityQuery.use(newEntity.getDelegator()).from(modelEntity.getEntityName())
+                                    .where(conditionRelatedPkFieldMap).orderBy("-statusDate").queryFirst();
+                            if (previousStatus != null) {
+                                previousStatus.put("statusEndDate", newEntity.get("statusDate"));
+                                previousStatus.store();
+                            }
+                        }
+                    }
                 }
             }
         }