svn commit: r1851881 - in /ofbiz/ofbiz-framework/branches/release18.12: ./ framework/entityext/minilang/ framework/entityext/servicedef/ framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1851881 - in /ofbiz/ofbiz-framework/branches/release18.12: ./ framework/entityext/minilang/ framework/entityext/servicedef/ framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/

Arun Patidar-4
Author: arunpatidar
Date: Wed Jan 23 06:29:03 2019
New Revision: 1851881

URL: http://svn.apache.org/viewvc?rev=1851881&view=rev
Log:
Applied fix from trunk for revision: 1851805
===

Fixed: EntitySync Push and Pull functionalities
(OFBIZ-10818)

Removed unneccessary service implementation and used entity-auto
Fixed some create/update code block in the flow

Modified:
    ofbiz/ofbiz-framework/branches/release18.12/   (props changed)
    ofbiz/ofbiz-framework/branches/release18.12/framework/entityext/minilang/EntitySyncServices.xml
    ofbiz/ofbiz-framework/branches/release18.12/framework/entityext/servicedef/services.xml
    ofbiz/ofbiz-framework/branches/release18.12/framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncContext.java

Propchange: ofbiz/ofbiz-framework/branches/release18.12/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jan 23 06:29:03 2019
@@ -10,4 +10,4 @@
 /ofbiz/branches/json-integration-refactoring:1634077-1635900
 /ofbiz/branches/multitenant20100310:921280-927264
 /ofbiz/branches/release13.07:1547657
-/ofbiz/ofbiz-framework/trunk:1850015,1850023,1850530,1850647,1850685,1850694,1850711,1850914,1850918,1850921,1850948,1850953,1851006,1851013,1851068,1851074,1851130,1851158,1851200,1851224,1851247,1851254,1851315,1851319,1851350,1851353,1851433,1851500
+/ofbiz/ofbiz-framework/trunk:1850015,1850023,1850530,1850647,1850685,1850694,1850711,1850914,1850918,1850921,1850948,1850953,1851006,1851013,1851068,1851074,1851130,1851158,1851200,1851224,1851247,1851254,1851315,1851319,1851350,1851353,1851433,1851500,1851805

