Wiki
Clone wikirbpl / Examples
Example processes implemented with rbpl
Back to the RBPL wiki.
Example 1 - Simplified email confirmation process
The scenario is a (very much) simplified process for confirming a user's email address, e.g. as part of a self-registration process.
Requirements
- Start the process with the email address to confirm
- Send an email to the provided address including a confirmation link
- Wait for a configurable amount of time for the confirmation link to be invoked
- Signal successful and unsuccessful (timeout) completion of the process
BPMN process model
Code examples
The main process model
#!scala class EmailConfirmationProcess(val ctx: ProcessContext, val initializer: Initializer[EmailConfirmationProcess.StartData]) extends BaseProcess(Initializer[EmailAddress](EmailConfirmationProcess.SendConfirmationEmailTaskName, initializer.payload.emailAddress) :: HNil, Some(initializer)) { import AndThenAPI._ import EmailConfirmationProcess._ def predicateArgument: Any = None def receiveRecover: Receive = Actor.emptyBehavior def receiveCommand: Receive = { case r: SendConfirmationEmailTask.EmailSent => persistAndHandleResult(r) { res => log.info("SendConfirmationEmailTask - result: {}", res) } andThen ( StopCurrentTask(), StartNewTask( "confirmation email sent", Initializer(ExpectConfimationLinkClickedTaskName, r.token)), StartTimer(ConfirmationTimerID, initializer.payload.awaitDuration)) case r: ExpectConfimationLinkClickedTask.LinkClicked => persistAndHandleResult(r) { res => log.info("PROCESS SUCESSFUL: ExpectConfimationLinkClickedTask - result: {}", res) } andThen ( StopCurrentTask(), StopTimer(EmailConfirmationProcess.ConfirmationTimerID), StopProcess()) case r @ TimerTask.TimerExpired(`ConfirmationTimerID`, _, _) => persistAndHandleResult(r) { res => log.info("PROCESS FAILURE: TimerTask.TimerExpired - result: {}", res) } andThen ( StopTask(ExpectConfimationLinkClickedTaskName), StopTimer(EmailConfirmationProcess.ConfirmationTimerID), StopProcess()) } }
Resulting runtime diagram
rbpl-core contains a utility for dumping the current state of the process to a DOT-based diagram. With the provided HTML wrapper can the state directly be viewed in a browser.
Process state after start
Happy flow without timer expiration
Exceptional flow with timer expiration
Simplifications
- Print the email on the console rather then sending a real email ;)
- Print the successful/unsuccessful result also to the console ... an proper business event will be added later
Example 2 - Simple CMMN case with multiple user tasks
The scenario is a simplified process for collecting various aspects of data from a user. It is modelled using a CMMN case and human tasks and implemented using the corresponding semantical representations from rbpl-core.
Requirements
- Start the process and the CMMN case as its initial (and currently only) task.
- Let the user work on the various human tasks.
- Visualise invalid data (mandatory fields not provided, illegal values)
- Conditionally enable "Provide Legal Guardian" human task if age is below legal age, use a business rule for this.
- Enable a "completion" button if the milestone of the case is reached.
CMMN case model
### BPMN process model
Updated