Author: jonesde
Date: Mon Sep 10 22:07:28 2007
New Revision: 574452

URL: http://svn.apache.org/viewvc?rev=574452&view=rev
Log:
Added service to re-receive messages in OagisMessageInfo records

Modified:
    ofbiz/trunk/specialpurpose/oagis/servicedef/secas.xml
    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

Modified: ofbiz/trunk/specialpurpose/oagis/servicedef/secas.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/servicedef/secas.xml?rev=574452&r1=574451&r2=574452&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/servicedef/secas.xml (original)
+++ ofbiz/trunk/specialpurpose/oagis/servicedef/secas.xml Mon Sep 10 22:07:28 
2007
@@ -20,7 +20,7 @@
 
 <service-eca xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
         
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/service-eca.xsd";>
-    <!-- uncomment these to enable OAGIS message sending
+    <!-- uncomment these to enable OAGIS message sending -->
     <eca service="changeOrderStatus" event="commit" run-on-error="false">
         <condition field-name="statusId" operator="equals" 
value="ORDER_APPROVED"/>
         <condition field-name="orderTypeId" operator="equals" 
value="SALES_ORDER"/>
@@ -35,5 +35,4 @@
         <condition field-name="statusId" operator="equals" 
value="RETURN_ACCEPTED"/>
         <action service="oagisSendReceiveDelivery" mode="async" 
persist="true"/>
     </eca>
-    -->
 </service-eca>

Modified: ofbiz/trunk/specialpurpose/oagis/servicedef/services.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/servicedef/services.xml?rev=574452&r1=574451&r2=574452&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/servicedef/services.xml (original)
+++ ofbiz/trunk/specialpurpose/oagis/servicedef/services.xml Mon Sep 10 
22:07:28 2007
@@ -68,6 +68,16 @@
         location="org.ofbiz.oagis.OagisServices" invoke="oagisMessageHandler" 
auth="false">
         <implements service="serviceStreamInterface"/>
         <implements service="oagisMessageIdOutInterface"/>
+        <attribute name="isErrorRetry" type="Boolean" mode="IN" 
optional="true"/>
+        <override name="outputStream" optional="true"/>
+    </service>
+    
+    <service name="oagisReReceiveMessage" engine="java" 
transaction-timeout="300"
+        location="org.ofbiz.oagis.OagisServices" 
invoke="oagisReReceiveMessage" auth="false">
+        <attribute name="logicalId" type="String" mode="IN" optional="true"/>
+        <attribute name="component" type="String" mode="IN" optional="true"/>
+        <attribute name="task" type="String" mode="IN" optional="true"/>
+        <attribute name="referenceId" type="String" mode="IN" 
optional="false"/>
     </service>
     
     <!-- Confirm BOD Messages, general flow and error handling -->    

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?rev=574452&r1=574451&r2=574452&view=diff
==============================================================================
--- 
ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java
 (original)
+++ 
ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java
 Mon Sep 10 22:07:28 2007
@@ -692,6 +692,11 @@
 
         Element dataAreaElement = UtilXml.firstChildElement(receiveRmaElement, 
"ns:DATAAREA");
         Element acknowledgeDeliveryElement = 
UtilXml.firstChildElement(dataAreaElement, "ns:ACKNOWLEDGE_DELIVERY");
+
+        // get the first returnId from the list so we at least have something 
in the info record
+        Element firstReceiptlnElement = 
UtilXml.firstChildElement(acknowledgeDeliveryElement, "ns:RECEIPTLN");
+        Element firstDocRefElement = 
UtilXml.firstChildElement(firstReceiptlnElement, "os:DOCUMNTREF");
+        String firstReturnId = UtilXml.childElementValue(firstDocRefElement, 
"of:DOCUMENTID");
         
         String facilityId = 
UtilProperties.getPropertyValue("oagis.properties", 
"Oagis.Warehouse.PoReceiptFacilityId");
         String locationSeqId = 
UtilProperties.getPropertyValue("oagis.properties", 
"Oagis.Warehouse.ReturnReceiptLocationSeqId");
@@ -735,6 +740,7 @@
         comiCtx.put("bsrNoun", bsrNoun);
         comiCtx.put("bsrRevision", bsrRevision);
         comiCtx.put("processingStatusId", "OAGMP_RECEIVED");
