[Yanel-commits] rev 57318 - public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/workflow

michi at wyona.com michi at wyona.com
Tue Mar 15 10:13:15 CET 2011


Author: michi
Date: 2011-03-15 10:13:15 +0100 (Tue, 15 Mar 2011)
New Revision: 57318

Modified:
   public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/workflow/EmailAction.java
Log:
parse email addresses

Modified: public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/workflow/EmailAction.java
===================================================================
--- public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/workflow/EmailAction.java	2011-03-15 08:55:54 UTC (rev 57317)
+++ public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/workflow/EmailAction.java	2011-03-15 09:13:15 UTC (rev 57318)
@@ -42,6 +42,33 @@
      * @see org.wyona.yanel.core.workflow.Action#execute(WorkflowableV1, Workflow, String)
      */
     public void execute(WorkflowableV1 workflowable, Workflow workflow, String revision) throws WorkflowException {
-        log.warn("Send emails to: " + expression);
+        String[] emailAddresses = getEmailAddresses();
+        if (emailAddresses != null) {
+            for (int i = 0; i < emailAddresses.length; i++) {
+                log.warn("Send email to: " + emailAddresses[i]);
+            }
+        } else {
+            throw new WorkflowException("No email addresses!");
+        }
     }
+
+    /**
+     * Get email addresses
+     */
+    private String[] getEmailAddresses() throws WorkflowException {
+        if (expression != null) {
+            String[] ea = expression.split(",");
+            String[] emails = new String[ea.length]; // TODO: Make more fault tolerant
+            for(int i = 0; i < ea.length; i++) {
+                if (ea[i].indexOf("@") < 1) {
+                    throw new WorkflowException("No such email address: " + ea[i]);
+                } else {
+                    emails[i] = ea[i].trim();
+                }
+            }
+            return emails;
+        } else {
+            return null;
+        }
+    }
 }



More information about the Yanel-commits mailing list