SlideShare a Scribd company logo
Advanced Workflow: Deeper Dive!
                     Nick Smith!
    Senior Software Engineer, Services Team, Alfresco!
Agenda!

Service Tasks
  •  Java Delegate Class!
  •  Java Delegate Bean!
  •  Arbitrary Expressions!

Listeners
  •  Execution Listeners!
  •  Task Listeners!

Scripting
  •  Scope Variables!
  •  Execution Variables!
  •  Examples!

Timers
Questions
Service Tasks
            !
Service Tasks!

  •  Service Tasks allow Java code to be executed as part of a
     workflow!

  •  Allows easy unit testing and code re-use!
  •  Three ways to implement:!
    •    JavaDelegate Class!
    •    JavaDelegate Bean:!

    •    Arbitrary Expression!
Service Tasks: Java Delegate Class!

  •  The supplied class must implement JavaDelegate interface!
  •  Fields can be set on the class!

  •  Use the ʻactiviti:classʼ attribute to specify the delegate class

  <serviceTask id=“getMimetypet" name=“Get Mimetype”
     activiti:class="org.alfresco.examples.MimetypeGetter“ >
    <extensionElements>
      <activiti:field name=“document">
        <activiti:expression>${dcwkflw_document}</activiti:expression>
      </activiti:field>
    </extensionElements>
  </serviceTask>
Service Tasks: Java Delegate Bean!

  •  The supplied bean must implement JavaDelegate interface!
  •  The same bean instance is used for all executions!

  •  The bean must be defined in Spring and registered with the
     activitiBeanRegistry!

  •  Use ʻactiviti:delegateExpressionʼ attribute to specify the
     delegate bean in the process definition:!

  <serviceTask id=“getMimetype" name=“Get Mimetype“
    activiti:delegateExpression="${mimetypeGetter}" />
Service Tasks: Java Delegate Bean!

  •  Recommended to extend BaseJavaDelegate class!
  •  Recommend extending baseJavaDelegate bean!

  •  If the bean class extends BaseJavaDelegate and the Spring bean
     definition extends baseJavaDelegate, then the bean will
     automatically be registered with the activitiBeanRegistry and will
     have access to the serviceRegistry!

  <bean id=“mimetypeGetter" parent="baseJavaDelegate"
       class="org.alfresco.example.MimetypeGetter" />
Service Tasks: Java Delegate Bean!
public class MimetypeGetter extends BaseJavaDelegate
{
    @Override
    public void execute(DelegateExecution execution) throws Exception
    {
        ScriptNode document = (ActivitiScriptNode) execution.getVariable("dcwkflw_document");
        NodeRef nodeRef = document.getNodeRef();

        ServiceRegistry serviceRegistry = getServiceRegistry();
        FileFolderService fileService = serviceRegistry.getFileFolderService();
        FileInfo file = fileService.getFileInfo(nodeRef);
        String mimetype = file.getContentData().getMimetype();

        execution.setVariable("dcwkflw_mimetype“, mimetype);
    }
}
Service Tasks: Arbitrary Expression!

  •  Execute any arbitrary expression!
  •  The expression may reference any bean defined in Spring and
     registered with the activitiBeanRegistry!
  •  A process variable can be specified for the return value using the
     activiti:result attribute!

  <serviceTask id=”getMimetype” name="Get Mimetype" activiti:resultVariable="dcwkflw_mimetype"
   activiti:expression=“${mimetypeGetter.getMimetype(dcwkflow_document)}” />!
Listeners
        !
Listeners!

  •  Used to react to certain events during workflow execution!
  •  Two types: TaskLisener and ExecutionListener!

  •  Three ways to configure, as with ServiceTasks:!
     •    Listener Class:!
     <activiti:executionListener class="org.alfresco.example.MyExecutionListener" event=“start” />!

     •    Listener Bean:!
     <activiti:taskListener delegateExpression=“${myTaskListener}" event=“create" />!

     •    Arbitrary Expression
  <activiti:executionListener expression=“myPojo.myMethod(myVar)" event="start" />
Listeners: Execution Listener Events!
  •  Event: Execution (Workflow) starts or ends!
  <extensionElements>
    <activiti:executionListener class=“org.alfresco.example.ExecutionEventLogger" event=“start” />
  </extensionElements>!

