12 Replies Latest reply on Feb 11, 2010 6:03 PM by Ronald van Kuijk

    No public metadata API?

    Bill Burke Master

      I'm prototyping a new REST interface for jbpm for the REST-* effort.  One thing I've noticed is that there seems to be no public API to get information about a process definition or instance.

       

      For example, I'd like to be able to know the current state of an execution, and what outgoing transitions are able to be executed.  I figured out how to get this information at runtime, but it seems to be an "internal" api (its in a *.internal.* package).

       

      I also wanted to generate an XML document from a ProcessDefinition, but again, all metadata seems to be *very* hidden.  I had to really dive into the internals of jbpm to be able to get this information.

       

      Maybe I'm just missing something?

       

      Thanks.

        • 1. Re: No public metadata API?
          Mauricio Salatino Master

          Hi Bill,

          At least in jBPM 3.2.6 you can use the Command API to interact with jBPM. In that way you don't need to transport all the jBPM POJOs to the client (you just use primitive types and Strings.).

          I suppose that in jBPM 4 it's the same idea.

          Greetings.

          • 2. Re: No public metadata API?
            Sebastian Schneider Master

            Are you using jBPM 4.3 or jBPM 3.2? In jBPM 4.3 there is the ExecutionService. Using it you can retrieve process instances by their ids:

            {code}

            ProcessInstance processInstance = executionService.findProcessInstanceById(processInstanceId);

            {code}

             

            Afterwards you can use the following methods to retrieve some of the information you wanted:

            {code}

            processInstance.findActiveActivityNames();

            processInstance.getState();

            processInstance.getProcessDefinitionId():

            ..

            {code}

             

            HTH. If you could be a bit more specific on the data you want to retrieve we would be able to help more. Maybe it's something which is not possible through the API right now but would make sense and thus be useful to others, too. In this case: why not fill a JIRA issue after discussion?

            • 3. Re: No public metadata API?
              Sebastian Schneider Master
              Why the heck is the wiki markup syntax not working?
              • 4. Re: No public metadata API?
                Bill Burke Master
                Specific data?  I want a pointer to the current state and be able to find out what outgoing transitions are available.
                • 5. Re: No public metadata API?
                  Bill Burke Master
                  I'm using 4.3 FYI.  Also, again, i've been able to get at this information but only through "internal" apis.
                  • 6. Re: No public metadata API?
                    Joram Barrez Master

                    Outgoing/Incoming transitions are possible on trunk, so I guess this was added to the API just recentrly.

                     

                    To know which activities are currently active, you can use the operations on the ProcessInstance (findActiveActivities). Much of that kind of data can be retrieved through the query API (eg executionService.createProcessInstanceQuery).

                     

                    The XML itself is indeed not queryable through the 'official' API.

                    • 7. Re: No public metadata API?
                      Bill Burke Master

                      I guess I'm missing how to get an Activity plus how to get the transitions that are available out of the activity.  I don't currently see any query api to get this information within JBPM 4.3

                       

                      Currently I'm getting a "no environment to get org.jbpm.pvm.internal.session.RepositorySession" error when I do this:

                       

                            engine.getExecutionService().signalExecutionById(pid);
                            instance = engine.getExecutionService().findProcessInstanceById(pid);
                            ExecutionImpl execution = (ExecutionImpl)instance;
                            Activity current = execution.getActivity();

                       

                      getActivity() is throwing it.  What I want to get at runtime is the available transitions out of the current wait state.

                      • 8. Re: No public metadata API?
                        Bill Burke Master

                        Well, I got it to work doing this:

                         

                        import org.jbpm.pvm.internal.model.Activity;
                        import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
                        import org.jbpm.pvm.internal.model.Transition;

                         

                         

                        {...

                              if (instance.findActiveActivityNames().size() < 1) return;
                              String activityName = instance.findActiveActivityNames().iterator().next();

                         

                              ProcessDefinitionImpl pd = (ProcessDefinitionImpl)engine.getRepositoryService().createProcessDefinitionQuery().processDefinitionId(instance.getProcessDefinitionId()).uniqueResult();
                              Activity current = pd.findActivity(activityName);
                              for (Transition transition : current.getOutgoingTransitions())
                              {...}

                        }

                        • 9. Re: No public metadata API?
                          Ronald van Kuijk Master

                          Bill,

                           

                          If you want access to the internal 'model', cast the Execution to OpenExecution:

                           

                              OpenExecution e = (OpenExecution)processInstance.findActiveExecutionIn(activityName);
                              e.getActivity().getOutgoingTransitions();

                           

                          No need to use internal classes then. This still has to be added to the executionService. Getting transitions was only available for the taskService.

                           

                          Regarding creating xml from the definition, that is not needed:

                           

                              List<Deployment> dep = repositoryService.createDeploymentQuery().page(0, 10).list();
                             
                              for (Deployment deployment : dep) {
                               
                                Set<String> resources = repositoryService.getResourceNames(deployment.getId());
                                for (String resource : resources) {

                                  // e.g. test firstif the resourcename ends with .jpdl.xml

                                  InputStream is = repositoryService.getResourceAsStream(deployment.getId(),resource);
                                  ...
                                }
                              }
                             

                           

                          Cheers,

                           

                          Ronald

                          • 10. Re: No public metadata API?
                            Ronald van Kuijk Master
                            No, but it can be retrieved via the repository service, see my comment below.
                            • 11. Re: No public metadata API?
                              Bill Burke Master
                              Ronald.  This API is not in 4.3.  Not sure I want to be using trunk...
                              • 12. Re: No public metadata API?
                                Ronald van Kuijk Master

                                Sorry, should have indeed mentioned that this was trunk. 4.4 is to be released in 6 weeks I think, following the 3 month release cycle. So it's up to you.

                                 

                                I've been thinking about a rest interface to, more directly on jBPM. My thoughts were to even include in IN the project and just follow the methods of the services by annotating them.

                                 

                                Looking forward to your implementation.

                                 

                                Cheers,

                                 

                                Ronald