Sorry, the real code is this:

  | public void removeStateProcessInstance(Integer keyRef, String processNname, 
String state) {
  |             JbpmContext jc = jbpmConfiguration.createJbpmContext();
  |             TaskMgmtSession tms = jc.getTaskMgmtSession();
  |             try {
  |                     GraphSession gs = jc.getGraphSession();
  |                     ProcessDefinition pd = 
gs.findLatestProcessDefinition(processName);
  |                     
  |                     List processInstances = 
gs.findProcessInstances(pd.getId());
  |                     if (processInstances.isEmpty() == false) {
  |                             ListIterator listProcessInstances = 
processInstances.listIterator();
  |                             while (listProcessInstances.hasNext() ) {
  |                                     ProcessInstance pi = 
(ProcessInstance)listProcessInstances.next();
  |                                     ContextInstance contextInstance = 
pi.getContextInstance();
  |                                     
if(contextInstance.getVariable("key")!=null) {
  |                                             if(keyRef.intValue() == 
Integer.parseInt(contextInstance.getVariable("key").toString())) {
  |                                                 
  |                                                     //Obtém o 
TaskInstanceId da última tarefa da lista actual
  |                                                     Iterator taskInstances 
= pi.getTaskMgmtInstance().getTaskInstances().iterator();
  |                                                     TaskInstance ti = null;
  |                                                     
  |                                                     long tid = 0;
  |                                                     while 
(taskInstances.hasNext()) {
  |                                                             ti = 
(TaskInstance) taskInstances.next();
  |                                                             
if(ti.getName().equals(state)) tid = ti.getId();        
  |                                                 }
  |                                                     
  |                                                     //Put 'End' field to 
null and get token node
  |                                                     Node node = null;
  |                                                     ArrayList<Long> x = new 
ArrayList<Long>();
  |                                                     for(Iterator 
i=pi.getTaskMgmtInstance().getTaskInstances().iterator(); i.hasNext();) {
  |                                                             ti = 
(TaskInstance) i.next();
  |                                                             
if(ti.getId()==tid) {
  |                                                                     
ti.setEnd(null);
  |                                                                     node = 
ti.getToken().getNode();
  |                                                             }
  |                                                             
  |                                                             
if(ti.getId()>tid){
  |                                                                     
x.add(ti.getId());                                                              
                                                                        
  |                                                             }
  |                                                 }
  |                                                     
  |                                                     
  |                                                     Token token = 
pi.getRootToken();
  |                                                     token.setNode(node);
  |                                                     
  |                                                     int i;
  | //remove taskInstances
  |                                                     for(i=0;i<x.size();i++) 
{
  |                                                             TaskInstance 
tit = tms.loadTaskInstance(Long.parseLong(x.get(i).toString()));
  |                                                             
pi.getTaskMgmtInstance().removeTaskInstance(tit);
  |                                                             
  |                                                     }
  |                                                     
  |                                             }
  |                                     }
  |                                     jc.save(pi);
  |                                     break;
  |                             }
  |                     }                       
  |             }catch (Exception e) {
  |                     System.out.println(e.getMessage());
  |             } finally {
  |                     jc.close();
  |             }   
  |     }                       
  | 

It doesn't save the changes in the db!
Is there any restriction to remove taskInstances?

Thanks in advance!

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

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4003867

_______________________________________________
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to