final String parentTaskInstanceId) throws EngineException,
KernelException {
final String wfprocessId = workflowProcessId;
final WorkflowDefinition workflowDef = runtimeContext.getDefinitionService().getTheLatestVersionOfWorkflowDefinition(wfprocessId);
final WorkflowProcess wfProcess = workflowDef.getWorkflowProcess();
if (wfProcess == null) {
throw new RuntimeException(
"Workflow process NOT found,id=[" + wfprocessId
+ "]");
}
IProcessInstance processInstance = (IProcessInstance) this.execute(new IWorkflowSessionCallback() {
public Object doInWorkflowSession(RuntimeContext ctx)
throws EngineException, KernelException {
ProcessInstance processInstance = new ProcessInstance();
processInstance.setCreatorId(creatorId);
processInstance.setProcessId(wfProcess.getId());
processInstance.setVersion(workflowDef.getVersion());
processInstance.setDisplayName(wfProcess.getDisplayName());
processInstance.setName(wfProcess.getName());
processInstance.setState(IProcessInstance.INITIALIZED);
processInstance.setCreatedTime(ctx.getCalendarService()
.getSysDate());
processInstance
.setParentProcessInstanceId(parentProcessInstanceId);
processInstance.setParentTaskInstanceId(parentTaskInstanceId);
ctx.getPersistenceService().saveOrUpdateProcessInstance(
processInstance);
return processInstance;
}
});
// 初始化流程变量
processInstance.setProcessInstanceVariables(new HashMap<String, Object>());
List<DataField> datafields = wfProcess.getDataFields();
for (int i = 0; datafields != null && i < datafields.size(); i++) {
DataField df = datafields.get(i);
if (df.getDataType().equals(DataField.STRING)) {
if (df.getInitialValue() != null) {
processInstance.setProcessInstanceVariable(df