Outjected ScopeType.BUSINESS_PROCESS JBPM variable scope: task or process?
aconn7 Mar 5, 2009 6:33 PMAre outjected BUSINESS_PROCESS variables scoped to the processInstance or taskInstance? The processInstance would seem more natural, but in my experimentation, it seems to be taskInstance.
I am attempting to outject a row id as documentId for reference throughout the life of my business process. I am outjecting documentId upon @CreateProcess:
@Name("rfcHome")
public class RfcHome extends EntityHome<RfcBase> {
@Out(scope = ScopeType.BUSINESS_PROCESS, required=false) protected String documentId;
@Override @CreateProcess(definition="rfc")
public String persist() {
String returnVal = super.persist();
setDocumentId(getId().toString());
return returnVal;
}
public String getDocumentId() {
return documentId;
}
public void setDocumentId(String documentId) {
this.documentId = documentId;
}
This all seems to work fine and documentId is accessible when querying taskInstanceList for the first task in my jpdl :
public List<TaskInstance> getDocumentTaskList(){
List<TaskInstance> filteredTaskInstanceList = new ArrayList<TaskInstance>();
for (TaskInstance task : taskInstanceList){
if (task.hasVariable("documentId")){
Object object = task.getVariable("documentId");
String documentId="";
if (Long.class.isInstance(object)){
documentId = ((Long)object).toString();
} else {
documentId = (String)object;
}
if (documentId.equalsIgnoreCase(rfcHome.getId().toString())){
filteredTaskInstanceList.add(task);
}
}
}
return filteredTaskInstanceList;
}
This cool little filtering allows me to show the user their open tasks on a specific document. Here is my jpdl:
<process-definition xmlns="" name="rfc" >
<start-state name="start">
<transition to="submit"/>
</start-state>
<task-node name="submit">
<description>
Submit for review
</description>
<task name="Complete new ECR">
<description>
New RFC waiting for submit or cancel
</description>
<assignment actor-id="#{actor.id}"></assignment>
</task>
<transition name="submit" to="CCB Approve"/>
</task-node>
<task-node name="CCB Approve" create-tasks="false" >
<event type="node-enter">
<action expression="#{rfcJbpmAction.assignCcbApprovers}" />
</event>
<description>Must be approved by each member of the CCB</description>
<task name="ccbapproval" />
<transition to="end"></transition>
</task-node>
<end-state name='end' >
</end-state>
</process-definition>
However ...
After completing the submit task and transitioning to the CCB Approve task, documentId is no longer available. Upon querying the jbpm_variableinstance table, I can see clearly that the TOKEN_, TOKENVARIABLEMAP_ and PROCESSINSTANCE_ column values are being NULL ed out.
I am doing nothing particularly special or explicitly in my task completion component that would cause this:
@Name("rfcJbpmTask")
@AutoCreate
public class RfcJbpmTask {
@In EntityManager entityManager;
@In private RfcHome rfcHome;
@In(required=false) private TaskInstance taskInstance;
@In(required=false) private List<TaskInstance> taskInstanceList;
@In(required=false) private ProcessInstance processInstance;
public RfcJbpmTask() {}
@BeginTask @EndTask(transition="submit")
public String submit(){
return "success";
}
}
What is going on here? Shouldnt the variable be scoped to the processInstance ? taskInstance scope seems to really limit the usefulness of being able to outject.
As an alternative, I have resorted to explicitly creating variables in the jpdl itself. This method has worked just fine:
<start-state name="start">
<transition to="Status NEW Phase ECR">
<action name="Set DocumentId" expression="#{businessProcessContext.set(\'documentId\',rfcHome.id)}}"></action>
</transition>
</start-state>