+        comiCtx.put("returnId", firstReturnId);
         comiCtx.put("userLogin", userLogin);
         if (OagisServices.debugSaveXmlIn) {
             try {
@@ -846,7 +852,8 @@
                         List serialNumsList = FastList.newInstance();
                         List invDetailList = 
UtilXml.childElementList(receiptLnElement, "ns:INVDETAIL");
                         if (UtilValidate.isNotEmpty(invDetailList)) {
-                            for (Iterator j = invDetailList.iterator(); 
j.hasNext();) {
+                            Iterator j = invDetailList.iterator();
+                            while (j.hasNext()) {
                                 Element invDetailElement = (Element) j.next();
                                 String serialNumber = 
UtilXml.childElementValue(invDetailElement, "of:SERIALNUM");
                                 if (UtilValidate.isNotEmpty(serialNumber)) {

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?rev=574452&r1=574451&r2=574452&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java 
(original)
+++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java Mon 
Sep 10 22:07:28 2007
@@ -46,6 +46,7 @@
 import javolution.util.FastMap;
 
 import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.GeneralException;
 import org.ofbiz.base.util.HttpClient;
 import org.ofbiz.base.util.SSLUtil;
 import org.ofbiz.base.util.UtilDateTime;
@@ -432,11 +433,60 @@
         return result;
     }
     
+    public static Map oagisReReceiveMessage(DispatchContext ctx, Map context) {
+        GenericDelegator delegator = ctx.getDelegator();
+        LocalDispatcher dispatcher = ctx.getDispatcher();
+
+        String logicalId = (String) context.get("logicalId");
+        String component = (String) context.get("component");
+        String task = (String) context.get("task");
+        String referenceId = (String) context.get("referenceId");
+        Map oagisMessageInfoKey = UtilMisc.toMap("logicalId", logicalId, 
"component", component, "task", task, "referenceId", referenceId);
+        
+        try {
+            GenericValue oagisMessageInfo = null;
+            
+            if (UtilValidate.isNotEmpty(referenceId) && 
(UtilValidate.isEmpty(component) || UtilValidate.isEmpty(task) || 
UtilValidate.isEmpty(referenceId))) {
+                // try looking up by just the referenceId, those alone are 
often unique, return error if there is more than one result
+                List oagisMessageInfoList = 
delegator.findByAnd("OagisMessageInfo", UtilMisc.toMap("referenceId", 
referenceId));
+                if (oagisMessageInfoList.size() == 1) {
+                    oagisMessageInfo = (GenericValue) 
oagisMessageInfoList.get(0);
+                } else if (oagisMessageInfoList.size() > 1) {
+                    return ServiceUtil.returnError("Looked up by referenceId 
because logicalId, component, or task were not passed in but found more than 
one [" + oagisMessageInfoList.size() + "] record with referenceId [" + 
referenceId + "]");
+                }
+            } else {
+                oagisMessageInfo = 
delegator.findByPrimaryKey("OagisMessageInfo", oagisMessageInfoKey);
+            }
+            
+            if (oagisMessageInfo == null) {
+                return ServiceUtil.returnError("Could not find 
OagisMessageInfo record with key [" + oagisMessageInfoKey + "], not rerunning 
message.");
+            }
+            
+            String fullMessageXml = 
oagisMessageInfo.getString("fullMessageXml");
+            if (UtilValidate.isEmpty(fullMessageXml)) {
+                return ServiceUtil.returnError("There was no fullMessageXml 
text in OagisMessageInfo record with key [" + oagisMessageInfoKey + "], not 
rerunning message.");
+            }
+            
+            // we know we have text now, run it!
+            ByteArrayInputStream bis = new 
ByteArrayInputStream(fullMessageXml.getBytes("UTF-8"));
+            Map result = dispatcher.runSync("oagisMessageHandler", 
UtilMisc.toMap("inputStream", bis, "isErrorRetry", Boolean.TRUE));
+            if (ServiceUtil.isError(result)) {
+                return ServiceUtil.returnError("Error trying to re-receive 
message with ID [" + oagisMessageInfoKey + "]", null, null, result);
+            }
+            return ServiceUtil.returnSuccess();
+        } catch (Exception e) {
+            String errMsg = "Error re-receiving message with ID [" + 
oagisMessageInfoKey + "]: " + e.toString();
+            Debug.logError(e, errMsg, module);
+            return ServiceUtil.returnError(errMsg);
+        }
+    }
+    
     public static Map oagisMessageHandler(DispatchContext ctx, Map context) {
         GenericDelegator delegator = ctx.getDelegator();
         LocalDispatcher dispatcher = ctx.getDispatcher();
         InputStream in = (InputStream) context.get("inputStream");
         List errorList = FastList.newInstance();
+        Boolean isErrorRetry = (Boolean) context.get("isErrorRetry");
 
         GenericValue userLogin = null; 
         try {
@@ -511,7 +561,7 @@
         
         // call async, no additional results to return: Map subServiceResult = 
FastMap.newInstance();
         if (UtilValidate.isNotEmpty(oagisMessageInfo)) {
-            if 
("OAGMP_SYS_ERROR".equals(oagisMessageInfo.getString("processingStatusId"))) {
+            if (Boolean.TRUE.equals(isErrorRetry) || 
"OAGMP_SYS_ERROR".equals(oagisMessageInfo.getString("processingStatusId"))) {
                 // there was an error last time, tell the service this is a 
retry
                 messageProcessContext.put("isErrorRetry", Boolean.TRUE);
             } else {


Reply via email to