ProcessDefinition spDef = ProcessDefinitionFactory.getInstance(instance.getProcessTransactionContext()).getDefinition(spVersionId);
Vector scopeActitivies = new Vector();
Vector firstLevelChild = spDef.getChildActivities();
SequenceActivity sequence = null;
Vector subProcesses = subProcessActivity.getSubProcesses(instance);
ProcessInstance proxyInstance = instance.createSnapshot();
int j = 0;
for(int i=0; i<firstLevelChild.size(); i++){
if(firstLevelChild.get(i) instanceof ScopeActivity){
if(sequence==null){
sequence = new SequenceActivity();
sequence.setTracingTag(activity.getTracingTag());
}
ScopeActivity scopeChild = (ScopeActivity)firstLevelChild.get(i);
scopeActitivies.add(scopeChild);
SubProcessActivity segment_subProcessActivity = new SubProcessActivity();
segment_subProcessActivity.setName(scopeChild.getName());
segment_subProcessActivity.setDefinitionId(subProcessActivity.getDefinitionId());
segment_subProcessActivity.setTracingTag(activity.getTracingTag() + "_" + j);
segment_subProcessActivity.setStatus(instance, Activity.STATUS_READY);
boolean bAllisCompleted = (subProcesses.size() > 0);
for(int k=0; k<subProcesses.size(); k++){
ProcessInstance theProcessInstance = (ProcessInstance) subProcesses.get(k);
String status = theProcessInstance.getStatus(scopeChild.getTracingTag());
if(!Activity.STATUS_COMPLETED.equals(status)){
if(!Activity.STATUS_READY.equals(status)){
segment_subProcessActivity.setStatus(proxyInstance, Activity.STATUS_RUNNING);
bAllisCompleted = false;
break;
}else
bAllisCompleted = false;
}
}
if(bAllisCompleted)
segment_subProcessActivity.setStatus(proxyInstance, Activity.STATUS_COMPLETED);
sequence.addChildActivity(segment_subProcessActivity);
j++;
}
}
if (sequence!=null) {
SequenceActivityViewer seqViewer = new SequenceActivityViewer();
proxyInstance.setProcessDefinition(subProcessActivity.getProcessDefinition());
// if activity name is empty set activity name.
sequence.setName(activity.getName());
return seqViewer.render(sequence, proxyInstance, options);
}
}