svn commit: r566020 - in /ofbiz/trunk/specialpurpose/oagis: servicedef/services.xml src/org/ofbiz/oagis/OagisInventoryServices.java src/org/ofbiz/oagis/OagisServices.java src/org/ofbiz/oagis/OagisShipmentServices.java

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

svn commit: r566020 - in /ofbiz/trunk/specialpurpose/oagis: servicedef/services.xml src/org/ofbiz/oagis/OagisInventoryServices.java src/org/ofbiz/oagis/OagisServices.java src/org/ofbiz/oagis/OagisShipmentServices.java

jonesde
Author: jonesde
Date: Tue Aug 14 21:27:59 2007
New Revision: 566020

URL: http://svn.apache.org/viewvc?view=rev&rev=566020
Log:
Changed process incoming message services to save error status and the message handler that checks for existing messages to look for errors and allow the call to go through passing in a parameter so the services know they are processing an error retry, and changed them to handle that as needed

Modified:
    ofbiz/trunk/specialpurpose/oagis/servicedef/services.xml
    ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java
    ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java
    ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java

Modified: ofbiz/trunk/specialpurpose/oagis/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/servicedef/services.xml?view=diff&rev=566020&r1=566019&r2=566020
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/servicedef/services.xml (original)
+++ ofbiz/trunk/specialpurpose/oagis/servicedef/services.xml Tue Aug 14 21:27:59 2007
@@ -131,6 +131,7 @@
         <description>Process incoming Inventory Sync message</description>
         <implements service="oagisMessageIdOutInterface"/>
         <attribute name="document" type="org.w3c.dom.Document" mode="IN" optional="false"/>
+        <attribute name="isErrorRetry" type="Boolean" mode="IN" optional="true"/>
     </service>
     
     <!-- DEJ20070808 added max-rety=3 because this is run async persisted just in case there is a transaction problem under heavy load -->
@@ -139,6 +140,7 @@
         <description>Process incoming shipment message</description>
         <implements service="oagisMessageIdOutInterface"/>
         <attribute name="document" type="org.w3c.dom.Document" mode="IN" optional="false"/>
+        <attribute name="isErrorRetry" type="Boolean" mode="IN" optional="true"/>
     </service>
     
     <service name="receivePoAcknowledge" engine="java" transaction-timeout="300" max-retry="3"
@@ -146,6 +148,7 @@
         <description>Process PO Acknowledge message</description>
         <implements service="oagisMessageIdOutInterface"/>
         <attribute name="document" type="org.w3c.dom.Document" mode="IN" optional="false"/>
+        <attribute name="isErrorRetry" type="Boolean" mode="IN" optional="true"/>
     </service>
     
     <service name="receiveRmaAcknowledge" engine="java" transaction-timeout="300" max-retry="3"
@@ -153,6 +156,7 @@
         <description>Process RMA Acknowledge message</description>
         <implements service="oagisMessageIdOutInterface"/>
         <attribute name="document" type="org.w3c.dom.Document" mode="IN" optional="false"/>
+        <attribute name="isErrorRetry" type="Boolean" mode="IN" optional="true"/>
         <attribute name="inventoryItemIdList" type="List" mode="OUT" optional="true"/>
     </service>
 </services>

Modified: ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java?view=diff&rev=566020&r1=566019&r2=566020
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java (original)
+++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java Tue Aug 14 21:27:59 2007
@@ -20,10 +20,6 @@
 
 import java.io.IOException;
 import java.sql.Timestamp;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
