Collection<WorkflowProcess> runningProcessList = new ArrayList<WorkflowProcess>();
try {
sc = connect();
WfProcessIterator pi = sc.get_iterator_process();
String sharkExpression = "statenotequals.(\"open.running\")";
String sqlExpression = "State IN (SELECT oid FROM SHKProcessStates WHERE Name <> 'open.running')";
if (packageId != null && packageId.trim().length() > 0) {
sharkExpression += " && packageIdequals.(\"" + packageId + "\")";
sqlExpression += " AND ProcessDefinition IN (SELECT oid FROM SHKProcessDefinitions WHERE PackageId = '" + packageId + "')";
}
if (processId != null && processId.trim().length() > 0) {
sharkExpression += " && key.indexOf(\"" + processId + "\") != -1)";
sqlExpression += " AND Id LIKE '%" + processId + "%'";
}
if (processName != null && processName.trim().length() > 0) {
sharkExpression += " && name.indexOf(\"" + processName + "\") != -1)";
sqlExpression += " AND Name LIKE '%" + processName + "%'";
}
if (version != null && version.trim().length() > 0) {
sharkExpression += " && versionequals.(\"" + version + "\")";
sqlExpression += " AND ProcessDefinition IN (SELECT oid FROM SHKProcessDefinitions WHERE ProcessDefinitionVersion = '" + version + "')";
}
if (start == null) {
start = 0;
}
String queryExpression = "/*startAt " + start + " startAt*/";
if (rows != null && rows > 0) {
queryExpression += "/*limit " + rows + " limit*/";
}
String sortStr = "";
if (sort != null && sort.trim().length() > 0) {
sortStr += " ORDER BY " + sort;
sortStr += (desc != null && desc.booleanValue()) ? " DESC" : "";
}
String query_expression = "(" + sharkExpression + ")" + " /*sql (" + sqlExpression + ") " + sortStr + " sql*/ " + queryExpression;
pi.set_query_expression(query_expression);
WfProcess[] wfRunningProcessList = pi.get_next_n_sequence(0);
for (int i = 0; i < wfRunningProcessList.length; ++i) {
WfProcess wfProcess = wfRunningProcessList[i];
WfProcessMgr manager = wfProcess.manager();