14 Replies Latest reply on May 11, 2007 11:26 AM by s b

    how list processes?

    s b Newbie

      If you have a workflow process definition and create multiple instances of the process, is there a way to get a list of all the processes that you have started?

      Let's say we have a method to start processes as follows, with a static jbpmConfiguration member visible somewhere and using hibernate for persistence:

      public long startProcess(String orgNumber, String suborgNumber) throws RMSException{
       long processID = -1;
       log.info("Entering startEfileDestructionProcess");
      
       //Check if the jbpmConfiguration has been setup
       if( jbpmConfiguration == null ){
       //retrieve it
       log.info("JBPMConfiguration was null, creating instance.");
       jbpmConfiguration = JbpmConfiguration.getInstance();
       }
      
       //Doing a try and catch for all so the RMSException can contain the relevant info
       // Lookup the pojo persistence context-builder that is configured above
       JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
       log.info("Retrieved jbpmContext.");
       try {
      
      
       //GraphSession graphSession = jbpmContext.getGraphSession();
      
       //ProcessDefinition processDefinition =
       log.info("Creating process");
      
       // With the processDefinition that we retrieved from the database, we
       // can create an execution of the process definition just like in the
       // hello world example (which was without persistence).
       ProcessInstance processInstance = jbpmContext.newProcessInstance("JBPMEfileProcess");
       log.info("Created process");
       processID = processInstance.getId();
       log.info("ProcessID is ["+processID+"]");
      
       //Set the key variables
       processInstance.getContextInstance().createVariable("OrgNumber",orgNumber);
      
       log.info("Set Org Number");
       processInstance.getContextInstance().createVariable("SubOrgNumber",suborgNumber);
       log.info("Set SubOrg Number");
      
       // Now the processInstance is saved in the database. So the
       // current state of the execution of the process is stored in the
       // database.
       //Connection myConnect = jbpmContext.getConnection();
       //PreparedStatement myStatement = myConnect.prepareStatement("SET IDENTITY_INSERT JBPM_PROCESSINSTANCE OFF");
       //myStatement.execute();
       //myStatement.close();
       processInstance.signal();
       jbpmContext.save(processInstance);
       log.info("Saved New Process");
       }catch(Exception e){
       String message = "Error creating new RMS process["+e.getMessage()+"]";
       e.printStackTrace();
       throw new RMSException(1,message);
       }
       finally {
       // Tear down the pojo persistence context.
       jbpmContext.close();
       }
      
       log.info("Exiting startEfileDestructionProcess, created processID["+processID+"]");
       return processID;
       }
      


      Is there a way to get a list of all the processes, short of saving the process ids myself somewhere?

        • 1. Re: how list processes?
          Ronald van Kuijk Master

           

          "simonbaker" wrote:
          If you have a workflow process definition and create multiple instances of the process, is there a way to get a list of all the processes that you have started?


          No, you have to write your own hibernate query for this.

          "simonbaker" wrote:
          Is there a way to get a list of all the processes, short of saving the process ids myself somewhere?


          All instances of a process or all processes definitions?

          • 2. Re: how list processes?
            s b Newbie

            It is all process instances we are interested in. The reason is that users (actors) may participate in several instances of the same workflow process. Imagine a manager who approves insurance policies for several departments, and there is a separate policy underwriting workflow process for each department. We'd like to get all the tasks for the manager. Our thought is to iterate over all process instances and get any tasks for the manager in any of the processes so the manager can complete the tasks.

            • 3. Re: how list processes?
              Ronald van Kuijk Master

              please be explicit. You state 2 things:
              - all processinstances
              - all tasks of the manager

              For you they seam related because of your last statement.

              And you know what.... (sorry, an aggravated answer again) this is the default behaviour of jbpm. When you get the tasklist by actor. All tasks of the actor of all processinstances

              • 4. Re: how list processes?
                s b Newbie

                 

                "kukeltje" wrote:
                please be explicit. You state 2 things:
                - all processinstances
                - all tasks of the manager

                For you they seam related because of your last statement.

                And you know what.... (sorry, an aggravated answer again) this is the default behaviour of jbpm. When you get the tasklist by actor. All tasks of the actor of all processinstances


                You're right, I don't "get" JBPM yet. Haven't figured out "scoping" of objects at runtime, such as actor ids -- are they visible across process definitions, across JbpmContexts, across JbpmConfigurations, just plain global, etc. Lots of questions, lots of code to read.

                • 5. Re: how list processes?
                  Jean-Louis Rastapoc Newbie

                  Too much code to read I would say. jBPM is really poorly documented and NO : code isn't documentation!

                  Yesterday I spend the day making some scenario to work. I would have spend only half an hour if there was some good documentation and less code reading.

                  I'm currently trying to find a good workflow solution and jBPM seems to be great... but ... I don't think I will go for it because of documentation.

                  I'm still an intern here and I'm not sure if I'll stay here for a long time... so I got 2 choice right now :
                  - spend a lot of time writing a documentation,
                  - take another well-documented solution and spend my time really using it.

                  In the first place I tried jBPM because of the community that seemed to be great but in fact there is something like... only kukeltje in here (thanks btw ;) Yes he helps A LOT but he can't solve everybody's problems.

                  Hey developpers! I know coding is fun and writing documentation is boring but since you want to get people to use your product you don't have the choice...

                  PS : sorry for my english and for the thread deviation

                  PPS : I wonder if some developer will ever have the time to read that :/

                  • 6. Re: how list processes?
                    Ronald van Kuijk Master

                    The code of the core is partly documentation, but the testcases are great documentation. Realy simple isolated examples of how to use the api and great in combination with the javadocs. I've worked with several engine and the testcases of jBPM helped me more than thick fat pdf documents of other suppliers. (and a lot more than 1 day to get something running)

                    Besides that and without wanting to offend you, we get 2 types of feedback on the docs/engine: It's really sufficient and it s*cks. From my experience with both types of responses, the former is from people who read the docs to some extend, use the javadocs, experiment a little and 'get' it. The latter is from people who do not get it. Either because the think in/come from a really different direction, do not know java are lazy (not saying you are) or any other 'cause'.

                    Your question e.g. on how to get all tasks for a user for all running processes is a question I would normally not answer, simply because it is the default behaviour cases you could have seen that.

                    About the number of users in the forum. Yes, I have a lot of posts, but often I consult core developers and more and more other users kick in, Ed, Bernd, Martin (an eager JBoss/redhat employee) etc... (don't shoot if I forgot someone). And for the basic newbie stuff, lots of user already help each other out.





                    • 7. Re: how list processes?
                      Edward Staub Expert

                      Ronald,

                      I'm afraid I don't fit in either camp.
                      I think the doc is pretty badly inadequate.

                      Because of the problems with the search engine, and the problems inherent in trying to use text to search for a concept that others may have expressed differently, I don't think "STFF" is warranted nearly as often as you do. The fact that the same questions keep coming in should be a hint, not that the users clueless and/or lazy, but that the info should be out there in a more accessible format.

                      I think the same thing about the products of my own company, so maybe I'm just a crazy-for-docs kind of guy.

                      -Ed Staub

                      • 8. Re: how list processes?
                        Ronald van Kuijk Master

                        STFF can also be done by using google... works a lot better, but that is another item and I agree that searching the forum with the 'forum-search' is inadequate.

                        but again, the doc is more that the html, the examples/testcases (yes, in the source) are really expressive.

                        Could be that you fit in neither camp, but you (at least) did not come up with a question like the one this post started with. For more complex issues the docs are (atm) not sufficient, nor are the examples/testcases. Michael Putz however is doing a great job in adding wiki pages on more complex things so we are improving in that area as well. And I never said or even thought we were doing a great job on the docs, just that they are (just like bpm in general) not for just anyone to be used.

                        • 9. Re: how list processes?
                          s b Newbie

                          Where is this so-called "default behavior" documented?

                          How would someone know what the scope of getTaskList() is from the documentation? Global to what? Processes, contexts, configurations? Where is there a good explanation of the concept of "JbpmContext" for instance?

                          Also, the docs don't even say what kind of object you get a list of, I mean, that is a minimum requirement of documentation. Start looking at the code and you drill eventually down to a hibernate "query.list()" and you're really deep in the weeds. One layer uses the name "getTaskList(..)", a layer down uses "getTaskInstances(..)". I guess I should believe the name "getTaskInstances" implies I'll get back a list of TaskInstance objects, but it isn't determined by reading a few layers of code.

                          • 10. Re: how list processes?
                            Edward Staub Expert

                            Simon,

                            I've had the same experience - eventually drilling all the way down to the hibernate query to figure out what I was going to get from this frequently-used call or one similar to it (I don't remember). It would be another matter if we were talking about infrequently-used methods, but this is mainstream stuff.

                            -Ed Staub

                            • 11. Re: how list processes?
                              Ronald van Kuijk Master

                              The api docs of JbpmContext.getTaskList() state:

                              fetches the tasklist for the current authenticated actor.


                              So there is no word about a processcontext or whatever, it is on the jBPM context, so for me that is all tasks of all processes.

                              • 12. Re: how list processes?
                                s b Newbie

                                 

                                "kukeltje" wrote:
                                The api docs of JbpmContext.getTaskList() state:

                                fetches the tasklist for the current authenticated actor.


                                So there is no word about a processcontext or whatever, it is on the jBPM context, so for me that is all tasks of all processes.


                                This kind of dialog is helpful.

                                My other question was: how do you know what object type is in the list returned by getTaskList()?

                                ----------------------------- General Discussion ------------------------
                                I'm going to state some stuff, probably wrong, and welcome corrections in the spirit of a dialog to help understand the concepts behind jBPM.

                                What is hard for me to grasp from browsing the API is the scoping and role of objects such as process definitions, process instances, tasks, task instances, even JbpmConfigurations and JbpmContexts.

                                It seems a JbpmConfiguration determines which "services" are used when a JbpmContext instance is created. This includes the "persistance service". I can imagine that someone could develop a persistance service that uses more than one database, so there is no assumption that a JbpmConfiguration is mapped to a particular database. But I think a JbpmConfiguration is mapped to a single persistance service.

                                The JbpmContext instance is created from a particular JbpmConfiguration instance, and exposes "some services" for use in the workflow processing. I see that we can create a JbpmContext with a name as well, by using
                                JbpmConfiguration.createJbpmContext(java.lang.String name)
                                -- what does that mean? Can transactions in JbpmContexts with different names occur simultaneously (without conflict).

                                A service of great interest is the "persistance" service, which theoretically should be abstract so we never should need to know how it works and we should never need to access a database directly, etc. The JbpmContext instance magically seems to create a transaction encompassing the various "instance" objects that we create with the JbpmContext instance object and interact with (ProcessInstance, TaskInstance, etc.). A JbpmContext instance seems to be related to a concept called a "session", which implies some kind of connection and related transaction processing ability.

                                I think the confusion I have is thinking that JbpmConfigurations and JbpmContexts are somehow containers for workflow objects, but they are not. The objects exist in the persistance system (typically a database), and I guess it would be possible for different JbpmConfigurations to provide services that access the same objects.

                                So there is no real "container" for workflow objects at the API level, you can access them by name and/or Id, although the persistance layer is probably intended to serve as a container. I'm not saying I'd want to do this, but theoretically I could configure two different persistance mechanisms to access the same database using the same table names and other conventions. Then I could create two different JbpmConfiguration objects based on these two different services. I could use one configuration and a JbpmContext instance to deploy a ProcessDefinition and create a new ProcessInstance. I could (maybe) then use the second configuration and a JbpmContext instance to retrieve that ProcessInstance by Id and work with it.

                                Or could I? That is a question. Does a JbpmContext know whether a ProcessDefinition has been deployed by JbpmContext created from the same or different JbpmConfiguration? Or does it matter? In other words, is there any real containership implied by a JbpmConfiguration?

                                Normally I would think that if I deploy a ProcessDefinition with a particular JbpmConfiguration (using a JbpmContext created from that JbpmConfiguration), then I could only access that ProcessDefinition or instances of it using a JbpmContext created from the same JbpmConfiguration -- but I'm not sure.

                                Ok, that's as far as I can get with this. I'd like to hear others' understanding of the jBPM concepts.





                                • 13. Re: how list processes?
                                  Ronald van Kuijk Master

                                  Simon,

                                  I'd like to follow up on this, but would you want to start a new topic for this with a sujbject like 'general concepts' or something like this. That way if the search works better people can find this new 'interesting' thread.

                                  • 14. Re: how list processes?
                                    s b Newbie

                                     

                                    "kukeltje" wrote:
                                    Simon,

                                    I'd like to follow up on this, but would you want to start a new topic for this with a sujbject like 'general concepts' or something like this. That way if the search works better people can find this new 'interesting' thread.


                                    Sure, if it's OK I'll just use the previous message to start the thread.

                                    On the topic of this thread, how would you determine the type of object returned in the List of getThreadList()? I traced it down to a hibernate call, "query.list()", how much further do you need to go?