How to MODIFY an existing process by the API?
Objectif: I want to CHANGE a process, and ADD between Step 1 and Step 2 a new task, called "Blue Step". To create this task, I want to duplicate the task "Model A" present in the process.
So, I need to :
* delete the transition between Step 1 and Step 2
* duplicate the task "Model A" to a new one and rename it "Blue Step"
* Create transition "Step 1" => "Blue Step" => "Step 2"
* save the new process with a new version.
Version : 7.10.x
1/ I see that in the javadoc DesignProcessDefinitionImpl: public void setProcessContainer(FlowElementContainerDefinition processContainer)
So I do that
FlowElementContainerDefinition flowElementContainer= currentDesignProcessDefinition.getFlowElementContainer(); DesignProcessDefinitionImpl newProcessDesign = new DesignProcessDefinitionImpl(); newProcessDesign.setProcessContainer(flowElementContainer);
but the compiler told me
The method setProcessContainer(org.bonitasoft.engine.bpm.flownode.impl.FlowElementContainerDefinition) in the type DesignProcessDefinitionImpl is not applicable for the arguments (org.bonitasoft.engine.bpm.flownode.FlowElementContainerDefinition) ==> the javadoc 7.10 is not up to date with the JAR 7.10 ? 2/ I have a FlowElementContainerDefinition, and I would like to remove a transition, copy a task, add transitions. There are nothing here to do that. Let say this object is only to GET. ==> I found a FlowElementContainerBuilder, so I assume I have to use the builder. Where is the new FlowElementContainerBuilder from an existing definition? The constructor invokes two another object that I don't know where to get them. FlowElementContainerBuilder(FlowElementContainerDefinitionImpl container, ProcessDefinitionBuilder processDefinitionBuilder) There are only some method like addAutomaticTask(String taskName) ==> but I would like to have a addFlowElementBuilder where I got this information directly from the FlowElementContainerDefinition.iterate(). Is it possible? ==> Else, does that mean I have to COPY everything differently (automatic tasks, user tasks, gateway...)? Road will be long and I don't see how to add a form / Operations/ Boundary event in an automatic tasks ==> Finally, if I use this object, how do I get the process Design ? - I don't have a done() - I see a protected FlowElementContainerDefinitionImpl getContainer() but it's protected - I see a DesignProcessDefinition getProcess() ==> Is that the way to get the process Design ? But how do I give the processName and the processVersion ? 3/ is that possible to access the XML, then to work directly with the XML, and creates a process from the XML definition? I look then to SEARCH the XML as a Text, then to LOAD the process as a Text.
When you retrieve an existing DesignProcessDefinition from the API it returns an immutable model.
To achieve your use case you must use the ProcessDefinitionBuilder and recreate your version from scratch using the builder. You can browse the existing version to duplicate its content.
It is absolutely NOT recommended to directly modify the xml.