svn commit: r562279 - in /ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis: OagisInventoryServices.java OagisServices.java 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: r562279 - in /ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis: OagisInventoryServices.java OagisServices.java OagisShipmentServices.java

jonesde
Author: jonesde
Date: Thu Aug  2 15:24:09 2007
New Revision: 562279

URL: http://svn.apache.org/viewvc?view=rev&rev=562279
Log:
Small changes for better error handling

Modified:
    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/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=562279&r1=562278&r2=562279
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java (original)
+++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java Thu Aug  2 15:24:09 2007
@@ -210,7 +210,10 @@
         if (inventoryMapList.size() > 0) {
             // prepare information to send mail
             Map sendMap = FastMap.newInstance();
+
+            String sendToEmail = UtilProperties.getPropertyValue("oagis.properties", "oagis.notification.email.sendTo");
     
+            /* DEJ20070802 changed to get email address from properties file, should be way easier to manage
             // get facility email address
             List facilityContactMechs = null;
             GenericValue contactMech = null;
@@ -221,6 +224,7 @@
                 errorMapList.add(UtilMisc.toMap("reasonCode", "GenericEntityException", "description", errMsg));
                 Debug.logError(e, errMsg, module);
             }
+
             Iterator fcmIter  = facilityContactMechs.iterator();
             while(fcmIter.hasNext()) {
                 GenericValue facilityContactMech = (GenericValue) fcmIter.next();
@@ -238,47 +242,52 @@
                     sendMap.put("sendTo", emailString);
                 }
             }
+            */
             
-            GenericValue productStoreEmail = null;
-            String productStoreId = UtilProperties.getPropertyValue("oagis.properties", "Oagis.Warehouse.SyncInventoryProductStoreId");
-            try {
-                productStoreEmail = delegator.findByPrimaryKey("ProductStoreEmailSetting", UtilMisc.toMap("productStoreId", productStoreId, "emailType", "PRDS_OAGIS_CONFIRM"));
-            } catch (GenericEntityException e) {
-                String errMsg = "Error Getting Entity ProductStoreEmailSetting: " + e.toString();
-                errorMapList.add(UtilMisc.toMap("reasonCode", "GenericEntityException", "description", errMsg));
-                Debug.logError(e, errMsg, module);
-            }
-            if (productStoreEmail != null) {
-                String bodyScreenLocation = productStoreEmail.getString("bodyScreenLocation");
-                sendMap.put("bodyScreenUri", bodyScreenLocation);
+            if (UtilValidate.isNotEmpty(sendToEmail)) {
+                String productStoreId = UtilProperties.getPropertyValue("oagis.properties", "Oagis.Warehouse.SyncInventoryProductStoreId");
+                GenericValue productStoreEmail = null;
+                try {
+                    productStoreEmail = delegator.findByPrimaryKey("ProductStoreEmailSetting", UtilMisc.toMap("productStoreId", productStoreId, "emailType", "PRDS_OAGIS_CONFIRM"));
+                } catch (GenericEntityException e) {
+                    String errMsg = "Error Getting Entity ProductStoreEmailSetting: " + e.toString();
+                    errorMapList.add(UtilMisc.toMap("reasonCode", "GenericEntityException", "description", errMsg));
+                    Debug.logError(e, errMsg, module);
+                }
+                if (productStoreEmail != null) {
+                    String bodyScreenLocation = productStoreEmail.getString("bodyScreenLocation");
+                    sendMap.put("bodyScreenUri", bodyScreenLocation);
+                } else {
+                    sendMap.put("bodyScreenUri", "component://oagis/widget/EmailOagisMessageScreens.xml#InventoryMismatchNotice");
+                }
+                if (locale == null) {
+                    locale = Locale.getDefault();
+                }
+
+                sendMap.put("sendTo", sendToEmail);
+                
+                sendMap.put("subject", productStoreEmail.getString("subject"));
+                sendMap.put("sendFrom", productStoreEmail.getString("fromAddress"));
+                sendMap.put("sendCc", productStoreEmail.getString("ccAddress"));
+                sendMap.put("sendBcc", productStoreEmail.getString("bccAddress"));
+                sendMap.put("contentType", productStoreEmail.getString("contentType"));
+                
+                Map bodyParameters = UtilMisc.toMap("inventoryMapList", inventoryMapList, "locale", locale);
+                sendMap.put("bodyParameters", bodyParameters);
+                sendMap.put("userLogin", userLogin);
+                
+                // send the notification
+                try {
+                    // run async so it will happen in the background AND so errors in sending won't mess this up
+                    dispatcher.runAsync("sendMailFromScreen", sendMap, true);
+                } catch(Exception e) {
+                    String errMsg = "Error Running Service sendMailFromScreen: " + e.toString();
+                    errorMapList.add(UtilMisc.toMap("reasonCode", "GenericServiceException", "description", errMsg));
+                    Debug.logError(e, errMsg, module);
+                }
             } else {
-                sendMap.put("bodyScreenUri", "component://oagis/widget/EmailOagisMessageScreens.xml#InventoryMismatchNotice");
-            }
-            if (locale == null) {
-                locale = Locale.getDefault();
-            }
-            sendMap.put("subject", productStoreEmail.getString("subject"));
-            sendMap.put("sendFrom", productStoreEmail.getString("fromAddress"));
-            sendMap.put("sendCc", productStoreEmail.getString("ccAddress"));
-            sendMap.put("sendBcc", productStoreEmail.getString("bccAddress"));
-            sendMap.put("contentType", productStoreEmail.getString("contentType"));
-            
-            Map bodyParameters = UtilMisc.toMap("inventoryMapList", inventoryMapList, "locale", locale);
-            sendMap.put("bodyParameters", bodyParameters);
-            sendMap.put("userLogin", userLogin);
-            
-            // send the notification
-            Map sendResp = null;
-            try {
-                sendResp = dispatcher.runSync("sendMailFromScreen", sendMap);
-                if (ServiceUtil.isError(sendResp)){
-                    String errMsg = ServiceUtil.getErrorMessage(sendResp);
-                    errorMapList.add(UtilMisc.toMap("reasonCode", "SendMailServiceError", "description", errMsg));
-                }
-            } catch(GenericServiceException e) {
-                String errMsg = "Error Running Service sendMailFromScreen: " + e.toString();
-                errorMapList.add(UtilMisc.toMap("reasonCode", "GenericServiceException", "description", errMsg));
-                Debug.logError(e, errMsg, module);
+                // no send to email address, just log to file
+                Debug.logImportant("No sendTo email address found in process syncInventory service: inventoryMapList: " + inventoryMapList, module);
             }
         }
       
@@ -306,11 +315,13 @@
             }
         }
         try {
-            Map comiResult = dispatcher.runSync("createOagisMessageInfo", comiCtx);
+            dispatcher.runAsync("createOagisMessageInfo", comiCtx, true);
+            /* now calling async for better error handling
             if (ServiceUtil.isError(comiResult)) {
                 String errMsg = ServiceUtil.getErrorMessage(comiResult);
                 errorMapList.add(UtilMisc.toMap("reasonCode", "CreateOagisMessageServiceError", "description", errMsg));
             }
+            */
         } catch (GenericServiceException e) {
             String errMsg = "Error creating OagisMessageInfo for the Incoming Message: " + e.toString();
             errorMapList.add(UtilMisc.toMap("reasonCode", "CreateOagisMessageInfoError", "description", errMsg));
@@ -513,11 +524,13 @@
             }
         }
         try {
-            Map comiResult = dispatcher.runSync("createOagisMessageInfo", comiCtx);
+            dispatcher.runAsync("createOagisMessageInfo", comiCtx, true);
+            /* running async for better error handling
             if (ServiceUtil.isError(comiResult)) {
                 String errMsg = ServiceUtil.getErrorMessage(comiResult);
                 errorMapList.add(UtilMisc.toMap("reasonCode", "CreateOagisMessageServiceError", "description", errMsg));
             }
+            */
         } catch (GenericServiceException e) {
             String errMsg = "Error creating OagisMessageInfo for the Incoming Message: " + e.toString();
             // TODO: reconsider sending this error back to other server, not much they can do about it, and it may not be a critical error causing the message to be rejected...
@@ -753,11 +766,13 @@
             }
         }
         try {
-            Map comiResult = dispatcher.runSync("createOagisMessageInfo", comiCtx);
+            dispatcher.runAsync("createOagisMessageInfo", comiCtx);
+            /* running async for better error handling
             if (ServiceUtil.isError(comiResult)) {
                 String errMsg = ServiceUtil.getErrorMessage(comiResult);
                 errorMapList.add(UtilMisc.toMap("reasonCode", "CreateOagisMessageServiceError", "description", errMsg));
             }
+            */
         } catch (GenericServiceException e) {
             String errMsg = "Error creating OagisMessageInfo for the Incoming Message: " + e.toString();
             // TODO: reconsider sending this error back to other server, not much they can do about it, and it may not be a critical error causing the message to be rejected...

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=562279&r1=562278&r2=562279
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java (original)
+++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java Thu Aug  2 15:24:09 2007
@@ -159,8 +159,10 @@
         oagisMsgInfoContext.put("userLogin", userLogin);
         try
         {
-            Map oagisMsgInfoResult = dispatcher.runSync("createOagisMessageInfo", oagisMsgInfoContext);
+            dispatcher.runAsync("createOagisMessageInfo", oagisMsgInfoContext, true);
+            /* running async for better error handling
             if (ServiceUtil.isError(oagisMsgInfoResult)) return ServiceUtil.returnError("Error creating OagisMessageInfo");
+            */
             
         } catch (GenericServiceException e) {
             Debug.logError(e, "Saving message to database failed", module);
@@ -257,12 +259,14 @@
         oagisMsgInfoCtx.put("outgoingMessage", "N");
         oagisMsgInfoCtx.put("userLogin", userLogin);
         try {
-            Map oagisMsgInfoResult = dispatcher.runSync("createOagisMessageInfo", oagisMsgInfoCtx);
+            dispatcher.runAsync("createOagisMessageInfo", oagisMsgInfoCtx, true);
+            /* running async for better error handling
             if (ServiceUtil.isError(oagisMsgInfoResult)){
                 String errMsg = "Error creating OagisMessageInfo for the Incoming Message: "+ServiceUtil.getErrorMessage(oagisMsgInfoResult);
                 errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "CreateOagisMessageInfoServiceError"));
                 Debug.logError(errMsg, module);
             }
+            */
         } catch (GenericServiceException e){
             String errMsg = "Error creating OagisMessageInfo for the Incoming Message: "+e.toString();
             errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "GenericServiceException"));

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=562279&r1=562278&r2=562279
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java (original)
+++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java Thu Aug  2 15:24:09 2007
@@ -155,12 +155,14 @@
         }
         
         try {
-            Map oagisMsgInfoResult = dispatcher.runSync("createOagisMessageInfo", oagisMsgInfoCtx);
+            dispatcher.runAsync("createOagisMessageInfo", oagisMsgInfoCtx, true);
+            /* running async for better error handling
             if (ServiceUtil.isError(oagisMsgInfoResult)){
                 String errMsg = ServiceUtil.getErrorMessage(oagisMsgInfoResult);
                 errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "CreateOagisMessageInfoServiceError"));
                 Debug.logError(errMsg, module);
             }
+            */
         } catch (GenericServiceException e){
             String errMsg = "Error creating OagisMessageInfo for the Incoming Message: "+e.toString();
             errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "GenericServiceException"));
@@ -501,7 +503,7 @@
                 }
                 
                 try {
-                    Map oagisMsgInfoResult = dispatcher.runSync("createOagisMessageInfo", comiCtx);
+                    dispatcher.runAsync("createOagisMessageInfo", comiCtx, true);
                 } catch (GenericServiceException e){
                     String errMsg = UtilProperties.getMessage(ServiceUtil.resource, "OagisErrorInCreatingDataForOagisMessageInfoEntity", (Locale) context.get("locale"));
                     Debug.logError(e, errMsg, module);
@@ -685,7 +687,7 @@
                 }
 
                 try {
-                    dispatcher.runSync("createOagisMessageInfo", comiCtx);
+                    dispatcher.runAsync("createOagisMessageInfo", comiCtx, true);
                 } catch (GenericServiceException e) {
                     String errMsg = UtilProperties.getMessage(ServiceUtil.resource, "OagisErrorInCreatingDataForOagisMessageInfoEntity", (Locale) context.get("locale"));
                     Debug.logError(e, errMsg, module);