Modified: ofbiz/ofbiz-framework/branches/release18.12/framework/entityext/minilang/EntitySyncServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/framework/entityext/minilang/EntitySyncServices.xml?rev=1851881&r1=1851880&r2=1851881&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/framework/entityext/minilang/EntitySyncServices.xml (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/framework/entityext/minilang/EntitySyncServices.xml Wed Jan 23 06:29:03 2019
@@ -40,27 +40,6 @@ under the License.
         </if-compare>
     </simple-method>
 
-    <!-- EntitySyncHistory services -->
-    <simple-method method-name="createEntitySyncHistory" short-description="Create EntitySyncHistory">
-        <make-value entity-name="EntitySyncHistory" value-field="newEntity"/>
-        <set-pk-fields map="parameters" value-field="newEntity"/>
-        <now-timestamp field="newEntity.startDate"/>
-        <field-to-result field="newEntity.startDate" result-name="startDate"/>
-        <set-nonpk-fields map="parameters" value-field="newEntity"/>
-        <create-value value-field="newEntity"/>
-
-        <!-- also set the lastHistoryStartDate on the EntitySync -->
-        <entity-one entity-name="EntitySync" value-field="entitySync"/>
-        <set from-field="newEntity.startDate" field="entitySync.lastHistoryStartDate"/>
-        <store-value value-field="entitySync"/>
-    </simple-method>
-    <simple-method method-name="deleteEntitySyncHistory" short-description="Delete EntitySyncHistory">
-        <make-value entity-name="EntitySyncHistory" value-field="lookupPKMap"/>
-        <set-pk-fields map="parameters" value-field="lookupPKMap"/>
-        <find-by-primary-key map="lookupPKMap" value-field="lookedUpValue"/>
-        <remove-value value-field="lookedUpValue"/>
-    </simple-method>
-
     <!-- EntitySyncInclude services -->
     <simple-method method-name="createEntitySyncInclude" short-description="Create EntitySyncInclude">
         <make-value entity-name="EntitySyncInclude" value-field="newEntity"/>

Modified: ofbiz/ofbiz-framework/branches/release18.12/framework/entityext/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/framework/entityext/servicedef/services.xml?rev=1851881&r1=1851880&r2=1851881&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/framework/entityext/servicedef/services.xml (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/framework/entityext/servicedef/services.xml Wed Jan 23 06:29:03 2019
@@ -200,22 +200,28 @@ under the License.
         <permission-service service-name="entitySyncPermissionCheck" main-action="DELETE"/>
         <auto-attributes include="pk" mode="IN" optional="false"/>
     </service>
-    <service name="createEntitySyncHistory" default-entity-name="EntitySyncHistory" engine="simple"
-            location="component://entityext/minilang/EntitySyncServices.xml" invoke="createEntitySyncHistory" auth="true" require-new-transaction="true">
+
+    <service name="updateEntitySyncRunning" default-entity-name="EntitySync" engine="entity-auto" invoke="update" auth="true">
+        <description>Update EntitySync</description>
+        <permission-service service-name="entitySyncPermissionCheck" main-action="UPDATE"/>
+        <auto-attributes include="pk" mode="IN" optional="false"/>
+        <auto-attributes include="nonpk" mode="IN" optional="true"/>
+    </service>
+
+    <service name="createEntitySyncHistory" default-entity-name="EntitySyncHistory" engine="entity-auto" invoke="create" auth="true">
         <description>Create EntitySyncHistory</description>
         <permission-service service-name="entitySyncPermissionCheck" main-action="CREATE"/>
-        <auto-attributes include="pk" mode="IN" optional="false"/>
+        <auto-attributes include="pk" mode="INOUT" optional="false"/>
         <auto-attributes include="nonpk" mode="IN" optional="true"/>
         <override name="startDate" mode="OUT"/>
     </service>
-    <service name="updateEntitySyncHistory" default-entity-name="EntitySyncHistory" engine="entity-auto" invoke="update" auth="true" require-new-transaction="true">
+    <service name="updateEntitySyncHistory" default-entity-name="EntitySyncHistory" engine="entity-auto" invoke="update" auth="true">
         <description>Update EntitySyncHistory</description>
         <permission-service service-name="entitySyncPermissionCheck" main-action="UPDATE"/>
         <auto-attributes include="pk" mode="IN" optional="false"/>
         <auto-attributes include="nonpk" mode="IN" optional="true"/>
     </service>
-    <service name="deleteEntitySyncHistory" default-entity-name="EntitySyncHistory" engine="simple"
-            location="component://entityext/minilang/EntitySyncServices.xml" invoke="deleteEntitySyncHistory" auth="true" require-new-transaction="true">
+    <service name="deleteEntitySyncHistory" default-entity-name="EntitySyncHistory" engine="entity-auto" invoke="delete" auth="true">
         <description>Delete EntitySyncHistory</description>
         <permission-service service-name="entitySyncPermissionCheck" main-action="DELETE"/>
         <auto-attributes include="pk" mode="IN" optional="false"/>

Modified: ofbiz/ofbiz-framework/branches/release18.12/framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncContext.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncContext.java?rev=1851881&r1=1851880&r2=1851881&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncContext.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncContext.java Wed Jan 23 06:29:03 2019
@@ -302,11 +302,17 @@ public class EntitySyncContext {
     public void createInitialHistory() throws SyncDataErrorException, SyncServiceErrorException {
         String errorMsg = "Not running EntitySync [" + entitySyncId + "], could not create EntitySyncHistory";
         try {
-            Map<String, Object> initialHistoryRes = dispatcher.runSync("createEntitySyncHistory", UtilMisc.toMap("entitySyncId", entitySyncId, "runStatusId", "ESR_RUNNING", "beginningSynchTime", this.currentRunStartTime, "lastCandidateEndTime", this.currentRunEndTime, "userLogin", userLogin));
+            Timestamp startDateTime = UtilDateTime.nowTimestamp();
+            Map<String, Object> initialHistoryRes = dispatcher.runSync("createEntitySyncHistory", UtilMisc.toMap("entitySyncId", entitySyncId, "runStatusId", "ESR_RUNNING", "beginningSynchTime", this.currentRunStartTime, "lastCandidateEndTime", this.currentRunEndTime, "startDate", startDateTime, "userLogin", userLogin));
             if (ServiceUtil.isError(initialHistoryRes)) {
                 throw new SyncDataErrorException(errorMsg, null, null, initialHistoryRes, null);
             }
             this.startDate = (Timestamp) initialHistoryRes.get("startDate");
+
+            Map<String, Object> result = dispatcher.runSync("updateEntitySync", UtilMisc.toMap("entitySyncId", entitySyncId, "lastHistoryStartDate", this.startDate, "userLogin", userLogin));
+            if (ServiceUtil.isError(result)) {
+                throw new SyncDataErrorException(errorMsg, null, null, result, null);
+            }
         } catch (GenericServiceException e) {
             throw new SyncServiceErrorException(errorMsg, e);
         }
@@ -768,43 +774,51 @@ public class EntitySyncContext {
             // store latest result on EntitySync, ie update lastSuccessfulSynchTime, should run in own tx
             Map<String, Object> updateEsRunResult = dispatcher.runSync("updateEntitySyncRunning", UtilMisc.toMap("entitySyncId", entitySyncId, "lastSuccessfulSynchTime", this.currentRunEndTime, "userLogin", userLogin));
 
-            // store result of service call on history with results so far, should run in own tx
-            Map<String, Object> updateHistoryMap = UtilMisc.toMap("entitySyncId", entitySyncId, "startDate", startDate,
-                    "lastSuccessfulSynchTime", this.currentRunEndTime, "lastCandidateEndTime", this.getNextRunEndTime(),
-                    "lastSplitStartTime", this.splitStartTime);
-            updateHistoryMap.put("toCreateInserted", toCreateInserted);
-            updateHistoryMap.put("toCreateUpdated", toCreateUpdated);
-            updateHistoryMap.put("toCreateNotUpdated", toCreateNotUpdated);
-            updateHistoryMap.put("toStoreInserted", toStoreInserted);
-            updateHistoryMap.put("toStoreUpdated", toStoreUpdated);
-            updateHistoryMap.put("toStoreNotUpdated", toStoreNotUpdated);
-            updateHistoryMap.put("toRemoveDeleted", toRemoveDeleted);
-            updateHistoryMap.put("toRemoveAlreadyDeleted", toRemoveAlreadyDeleted);
-            updateHistoryMap.put("runningTimeMillis", runningTimeMillis);
-            updateHistoryMap.put("totalStoreCalls", totalStoreCalls);
-            updateHistoryMap.put("totalSplits", totalSplits);
-            updateHistoryMap.put("totalRowsExported", totalRowsExported);
-            updateHistoryMap.put("totalRowsToCreate", totalRowsToCreate);
-            updateHistoryMap.put("totalRowsToStore", totalRowsToStore);
-            updateHistoryMap.put("totalRowsToRemove", totalRowsToRemove);
-            updateHistoryMap.put("perSplitMinMillis", perSplitMinMillis);
-            updateHistoryMap.put("perSplitMaxMillis", perSplitMaxMillis);
-            updateHistoryMap.put("perSplitMinItems", perSplitMinItems);
-            updateHistoryMap.put("perSplitMaxItems", perSplitMaxItems);
-            updateHistoryMap.put("userLogin", userLogin);
-            Map<String, Object> updateEsHistRunResult = dispatcher.runSync("updateEntitySyncHistory", updateHistoryMap);
-
-            // now we have updated EntitySync and EntitySyncHistory, check both ops for errors...
-            if (ServiceUtil.isError(updateEsRunResult)) {
-                String errorMsg = "Error running EntitySync [" + entitySyncId + "], update of EntitySync record with lastSuccessfulSynchTime failed.";
-                throw new SyncDataErrorException(errorMsg, null, null, updateEsRunResult, null);
-            }
-
-            if (ServiceUtil.isError(updateEsHistRunResult)) {
-                String errorMsg = "Error running EntitySync [" + entitySyncId + "], update of EntitySyncHistory (startDate:[" + startDate + "]) record with lastSuccessfulSynchTime and result stats failed.";
-                throw new SyncDataErrorException(errorMsg, null, null, updateEsHistRunResult, null);
+            GenericValue entitySyncHistory = EntityQuery.use(delegator).from("EntitySyncHistory").where("startDate",startDate, "entitySyncId", entitySyncId).queryOne();
+            if(entitySyncHistory != null) {
+                // store result of service call on history with results so far, should run in own tx
+                ModelService model = dispatcher.getDispatchContext().getModelService("updateEntitySyncHistory");
+                Map<String, Object> updateHistoryMap = model.makeValid(entitySyncHistory, ModelService.IN_PARAM);
+
+                updateHistoryMap.put("lastSuccessfulSynchTime", this.currentRunEndTime);
+                updateHistoryMap.put("lastCandidateEndTime", this.getNextRunEndTime());
+                updateHistoryMap.put("lastSplitStartTime", Long.valueOf(this.splitStartTime));
+                updateHistoryMap.put("toCreateInserted", Long.valueOf(toCreateInserted));
+                updateHistoryMap.put("toCreateUpdated", Long.valueOf(toCreateUpdated));
+                updateHistoryMap.put("toCreateNotUpdated", Long.valueOf(toCreateNotUpdated));
+                updateHistoryMap.put("toStoreInserted", Long.valueOf(toStoreInserted));
+                updateHistoryMap.put("toStoreUpdated", Long.valueOf(toStoreUpdated));
+                updateHistoryMap.put("toStoreNotUpdated", Long.valueOf(toStoreNotUpdated));
+                updateHistoryMap.put("toRemoveDeleted", Long.valueOf(toRemoveDeleted));
+                updateHistoryMap.put("toRemoveAlreadyDeleted", Long.valueOf(toRemoveAlreadyDeleted));
+                updateHistoryMap.put("runningTimeMillis", Long.valueOf(runningTimeMillis));
+                updateHistoryMap.put("totalStoreCalls", Long.valueOf(totalStoreCalls));
+                updateHistoryMap.put("totalSplits", Long.valueOf(totalSplits));
+                updateHistoryMap.put("totalRowsExported", Long.valueOf(totalRowsExported));
+                updateHistoryMap.put("totalRowsToCreate", Long.valueOf(totalRowsToCreate));
+                updateHistoryMap.put("totalRowsToStore", Long.valueOf(totalRowsToStore));
+                updateHistoryMap.put("totalRowsToRemove", Long.valueOf(totalRowsToRemove));
+                updateHistoryMap.put("perSplitMinMillis", Long.valueOf(perSplitMinMillis));
+                updateHistoryMap.put("perSplitMaxMillis", Long.valueOf(perSplitMaxMillis));
+                updateHistoryMap.put("perSplitMinItems", Long.valueOf(perSplitMinItems));
+                updateHistoryMap.put("perSplitMaxItems", Long.valueOf(perSplitMaxItems));
+                updateHistoryMap.put("userLogin", userLogin);
+                Map<String, Object> updateEsHistRunResult = dispatcher.runSync("updateEntitySyncHistory", updateHistoryMap);
+
+                // now we have updated EntitySync and EntitySyncHistory, check both ops for errors...
+                if (ServiceUtil.isError(updateEsRunResult)) {
+                    String errorMsg = "Error running EntitySync [" + entitySyncId + "], update of EntitySync record with lastSuccessfulSynchTime failed.";
+                    throw new SyncDataErrorException(errorMsg, null, null, updateEsRunResult, null);
+                }
+
+
+                if (ServiceUtil.isError(updateEsHistRunResult)) {
+                    String errorMsg = "Error running EntitySync [" + entitySyncId + "], update of EntitySyncHistory (startDate:[" + startDate + "]) record with lastSuccessfulSynchTime and result stats failed.";
+                    throw new SyncDataErrorException(errorMsg, null, null, updateEsHistRunResult, null);
+                }
             }
-        } catch (GenericServiceException e) {
+
+        } catch (GenericServiceException | GenericEntityException e) {
             throw new SyncServiceErrorException("Error saving results reported from data store", e);
         }
     }
@@ -977,6 +991,11 @@ public class EntitySyncContext {
             }
             String serviceErrorMsg = "Error running EntitySync [" + entitySyncId + "], call to store service [" + targetServiceName + "] failed.";
             try {
+
+                //TODO: It should use authentic user instead of system, think on alternate solution
+                GenericValue userLogin = EntityQuery.use(delegator).from("UserLogin").where("userLoginId", "system").queryOne();
+                targetServiceMap.put("userLogin", userLogin);
+
                 Map<String, Object> remoteStoreResult = dispatcher.runSync(targetServiceName, targetServiceMap);
                 if (ServiceUtil.isError(remoteStoreResult)) {
                     throw new SyncOtherErrorException(serviceErrorMsg, null, null, remoteStoreResult, null);
@@ -1001,7 +1020,7 @@ public class EntitySyncContext {
                 this.toStoreNotUpdated += toStoreNotUpdatedCur;
                 this.toRemoveDeleted += toRemoveDeletedCur;
                 this.toRemoveAlreadyDeleted += toRemoveAlreadyDeletedCur;
-            } catch (GenericServiceException e) {
+            } catch (GenericServiceException | GenericEntityException e) {
                 throw new SyncServiceErrorException(serviceErrorMsg, e);
             }
         }