@@ -65,6 +61,8 @@
     
     public static Map syncInventory(DispatchContext ctx, Map context) {
         Document doc = (Document) context.get("document");
+        boolean isErrorRetry = Boolean.TRUE.equals(context.get("isErrorRetry"));
+
         GenericDelegator delegator = ctx.getDelegator();
         LocalDispatcher dispatcher = ctx.getDispatcher();
         Locale locale = (Locale) context.get("locale");
@@ -122,7 +120,11 @@
             }
         }
         try {
-            dispatcher.runSync("createOagisMessageInfo", comiCtx, 60, true);
+            if (isErrorRetry) {
+                dispatcher.runSync("updateOagisMessageInfo", comiCtx, 60, true);
+            } else {
+                dispatcher.runSync("createOagisMessageInfo", comiCtx, 60, true);
+            }
         } catch (GenericServiceException e) {
             String errMsg = "Error creating OagisMessageInfo for the Incoming Message: " + e.toString();
             Debug.logError(e, errMsg, module);
@@ -302,6 +304,14 @@
         result.put("userLogin", userLogin);
 
         if (errorMapList.size() > 0) {
+            try {
+                comiCtx.put("processingStatusId", "OAGMP_PROC_ERROR");
+                dispatcher.runSync("updateOagisMessageInfo", comiCtx, 60, true);
+            } catch (GenericServiceException e){
+                String errMsg = "Error updating OagisMessageInfo for the Incoming Message: " + e.toString();
+                Debug.logError(e, errMsg, module);
+            }
+
             // call services createOagisMsgErrInfosFromErrMapList and for incoming messages oagisSendConfirmBod
             Map saveErrorMapListCtx = FastMap.newInstance();
             saveErrorMapListCtx.put("logicalId", logicalId);
@@ -333,8 +343,8 @@
             result.putAll(ServiceUtil.returnError("Errors found processing message; information saved and return error sent back"));
             return result;
         } else {
-            comiCtx.put("processingStatusId", "OAGMP_PROC_SUCCESS");
             try {
+                comiCtx.put("processingStatusId", "OAGMP_PROC_SUCCESS");
                 dispatcher.runSync("updateOagisMessageInfo", comiCtx, 60, true);
             } catch (GenericServiceException e){
                 String errMsg = "Error updating OagisMessageInfo for the Incoming Message: " + e.toString();
@@ -349,6 +359,8 @@
     
     public static Map receivePoAcknowledge(DispatchContext ctx, Map context) {
         Document doc = (Document) context.get("document");
+        boolean isErrorRetry = Boolean.TRUE.equals(context.get("isErrorRetry"));
+
         LocalDispatcher dispatcher = ctx.getDispatcher();
         GenericDelegator delegator = ctx.getDelegator();
         List errorMapList = FastList.newInstance();
@@ -409,7 +421,11 @@
             }
         }
         try {
-            dispatcher.runSync("createOagisMessageInfo", comiCtx, 60, true);
+            if (isErrorRetry) {
+                dispatcher.runSync("updateOagisMessageInfo", comiCtx, 60, true);
+            } else {
+                dispatcher.runSync("createOagisMessageInfo", comiCtx, 60, true);
+            }
         } catch (GenericServiceException e) {
             String errMsg = "Error creating OagisMessageInfo for the Incoming Message: " + e.toString();
             Debug.logError(e, errMsg, module);
@@ -529,6 +545,14 @@
         result.put("userLogin", userLogin);
 
         if (errorMapList.size() > 0) {
+            try {
+                comiCtx.put("processingStatusId", "OAGMP_PROC_ERROR");
+                dispatcher.runSync("updateOagisMessageInfo", comiCtx, 60, true);
+            } catch (GenericServiceException e){
+                String errMsg = "Error updating OagisMessageInfo for the Incoming Message: " + e.toString();
+                Debug.logError(e, errMsg, module);
+            }
+
             // call services createOagisMsgErrInfosFromErrMapList and for incoming messages oagisSendConfirmBod
             Map saveErrorMapListCtx = FastMap.newInstance();
             saveErrorMapListCtx.put("logicalId", logicalId);
@@ -576,6 +600,8 @@
     
     public static Map receiveRmaAcknowledge(DispatchContext ctx, Map context) {
         Document doc = (Document) context.get("document");
+        boolean isErrorRetry = Boolean.TRUE.equals(context.get("isErrorRetry"));
+
         LocalDispatcher dispatcher = ctx.getDispatcher();
         GenericDelegator delegator = ctx.getDelegator();
         List errorMapList = FastList.newInstance();
@@ -643,7 +669,11 @@
             }
         }
         try {
-            dispatcher.runSync("createOagisMessageInfo", comiCtx, 60, true);
+            if (isErrorRetry) {
+                dispatcher.runSync("updateOagisMessageInfo", comiCtx, 60, true);
+            } else {
+                dispatcher.runSync("createOagisMessageInfo", comiCtx, 60, true);
+            }
         } catch (GenericServiceException e) {
             String errMsg = "Error creating OagisMessageInfo for the Incoming Message: " + e.toString();
             Debug.logError(e, errMsg, module);
@@ -879,6 +909,14 @@
         result.put("userLogin", userLogin);
 
         if (errorMapList.size() > 0) {
+            try {
+                comiCtx.put("processingStatusId", "OAGMP_PROC_ERROR");
+                dispatcher.runSync("updateOagisMessageInfo", comiCtx, 60, true);
+            } catch (GenericServiceException e){
+                String errMsg = "Error updating OagisMessageInfo for the Incoming Message: " + e.toString();
+                Debug.logError(e, errMsg, module);
+            }
+
             // call services createOagisMsgErrInfosFromErrMapList and for incoming messages oagisSendConfirmBod
             Map saveErrorMapListCtx = FastMap.newInstance();
             saveErrorMapListCtx.put("logicalId", logicalId);

Modified: ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java?view=diff&rev=566020&r1=566019&r2=566020
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java (original)
+++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java Tue Aug 14 21:27:59 2007
@@ -459,78 +459,87 @@
         }
         
         GenericValue oagisMessageInfo = null;
+        Map oagisMessageInfoKey = UtilMisc.toMap("logicalId", logicalId, "component", component, "task", task, "referenceId", referenceId);
         try {
-            oagisMessageInfo = delegator.findByPrimaryKey("OagisMessageInfo", UtilMisc.toMap("logicalId", logicalId, "component", component, "task", task, "referenceId", referenceId));
+            oagisMessageInfo = delegator.findByPrimaryKey("OagisMessageInfo", oagisMessageInfoKey);
         } catch (GenericEntityException e) {
             String errMsg = "Error Getting Entity OagisMessageInfo: " + e.toString();
             Debug.logError(e, errMsg, module);
         }
         
+        Map messageProcessContext = UtilMisc.toMap("document", doc);
+        
         // call async, no additional results to return: Map subServiceResult = FastMap.newInstance();
-        if (UtilValidate.isEmpty(oagisMessageInfo)) {
-            if (bsrVerb.equalsIgnoreCase("CONFIRM") && bsrNoun.equalsIgnoreCase("BOD")) {
-                try {
-                    // subServiceResult = dispatcher.runSync("receiveConfirmBod", UtilMisc.toMap("document", doc));
-                    dispatcher.runAsync("receiveConfirmBod", UtilMisc.toMap("document", doc), true);
-                } catch (GenericServiceException e) {
-                    String errMsg = "Error running service receiveConfirmBod: " + e.toString();
-                    errorList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "GenericServiceException"));
-                    Debug.logError(e, errMsg, module);
-                }
-            } else if (bsrVerb.equalsIgnoreCase("SHOW") && bsrNoun.equalsIgnoreCase("SHIPMENT")) {
+        if (UtilValidate.isNotEmpty(oagisMessageInfo)) {
+            if ("OAGMP_PROC_ERROR".equals(oagisMessageInfo.getString("processingStatusId")) ||
+                    "OAGMP_ERRCONFSENT".equals(oagisMessageInfo.getString("processingStatusId"))) {
+                // there was an error last time, tell the service this is a retry
+                messageProcessContext.put("isErrorRetry", Boolean.TRUE);
+            } else {
+                String errMsg = "Message already received with ID: " + oagisMessageInfoKey;
+                Debug.logError(errMsg, module);
+                return ServiceUtil.returnError(errMsg);
+            }
+        }
+        
+        if (bsrVerb.equalsIgnoreCase("CONFIRM") && bsrNoun.equalsIgnoreCase("BOD")) {
+            try {
+                // subServiceResult = dispatcher.runSync("receiveConfirmBod", messageProcessContext);
+                dispatcher.runAsync("receiveConfirmBod", messageProcessContext, true);
+            } catch (GenericServiceException e) {
+                String errMsg = "Error running service receiveConfirmBod: " + e.toString();
+                errorList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "GenericServiceException"));
+                Debug.logError(e, errMsg, module);
+            }
+        } else if (bsrVerb.equalsIgnoreCase("SHOW") && bsrNoun.equalsIgnoreCase("SHIPMENT")) {
+            try {
+                //subServiceResult = dispatcher.runSync("showShipment", messageProcessContext);
+                // DEJ20070808 changed to run asynchronously and persisted so that if it fails it will retry; for transaction deadlock and other reasons
+                dispatcher.runAsync("showShipment", messageProcessContext, true);
+            } catch (GenericServiceException e) {
+                String errMsg = "Error running service showShipment: " + e.toString();
+                errorList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "GenericServiceException"));
+                Debug.logError(e, errMsg, module);
+            }
+        } else if (bsrVerb.equalsIgnoreCase("SYNC") && bsrNoun.equalsIgnoreCase("INVENTORY")) {
+            try {
+                //subServiceResult = dispatcher.runSync("syncInventory", messageProcessContext);
+                // DEJ20070808 changed to run asynchronously and persisted so that if it fails it will retry; for transaction deadlock and other reasons
+                dispatcher.runAsync("syncInventory", messageProcessContext, true);
+            } catch (GenericServiceException e) {
+                String errMsg = "Error running service syncInventory: " + e.toString();
+                errorList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "GenericServiceException"));
+                Debug.logError(e, errMsg, module);
+            }
+        } else if (bsrVerb.equalsIgnoreCase("ACKNOWLEDGE") && bsrNoun.equalsIgnoreCase("DELIVERY")) {
+            Element dataAreaElement = UtilXml.firstChildElement(rootElement, "ns:DATAAREA");
+            Element ackDeliveryElement = UtilXml.firstChildElement(dataAreaElement, "ns:ACKNOWLEDGE_DELIVERY");
+            Element receiptlnElement = UtilXml.firstChildElement(ackDeliveryElement, "ns:RECEIPTLN");
+            Element docRefElement = UtilXml.firstChildElement(receiptlnElement, "os:DOCUMNTREF");
+            String docType = UtilXml.childElementValue(docRefElement, "of:DOCTYPE");
+            if ("PO".equals(docType)) {
                 try {
-                    //subServiceResult = dispatcher.runSync("showShipment", UtilMisc.toMap("document", doc));
-                    // DEJ20070808 changed to run asynchronously and persisted so that if it fails it will retry; for transaction deadlock and other reasons
-                    dispatcher.runAsync("showShipment", UtilMisc.toMap("document", doc), true);
+                    //subServiceResult = dispatcher.runSync("receivePoAcknowledge", messageProcessContext);
+                    dispatcher.runAsync("receivePoAcknowledge", messageProcessContext, true);
                 } catch (GenericServiceException e) {
-                    String errMsg = "Error running service showShipment: " + e.toString();
+                    String errMsg = "Error running service receivePoAcknowledge: " + e.toString();
                     errorList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "GenericServiceException"));
                     Debug.logError(e, errMsg, module);
                 }