  •  Event: Activiti (Workflow Node) starts or ends!
  <userTask id=“theTask” name=“The Task” >
    <extensionElements>
       <activiti:executionListener delegateExpression=“${executionEventLogger}" event=“end” />
    </extensionElements>
  </userTask>!

  •  Event: Sequence Flow (Transition) is taken!
  <sequenceFlow id=“theFlow” sourceRef=“theTask” targetRef=“theEnd” >
    <extensionElements>
       <activiti:executionListener expression=“${logger.info(execution.eventName)}" />
    </ sequenceFlow >
  </userTask>
Listeners: Execution Listener Implementation!

  Execution Listener class or delegate bean must implement
        ExecutionListener interface:!

  public class ExecutionEventLogger implements ExecutionListener
  {
    private static final Log LOGGER = LogFactory.getLog(ExecutionEventLogger.class);

       @Override
       public void notify(DelegateExecution execution) throws Exception
       {
         String eventName = execution.getEventName();
         LOGGER.info("Received event: " + eventName);
       }

  }!
Listeners: Task Listener Events!
  •  All Task Listeners defined inside task elements:!
  <userTask id=“theTask” name=“The Task” >
    <extensionElements>
       <activiti:taskListener ... [Listener Details] ... />
    </extensionElements>
  </userTask>!

  •  Event: assignment is called when a task is assigned to a user,
      usually called before create:!
  <activiti:taskListener event=“assignment” class=“org.alfresco.example.TaskEventLogger” />

  •  Event: create is called when the task is created, after assignment:!
  <activiti:taskListener event=“create” delegateExpression=“${taskEventLogger}” />

  •  Event: completed is called when the task is completed:!
  <activiti:taskListener event=“completed” expression=“${logger.info(task.eventName)}” />
Listeners: Task Listener Implementation!

  Task Listener class or delegate bean must implement TaskListener
       interface:!

  public class ExecutionEventLogger implements TaskListener
  {
    private static final Log LOGGER = LogFactory.getLog(ExecutionEventLogger.class);

      @Override
      public void notify(DelegateTask task)
      {
        String eventName = task.getEventName();
        LOGGER.info("Received event: " + eventName);
      }

  }
Scripting!
Scripting!

  •  Scripting Lagnuage:!
    •    JavaScript!



  •  Activiti Implementations:!
    •    AlfrescoScriptDelegate!

    •    ScriptExecutionListener !

    •    ScriptTaskListener!
Scripting: Scope Variables!

  •  person ScriptNode, the current user!
  •  userhome ScriptNode, the home space of the current user!

  •  execution DelegateExecution, the current execution.!
  •  task DelegateTask, the current task (ScriptTaskListener only)!
  •  cancelled boolean, was the execution cancelled
    (ScriptExecutionListener only)!
  •  deleted boolean, was the execution deleted
    (ScriptExecutionListener)!
Scripting: Execution Variables!

  •  All execution variables added to scope!

  •  Variable names translated from “prefix:suffix” to “prefix_suffix”!

  •  Associations and noderef properties converted to ScriptNodes!

  •  Use execution.setVariable(name, value) to modify variables!

  •  Check if a variable exists using:!
       if (typeof <variable name> != 'undefined')
Scripting: Examples!

  •  Copy a task variable to a process variable:
    execution.setVariable('dcwkflw_reviewOutcome', task.getVariable('dcwkflw_reviewOutcome'));



  •  Set a task property from a pocess variable if it exists:
    if (typeof bpm_workflowDueDate != 'undefined') task.dueDate = bpm_workflowDueDate;



  •  Apply an aspect ʻdcwkflw:publishedʼ to a document:
    var presentation = bpm_package.children[0]; // Get the presentation
    presentation.addAspect('dcwkflw:published'); // Apply published aspect
Timers
     !
Timers!

  •  Timers are used to delay an event until a specified time/duration!
  •  Timers can be attached to three types of event:!
    •    startEvent: Starts the workflow!
    •    intermediateCatchEvent: Between nodes/events!

    •    boundaryEvent: Associated with a node (e.g. a userTask)!

