Hello,

Just wanted to share how I accomplished this query. although it is not, let say 
hibernate way or jbpm way, but it work.


  | 
  | @SuppressWarnings("unchecked")
  |     public List<Task> findNextTasksByProcessInstance(final ProcessInstance 
process)
  |     {
  |             try {
  |                     return (List<Task>) jbpmTemplate.execute(new 
JbpmCallback() {
  | 
  |                             public Object doInJbpm(JbpmContext context)
  |                                             throws JbpmException {
  |                                     
  |                                     final long processDefId = 
process.getProcessDefinition().getId();
  |                                     
  |                                     final GraphSession sess = 
context.getGraphSession();
  |                                     final ProcessDefinition def = 
sess.getProcessDefinition(processDefId);
  |                                     final Map<String, Task> task = 
def.getTaskMgmtDefinition().getTasks();
  |                                     final Set<String> taskSet = 
task.keySet();
  |                                     
  |                                     final Session session = 
context.getSession();
  |                                     final Query query = 
session.getNamedQuery("findNextTasksByProcessInstance");
  |                                     query.setEntity("processInstance", 
process);
  |                                     final List<String> taskInstance = 
query.list();
  |                                     
  |                                     return 
JbpmEngineUtils.getNextTasks(taskSet, taskInstance, task);
  |                             }
  |                     });
  |             } catch (Exception e) {
  |                     throw new CCTIException("No task instance get", e);
  |             }
  |     }
  | 

then subtract the activeTask from possibletask:


  | public static List<String> getNextTasks(Set<String> 
possibleTask,List<String> completedTask,Map<String,Task> task)
  |     {
  |             final List<String> nextTasks = new ArrayList<String>();
  |             
  |             final Set<String> tmpPossibleTask = new 
HashSet<String>(possibleTask);
  |             final List<String> tmpActiveTask = new 
ArrayList<String>(completedTask);
  |             final Map<String, Task> mapTask = new HashMap<String, 
Task>(task);
  |             
  |             for(String s : tmpActiveTask)
  |             {
  |                     if ( tmpPossibleTask.contains(s) )
  |                     {
  |                             tmpPossibleTask.remove(s);
  |                     }
  |             }
  |             Iterator<String> ite = tmpPossibleTask.iterator();
  |             while (ite.hasNext()) {
  |                     final String string =  ite.next();
  |                     final Task taskLeft = mapTask.get(string);
  |                     nextTasks.add(taskLeft.getDescription());
  |             }
  |             return nextTasks;
  |     }
  | 

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4251736#4251736

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4251736
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to