cancel
Showing results for 
Search instead for 
Did you mean: 

Add a receive task after my task programmatically

esseti
Champ in-the-making
Champ in-the-making
Hi all,
is there a way to post-process the Process adding (programmatically) a task (receive task)?
I've to add this task after my personalised Java Task  .
     <serviceTask id="servicetask1" name="MyTaskName" activiti:class="com.example.MyTask" activiti:extensionId="MyTask">
in theory what i should do is (pseudocode)

process = magic.getProcess();
for(MyTask task: process.getTaskByType(MyTask){
// save the next task
      Task temp = task.next;
// create the receive
      Receive r_task = new ReceiveTask(id,name);
// put the receive after my task
      task.next = r_task;
// add the temp as next of the receive
      r_task.next = temp;

}

is there anything like this that i can do?
19 REPLIES 19

jbarrez
Star Contributor
Star Contributor
The error is pretty obvious: it cant find the ProcessEngine class. So it seems the activiti-engine jar is not on your classpath?

esseti
Champ in-the-making
Champ in-the-making
yes it's.
this is what i've in the libraries of the project

activiti-bpmn-converter-5.12.1.jar
activiti-bpmn-layout-5.12.1.jar
activiti-bpmn-model-5.12.1.jar
activiti-common-rest-5.12.1.jar
activiti-engine-5.12.1.jar
activiti-rest-5.12.1.jar
activiti-simple-workflow-5.12.1.jar
activiti-spring-5.12.1.jar

frederikherema1
Star Contributor
Star Contributor
The NoClassDef indicates the class was present at compile-time but not in the runtime-classpath. So make sure the class path of your tomcat actually contains the libraries…

esseti
Champ in-the-making
Champ in-the-making
is the list i posted before correct?
i tried to copy it into the lib of tomcat and run it again. still the same error.

ciao

frederikherema1
Star Contributor
Star Contributor
You only have the actvivi-* jars, but activiti has other dependencies as well (e.g. myBatis, spring, …). Please use all dependencies that are mentioned in the pom.xml file or use the /lib/*.jar from the activiti-rest.war.

esseti
Champ in-the-making
Champ in-the-making
with all the libraries of /lib/*.jar it works.

frederikherema1
Star Contributor
Star Contributor
Great! The /lib/* also contains libraries for the UI. So if you don't need that, you can remove them. Best to use maven though, this way you'll only end up with the jar you actually need when you only require the engine itself…

esseti
Champ in-the-making
Champ in-the-making
I'm trying to do the parsing using java.
i've both model and process, but i don't get how i can parse the process and find out what are my classes.
with XML i was simply searching for all the tasks that have activiti:impl="mycalss".
from process class, instead, i can get all the flow elements but nothing else except the name.
what can i do?

frederikherema1
Star Contributor
Star Contributor
You should cast the flow-elements (after checking type with instanceof) to org.activiti.bpmn.model.ServiceTask. On there, you can call getImplementation(), which returns the classname you need…

esseti
Champ in-the-making
Champ in-the-making
thanks.
just for the record, if someone need an example here my code https://github.com/esseti/BPMN4Crowd-Compiler not the best coding, but works.