[jbpm-commits] JBoss JBPM SVN: r4572 - in jbpm4/branches/email: .settings and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Apr 16 17:39:27 EDT 2009


Author: alex.guizar at jboss.com
Date: 2009-04-16 17:39:27 -0400 (Thu, 16 Apr 2009)
New Revision: 4572

Modified:
   jbpm4/branches/email/.project
   jbpm4/branches/email/.settings/org.maven.ide.eclipse.prefs
   jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java
   jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/spi/MailProducer.java
Log:
change mail producer to return collection

Modified: jbpm4/branches/email/.project
===================================================================
--- jbpm4/branches/email/.project	2009-04-16 19:32:12 UTC (rev 4571)
+++ jbpm4/branches/email/.project	2009-04-16 21:39:27 UTC (rev 4572)
@@ -1,12 +1,17 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-	<name>jbpm4</name>
-	<comment></comment>
-	<projects>
-	</projects>
-	<buildSpec>
-	</buildSpec>
-	<natures>
-		<nature>org.maven.ide.eclipse.maven2Nature</nature>
-	</natures>
-</projectDescription>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>jbpm4</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.maven.ide.eclipse.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.maven.ide.eclipse.maven2Nature</nature>
+	</natures>
+</projectDescription>

Modified: jbpm4/branches/email/.settings/org.maven.ide.eclipse.prefs
===================================================================
--- jbpm4/branches/email/.settings/org.maven.ide.eclipse.prefs	2009-04-16 19:32:12 UTC (rev 4571)
+++ jbpm4/branches/email/.settings/org.maven.ide.eclipse.prefs	2009-04-16 21:39:27 UTC (rev 4572)
@@ -1,8 +1,9 @@
-#Wed Mar 25 11:07:34 CET 2009
-activeProfiles=
-eclipse.preferences.version=1
-fullBuildGoals=
-includeModules=false
-resolveWorkspaceProjects=true
-resourceFilterGoals=
-version=1
+#Thu Apr 16 16:21:44 CDT 2009
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+skipCompilerPlugin=true
+version=1

