9 Replies Latest reply on Aug 15, 2006 6:34 AM by olivier_debels

    how to retrieve task instance/process instances in a specifi

      Hi

      I went through the APIs. And i find there is no direct API to help getting
      (1)task instances which is in waiting status in a specific TaskNode.
      (2)process instances which is in waiting status in a specific TaskNode.

      Please advice?
      yang

        • 1. Re: how to retrieve task instance/process instances in a spe
          kukeltje

          If you looked through the api, the next thing you should do is to look trough the sourcecode (
          it is such a good part of documentation) to see how comparable methods have implemented this. You'll be surprised how simple it is. Just learn HQL.

          • 2. Re: how to retrieve task instance/process instances in a spe

            kukeltje,

            i feel a bit strange why cannot post the simple answer here instead of going through the source code.

            never mind, if no direct answer, of course, i will looking the source code.
            yang

            • 3. Re: how to retrieve task instance/process instances in a spe

              got it.

              hibernate.queries.hbm.xml file....

              Although it is not difficult, if i want to use only EJBs 2 and not the hibernate code in my application code (i prefer to keep the hibernate stuff under the cover of the jbpm api)., it is no direct way.

              • 4. Re: how to retrieve task instance/process instances in a spe

                Is the following code the correct way to retrieve the taskinstances for the specific tasknode name and task name?

                 private java.util.List getTaskInstance(String tasknodename, String taskname) throws Exception {
                 log.debug("getTaskInstance() is called");
                 log.debug("" + ctx.getCallerPrincipal().getName());
                 JbpmConfiguration config = null;
                 JbpmContext jbpmContext = null;
                 java.util.List list = null;
                 java.util.List list2 = new ArrayList();
                 try {
                 InitialContext ic = new InitialContext();
                 config = (JbpmConfiguration) ic
                 .lookup("java:/jbpm/JbpmConfiguration");
                 jbpmContext = config.createJbpmContext();
                 list = jbpmContext.getTaskMgmtSession().findPooledTaskInstances(ctx.getCallerPrincipal().getName());
                 for(Iterator iter=list.iterator();iter.hasNext();){
                 TaskInstance taskinstance =(TaskInstance) iter.next();
                 Task task = taskinstance.getTask();
                 if(task.getName()!=null &&task.getName().equals(taskname) && task.getTaskNode().getName().equals(tasknodename)){
                 list2.add(taskinstance);
                 }
                 }
                 log.debug("return task instance set size ="+list2.size());
                 } finally {
                 if (jbpmContext != null)
                 jbpmContext.close();
                 }
                 return list2;
                 }
                


                • 5. Re: how to retrieve task instance/process instances in a spe
                  kukeltje

                   

                  "yxyang" wrote:
                  kukeltje,

                  i feel a bit strange why cannot post the simple answer here instead of going through the source code.


                  since it is good documentation, you learn from it, I do not know everything (e.g. forgot that the queries were moved to the hibernate file instead of code), You might be interested in doing it in hql and donate the code so everybody can take advantage...


                  • 6. Re: how to retrieve task instance/process instances in a spe
                    olivier_debels

                    I think it is much cleaner to just add your own queries.

                    It's rather easy if you just do it the same way as it is done in jbpm. Just create your own extra queries file and make sure it is loaded in your hibernateSessionFactory (by adding it in your hibernate.cfg.xml).

                    By doing this you can extend the jbpm stuff with your own queries without the need to change anything to the internal queries or mappings.

                    Then you can write some classes which shield you from the hibernate usage. You could f.e. add a new service or provide your own implementation for an existing one (by putting it in your own jbpm.cfg.xml).

                    Hope this helps,

                    Olivier.

                    • 7. Re: how to retrieve task instance/process instances in a spe
                      kukeltje

                      And if you did it the same way as in jBPM, it would be easy to incoporate IN jbpm if everybody thinks it is interesting enough.

                      • 8. Re: how to retrieve task instance/process instances in a spe

                         

                        "Olivier_Debels" wrote:
                        I think it is much cleaner to just add your own queries.

                        It's rather easy if you just do it the same way as it is done in jbpm. Just create your own extra queries file and make sure it is loaded in your hibernateSessionFactory (by adding it in your hibernate.cfg.xml).

                        By doing this you can extend the jbpm stuff with your own queries without the need to change anything to the internal queries or mappings.


                        Yes. It is partially true. It is only needed to change the hibernate.cfg.xml to include something like:
                         <!-- hql queries and type defs -->
                         <mapping resource="org/jbpm/db/hibernate.queries.hbm.xml" />
                        



                        Then you can write some classes which shield you from the hibernate usage. You could f.e. add a new service or provide your own implementation for an existing one (by putting it in your own jbpm.cfg.xml).

                        I just don't understand how to add my own jbpm.cfg.xml file. If i do this, what will happen to the existing configuration items in the original jbpm.cfg.xml file? After going through the source code, i found that all the Sessions like GraphSession, TaskMgntSession etc are obtained from JbpmContext which use the DBPersistenceService. And DBPersistenceService hardcode these sessions there.

                        What i can do is to create my own class like XXXSessioin and initialize it manually because it cannot be availalbe from JbpmContext.

                        Is this right?

                        comments?

                        Yang




                        • 9. Re: how to retrieve task instance/process instances in a spe
                          olivier_debels

                           

                          Yes. It is partially true. It is only needed to change the hibernate.cfg.xml to include something like:


                          That's what I said. You need to create a hibernate.cfg.xml with an additional mapping to your own queries xml.


                          I just don't understand how to add my own jbpm.cfg.xml file. If i do this, what will happen to the existing configuration items in the original jbpm.cfg.xml file?


                          You can create your own configuration file (default name is "jbpm.cfg.xml" but you can specify another name if you want to in JbpmConfiguration.getInstance() call). This will overwrite the configurations in default.jbpm.cfg.xml. So you just need to add the configuration settings you would like to change in your configuration file.

                          After going through the source code, i found that all the Sessions like GraphSession, TaskMgntSession etc are obtained from JbpmContext which use the DBPersistenceService. And DBPersistenceService hardcode these sessions there.

                          What i can do is to create my own class like XXXSessioin and initialize it manually because it cannot be availalbe from JbpmContext.

                          Is this right?

                          comments?



                          You can create your own persistenceService and use this one by adding your own DbPersistenceServiceFactory in your configuration file. There you can do whatever your want. Best is to subclass the existing DbPersistenceService and start from there I guess.


                          Olivier