-
1. Re: Mail template for custom MailProducer
rebody Apr 19, 2010 2:22 AM (in response to kevinmoodley)Hi kevin,
You could get MailTemplate using EnvironmentImpl. Like this:
MailTemplateRegistry templateRegistry = EnvironmentImpl .getFromCurrent(MailTemplateRegistry.class); MailTemplate template = templateRegistry.getTemplate( "test-template");
-
2. Re: Mail template for custom MailProducer
kevinmoodley Apr 19, 2010 10:29 AM (in response to rebody)Thanks Huishengrebody,
Your technique to get the template worked but I was not sure where to put this code. For now, I tested it by putting your code in the CustomMailProducer default constructor. I could move it into the produce() method, but I was wondering if there was a dynamic way to get the template name - maybe from the Execution?
How does the default MailProducerImpl get the template name?
Thanks
Kevin
-
3. Re: Mail template for custom MailProducer
rebody Apr 19, 2010 10:46 PM (in response to kevinmoodley)Hi Kevin,
The codes I showed you comes from org.jbpm.jpdl.internal.xml.JpdlParser.java. The PVM will parse mail-template and register them to MailTemplateRegistry, so we could find MailTemplate by template name from MailTemplateRegistry. I cannot find a way to inject MailTemplate object by only using the XML configuration. So I am afraid that we have to write these codes to get MailTemplate.
And, here is development forum, you really should post this content to user forum. Thanks.
-
4. Re: Mail template for custom MailProducer
rebody Apr 20, 2010 3:38 AM (in response to kevinmoodley)Hi Kevin,
Fortunately, I saw a same issue in the JIRA. You could add comment on it.
-
5. Re: Mail template for custom MailProducer
aguizar Apr 20, 2010 9:12 PM (in response to kevinmoodley)Here is how you can specify a named template for a custom mail producer:
<mail name='send mail' class='org.example.CustomMailProducer'> <field name='templateName'><string value='rectify-template'/></field> <transition to='end' /> </mail>
Here is the custom mail producer code:
public class CustomMailProducer extends MailProducerImpl { private String templateName; public Collection<Message> produce(Execution execution) { MailTemplateRegistry templateRegistry = EnvironmentImpl .getFromCurrent(MailTemplateRegistry.class); setTemplate(templateRegistry.getTemplate(templateName)); return super.produce(execution); } }
It should be possible to inject a reference to the template registry into the bean, but it is not currently possible due to the way the custom mail producer is parsed. I will fix this in JBPM-2844.
-
6. Re: Mail template for custom MailProducer
aguizar Apr 20, 2010 9:13 PM (in response to rebody)Huisheng, is JBPM-2844 the issue you refer to?
-
7. Re: Mail template for custom MailProducer
rebody Apr 20, 2010 10:12 PM (in response to aguizar)Hi Alejandro,
Yes, it is the JBPM-2844. I had seen you move it the jBPM-4.4.
But the priority of this issue is not very high. I want to notice that there is a serious issue https://jira.jboss.org/jira/browse/JBPM-2794 that many people has met.
Please reference http://community.jboss.org/thread/150965 and http://community.jboss.org/thread/150555. If you have enough time, please review this, thank your very much.
-
8. Re: Mail template for custom MailProducer
kevinmoodley Apr 20, 2010 11:06 PM (in response to aguizar)Hi,
Thanks for looking into this.
Will the field tag work inside a notification tag in a task?
<task assignee="kmoodley" g="210,250,92,52" name="User Review">
<notification class="com.kevinmoodley.bpm.mail.CustomMailProducer">
<field name="templateName"> <string value="test-template"/></field>
</notification><transition g="-42,-18" name="CANCEL" to="end1"/>
<transition g="-42,-18" name="RESTART" to="end2"/>
</task>I know that the xsd does not support it, but then again the class attribute in <notification> is not is the xsd either.
By the way, most user only create create a custom MailProducer to bypass the requirement of the default MailProducerImpl that mail recepients need to exist in the Indentity tables.
~~~~~~
List<User> users = identitySession.findUsersById(userIds);
~~~~~
Don't quite understand that, especially if I want the workflow to trigger an email to an external customer.
Anyway, this is not a serious issue. Moving back to the User forum now.
Thanks
-
9. Re: Mail template for custom MailProducer
aguizar Apr 21, 2010 1:58 PM (in response to kevinmoodley)By the way, most user only create create a custom MailProducer to bypass the requirement of the default MailProducerImpl that mail recepients need to exist in the Indentity tables.
~~~~~~
List<User> users = identitySession.findUsersById(userIds);
~~~~~
Don't quite understand that, especially if I want the workflow to trigger an email to an external customer.
The code you indicate is guarded by a condition:
String userList = fromTemplate.getUsers(); if (userList != null) { String[] userIds = tokenizeActors(userList, execution); List<User> users = identitySession.findUsersById(userIds); email.addFrom(resolveAddresses(users, addressResolver)); }
If you don't need users and groups from the identity tables, your template should only specify the addresses attribute to enumerate recipients. Avoiding the users and groups attributes also prevents access to the identity session. However, since you have looked at the source code you probably knew this already - am I missing something?