  •  Three ways to set trigger time:!
    •    timeDate: Triggers at specified date/time!

    •    timeDuration: Triggers after specified delay duration!

    •    timeCycle: Triggers repeatedly with specified delay/interval!

  •  All dates/times/durations/intervals use ISO8601 format!
Timers: Start Event Date Example!

 •  Create a workflow which sends a Christmas Greeting
 <!-- Start workflow at 12:05 on Christmas Day -->
 <startEvent id="start" >
       <timerEventDefinition>
          <timeDate>2011-12-25T12:05:00</timeDate>
        </timerEventDefinition>
    </startEvent>


 <sequenceFlow id='flow1' sourceRef='start' targetRef='sendGreeting' />
Timers: Intermediate Event Delay Example!

 •  Delay after some service task performs some asynchronous event

     to wait for the job to complete:!

 <sequenceFlow id='flow1' sourceRef='asyncJob' targetRef='waitForJobToFinish' />

 <!-- Wait 1 hour 30 mins for the job to finish -->
 <intermediateEvent id="waitForJobToFinish" >
   <timerEventDefinition>
      <timeDuration>PT1H30M</timeDate>
   </timerEventDefinition>
 </intermediateEvent>

 <sequenceFlow id='flow2' sourceRef='waitForJobToFinish' targetRef='nextTask' />
Timers: Repeating Boundary Event Example!

 •  Send a reminder email if a task isnʼt completed after 1 week.

     Repeat the email every day for 3 days:!
  <userTask id="theTask" >

  <!-- Wait 1 week, then repeat every 2 days a further 2 times -->
  <boundaryEvent id="repeatingNotification" cancelActivity="false" attachedToRef="theTask" />
    <timerEventDefinition>
       <timeCycle>R3/P1W/P1D</timeDate>
    </timerEventDefinition>
  </boundaryEvent>


  <sequenceFlow id='flow1' sourceRef='repeatingNotification' targetRef='sendEmail' />

