-
1. Re: removeTaskInstance doesn't work!
kukeltje Jan 17, 2007 9:35 PM (in response to mindthegap)uhhmmm... you pass a taskinstancereference to a method wgich creates a new process (so no taskinstances) and want to remove "it" ..... that will never work. I'd even expect an exception, but that might be a runtime exception....
-
2. Re: removeTaskInstance doesn't work!
mindthegap Jan 19, 2007 10:28 AM (in response to mindthegap)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! -
3. Re: removeTaskInstance doesn't work!
kukeltje Jan 19, 2007 12:29 PM (in response to mindthegap)don't see anything wrong with that at first site. Are you sure anthing 'should' be removed.....? Do you see in the debug of jbpm that anything is being tried to be removed?
And btw, why do you want to remove taskinstances from the db? -
4. Re: removeTaskInstance doesn't work!
mindthegap Jan 19, 2007 12:34 PM (in response to mindthegap)I Ronald,
If i delete the specific row in jbpm_logs then i can delete the taskInstance.
Id like to give to the user the possibility of making undo.
Can Process logs be used to implement the undo?
Thanks! -
5. Re: removeTaskInstance doesn't work!
kukeltje Jan 19, 2007 12:42 PM (in response to mindthegap)Aren't there any exceptions then? Like fk contraint violations???
And yes, using the logs is one of the things to use when implementing undo. See jbpm 2.0 on how that was done and look at the jira for some undo info -
6. Re: removeTaskInstance doesn't work!
mindthegap Jan 19, 2007 12:50 PM (in response to mindthegap)No exceptions :(
The code i show to you runs perfectly and in debug i inspect the return of getTaskInstances method and the taskInstances are removed...but after closing the context my db remains the same!! :)
Ok, im going to read the documentation.
But btw the best way to implementing undo is through process_logs?
Thanks Ronald -
7. Re: removeTaskInstance doesn't work!
kukeltje Jan 19, 2007 1:27 PM (in response to mindthegap)using the processlogs plays an important role for sure, but there is more to it (details unknown to me)
If you turn on hibernate sql showing, do you see statements that they are removed? Other things I'm thinking of are: transaction not committed, hibernate config to fail silently if there are fk constraints violated??? turn on hibernate debugging..
Ronald -
8. Re: removeTaskInstance doesn't work!
mindthegap Jan 22, 2007 6:49 AM (in response to mindthegap)Hi!
After turning on the show sql parameter i saw that no DELETE statement appears in my console.
So i do this test case that is OK and continues to not show any DELETE jbpm.TASKINSTANCE...:public void testToken() { JbpmContext jc = jbpmConfiguration.createJbpmContext(); TaskMgmtSession tms = jc.getTaskMgmtSession(); try { GraphSession gs = jc.getGraphSession(); ProcessDefinition pd = gs.findLatestProcessDefinition("XXX"); ProcessInstance pi = new ProcessInstance(pd); Token token = pi.getRootToken(); assertEquals("INIT", token.getNode().getName()); pi.signal(); assertEquals("REG", token.getNode().getName()); pi.signal(); assertEquals("PRO", token.getNode().getName()); //remove logs ( a despaired try :))) LoggingInstance li = pi.getLoggingInstance(); List x= li.getLogs(); x.removeAll(x); TaskInstance tit = (TaskInstance) tms.findTaskInstancesByToken(token.getId()).get(0); assertEquals("REG", tit.getName()); pi.getTaskMgmtInstance().removeTaskInstance(tit); jc.save(pi); }catch (Exception e) { System.out.println("no catch enter :("); } finally { jc.close(); } }
Any idea?
Thanks in advance -
9. Re: removeTaskInstance doesn't work!
kukeltje Jan 22, 2007 11:32 AM (in response to mindthegap)do you see sql statements at all?
-
10. Re: removeTaskInstance doesn't work!
mindthegap Jan 23, 2007 10:51 AM (in response to mindthegap)Yep
Hibernate: select processdef0_.ID_ ... Hibernate: insert into JBPM_TOKEN ... Hibernate: insert into JBPM_PROCESSINSTANCE ... Hibernate: select definition0_.PROCESSDEFINITION_ ... Hibernate: select events0_.PROCESSDEFINITION_ ... Hibernate: select startstate0_.ID_ ... Hibernate: select leavingtra0_.FROM_ ... Hibernate: select events0_.NODE_ ... Hibernate: select events0_.TRANSITION_ ... Hibernate: select node0_.ID_ ... Hibernate: select events0_.NODE_ ... Hibernate: select tasks0_.TASKNODE_ ... Hibernate: insert into JBPM_TASKINSTANCE ... Hibernate: select events0_.TASK_ ... Hibernate: select leavingtra0_.FROM_ ... Hibernate: select events0_.TRANSITION_ ... Hibernate: select node0_.ID_ ... Hibernate: select events0_.NODE_ ... Hibernate: select tasks0_.TASKNODE_ ... Hibernate: insert into JBPM_TASKINSTANCE ... Hibernate: select events0_.TASK_ ... Hibernate: insert into JBPM_MODULEINSTANCE ... Hibernate: insert into JBPM_MODULEINSTANCE ... Hibernate: update JBPM_TOKEN ... Hibernate: update JBPM_PROCESSINSTANCE ... Hibernate: update JBPM_TASKINSTANCE ... Hibernate: update JBPM_TASKINSTANCE ... Hibernate: update JBPM_MODULEINSTANCE ... Hibernate: update JBPM_MODULEINSTANCE ... Hibernate: select taskinstan0_.ID_ ...
Strange...isnt it?
Thanks
RQ_ -
11. Re: removeTaskInstance doesn't work!
dleerob Dec 21, 2007 2:14 AM (in response to mindthegap)I have the same problem where my removeTaskInstance isnt actually saving the changes to the db. My task instance still exists after calling that method.
Method removeTaskInstance fail becausa a constraint violation.
But if i delete processLogs it seems to work.
RQ_
How did you delete the processLogs?