svn commit: r1818557 - in /ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email: EmailServices.java NotificationServices.java

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

svn commit: r1818557 - in /ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email: EmailServices.java NotificationServices.java

mbrohl
Author: mbrohl
Date: Mon Dec 18 12:21:16 2017
New Revision: 1818557

URL: http://svn.apache.org/viewvc?rev=1818557&view=rev
Log:
Improved: General refactoring and code improvements, package
org.apache.ofbiz.common.email.
(OFBIZ-9876)

Thanks Julian Leichert for reporting and providing the patches.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java
    ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email/NotificationServices.java

Modified: ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java?rev=1818557&r1=1818556&r2=1818557&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java Mon Dec 18 12:21:16 2017
@@ -139,8 +139,12 @@ public class EmailServices {
         if (UtilValidate.isNotEmpty(redirectAddress)) {
             StringBuilder sb = new StringBuilder();
             sb.append(" [To: ").append(sendTo);
-            if (UtilValidate.isNotEmpty(sendCc)) sb.append(", Cc: ").append(sendCc);
-            if (UtilValidate.isNotEmpty(sendBcc)) sb.append(", Bcc: ").append(sendBcc);
+            if (UtilValidate.isNotEmpty(sendCc)) {
+                sb.append(", Cc: ").append(sendCc);
+            }
+            if (UtilValidate.isNotEmpty(sendBcc)) {
+                sb.append(", Bcc: ").append(sendBcc);
+            }
             sb.append("]");
             subject += sb.toString();
             sendTo = redirectAddress;
@@ -305,10 +309,6 @@ public class EmailServices {
             Debug.logError(e, "MessagingException when creating message to [" + sendTo + "] from [" + sendFrom + "] cc [" + sendCc + "] bcc [" + sendBcc + "] subject [" + subject + "]", module);
             Debug.logError("Email message that could not be created to [" + sendTo + "] had context: " + context, module);
             return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonEmailSendMessagingException", UtilMisc.toMap("sendTo", sendTo, "sendFrom", sendFrom, "sendCc", sendCc, "sendBcc", sendBcc, "subject", subject), locale));
-        } catch (IOException e) {
-            Debug.logError(e, "IOExcepton when creating message to [" + sendTo + "] from [" + sendFrom + "] cc [" + sendCc + "] bcc [" + sendBcc + "] subject [" + subject + "]", module);
-            Debug.logError("Email message that could not be created to [" + sendTo + "] had context: " + context, module);
-            return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonEmailSendIOException", UtilMisc.toMap("sendTo", sendTo, "sendFrom", sendFrom, "sendCc", sendCc, "sendBcc", sendBcc, "subject", subject), locale));
         }
 
         // check to see if sending mail is enabled
@@ -432,20 +432,34 @@ public class EmailServices {
         List<String> xslfoAttachScreenLocationListParam = UtilGenerics.checkList(serviceContext.remove("xslfoAttachScreenLocationList"));
         List<String> attachmentNameListParam = UtilGenerics.checkList(serviceContext.remove("attachmentNameList"));
         VisualTheme visualTheme = (VisualTheme) rServiceContext.get("visualTheme");
-        if (visualTheme == null) visualTheme = ThemeFactory.resolveVisualTheme(null);
+        if (visualTheme == null) {
+            visualTheme = ThemeFactory.resolveVisualTheme(null);
+        }
         
         List<String> xslfoAttachScreenLocationList = new LinkedList<>();
         List<String> attachmentNameList = new LinkedList<>();
-        if (UtilValidate.isNotEmpty(xslfoAttachScreenLocationParam)) xslfoAttachScreenLocationList.add(xslfoAttachScreenLocationParam);
-        if (UtilValidate.isNotEmpty(attachmentNameParam)) attachmentNameList.add(attachmentNameParam);
-        if (UtilValidate.isNotEmpty(xslfoAttachScreenLocationListParam)) xslfoAttachScreenLocationList.addAll(xslfoAttachScreenLocationListParam);
-        if (UtilValidate.isNotEmpty(attachmentNameListParam)) attachmentNameList.addAll(attachmentNameListParam);
+        if (UtilValidate.isNotEmpty(xslfoAttachScreenLocationParam)) {
+            xslfoAttachScreenLocationList.add(xslfoAttachScreenLocationParam);
+        }
+        if (UtilValidate.isNotEmpty(attachmentNameParam)) {
+            attachmentNameList.add(attachmentNameParam);
+        }
+        if (UtilValidate.isNotEmpty(xslfoAttachScreenLocationListParam)) {
+            xslfoAttachScreenLocationList.addAll(xslfoAttachScreenLocationListParam);
+        }
+        if (UtilValidate.isNotEmpty(attachmentNameListParam)) {
+            attachmentNameList.addAll(attachmentNameListParam);
+        }
         
         List<String> attachmentTypeList = new LinkedList<>();
         String attachmentTypeParam = (String) serviceContext.remove("attachmentType");
         List<String> attachmentTypeListParam = UtilGenerics.checkList(serviceContext.remove("attachmentTypeList"));
-        if (UtilValidate.isNotEmpty(attachmentTypeParam)) attachmentTypeList.add(attachmentTypeParam);
-        if (UtilValidate.isNotEmpty(attachmentTypeListParam)) attachmentTypeList.addAll(attachmentTypeListParam);
+        if (UtilValidate.isNotEmpty(attachmentTypeParam)) {
+            attachmentTypeList.add(attachmentTypeParam);
+        }
+        if (UtilValidate.isNotEmpty(attachmentTypeListParam)) {
+            attachmentTypeList.addAll(attachmentTypeListParam);
+        }
         
         Locale locale = (Locale) serviceContext.get("locale");
         Map<String, Object> bodyParameters = UtilGenerics.checkMap(serviceContext.remove("bodyParameters"));
@@ -476,10 +490,7 @@ public class EmailServices {
         ScreenStringRenderer screenStringRenderer = null;
         try {
             screenStringRenderer = new MacroScreenRenderer("screen", visualTheme.getModelTheme().getScreenRendererLocation("screen"));
-        } catch (TemplateException e) {
-            Debug.logError(e, "Error rendering screen for email: " + e.toString(), module);
-            return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonEmailSendRenderingScreenEmailError", UtilMisc.toMap("errorString", e.toString()), locale));
-        } catch (IOException e) {
+        } catch (TemplateException | IOException e) {
             Debug.logError(e, "Error rendering screen for email: " + e.toString(), module);
             return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonEmailSendRenderingScreenEmailError", UtilMisc.toMap("errorString", e.toString()), locale));
         }
@@ -490,16 +501,7 @@ public class EmailServices {
         if (bodyScreenUri != null) {
             try {
                 screens.render(bodyScreenUri);
-            } catch (GeneralException e) {
-                Debug.logError(e, "Error rendering screen for email: " + e.toString(), module);
-                return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonEmailSendRenderingScreenEmailError", UtilMisc.toMap("errorString", e.toString()), locale));
-            } catch (IOException e) {
-                Debug.logError(e, "Error rendering screen for email: " + e.toString(), module);
-                return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonEmailSendRenderingScreenEmailError", UtilMisc.toMap("errorString", e.toString()), locale));
-            } catch (SAXException e) {
-                Debug.logError(e, "Error rendering screen for email: " + e.toString(), module);
-                return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonEmailSendRenderingScreenEmailError", UtilMisc.toMap("errorString", e.toString()), locale));
-            } catch (ParserConfigurationException e) {
+            } catch (GeneralException | IOException | SAXException | ParserConfigurationException e) {
                 Debug.logError(e, "Error rendering screen for email: " + e.toString(), module);
                 return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonEmailSendRenderingScreenEmailError", UtilMisc.toMap("errorString", e.toString()), locale));
             }
@@ -592,7 +594,9 @@ public class EmailServices {
         // also expand the subject at this point, just in case it has the FlexibleStringExpander syntax in it...
         String subject = (String) serviceContext.remove("subject");
         subject = FlexibleStringExpander.expandString(subject, screenContext, locale);
-        Debug.logInfo("Expanded email subject to: " + subject, module);
+        if (Debug.infoOn()) {
+            Debug.logInfo("Expanded email subject to: " + subject, module);
+        }
         serviceContext.put("subject", subject);
         serviceContext.put("partyId", partyId);
         if (UtilValidate.isNotEmpty(orderId)) {
@@ -602,7 +606,9 @@ public class EmailServices {
             serviceContext.put("custRequestId", custRequestId);
         }            
         
-        if (Debug.verboseOn()) Debug.logVerbose("sendMailFromScreen sendMail context: " + serviceContext, module);
+        if (Debug.verboseOn()) {
+            Debug.logVerbose("sendMailFromScreen sendMail context: " + serviceContext, module);
+        }
 
         Map<String, Object> result = ServiceUtil.returnSuccess();
         Map<String, Object> sendMailResult;
@@ -724,7 +730,7 @@ public class EmailServices {
         private String contentType;
         private byte[] contentArray;
 
-        public ByteArrayDataSource(byte[] content, String contentType) throws IOException {
+        public ByteArrayDataSource(byte[] content, String contentType) {
             this.contentType = contentType;
             this.contentArray = content.clone();
         }
@@ -733,7 +739,7 @@ public class EmailServices {
             return contentType == null ? "application/octet-stream" : contentType;
         }
 
-        public InputStream getInputStream() throws IOException {
+        public InputStream getInputStream() {
             return new ByteArrayInputStream(contentArray);
         }
 

Modified: ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email/NotificationServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email/NotificationServices.java?rev=1818557&r1=1818556&r2=1818557&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email/NotificationServices.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email/NotificationServices.java Mon Dec 18 12:21:16 2017
@@ -146,7 +146,7 @@ public class NotificationServices {
             // make sure we have a valid body before sending
             if (body != null) {
                 // retain only the required attributes for the sendMail service
-                Map<String, Object> emailContext =  new LinkedHashMap<String, Object>();
+                Map<String, Object> emailContext =  new LinkedHashMap<>();
                 emailContext.put("sendTo", context.get("sendTo"));
                 emailContext.put("body", body);
                 emailContext.put("sendCc", context.get("sendCc"));
@@ -194,7 +194,7 @@ public class NotificationServices {
         Locale locale = (Locale) context.get("locale");
         Map<String, Object> result = null;
         if (templateData == null) {
-            templateData =  new LinkedHashMap<String, Object>();
+            templateData =  new LinkedHashMap<>();
         }
 
         try {