  <serviceTask id="sendEmail" activiti:delegateExpression="${sendEmailDelegate}" />
Questions ?!

More Related Content

PDF
BPM-1 Introduction to Advanced Workflows
PDF
BPM-2 Introduction to Advanced Workflows
PDF
Primefaces Nextgen Lju
PDF
Get AngularJS Started!
PDF
Vuejs testing
PDF
Javascript MVC & Backbone Tips & Tricks
PDF
Angular JS blog tutorial
PPTX
Javascript first-class citizenery
BPM-1 Introduction to Advanced Workflows
BPM-2 Introduction to Advanced Workflows
Primefaces Nextgen Lju
Get AngularJS Started!
Vuejs testing
Javascript MVC & Backbone Tips & Tricks
Angular JS blog tutorial
Javascript first-class citizenery

What's hot (20)

PDF
Building and deploying React applications
PPTX
Basics of AngularJS
PDF
Sane Async Patterns
PDF
Enjoy the vue.js
PPTX
Обзор автоматизации тестирования на JavaScript
PDF
PrimeTime JSF with PrimeFaces - Dec 2014
PDF
Reliable Javascript
PDF
AtlasCamp 2015: Connect everywhere - Cloud and Server
PDF
Angular js routing options
PPTX
AngularJS Directives
PDF
Angular Promises and Advanced Routing
PDF
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
PPTX
Dart and AngularDart
PDF
Laravel 8 export data as excel file with example
PPTX
Modules and injector
PDF
Dethroning Grunt: Simple and Effective Builds with gulp.js
PDF
Building a js widget
PDF
The Rails Way
PDF
Introduction to backbone presentation
PPT
Training in Android with Maven
Building and deploying React applications
Basics of AngularJS
Sane Async Patterns
Enjoy the vue.js
Обзор автоматизации тестирования на JavaScript
PrimeTime JSF with PrimeFaces - Dec 2014
Reliable Javascript
AtlasCamp 2015: Connect everywhere - Cloud and Server
Angular js routing options
AngularJS Directives
Angular Promises and Advanced Routing
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
Dart and AngularDart
Laravel 8 export data as excel file with example
Modules and injector
Dethroning Grunt: Simple and Effective Builds with gulp.js
Building a js widget
The Rails Way
Introduction to backbone presentation
Training in Android with Maven
Ad

Viewers also liked (8)

PDF
JWT-To-Activiti
PPTX
Activiti - the Open Source Business Process Management platform by Alfresco
PDF
Launching Activiti v6 (Activiti Community Day Paris 2015)
PDF
Introduction to Activiti
PPTX
Introduction to Activiti BPM
PDF
BPMN 2.0 Tutorial 01 - Basic Constructs
PDF
Introduction à BPMN 2.0 - Business Process Modeling Notation
JWT-To-Activiti
Activiti - the Open Source Business Process Management platform by Alfresco
Launching Activiti v6 (Activiti Community Day Paris 2015)
Introduction to Activiti
Introduction to Activiti BPM
BPMN 2.0 Tutorial 01 - Basic Constructs
Introduction à BPMN 2.0 - Business Process Modeling Notation
Ad

Similar to BPM-3 Advanced Workflow Deep Dive (20)

PDF
BPM-4 Migration from jBPM to Activiti
PDF
Introduction to advanced workflow
PDF
jBPM5 Community Training Module #5: Domain Specific Processes
PDF
Actions rules and workflow in alfresco
PDF
Alfresco Developer Series: Advanced Workflows
PDF
Introducing Workflow Architectures Using Grails - Greach 2015
PPT
Sap Tech Ed06 Asug Wf
ODP
BPMN2 primer
PPTX
ODP
jBPM, open source BPM
PDF
Workflow Yapceu2010
PDF
Extensible API Management
PDF
Extensible Api Management with WSO2 API Manager
PPTX
Mcknight well built extensions
PDF
BPMN tutorial by Draw Libre Office
PPTX
BPMN 2.0 - an introduction to the Level 1 Palette
PPT
]project-open[ Workflow Developer Tutorial Part 2
PDF
Why To Consider BPMN 2.0
PDF
COScheduler
PPTX
Alfresco Devcon 2010: A new kind of BPM with Activiti
BPM-4 Migration from jBPM to Activiti
Introduction to advanced workflow
jBPM5 Community Training Module #5: Domain Specific Processes
Actions rules and workflow in alfresco
Alfresco Developer Series: Advanced Workflows
Introducing Workflow Architectures Using Grails - Greach 2015
Sap Tech Ed06 Asug Wf
BPMN2 primer
jBPM, open source BPM
Workflow Yapceu2010
Extensible API Management
Extensible Api Management with WSO2 API Manager
Mcknight well built extensions
BPMN tutorial by Draw Libre Office
BPMN 2.0 - an introduction to the Level 1 Palette
]project-open[ Workflow Developer Tutorial Part 2
Why To Consider BPMN 2.0
COScheduler
Alfresco Devcon 2010: A new kind of BPM with Activiti

More from Alfresco Software (20)

PPTX
Alfresco Day Benelux Inholland studentendossier
PPTX
Alfresco Day Benelux Hogeschool Inholland Records Management application
PPTX
Alfresco Day BeNelux: Customer Success Showcase - Saxion Hogescholen
PPTX
Alfresco Day BeNelux: Customer Success Showcase - Gemeente Amsterdam
PPTX
Alfresco Day BeNelux: The success of Alfresco
PDF
Alfresco Day BeNelux: Customer Success Showcase - Credendo Group
PDF
Alfresco Day BeNelux: Digital Transformation - It's All About Flow
PDF
Alfresco Day Vienna 2016: Activiti – ein Katalysator für die DMS-Strategie be...
PDF
Alfresco Day Vienna 2016: Elektronische Geschäftsprozesse auf Basis von Alfre...
PDF
Alfresco Day Vienna 2016: Alfrescos neue Rest API
PDF
Alfresco Day Vienna 2016: Support Tools für die Admin-Konsole
PDF
Alfresco Day Vienna 2016: Entwickeln mit Alfresco
PDF
Alfresco Day Vienna 2016: Activiti goes enterprise: Die Evolution der BPM Sui...
PDF
Alfresco Day Vienna 2016: Partner Lightning Talk: Westernacher
PDF
Alfresco Day Vienna 2016: Bringing Content & Process together with the App De...
PDF
Alfresco Day Vienna 2016: Partner Lightning Talk - it-novum
PDF
Alfresco Day Vienna 2016: How to Achieve Digital Flow in the Enterprise - Joh...
PDF
Alfresco Day Warsaw 2016 - Czy możliwe jest spełnienie wszystkich regulacji p...
PDF
Alfresco Day Warsaw 2016: Identyfikacja i podpiselektroniczny - Safran
PDF
Alfresco Day Warsaw 2016: Advancing the Flow of Digital Business
Alfresco Day Benelux Inholland studentendossier
Alfresco Day Benelux Hogeschool Inholland Records Management application
Alfresco Day BeNelux: Customer Success Showcase - Saxion Hogescholen
Alfresco Day BeNelux: Customer Success Showcase - Gemeente Amsterdam
Alfresco Day BeNelux: The success of Alfresco
Alfresco Day BeNelux: Customer Success Showcase - Credendo Group
Alfresco Day BeNelux: Digital Transformation - It's All About Flow
Alfresco Day Vienna 2016: Activiti – ein Katalysator für die DMS-Strategie be...
Alfresco Day Vienna 2016: Elektronische Geschäftsprozesse auf Basis von Alfre...
Alfresco Day Vienna 2016: Alfrescos neue Rest API
Alfresco Day Vienna 2016: Support Tools für die Admin-Konsole
Alfresco Day Vienna 2016: Entwickeln mit Alfresco
Alfresco Day Vienna 2016: Activiti goes enterprise: Die Evolution der BPM Sui...
Alfresco Day Vienna 2016: Partner Lightning Talk: Westernacher
Alfresco Day Vienna 2016: Bringing Content & Process together with the App De...
Alfresco Day Vienna 2016: Partner Lightning Talk - it-novum
Alfresco Day Vienna 2016: How to Achieve Digital Flow in the Enterprise - Joh...
Alfresco Day Warsaw 2016 - Czy możliwe jest spełnienie wszystkich regulacji p...
Alfresco Day Warsaw 2016: Identyfikacja i podpiselektroniczny - Safran
Alfresco Day Warsaw 2016: Advancing the Flow of Digital Business

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Cloud computing and distributed systems.
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
KodekX | Application Modernization Development
PDF
Approach and Philosophy of On baking technology
PPTX
MYSQL Presentation for SQL database connectivity
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Modernizing your data center with Dell and AMD
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
GamePlan Trading System Review: Professional Trader's Honest Take
Diabetes mellitus diagnosis method based random forest with bat algorithm
Understanding_Digital_Forensics_Presentation.pptx
Unlocking AI with Model Context Protocol (MCP)
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Cloud computing and distributed systems.
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
KodekX | Application Modernization Development
Approach and Philosophy of On baking technology
MYSQL Presentation for SQL database connectivity
NewMind AI Weekly Chronicles - August'25 Week I
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Modernizing your data center with Dell and AMD

BPM-3 Advanced Workflow Deep Dive

  • 1. Advanced Workflow: Deeper Dive! Nick Smith! Senior Software Engineer, Services Team, Alfresco!
  • 2. Agenda! Service Tasks •  Java Delegate Class! •  Java Delegate Bean! •  Arbitrary Expressions! Listeners •  Execution Listeners! •  Task Listeners! Scripting •  Scope Variables! •  Execution Variables! •  Examples! Timers Questions
  • 4. Service Tasks! •  Service Tasks allow Java code to be executed as part of a workflow! •  Allows easy unit testing and code re-use! •  Three ways to implement:! •  JavaDelegate Class! •  JavaDelegate Bean:! •  Arbitrary Expression!
  • 5. Service Tasks: Java Delegate Class! •  The supplied class must implement JavaDelegate interface! •  Fields can be set on the class! •  Use the ʻactiviti:classʼ attribute to specify the delegate class <serviceTask id=“getMimetypet" name=“Get Mimetype” activiti:class="org.alfresco.examples.MimetypeGetter“ > <extensionElements> <activiti:field name=“document"> <activiti:expression>${dcwkflw_document}</activiti:expression> </activiti:field> </extensionElements> </serviceTask>
  • 6. Service Tasks: Java Delegate Bean! •  The supplied bean must implement JavaDelegate interface! •  The same bean instance is used for all executions! •  The bean must be defined in Spring and registered with the activitiBeanRegistry! •  Use ʻactiviti:delegateExpressionʼ attribute to specify the delegate bean in the process definition:! <serviceTask id=“getMimetype" name=“Get Mimetype“ activiti:delegateExpression="${mimetypeGetter}" />
  • 7. Service Tasks: Java Delegate Bean! •  Recommended to extend BaseJavaDelegate class! •  Recommend extending baseJavaDelegate bean! •  If the bean class extends BaseJavaDelegate and the Spring bean definition extends baseJavaDelegate, then the bean will automatically be registered with the activitiBeanRegistry and will have access to the serviceRegistry! <bean id=“mimetypeGetter" parent="baseJavaDelegate" class="org.alfresco.example.MimetypeGetter" />
  • 8. Service Tasks: Java Delegate Bean! public class MimetypeGetter extends BaseJavaDelegate { @Override public void execute(DelegateExecution execution) throws Exception { ScriptNode document = (ActivitiScriptNode) execution.getVariable("dcwkflw_document"); NodeRef nodeRef = document.getNodeRef(); ServiceRegistry serviceRegistry = getServiceRegistry(); FileFolderService fileService = serviceRegistry.getFileFolderService(); FileInfo file = fileService.getFileInfo(nodeRef); String mimetype = file.getContentData().getMimetype(); execution.setVariable("dcwkflw_mimetype“, mimetype); } }
  • 9. Service Tasks: Arbitrary Expression! •  Execute any arbitrary expression! •  The expression may reference any bean defined in Spring and registered with the activitiBeanRegistry! •  A process variable can be specified for the return value using the activiti:result attribute! <serviceTask id=”getMimetype” name="Get Mimetype" activiti:resultVariable="dcwkflw_mimetype" activiti:expression=“${mimetypeGetter.getMimetype(dcwkflow_document)}” />!
  • 11. Listeners! •  Used to react to certain events during workflow execution! •  Two types: TaskLisener and ExecutionListener! •  Three ways to configure, as with ServiceTasks:! •  Listener Class:! <activiti:executionListener class="org.alfresco.example.MyExecutionListener" event=“start” />! •  Listener Bean:! <activiti:taskListener delegateExpression=“${myTaskListener}" event=“create" />! •  Arbitrary Expression <activiti:executionListener expression=“myPojo.myMethod(myVar)" event="start" />
  • 12. Listeners: Execution Listener Events! •  Event: Execution (Workflow) starts or ends! <extensionElements> <activiti:executionListener class=“org.alfresco.example.ExecutionEventLogger" event=“start” /> </extensionElements>! •  Event: Activiti (Workflow Node) starts or ends! <userTask id=“theTask” name=“The Task” > <extensionElements> <activiti:executionListener delegateExpression=“${executionEventLogger}" event=“end” /> </extensionElements> </userTask>! •  Event: Sequence Flow (Transition) is taken! <sequenceFlow id=“theFlow” sourceRef=“theTask” targetRef=“theEnd” > <extensionElements> <activiti:executionListener expression=“${logger.info(execution.eventName)}" /> </ sequenceFlow > </userTask>
  • 13. Listeners: Execution Listener Implementation! Execution Listener class or delegate bean must implement ExecutionListener interface:! public class ExecutionEventLogger implements ExecutionListener { private static final Log LOGGER = LogFactory.getLog(ExecutionEventLogger.class); @Override public void notify(DelegateExecution execution) throws Exception { String eventName = execution.getEventName(); LOGGER.info("Received event: " + eventName); } }!
  • 14. Listeners: Task Listener Events! •  All Task Listeners defined inside task elements:! <userTask id=“theTask” name=“The Task” > <extensionElements> <activiti:taskListener ... [Listener Details] ... /> </extensionElements> </userTask>! •  Event: assignment is called when a task is assigned to a user, usually called before create:! <activiti:taskListener event=“assignment” class=“org.alfresco.example.TaskEventLogger” /> •  Event: create is called when the task is created, after assignment:! <activiti:taskListener event=“create” delegateExpression=“${taskEventLogger}” /> •  Event: completed is called when the task is completed:! <activiti:taskListener event=“completed” expression=“${logger.info(task.eventName)}” />
  • 15. Listeners: Task Listener Implementation! Task Listener class or delegate bean must implement TaskListener interface:! public class ExecutionEventLogger implements TaskListener { private static final Log LOGGER = LogFactory.getLog(ExecutionEventLogger.class); @Override public void notify(DelegateTask task) { String eventName = task.getEventName(); LOGGER.info("Received event: " + eventName); } }
  • 17. Scripting! •  Scripting Lagnuage:! •  JavaScript! •  Activiti Implementations:! •  AlfrescoScriptDelegate! •  ScriptExecutionListener ! •  ScriptTaskListener!
  • 18. Scripting: Scope Variables! •  person ScriptNode, the current user! •  userhome ScriptNode, the home space of the current user! •  execution DelegateExecution, the current execution.! •  task DelegateTask, the current task (ScriptTaskListener only)! •  cancelled boolean, was the execution cancelled (ScriptExecutionListener only)! •  deleted boolean, was the execution deleted (ScriptExecutionListener)!
  • 19. Scripting: Execution Variables! •  All execution variables added to scope! •  Variable names translated from “prefix:suffix” to “prefix_suffix”! •  Associations and noderef properties converted to ScriptNodes! •  Use execution.setVariable(name, value) to modify variables! •  Check if a variable exists using:! if (typeof <variable name> != 'undefined')
  • 20. Scripting: Examples! •  Copy a task variable to a process variable: execution.setVariable('dcwkflw_reviewOutcome', task.getVariable('dcwkflw_reviewOutcome')); •  Set a task property from a pocess variable if it exists: if (typeof bpm_workflowDueDate != 'undefined') task.dueDate = bpm_workflowDueDate; •  Apply an aspect ʻdcwkflw:publishedʼ to a document: var presentation = bpm_package.children[0]; // Get the presentation presentation.addAspect('dcwkflw:published'); // Apply published aspect
  • 21. Timers !
  • 22. Timers! •  Timers are used to delay an event until a specified time/duration! •  Timers can be attached to three types of event:! •  startEvent: Starts the workflow! •  intermediateCatchEvent: Between nodes/events! •  boundaryEvent: Associated with a node (e.g. a userTask)! •  Three ways to set trigger time:! •  timeDate: Triggers at specified date/time! •  timeDuration: Triggers after specified delay duration! •  timeCycle: Triggers repeatedly with specified delay/interval! •  All dates/times/durations/intervals use ISO8601 format!
  • 23. Timers: Start Event Date Example! •  Create a workflow which sends a Christmas Greeting <!-- Start workflow at 12:05 on Christmas Day --> <startEvent id="start" > <timerEventDefinition> <timeDate>2011-12-25T12:05:00</timeDate> </timerEventDefinition> </startEvent> <sequenceFlow id='flow1' sourceRef='start' targetRef='sendGreeting' />
  • 24. Timers: Intermediate Event Delay Example! •  Delay after some service task performs some asynchronous event to wait for the job to complete:! <sequenceFlow id='flow1' sourceRef='asyncJob' targetRef='waitForJobToFinish' /> <!-- Wait 1 hour 30 mins for the job to finish --> <intermediateEvent id="waitForJobToFinish" > <timerEventDefinition> <timeDuration>PT1H30M</timeDate> </timerEventDefinition> </intermediateEvent> <sequenceFlow id='flow2' sourceRef='waitForJobToFinish' targetRef='nextTask' />
  • 25. Timers: Repeating Boundary Event Example! •  Send a reminder email if a task isnʼt completed after 1 week. Repeat the email every day for 3 days:! <userTask id="theTask" > <!-- Wait 1 week, then repeat every 2 days a further 2 times --> <boundaryEvent id="repeatingNotification" cancelActivity="false" attachedToRef="theTask" /> <timerEventDefinition> <timeCycle>R3/P1W/P1D</timeDate> </timerEventDefinition> </boundaryEvent> <sequenceFlow id='flow1' sourceRef='repeatingNotification' targetRef='sendEmail' /> <serviceTask id="sendEmail" activiti:delegateExpression="${sendEmailDelegate}" />