Create a new workflow
- In the project
business-workflow-scenarios
, right click on the source folder/src/main/resources
and click onNew > Others...
- Open the
BPMN2
folder and selectjBPM Process Diagram
. Pressnext
. - Fill the information as following:
- The process contains, per default, an untyped start event. We will keep it as it so far.
Define a custom send email work item handler (task)
In order to use custom work item handlers in the Eclipse BPMN editor, we need to create 2 files used exclusively at development time.
In the
/src/main/resources/META-INF
, create a file namedWorkItemDefinitions.wid
and fill it as following:Good to know
The
name
property will be used later on to link the definition with the implementation class.In the
/src/main/resources/META-INF
, create a file nameddrools.rulebase.conf
and fill it as following:- If the
EmailPublicationWorkflow.bpmn2
files is open, close and reopen it. We should see now a new category calledCustom Tasks
in the palette. It should contains one task called as thedisplayName
property defined in theWorkItemDefinitions.wid
file.
Draw the custom workflow
In the BPMN editor, drag and drop the
SendEmailNotification
task and anEnd
events into the diagram.- Link the
Start
event with theSendEmailNotification
task and theSendEmailNotification
task with theEnd
event. We should obtain this: - To extend the default publication workflow, drag and drop a
Reusable Process
(underSub Processes
folder) between theStart
event and theSendEmailNotification
task. We should obtain this: Click on the
Call Activity 1
element, and change the properties as following:Good to know
To link to an existing process, we must refer to it thanks to its process id. The default publication process id is
info.magnolia.workflow.ReviewForPublication
.- Still in the element properties panel, open the
General
tab and change the name toReviewForPublication
. You can set any other meaningful name here.
Set the tasks parameters
First, we need to define the
java.util.Map
type in the process (it's not part of the default types). In the global diagramProperties
panel, click on theDefinitions
tab and press on the+
icon. In the dialog box, search for java.util.Map and select it. We should see the following entries in the interface:
Let's create the process variables. In the same
Properties
panel, click on theData Items
tab and open theLocal Variable
section. Add a process variable calledmgnlData
typejava.util.Map
and another calledcommandName
typeString
. You should obtain the following screen:
- Map the
mgnlData
and thecommandName
variables as input data for the call activityReviewForPublication
. Click on the call activity diagram element, go theProperties
panel and open theI/O Parameters
tab. Expand theInput Data Mapping
section, click on the+
icon and map the variable as following: - Map the
mgnlData
variable as input data for the taskSendEmailNotification
.
Implement the SendEmailNotification task
Implement the work item handler definition. We need two String properties storing the mail template name to use to build the email and the command name to execute.
Implement the work item handler.
Implement the email template.
Configure Magnolia
- Add a new email template definition. Open the config app and browse to the node
/modules/mail/config/templatesConfiguration
. Create a template calledemailNotification
and fill it as following: Add a new work item handler definition. Still in the config app, browse to the node
/modules/business-workflows-scenarios
. Create a folder calledworkItemHandlers
and a sub node calledsendEmail
(same name as the one defined in the the .wid file). Enter the following properties:Good to know
The default mail command is called
sendMail
.
The mail template property value must be the same as the template node name defined in the previous step.- Add a new publication workflow. Still in the config app and in the same node, create a folder called
workflows
. Enter the following properties. - Apply the new workflow to the publication command. Still in the config app, browse to the node
/modules/workflow/commands/workflow/activate/activate
. Set the workflow property value with the name of the workflow node created in the previous step. You should see the following screen: - Restart your Tomcat server.
Test the workflow
- Go to the config app and browse to the node
/server/activation/subscribers/magnoliaPublic8080
. Set theactive
property tofalse
. - Go the pages app and select the page called "
Other
". - Press
Publish
. Follow the publication procedure. At the end, you should have received an email in your mail box.
Just in case you can't get it working, here are some configs:
1 Comment
Bradley Andersen
would be nice to have a drop-down, for example, that allows you to pick to whom the notification will be sent ... one possibility would be to add it to the publish dialog, would set a property.