-            } else if (bsrVerb.equalsIgnoreCase("SYNC") && bsrNoun.equalsIgnoreCase("INVENTORY")) {
+            } else if ("RMA".equals(docType)) {
                 try {
-                    //subServiceResult = dispatcher.runSync("syncInventory", UtilMisc.toMap("document", doc));
-                    // DEJ20070808 changed to run asynchronously and persisted so that if it fails it will retry; for transaction deadlock and other reasons
-                    dispatcher.runAsync("syncInventory", UtilMisc.toMap("document", doc), true);
+                    //subServiceResult = dispatcher.runSync("receiveRmaAcknowledge", messageProcessContext);
+                    dispatcher.runAsync("receiveRmaAcknowledge", messageProcessContext, true);
                 } catch (GenericServiceException e) {
-                    String errMsg = "Error running service syncInventory: " + e.toString();
+                    String errMsg = "Error running service receiveRmaAcknowledge: " + e.toString();
                     errorList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "GenericServiceException"));
                     Debug.logError(e, errMsg, module);
                 }
-            } else if (bsrVerb.equalsIgnoreCase("ACKNOWLEDGE") && bsrNoun.equalsIgnoreCase("DELIVERY")) {
-                Element dataAreaElement = UtilXml.firstChildElement(rootElement, "ns:DATAAREA");
-                Element ackDeliveryElement = UtilXml.firstChildElement(dataAreaElement, "ns:ACKNOWLEDGE_DELIVERY");
-                Element receiptlnElement = UtilXml.firstChildElement(ackDeliveryElement, "ns:RECEIPTLN");
-                Element docRefElement = UtilXml.firstChildElement(receiptlnElement, "os:DOCUMNTREF");
-                String docType = UtilXml.childElementValue(docRefElement, "of:DOCTYPE");
-                if ("PO".equals(docType)){
-                    try {
-                        //subServiceResult = dispatcher.runSync("receivePoAcknowledge", UtilMisc.toMap("document", doc));
-                        dispatcher.runAsync("receivePoAcknowledge", UtilMisc.toMap("document", doc), true);
-                    } catch (GenericServiceException e) {
-                        String errMsg = "Error running service receivePoAcknowledge: " + e.toString();
-                        errorList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "GenericServiceException"));
-                        Debug.logError(e, errMsg, module);
-                    }
-                } else if ("RMA".equals(docType)) {
-                    try {
-                        //subServiceResult = dispatcher.runSync("receiveRmaAcknowledge", UtilMisc.toMap("document", doc));
-                        dispatcher.runAsync("receiveRmaAcknowledge", UtilMisc.toMap("document", doc), true);
-                    } catch (GenericServiceException e) {
-                        String errMsg = "Error running service receiveRmaAcknowledge: " + e.toString();
-                        errorList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "GenericServiceException"));
-                        Debug.logError(e, errMsg, module);
-                    }
-                } else {
-                    return ServiceUtil.returnError("For Acknowledge Delivery message could not determine if it is for a PO or RMA. DOCTYPE from message is " + docType);
-                }
             } else {
-                String errMsg = "Unknown Message Received";
-                Debug.logError(errMsg, module);
-                return ServiceUtil.returnError(errMsg);
+                return ServiceUtil.returnError("For Acknowledge Delivery message could not determine if it is for a PO or RMA. DOCTYPE from message is " + docType);
             }
         } else {
-            String errMsg = "Message has been already received";
+            String errMsg = "Unknown Message Type Received, verb/noun combination not supported: verb=[" + bsrVerb + "], noun=[" + bsrNoun + "]";
             Debug.logError(errMsg, module);
             return ServiceUtil.returnError(errMsg);
         }

