cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic assignment

hmartim
Champ in-the-making
Champ in-the-making
Hi,

an excellent extension of the Activiti is the possibility of defining "activiti:assignee" and "activiti:candidateUsers" of a UserTask via a Spring bean operation like "$ {ldapService.findManagerForEmployee (loan)}" or "$ {ldapService.findAllSales ()}".

This allows dynamic definition of resources for a UserTask, similar to the "parametrized Resource/Role" of BPMN 2.0.

However, there are some situations in which resources dynamically retrieved in the creation of UserTask (which are responsible for the task) may change while the task has not yet been assigned or completed. For example, the employee's manager was replaced, so a new person/user is responsable for the task.

Could the engine offer a way to recover the UserTasks whose responsables were defined by a method (Spring Bean)? And still offer a operation, for example, that allow re-run this definition of responsables (or assignee canditateUsers) of these tasks?

Thus, a processing of the application could periodically (or as consequence of some event) trigger the engine to make this update.

Or is there another way to do this update?

Thanks,
Hudson.
14 REPLIES 14

frederikherema1
Star Contributor
Star Contributor
Yes, you're right, the parsers are applied when the process is deployed OR when it's fetched from the DB (when not in cache). So all process-definitions that are used by activiti are guaranteed to have these listeners applied…

The Pre and Post-methods control when the listeners are called: before the activiti-ones or after (eg. a lot of the history is done using parseListeners). Both setXXParseListener and setCustomXXXBPMNParseLIsteners will work.

heymjo
Champ on-the-rise
Champ on-the-rise
this is a very interesting extension point so i was trying it out :


public class AssignmentCheckParseListener implements BpmnParseListener{

    public void parseUserTask(Element userTaskElement, ScopeImpl scope, ActivityImpl activity) {
        activity.addExecutionListener(TaskListener.EVENTNAME_ASSIGNMENT, new ExecutionListener() {
            public void notify(DelegateExecution execution) throws Exception {
                System.out.println("@@@@@@@@@@@@" + execution.getId());
            }
        });
    }
….

and my spring configuration bean


    ….
    <property name="preParseListeners">
      <util:list>
        <bean class="my.AssignmentCheckParseListener"/>
      </util:list>
    </property>
  </bean>

From debug stepping i see that my parselistener is invoked correctly for each user task in the workflow. But during execution, the executionlistener is not fired when the task gets claimed, odd.

Also, would such an executionlistener be the proper way of re-checking the candidate groups at the moment of assignment ? My aim is to throw an exception when the task is picked up by a user who no longer is part of the task's candidategroup.

heymjo
Champ on-the-rise
Champ on-the-rise
<yawn> ignore my post it's friday afternoon.

the correct way to add the tasklistener is this


    public void parseUserTask(Element userTaskElement, ScopeImpl scope, ActivityImpl activity) {
        TaskDefinition taskDefinition = ((UserTaskActivityBehavior) activity.getActivityBehavior()).getTaskDefinition();

        taskDefinition.addTaskListener(TaskListener.EVENTNAME_ASSIGNMENT,
                new TaskListener() {
                    public void notify(DelegateTask delegateTask) {
                        System.out.println("@@@@@@@@@@@@@" + delegateTask.getName());
                    }
                });
    }

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
Thanks for investigating this yourself a little more AND reporting back (after getting it to work) wished that more people would do this.

frederikherema1
Star Contributor
Star Contributor
Glad it works!