svn commit: r1851805 - in /ofbiz/ofbiz-framework/trunk/framework/entityext: minilang/EntitySyncServices.xml servicedef/services.xml src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncContext.java

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

svn commit: r1851805 - in /ofbiz/ofbiz-framework/trunk/framework/entityext: minilang/EntitySyncServices.xml servicedef/services.xml src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncContext.java

Arun Patidar-4
Author: arunpatidar
Date: Tue Jan 22 11:51:46 2019
New Revision: 1851805

URL: http://svn.apache.org/viewvc?rev=1851805&view=rev
Log:
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/trunk/framework/entityext/minilang/EntitySyncServices.xml
    ofbiz/ofbiz-framework/trunk/framework/entityext/servicedef/services.xml
    ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncContext.java

Modified: ofbiz/ofbiz-framework/trunk/framework/entityext/minilang/EntitySyncServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entityext/minilang/EntitySyncServices.xml?rev=1851805&r1=1851804&r2=1851805&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entityext/minilang/EntitySyncServices.xml (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entityext/minilang/EntitySyncServices.xml Tue Jan 22 11:51:46 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/trunk/framework/entityext/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entityext/servicedef/services.xml?rev=1851805&r1=1851804&r2=1851805&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entityext/servicedef/services.xml (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entityext/servicedef/services.xml Tue Jan 22 11:51:46 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/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncContext.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncContext.java?rev=1851805&r1=1851804&r2=1851805&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncContext.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncContext.java Tue Jan 22 11:51:46 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);
             }
         }