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

esseti
Champ in-the-making
Champ in-the-making
i ended up to do it via a XML parser. yet, if you do like this the diagram is not stored in the activiti engine.

esseti
Champ in-the-making
Champ in-the-making
thnx, i'll give it a try.

trademak
Star Contributor
Star Contributor
With the activiti-bpmn-converter module you can read a BPMN XML to a POJO model. Then in the POJO model you can add the receive task like you to do, and then generate the new BPMN XML out of there. You can look at the org.activiti.bpmn.converter.BpmnXMLConverter class.

Best regards,

esseti
Champ in-the-making
Champ in-the-making
one thing.
i noticed that if i add the task via XML the diagram of the process is not stored nor accesible. this probably because the shapes do not match the diagram.
if i use solution here, will the diagram be available later? or what?
ciao

frederikherema1
Star Contributor
Star Contributor
Diagram information needs to be added manually, if you want to have that. Another option is to remove the existing diagram-info altogether, add the correct tasks and sequence-flows to the POJO-model and run the (experimental) auto-layout. See my blog for an example: http://stacktrace.be/blog/2013/03/dynamic-process-creation-and-deployment-in-100-lines/

After this, you add the BPMNModel POJO to a new deployment and the image will be generated at deploy-time.

esseti
Champ in-the-making
Champ in-the-making
can this be done via rest API? i'm working with python (plain XML so far), calling the APIs to deployment and to start it.
in other case i can create a small "compiler" to do what i need.
can i add this function, maybe with a button, to the eclipse tool?

trademak
Star Contributor
Star Contributor
No this is not available in the REST API, but you could add your own REST service to it. In Eclipse you would have to implement the same logic as Frederik mentioned.

Best regards,

esseti
Champ in-the-making
Champ in-the-making
I see.
wouldn't make it sense to add an if condition on the deployment API that checks if diagram is correct (right now it raises a WARN  org.activiti.engine.impl.bpmn.deployer.BpmnDeployer  - Error while generating process diagram, image will not be stored in repository) and in case do the new BpmnAutoLayout(model).execute();?
or simply store whatever is in the  <bpmndi:BPMNDiagram> without checking if it matches the actual diagram.

PS: would be terrific to have an API that returns the diagram (png) with the current task rounded by the red circle, as it happens for the activiti explorer. but probably it's out of scope.

esseti
Champ in-the-making
Champ in-the-making
i'm trying to setup a java web app to create a rest api for doing what i need.
i got stuck at the init.
i've the ServletContextListener that does the init and destroy.
and the activiti.cfg.xml in the src folder:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="processEngineConfiguration"
  class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
  <property name="databaseSchemaUpdate" value="true" />
  <property name="jobExecutorActivate" value="false" />
  <property name="jdbcUrl" value="jdbc:mysql://../activiti" />
  <property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
  <property name="jdbcUsername" value="root" />
  <property name="jdbcPassword" value="psw" />
</bean>
</beans>

but when lunching the project i got this error

SEVERE: Exception sending context destroyed event to listener instance of class org.crowdcomputer.ProcessEngineServletContextListener
java.lang.NoClassDefFoundError: Could not initialize class org.activiti.engine.ProcessEngines
at org.crowdcomputer.ProcessEngineServletContextListener.contextDestroyed(ProcessEngineServletContextListener.java:42)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4927)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5573)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:680)

any help? error message doesn't say much to me.