private ActivityInstance complete(ActivityInstance ai, String context, Map<String, ?> data) {
   WorkflowService ws = sf.getWorkflowService();
   if (ai.getState() != ActivityInstanceState.Application) {
     ai = ws.activate(ai.getOID());
   }
   ai = ws.complete(ai.getOID(), context, data);
   return ai;
 }
 @SuppressWarnings("unchecked")
 private List<ActivityInstance> getWorklist(EvaluationPolicy... policies) {
   WorkflowService ws = sf.getWorkflowService();
   WorklistQuery query = WorklistQuery.findCompleteWorklist();
   if (policies != null) {
     for (EvaluationPolicy policy : policies) {
       query.setPolicy(policy);
     }
   }
   Worklist worklist = ws.getWorklist(query);
   return worklist.getCumulatedItems();
 }
 @SuppressWarnings("unchecked")
 private List<ActivityInstance> getWorklist(ProcessInstance pi, EvaluationPolicy... policies) {
   WorkflowService ws = sf.getWorkflowService();
   WorklistQuery query = WorklistQuery.findCompleteWorklist();
   if (policies != null) {
     for (EvaluationPolicy policy : policies) {
       query.setPolicy(policy);
     }
   }
   query.getFilter().add(new ProcessInstanceFilter(pi.getOID(), false));
   Worklist worklist = ws.getWorklist(query);
   return worklist.getCumulatedItems();
 }