cancel
Showing results for 
Search instead for 
Did you mean: 

AbstractBpmnParseHandler in version 6 Beta

schommerc
Champ in-the-making
Champ in-the-making
New to Activiti and was tasked with upgrading from 5.18 to 6.0.  After pulling in the new jars, I noticed that AbstractBpmnParseHandler.findActivity(BpmnParse, UserTask) method no longer exists in the Abstract class.  Without really understanding the codebase, I've been trying to find a way to reimplement the following code:

@Override
    protected void executeParse(BpmnParse bpmnParse, UserTask element)
    {
        ActivityImpl activity = findActivity(element.getId()); // This method is the problem
        ActivityBehavior behavior = activity.getActivityBehavior();
        if (behavior instanceof UserTaskActivityBehavior)
        {
            addListeners((UserTaskActivityBehavior) behavior);
        }
        else if(behavior instanceof MultiInstanceActivityBehavior)
        {
            MultiInstanceActivityBehavior multiInstance = (MultiInstanceActivityBehavior) behavior;
            behavior = multiInstance.getInnerActivityBehavior();
            if(behavior instanceof UserTaskActivityBehavior)
            {
                addListeners((UserTaskActivityBehavior) behavior);
            }
        }
    }

Thanks in advance for any help on this!

-Chad
8 REPLIES 8

schommerc
Champ in-the-making
Champ in-the-making
The signature is wrong in the example above, I have findActivity(bpmnParse, element.getId());

But this is still a problem.  I tried looking at method calls for the BpmnParse to get an ActivityImpl, and I saw an ActivityBehaviorFactory method, thinking I could get the ActivityBehavior directly from the BpmnParse, but was unsuccessful. 

The body of the findActivity method is just
{
return bpmnParse.getCurrentScope().findActivity(id);
}
however, those methods do not seem to do exist for the bpmnParse object anymore either.  I see getCurrentProcess() but that doesn't seem like the same thing.

trademak
Star Contributor
Star Contributor
Hi,

You should be able to listeners directly on the UserTask element instead of the old ActivityImpl object. We removed the whole ActivityImpl structure and are now using the BpmnModel objects like UserTask directly for execution.

Best regards,

schommerc
Champ in-the-making
Champ in-the-making
Thanks Tijs,

I do not see any related to adding a listener as a method of the UserTask.  Can you tell me if I'm missing a step?

In my code, I would get the ActivityImpl, then the ActivityBehavior, then the TaskDefinition.  I would then loop through each listener and add it to the TaskDefinition. 

Are you saying I can skip all of that and add the listeners directly to the Usertask?  Can you provide an example or explain to me how I can add those directly (Since I do not see it as a method)?

Thanks again!

trademak
Star Contributor
Star Contributor
Hi,

There is a setTaskListeners method in the UserTask class. You can create instances of ActivitiListener to define the listener.

Best regards,

schommerc
Champ in-the-making
Champ in-the-making
Thanks again Tijs - you've been a huge help so far.

One last obstacle… It seems that the setTaskListeners only takes an ActivitiListener, and I have an existing collection of TaskListeners.  Without seeing the javadoc, I'm not sure what the differences are, only that they are not cross compatible.  Is there an easy way to convert these objects, or will I need to figure out where the TaskListeners collection is created and switch it to ActivitiListener?

Snippet:
    private List<TaskListener> taskListeners;

    @Override
    protected void executeParse(BpmnParse bpmnParse, UserTask userTask)
    {
     userTask.setTaskListeners(taskListeners);
    }

trademak
Star Contributor
Star Contributor
The ActivitListener is an abstract Object to represent the model for an execution and task listener in Activiti. So, on an Activiti listener you can define the class, expression and delegate expression text value in the implementation attribute. So in case you are using a Java class task listener you just set the implementation value to fully qualified class name.

Best regards,

jbarrez
Star Contributor
Star Contributor
Or, there is another way which is probably easier: the ActivitiListener has an 'instance' you can set. Put your TaskListener instance on it and it should work as before.

schommerc
Champ in-the-making
Champ in-the-making
Perfect, thank you both.  This seems to have solved the issue. Cheers!