Modified: ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java?view=diff&rev=566020&r1=566019&r2=566020
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java (original)
+++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java Tue Aug 14 21:27:59 2007
@@ -24,8 +24,6 @@
 import java.io.StringWriter;
 import java.io.Writer;
 import java.sql.Timestamp;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
@@ -96,6 +94,8 @@
 
     public static Map showShipment(DispatchContext ctx, Map context) {
         Document doc = (Document) context.get("document");
+        boolean isErrorRetry = Boolean.TRUE.equals(context.get("isErrorRetry"));
+        
         LocalDispatcher dispatcher = ctx.getDispatcher();
         GenericDelegator delegator = ctx.getDelegator();
         Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
@@ -158,7 +158,11 @@
         }
         
         try {
-            dispatcher.runSync("createOagisMessageInfo", oagisMsgInfoCtx, 60, true);
+            if (isErrorRetry) {
+                dispatcher.runSync("updateOagisMessageInfo", oagisMsgInfoCtx, 60, true);
+            } else {
+                dispatcher.runSync("createOagisMessageInfo", oagisMsgInfoCtx, 60, true);
+            }
             /* running async for better error handling
             if (ServiceUtil.isError(oagisMsgInfoResult)){
                 String errMsg = ServiceUtil.getErrorMessage(oagisMsgInfoResult);
@@ -424,6 +428,14 @@
         result.put("userLogin", userLogin);
 
         if (errorMapList.size() > 0) {
+            try {
+                oagisMsgInfoCtx.put("processingStatusId", "OAGMP_PROC_ERROR");
+                dispatcher.runSync("updateOagisMessageInfo", oagisMsgInfoCtx, 60, true);
+            } catch (GenericServiceException e){
+                String errMsg = "Error updating OagisMessageInfo for the Incoming Message: " + e.toString();
+                Debug.logError(e, errMsg, module);
+            }
+
             // call services createOagisMsgErrInfosFromErrMapList and for incoming messages oagisSendConfirmBod
             Map saveErrorMapListCtx = FastMap.newInstance();
             saveErrorMapListCtx.put("logicalId", logicalId);
@@ -455,12 +467,11 @@
             result.putAll(ServiceUtil.returnError("Errors found processing message; information saved and return error sent back"));
             return result;
         } else {
-            oagisMsgInfoCtx.put("processingStatusId", "OAGMP_PROC_SUCCESS");
             try {
+                oagisMsgInfoCtx.put("processingStatusId", "OAGMP_PROC_SUCCESS");
                 dispatcher.runSync("updateOagisMessageInfo", oagisMsgInfoCtx, 60, true);
             } catch (GenericServiceException e){
                 String errMsg = "Error updating OagisMessageInfo for the Incoming Message: " + e.toString();
-                // don't pass this back, nothing they can do about it: errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "GenericServiceException"));
                 Debug.logError(e, errMsg, module);
             }
         }