cancel
Showing results for 
Search instead for 
Did you mean: 

UserTask + ServiceTask

vire7777
Champ in-the-making
Champ in-the-making
Hi dear Activiti members

I'm searching for a way to solve one of my problem.
I would love to create a task that would be a mix of a userTask and a serviceTask
In fact I want to find a solution to let my workflow ask some parameters to the user with an interface and, when the parameters are in and the user is ok, then launch a java class treatment.

I know this is possible with 2 tasks but is that possible too with one ?

Further, could it be possible to create a task like that in the palette.
I need it for my company as we want to let the clients create their own workflow with our own palette tasks. And all these tasks need to launch a java treatment with some informations the user has to enter first.

Can you help me ?

Vivien
12 REPLIES 12

jbarrez
Star Contributor
Star Contributor
Sure, you would need to implement a custom ActivitiBehaviour and use it as a service task. The behaviour should mimic the user task ActivityBehaviour and add the extra logic afterwards.

Yes, adding to the palette in the Eclipse designer is possible.

vire7777
Champ in-the-making
Champ in-the-making
Where can i find a documentation about it ? Because i find no clue about ActivitiBehaviour or custom ActivitiBehaviour in the userguide…
I mean, how to create some in my palette as every components have to implements AbstractCustomServiceTask ?
Could you give me an example ?

jbarrez
Star Contributor
Star Contributor
The user guide does not document it, cause for 99% of the people it is not a use case they need.
The userguide does mention it:

<code>
[INTERNAL: non-public implementation classes] It is also possible to provide a class that implements the org.activiti.engine.impl.pvm.delegate.ActivityBehavior interface. Implementations have then access to the more powerful ActivityExecution that for example also allows to influence the control flow of the process. Note however that this is not a very good practice, and should be avoided as much as possible. So, it is advised to use the ActivityBehavior interface only for advanced use cases and if you know exactly what you're doing.
</code>

Activiti is open source. Open up for example the UserTaskActivityBehaviour to see how it can be done.

vire7777
Champ in-the-making
Champ in-the-making
Ok thanks a lot
I ll try it
But maybe i ll need your help as i m not an "advanced" activiti and java user ^^
So this advice is so important for me :

"Note however that this is not a very good practice, and should be avoided as much as possible. So, it is advised to use the ActivityBehavior interface only for advanced use cases and if you know exactly what you're doing."

jbarrez
Star Contributor
Star Contributor
The reason that those lines are in the userguide is because basically when you use that interface (instead of the regular JavaDelegate), you've got access to all the internals of the engine. You can do cool stuff with it, but you can also break your process if you don't know what you're doing.

In reality, it'll be ok. Simply let you inspire by all the ones that are shipped in the Activiti code. And if you're stuck somewhere, come back here with your questions.

vire7777
Champ in-the-making
Champ in-the-making
Thanks Smiley Happy
I'll try it
i m downloading the last Activiti version to see the sources and have a look to UserTaskActivityBehaviour Smiley Happy
Thanks for your support and if i have question, be sure i ll come back ^^

vire7777
Champ in-the-making
Champ in-the-making
I tried something like this
As i want a mix between the two tasks usertask and servicetask i just copy the servicetask code to implement it after th usertask :

<code>
package com.effisoft.designer.tasks;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.JavaDelegate;
import org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.delegate.JavaDelegateInvocation;
import org.activiti.engine.impl.el.ExpressionManager;
import org.activiti.engine.impl.pvm.delegate.ActivityBehavior;
import org.activiti.engine.impl.pvm.delegate.ActivityExecution;
import org.activiti.engine.impl.task.TaskDefinition;

/**
* activity implementation for the user/service task.
*
* @author Vivien René
*/
public class EffiTaskActivityBehavior extends UserTaskActivityBehavior implements ActivityBehavior, ExecutionListener {

protected TaskDefinition taskDefinition;
protected JavaDelegate javaDelegate;

public EffiTaskActivityBehavior(ExpressionManager expressionManager, TaskDefinition taskDefinition) {
  super(expressionManager, taskDefinition);
}

public EffiTaskActivityBehavior(ExpressionManager expressionManager, TaskDefinition taskDefinition, JavaDelegate javaDelegate) {
  super(expressionManager, taskDefinition);
  this.javaDelegate = javaDelegate;
}

public void execute(ActivityExecution execution) throws Exception {
  execute(execution);
  execute((DelegateExecution) execution);
  leave(execution);
}

public void signal(ActivityExecution execution, String signalName, Object signalData) throws Exception {
  leave(execution);
}

public void notify(DelegateExecution execution) throws Exception {
  execute((DelegateExecution) execution);
}

public void execute(DelegateExecution execution) throws Exception {
  Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new JavaDelegateInvocation(javaDelegate, execution));
}
}
</code>

In addition a little question :
Is it Activiti or Activity ? Smiley Tongue

jbarrez
Star Contributor
Star Contributor
It sure is Activiti 😉

Activity is used internally as it is a BPMN concept for a step in the process.

And yes, this is one way to do it. Probably the more 'clean' Java approach would be to use composition instead inheritance (ie have both the UserTaskActivityBehaviour and the ServiceTaskActivityBehaviour as members - but thats nitpicking).
But the most important thing: does it do what you expected it to do?

vire7777
Champ in-the-making
Champ in-the-making
1) About the palette
I really don't know if that does what i want because i don t know how to put this in the palette and test it.
Normally it would as i want a component which is both a human and service task.
Before my classes inherited AbstractCustomServiceTask and i had all to create a new element in the palette as
- getName
- contributeToPaletteDrawer
- getSmallIconPath
- etc…
.
Maybe i have to implement the interface CustomServiceTask with the same methods like in AbstractCustomServiceTask
.
But with this system, i realy don t know how to do to it in the designer
.
.
2) About the best implementation method
In addition, about what you told, how can you have both the UserTaskActivityBehaviour and the ServiceTaskActivityBehaviour as members ?
Because if my remembers are good, java has no multiple inheritance, hasn t it ?
.
In all cases, thanks a lot for your time as it helps me a lot Smiley Happy