3 Replies Latest reply on Oct 9, 2009 9:18 AM by shiva0

    Accessing the current task of a ProcessInstance and/or his s

    shiva0 Newbie

      So, I'm slowly starting to get the feel of the jbpm engine.

      But I've hit a brick wall... well found a bypass but let's start at the beggining.

      One process contains multiple subprocesses.
      I need to be able to fetch the list of all tasks associated to the "Master ProcessInstance". I've tried going thru the Execution query but I could never find how I can start from my ProcessInstance and access the sub-process execution without knowing it's specific ID.

      Until I started looking at the ExecutionImpl binding with the database. There is a getSubProcessInstance() method that is not available on the Execution interface.

      I could just cast and access it, but is there probably a reason it's not made available. So, how can I do what I need without that casting patch?

        • 1. Re: Accessing the current task of a ProcessInstance and/or h
          newcomer1 Newbie

          Have you found a solution for this? We are have the same use case were we have a process with a lot of subprocesses that create several tasks and we need a simple way to query for all the tasks for the process including tasks generated by its subprocesses. The interfaces have some limitations and we have seen the need to create our own custom repositories that works over the jbpm tables for some of these queries using oracle specific features to do queries over tree structures.

          jBPM seems very configurable and I think many projects will need to extend the basic service interfaces and the out of box query support using their own commands and extensions. The service interfaces cover the basic and most used features and I can understand that the jBPM development team wants to keep them slim.

          You could create a custom command, but for me it seems like you will not come away from a downcast if you for example need to create custom queries using the hibernate critereia api.

          • 2. Re: Accessing the current task of a ProcessInstance and/or h
            Adolf Grazou Newbie

            I would try :

            List<Task> currentTasks = yourProcessEngine.getTaskService()
            .createTaskQuery()
            .processInstanceId(yourProcessInstanceId)
            .list()


            You can also add various filters and/or order them by Name/ Priority, etc ...

            (http://docs.jboss.com/jbpm/v4/javadocs/)

            If you want all the subprocesses, you could also look at the following methods in org.jbpm.api.Execution
            getExecutions()
            findActiveActivityNames()
            getExecutionsMap()
            


            hope this helps.

            • 3. Re: Accessing the current task of a ProcessInstance and/or h
              shiva0 Newbie

              The TaskQuery won't let search by Parent ProcessInstance.

              getActiveActivityNames return the name of the active subprocess but not the ID. So it's useless for querying with TaskQuery.

              getExecutions() on the Parent ProcessInstance return empty since the execution is in the sub-process

              And I havn't checked the ExecutionsMap but should be the same as Executions I guess.

              So I'll keep the cast to ExcecutionImpl for now I guess...

              ---

              I encountered the same problem with the History. TaskHistory and ActivityHistory doesn't keep their parent / child relationship. Since the relationship is lost, there is no way to know which sub-process task is related to the parent ProcessInstance. The database keep no track of that information. Kinda bad, guess I'll have to keep a relationship table on the side.