try {
sc = connect();
Shark shark = Shark.getInstance();
AssignmentFilterBuilder aieb = shark.getAssignmentFilterBuilder();
WMSessionHandle sessionHandle = sc.getSessionHandle();
// filter by user
String username = getWorkflowUserManager().getCurrentUsername();
WMFilter filter = aieb.addUsernameEquals(sessionHandle, username);
// filter by package id
if (packageId != null && packageId.trim().length() > 0) {
filter = aieb.and(sessionHandle, filter, aieb.addPackageIdEquals(sessionHandle, packageId));
}
// filter by process definition id
if (processDefId != null && processDefId.trim().length() > 0) {
String pkgId = MiscUtilities.getProcessMgrPkgId(processDefId);
String processKey = MiscUtilities.getProcessMgrProcDefId(processDefId);
//String processVersion = MiscUtilities.getProcessMgrVersion(processDefId);
filter = aieb.and(sessionHandle, filter, aieb.addPackageIdEquals(sessionHandle, pkgId));
filter = aieb.and(sessionHandle, filter, aieb.addProcessDefIdEquals(sessionHandle, processKey));
//filter = aieb.and(sessionHandle, filter, aieb.addPackageVersionEquals(sessionHandle, processVersion));
}
// filter by process instance id
if (processId != null && processId.trim().length() > 0) {
filter = aieb.and(sessionHandle, filter, aieb.addProcessIdEquals(sessionHandle, processId));
}
// filter by activityDefId
if (activityDefId != null && activityDefId.trim().length() > 0) {
filter = aieb.and(sessionHandle, filter, aieb.addActivityDefIdEquals(sessionHandle, activityDefId));
}
// set sort
if (sort != null && sort.trim().length() > 0) {
boolean asc = (desc == null) || !desc;
filter = aieb.setOrderByCreatedTime(sessionHandle, filter, asc);
}
if (start != null) {
filter.setStartPosition(start);
}
if (rows != null && rows > 0) {
filter.setLimit(rows);
}
// execute
WfAssignmentIterator ai = sc.get_iterator_assignment();
ai.set_query_expression(aieb.toIteratorExpression(sessionHandle, filter));
WfAssignment[] wItems = ai.get_next_n_sequence(0);
for (int i = 0; i < wItems.length; ++i) {
WfAssignment wfa = wItems[i];
boolean acceptedStatus = wfa.get_accepted_status();
WorkflowAssignment ass = new WorkflowAssignment();