SharkConnection sc = null;
try {
sc = connect();
WMSessionHandle sessionHandle = sc.getSessionHandle();
WfAssignment wfa = null;
Shark shark = Shark.getInstance();
AssignmentFilterBuilder aieb = shark.getAssignmentFilterBuilder();
WMFilter filter = aieb.addActivityIdEquals(sessionHandle, activityId);
filter = aieb.and(sessionHandle, filter, aieb.addUsernameEquals(sessionHandle, replaceUser));
// execute
WfAssignmentIterator ai = sc.get_iterator_assignment();
ai.set_query_expression(aieb.toIteratorExpression(sessionHandle, filter));
WfAssignment[] wItems = ai.get_next_n_sequence(0);
if (wItems != null && wItems.length > 0) {
wfa = wItems[0];
}
WfResource res = sc.getResource(username);
if (res == null) {
CustomWfResourceImpl.createResource(sessionHandle, username);
res = sc.getResource(username);
}
if (wfa.get_accepted_status()) {
wfa.set_accepted_status(false);
}
if (wfa.assignee() == null || (wfa.assignee() != null && !res.resource_key().equals(wfa.assignee().resource_key()))) {
wfa.set_assignee(res);
}
WorkflowUtil.addAuditTrail(this.getClass().getName(), "assignmentReassignUser", activityId);
} catch (Exception ex) {