2 Replies Latest reply on Aug 10, 2015 7:58 PM by NIch Overend

    Trying to complete a workitem from a separate global listener, jBpm 6.2

    NIch Overend Newbie

      I have a requirement to be able to complete a work item from a separate global listener.

       

      I have been able to get most of this working, by creating a custom WorkItem which talks to my service, and by creating a listener, currently by implementing a singleton on top of ProcessEventListener although since this listener should be global and not bound to a particular process, I'm sure there is probably a more suitable choice.

       

      All of this works, until I actually try to complete the work item.

       

      I was trying via creating a CompletWorkItemCommand and endevouring to execute this, but I'm assuming that I wasn't getting the right KSession, or something like that as it was just failing to do anything, but not producing an error.

       

      Reading a little more, it appears that injecting ProcessService is probably the most recommended way of doing this, but I cannot currently get *any* service injected.

       

      Within my class I am using the following:

       

      @Inject
      private DeploymentService deploymentService;
      @Inject
      private RuntimeDataService dataService;
      @Inject
      private ProcessService processService;

       

      but all three variables remain null.

       

      I am using the Kie Workbench to run my application, so I am not doing any particular setup except to register my class as a listener in the DeploymentDescriptor through the UI.

       

      Can someone provide me with some information on the necessary steps to make this work, or an alternate approach if I'm going the wrong way.

       

      I should also mention, that I'm just getting up to speed with Java too, as I've been writing C# for the last decade, so please assume I know nothing, which is probably the case.

       

      Thanks!

       

       

      Nich

        • 1. Re: Trying to complete a workitem from a separate global listener, jBpm 6.2
          NIch Overend Newbie

          For completeness, the code I'm currently using, which doesn't work is:

           

          long workItemId = (long)commandMap.get("_workItemId");
          CompleteWorkItemCommand completeCommand = new CompleteWorkItemCommand(workItemId, commandMap);
          KieServices kieServices = KieServices.Factory.get();
          KieContainer kContainer = kieServices.getKieClasspathContainer();
          KieSession kSession = kContainer.newKieSession();
          WorkItemManager workItemManager = kSession.getWorkItemManager();
          workItemManager.completeWorkItem(workItemId, commandMap);
          logger.info("Execute Complete");
          kSession.dispose();

           

          This executes with no errors, but the process instance is not moved on, and stays halted where it was.

          • 2. Re: Trying to complete a workitem from a separate global listener, jBpm 6.2
            NIch Overend Newbie

            Having tried a variety of methods... The only one that seems to work is:

             

                    RuntimeManager manager = RuntimeManagerRegistry.get().getManager(deploymentId);       

                    RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());

                    KieSession kSession = engine.getKieSession();

            WorkItemManager workItemManager = kSession.getWorkItemManager();
            workItemManager.completeWorkItem(workItemId, commandMap);

             

            Is this legit? Or is there a better way? Using 6.2.0.Final.


            Thanks!