public ActivityReference getInitiatorHumanActivityReference(final ProcessTransactionContext ptc){
// if(!isInitiateByFirstWorkitem())
// throw new RuntimeException("this process definition is not allowed to be initiated by the first workitem.");
ActivityForLoop findingLoop = new ActivityForLoop(){
public void logic(Activity activity){
if(activity instanceof HumanActivity){
stop(activity);
}else if(activity instanceof SubProcessActivity){
// if(ptc==null){
// stop(null);
// return;
// }
stop(null);
if(GlobalContext.isDesignTime()){
return;
}
SubProcessActivity spAct = (SubProcessActivity)activity;
ProcessManagerRemote pm = null;
try{
if(ptc.getProcessManager()!=null)
pm = ptc.getProcessManager();
else
pm = (new ProcessManagerFactoryBean()).getProcessManagerForReadOnly();
String versionId = pm.getProcessDefinitionProductionVersion(spAct.getDefinitionIdOnly());
ProcessDefinition spDef = ProcessDefinitionFactory.getInstance(ptc).getDefinition(versionId);
if(spDef.isInitiateByFirstWorkitem()){
ActivityReference actRefReturnedFromSP = spDef.getInitiatorHumanActivityReference(ptc);
if(actRefReturnedFromSP==null){
stop(null);
return;
}
String scopeOfActFromSP = actRefReturnedFromSP.getAbsoluteTracingTag();
if(scopeOfActFromSP == null){
if(actRefReturnedFromSP.getActivity()!=null){
actRefReturnedFromSP.setAbsoluteTracingTag(spAct.getTracingTag() + "@" + actRefReturnedFromSP.getActivity().getTracingTag());
stop(actRefReturnedFromSP);
return;
}
stop(null);
return;
}
actRefReturnedFromSP.setAbsoluteTracingTag(spAct.getTracingTag() + "@" + scopeOfActFromSP);
stop(actRefReturnedFromSP);
}
}catch(Exception e){
throw new RuntimeException(e);
}finally{
if(ptc.getProcessManager()==null)
try {
pm.remove();
} catch (Exception e) {
}
}
}
}
};
findingLoop.run(this);
Object result = findingLoop.getReturnValue();
if(result instanceof HumanActivity){
ActivityReference ref = new ActivityReference();
ref.setActivity((Activity)result);
ref.setAbsoluteTracingTag(((Activity)result).getTracingTag());