ProcessInstance instance,
Map options) {
// TODO Auto-generated method stub
//pushParentTracingTag(options, activity.getTracingTag());
SubProcessActivity subProcessActivity = (SubProcessActivity)activity;
if(options.containsKey("replacingSubProcessTracingTag")){
String replacingSubProcessTracingTag = (String) options.get("replacingSubProcessTracingTag");
if(replacingSubProcessTracingTag.equals(activity.getTracingTag()))
{
try
{
Vector<String> subProcessInstanceIds;
subProcessInstanceIds = subProcessActivity.getSubprocessIds(instance);
Vector<String> subProcessInstanceLabels = subProcessActivity.getSubprocessLabels(instance);
String replacingSubProcessKey = (String) options.get("replacingSubProcessKey");
int subProcessIndex = subProcessInstanceLabels.indexOf(replacingSubProcessKey);
/*
int replacingKeySize = replacingSubProcessKey.length();
if(subProcessIndex < 0){
for(int i = 0 ; i < subProcessInstanceLabels.size() ; i++){
String extKey = (String)subProcessInstanceLabels.get(i);
System.out.println("before subString extKey["+extKey+"]");
if(extKey != null && extKey.length() > replacingKeySize){
extKey = extKey.substring(0, replacingKeySize);
}
System.out.println("after subString extKey["+extKey+"]");
if(extKey.equals(replacingSubProcessKey)){
subProcessIndex = i;
break;
}
}
}
*/
if(subProcessIndex > -1){
String replacingSubProcessInstanceId = (String)subProcessInstanceIds.get(subProcessIndex);
ProcessInstance replacingSubProcessInstance = instance.getProcessTransactionContext().getProcessManager().getProcessInstance(replacingSubProcessInstanceId);
SequenceActivityViewer defViewer = new SequenceActivityViewer();
return defViewer.render(replacingSubProcessInstance.getProcessDefinition(), replacingSubProcessInstance, options);
}else{
System.out.println("Although you've requested a sub process replacing option, there's no matching instance for the requested key["+ replacingSubProcessKey +"].");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* showing subprocess as no level
*/
if(subProcessActivity.isViewAlsoInMainProcess() && instance!=null){
try {
ProcessInstance replacingSubProcessInstance = (ProcessInstance) subProcessActivity.getSubProcesses(instance).get(0);
SequenceActivityViewer defViewer = new SequenceActivityViewer();
return defViewer.render(replacingSubProcessInstance.getProcessDefinition(), replacingSubProcessInstance, options);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* try showing sub process' outlines
*/
if(options.containsKey("showSubProcessOutline") && instance!=null){
try{
int segmentIndex = activity.getTracingTag().indexOf("_");
if(segmentIndex == -1){
String spDefId = subProcessActivity.getDefinitionIdOnly();
ProcessManagerBean processManager = instance.getProcessTransactionContext().getProcessManager();
String spVersionId = processManager.getProcessDefinitionProductionVersion(spDefId);
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++;
}