* @return
*/
public WorkflowProcessResult processStart(String processDefId, String processId, Map<String, String> variables, String startProcUsername, String parentProcessId, boolean startManually) {
processDefId = getConvertedLatestProcessDefId(processDefId);
SharkConnection sc = null;
WorkflowProcessResult result = new WorkflowProcessResult();
WorkflowProcess processStarted = new WorkflowProcess();
Collection<WorkflowActivity> activitiesStarted = new ArrayList<WorkflowActivity>();
String processInstanceId = "";
try {
if (startProcUsername != null && startProcUsername.trim().length() > 0) {
sc = connect(startProcUsername);
} else {
sc = connect();
}
// start process
WfProcessMgr mgr = sc.getProcessMgr(processDefId);
WfProcess wfProcess = null;
if (processId != null && processId.trim().length() > 0) {
wfProcess = sc.getProcess(processId);
processInstanceId = processId;
} else {
wfProcess = mgr.create_process(null);
processInstanceId = wfProcess.key();
}
if (variables != null) {
//set workflow variables if the key is found
Set<String> keys = variables.keySet();
if (keys != null && keys.size() > 0) {
Map contextSignature = wfProcess.manager().context_signature();
for (String key : keys) {
Object value = variables.get(key);
String signature = (String) contextSignature.get(key);
if (signature != null && signature.trim().length() > 0) {
if (signature.equals("java.lang.Long")) {
value = Long.parseLong((String) value);
} else if (signature.equals("java.lang.Boolean")) {
value = Long.parseLong((String) value);
} else if (signature.equals("java.lang.Double")) {
value = Double.parseDouble((String) value);
}
}
this.processVariable(processInstanceId, key, value);
}
}
}
//process linking
if (parentProcessId != null && parentProcessId.trim().length() > 0) {
internalAddWorkflowProcessLink(parentProcessId, processInstanceId);
}
if (!startManually) {
wfProcess.start();
}
// set started process in result
processStarted.setId(processDefId);
processStarted.setInstanceId(processInstanceId);
result.setProcess(processStarted);
//redirect to assignment view accordingly
if (wfProcess != null && !startManually) {
Shark shark = Shark.getInstance();
AdminMisc admin = shark.getAdminMisc();
WMSessionHandle sessionHandle = sc.getSessionHandle();
XPDLBrowser xpdl = shark.getXPDLBrowser();
WfActivity[] activityList = wfProcess.get_sequence_step(0);
WorkflowActivity activity = getNextActivity(sessionHandle, mgr, admin, xpdl, wfProcess.key(), activityList);