Modified: jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java
===================================================================
--- jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java	2009-04-16 19:32:12 UTC (rev 4571)
+++ jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java	2009-04-16 21:39:27 UTC (rev 4572)
@@ -51,201 +51,192 @@
  */
 public class MailProducerImpl implements MailProducer {
 
-	private MailTemplate template;
+  private MailTemplate template;
 
-	public MailTemplate getTemplate() {
-		return template;
-	}
+  public MailTemplate getTemplate() {
+    return template;
+  }
 
-	public void setTemplate(MailTemplate template) {
-		this.template = template;
-	}
+  public void setTemplate(MailTemplate template) {
+    this.template = template;
+  }
 
-	public Email produce(OpenExecution execution) {
-		try {
-			Email email = instantiateEmail(template);
-			fillRecipients(template, execution, email);
-			fillSubject(execution, email);
-			fillBody(execution, email);
-			return email;
-		}
-		catch (EmailException e) {
-			throw new JbpmException("could not produce email", e);
-		}
-	}
+  public Collection<Email> produce(OpenExecution execution) {
+    try {
+      Email email = instantiateEmail(template);
+      fillRecipients(template, execution, email);
+      fillSubject(execution, email);
+      fillBody(execution, email);
+      return Collections.singleton(email);
+    }
+    catch (EmailException e) {
+      throw new JbpmException("could not produce email", e);
+    }
+  }
 
-	protected Email instantiateEmail(MailTemplate template) {
-		return template.getHtml() != null ? new HtmlEmail() : template
-				.getAttachmentTemplates()
-				.isEmpty() ? new MultiPartEmail() : new SimpleEmail();
-	}
+  protected Email instantiateEmail(MailTemplate template) {
+    return template.getHtml() != null ? new HtmlEmail() : template.getAttachmentTemplates()
+        .isEmpty() ? new MultiPartEmail() : new SimpleEmail();
+  }
 
-	protected void fillRecipients(MailTemplate template, OpenExecution execution, Email email)
-			throws EmailException {
-		Environment environment = Environment.getCurrent();
-		IdentitySession identitySession = environment.get(IdentitySession.class);
-		RecipientNameBuilder recipientNameBuilder = environment.get(RecipientNameBuilder.class);
+  protected void fillRecipients(MailTemplate template, OpenExecution execution, Email email)
+      throws EmailException {
+    Environment environment = Environment.getCurrent();
+    IdentitySession identitySession = environment.get(IdentitySession.class);
+    RecipientNameBuilder recipientNameBuilder = environment.get(RecipientNameBuilder.class);
 
-		// to
-		RecipientTemplate to = template.getTo();
-		if (to != null) {
-			for (String address : evaluateRecipients(to.getAddresses(), execution)) {
-				email.addTo(address);
-			}
-			for (String actorId : evaluateRecipients(to.getActors(), execution)) {
-				Collection<User> users = resolveUsers(identitySession, actorId);
-				for (User user : users) {
-					email.addTo(user.getEmailAddress(), recipientNameBuilder.buildName(user));
-				}
-			}
-		}
+    // to
+    RecipientTemplate to = template.getTo();
+    if (to != null) {
+      for (String address : evaluateRecipients(to.getAddresses(), execution)) {
+        email.addTo(address);
+      }
+      for (String actorId : evaluateRecipients(to.getActors(), execution)) {
+        Collection<User> users = resolveUsers(identitySession, actorId);
+        for (User user : users) {
+          email.addTo(user.getEmailAddress(), recipientNameBuilder.buildName(user));
+        }
+      }
+    }
 
-		// cc
-		RecipientTemplate cc = template.getCc();
-		if (cc != null) {
-			for (String address : evaluateRecipients(cc.getAddresses(), execution)) {
-				email.addCc(address);
-			}
-			for (String actorId : evaluateRecipients(cc.getActors(), execution)) {
-				Collection<User> users = resolveUsers(identitySession, actorId);
-				for (User user : users) {
-					email.addCc(user.getEmailAddress(), recipientNameBuilder.buildName(user));
-				}
-			}
-		}
+    // cc
+    RecipientTemplate cc = template.getCc();
+    if (cc != null) {
+      for (String address : evaluateRecipients(cc.getAddresses(), execution)) {
+        email.addCc(address);
+      }
+      for (String actorId : evaluateRecipients(cc.getActors(), execution)) {
+        Collection<User> users = resolveUsers(identitySession, actorId);
+        for (User user : users) {
+          email.addCc(user.getEmailAddress(), recipientNameBuilder.buildName(user));
+        }
+      }
+    }
 
-		// bcc
-		RecipientTemplate bcc = template.getBcc();
-		if (bcc != null) {
-			for (String address : evaluateRecipients(bcc.getAddresses(), execution)) {
-				email.addBcc(address);
-			}
-			for (String actorId : evaluateRecipients(bcc.getActors(), execution)) {
-				Collection<User> users = resolveUsers(identitySession, actorId);
-				for (User user : users) {
-					email.addBcc(user.getEmailAddress(), recipientNameBuilder.buildName(user));
-				}
-			}
-		}
-	}
+    // bcc
+    RecipientTemplate bcc = template.getBcc();
+    if (bcc != null) {
+      for (String address : evaluateRecipients(bcc.getAddresses(), execution)) {
+        email.addBcc(address);
+      }
+      for (String actorId : evaluateRecipients(bcc.getActors(), execution)) {
+        Collection<User> users = resolveUsers(identitySession, actorId);
+        for (User user : users) {
+          email.addBcc(user.getEmailAddress(), recipientNameBuilder.buildName(user));
+        }
+      }
+    }
+  }
 
-	private String evaluateExpression(String expression, OpenExecution execution) {
-		ScriptManager scriptManager = Environment.getFromCurrent(ScriptManager.class);
-		return scriptManager
-				.evaluateExpression(expression, execution, template.getLanguage())
-				.toString();
-	}
+  private String evaluateExpression(String expression, OpenExecution execution) {
+    ScriptManager scriptManager = Environment.getFromCurrent(ScriptManager.class);
+    return scriptManager.evaluateExpression(expression, execution, template.getLanguage())
+        .toString();
+  }
 
-	private String[] evaluateRecipients(String recipients, OpenExecution execution) {
-		return evaluateExpression(recipients, execution).split("[,|\\s]+");
-	}
+  private String[] evaluateRecipients(String recipients, OpenExecution execution) {
+    return evaluateExpression(recipients, execution).split("[,|\\s]+");
+  }
 
-	private static Collection<User> resolveUsers(IdentitySession identitySession, String actorId) {
-		// first, try to resolve actorId as user
-		User user = identitySession.findUserById(actorId);
-		if (user != null)
-			return Collections.singleton(user);
+  private static Collection<User> resolveUsers(IdentitySession identitySession, String actorId) {
+    // first, try to resolve actorId as user
+    User user = identitySession.findUserById(actorId);
+    if (user != null) return Collections.singleton(user);
 
-		// next, try to resolve as group
-		Group group = identitySession.findGroupById(actorId);
-		if (group != null)
-			return identitySession.findUsersByGroup(actorId);
+    // next, try to resolve as group
+    Group group = identitySession.findGroupById(actorId);
+    if (group != null) return identitySession.findUsersByGroup(actorId);
 
-		// give up
-		return Collections.emptySet();
-	}
+    // give up
+    return Collections.emptySet();
+  }
 
-	protected void fillSubject(OpenExecution execution, Email email) {
-		email.setSubject(evaluateExpression(template.getSubject(), execution));
-	}
+  protected void fillSubject(OpenExecution execution, Email email) {
+    email.setSubject(evaluateExpression(template.getSubject(), execution));
+  }
 
-	protected void fillBody(OpenExecution execution, Email email) throws EmailException {
-		if (template.getHtml() == null) {
-			email.setMsg(evaluateExpression(template.getText(), execution));
-		}
-		else {
-			HtmlEmail htmlEmail = (HtmlEmail) email;
-			htmlEmail.setHtmlMsg(evaluateExpression(template.getHtml(), execution));
-			htmlEmail.setTextMsg(evaluateExpression(template.getText(), execution));
-		}
-	}
+  protected void fillBody(OpenExecution execution, Email email) throws EmailException {
+    if (template.getHtml() == null) {
+      email.setMsg(evaluateExpression(template.getText(), execution));
+    }
+    else {
+      HtmlEmail htmlEmail = (HtmlEmail) email;
+      htmlEmail.setHtmlMsg(evaluateExpression(template.getHtml(), execution));
+      htmlEmail.setTextMsg(evaluateExpression(template.getText(), execution));
+    }
+  }
 
-	protected void addAttachments(OpenExecution execution, Email email) throws EmailException {
-		List<AttachmentTemplate> attachmentTemplates = template.getAttachmentTemplates();
-		if (attachmentTemplates.isEmpty())
-			return;
+  protected void addAttachments(OpenExecution execution, Email email) throws EmailException {
+    List<AttachmentTemplate> attachmentTemplates = template.getAttachmentTemplates();
+    if (attachmentTemplates.isEmpty()) return;
 
-		MultiPartEmail multiPartEmail = (MultiPartEmail) email;
-		for (AttachmentTemplate attachmentTemplate : attachmentTemplates) {
-			EmailAttachment attachment = new EmailAttachment();
-			attachment.setDisposition(EmailAttachment.ATTACHMENT);
+    MultiPartEmail multiPartEmail = (MultiPartEmail) email;
+    for (AttachmentTemplate attachmentTemplate : attachmentTemplates) {
+      EmailAttachment attachment = new EmailAttachment();
+      attachment.setDisposition(EmailAttachment.ATTACHMENT);
 
-			// name
-			String name = attachmentTemplate.getName();
-			if (name != null)
-				attachment.setName(evaluateExpression(name, execution));
+      // name
+      String name = attachmentTemplate.getName();
+      if (name != null) attachment.setName(evaluateExpression(name, execution));
 
-			// description
-			String description = attachmentTemplate.getDescription();
-			if (description != null)
-				attachment.setDescription(evaluateExpression(description, execution));
+      // description
+      String description = attachmentTemplate.getDescription();
+      if (description != null)
+        attachment.setDescription(evaluateExpression(description, execution));
 
-			// file
-			String file = attachmentTemplate.getFile();
-			if (file != null) {
-				File targetFile = new File(evaluateExpression(file, execution));
-				if (!targetFile.isFile()) {
-					throw new EmailException("could not fetch attachment from " + targetFile);
-				}
-				attachment.setPath(targetFile.getPath());
-				// extract attachment name from file
-				if (name == null)
-					attachment.setName(targetFile.getName());
-			}
-			else {
-				URL targetUrl;
-				// url
-				String url = attachmentTemplate.getUrl();
-				if (url != null) {
-					try {
-						targetUrl = new URL(evaluateExpression(url, execution));
-					}
-					catch (MalformedURLException e) {
-						throw new EmailException("could not fetch attachment from " + url, e);
-					}
-				}
-				// resource
-				else {
-					String resource = attachmentTemplate.getResource();
-					targetUrl =
-							Environment.getCurrent().getClassLoader().getResource(
-									evaluateExpression(resource, execution));
-					if (targetUrl == null) {
-						throw new EmailException("could not fetch attachment from " + resource);
-					}
-				}
-				attachment.setURL(targetUrl);
-				// extract attachment name from url
-				if (name == null) {
-					String resourceName = extractResourceName(targetUrl);
-					attachment.setName(resourceName);
-				}
-			}
+      // file
+      String file = attachmentTemplate.getFile();
+      if (file != null) {
+        File targetFile = new File(evaluateExpression(file, execution));
+        if (!targetFile.isFile()) {
+          throw new EmailException("could not fetch attachment from " + targetFile);
+        }
+        attachment.setPath(targetFile.getPath());
+        // extract attachment name from file
+        if (name == null) attachment.setName(targetFile.getName());
+      }
+      else {
+        URL targetUrl;
+        // url
+        String url = attachmentTemplate.getUrl();
+        if (url != null) {
+          try {
+            targetUrl = new URL(evaluateExpression(url, execution));
+          }
+          catch (MalformedURLException e) {
+            throw new EmailException("could not fetch attachment from " + url, e);
+          }
+        }
+        // resource
+        else {
+          String resource = attachmentTemplate.getResource();
+          targetUrl =
+              Environment.getCurrent().getClassLoader().getResource(
+                  evaluateExpression(resource, execution));
+          if (targetUrl == null) {
+            throw new EmailException("could not fetch attachment from " + resource);
+          }
+        }
+        attachment.setURL(targetUrl);
+        // extract attachment name from url
+        if (name == null) {
+          String resourceName = extractResourceName(targetUrl);
+          attachment.setName(resourceName);
+        }
+      }
 
-			multiPartEmail.attach(attachment);
-		}
-	}
+      multiPartEmail.attach(attachment);
+    }
+  }
 
-	private static String extractResourceName(URL url) {
-		String path = url.getPath();
-		if (path == null || path.length() == 0)
-			return null;
+  private static String extractResourceName(URL url) {
+    String path = url.getPath();
+    if (path == null || path.length() == 0) return null;
 
-		// skip trailing slash
-		int sepIndex = path.lastIndexOf('/', path.length() - 1);
-		if (sepIndex == -1)
-			return null;
+    // skip trailing slash
+    int sepIndex = path.lastIndexOf('/', path.length() - 1);
+    if (sepIndex == -1) return null;
 
-		return path.substring(sepIndex);
-	}
+    return path.substring(sepIndex);
+  }
 }

Modified: jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/spi/MailProducer.java
===================================================================
--- jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/spi/MailProducer.java	2009-04-16 19:32:12 UTC (rev 4571)
+++ jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/spi/MailProducer.java	2009-04-16 21:39:27 UTC (rev 4572)
@@ -21,6 +21,8 @@
  */
 package org.jbpm.pvm.internal.email.spi;
 
+import java.util.Collection;
+
 import org.apache.commons.mail.Email;
 import org.jbpm.model.OpenExecution;
 
@@ -32,6 +34,6 @@
  */
 public interface MailProducer {
 
-  Email produce(OpenExecution execution);
+  Collection<Email> produce(OpenExecution execution);
 
 }




More information about the jbpm-commits mailing list