2 Replies Latest reply on Nov 6, 2014 2:44 AM by akoskm

    Manually triggering a WorkItem instance after restoring the runtime

    akoskm Newbie

      My goal is to trigger the WorkItem instance what was executing when I shut down the engine.

       

      I was ablo to retrieve the node that is currently executing, using GenericCommand like this:

       

      WorkItem workItem = appSess.getKsession().execute(new GenericCommand<WorkItem>() {
      
          @Override
          public WorkItem execute(Context context) {
              KieSession ksession = ((KnowledgeCommandContext) context).getKieSession();
              WorkflowProcessInstance pi = (WorkflowProcessInstance) ksession.getProcessInstance(appSess.getProcessInstanceId());
              if (pi != null) {
                  Collection<NodeInstance> nodes = pi.getNodeInstances();
                  try {
                      NodeInstance nodeInstance = nodes.iterator().next();
                      WorkItemNodeInstance workItemNodeInstance = (WorkItemNodeInstance) nodeInstance;
                      WorkItem workItem = workItemNodeInstance.getWorkItem();
                      return workItem;
                  } catch (NoSuchElementException nsee) {
                      /**
                       * this is about retrieving the currently active
                       * node. if it fails the process is probably
                       * isn't working but the execution status
                       * remained active for some reason. This makes
                       * the client to check for the currently active
                       * node constantly.
                       */
                  }
              }
              return null;
          }
      });
      

       

      now I have access to the WorkItem instance, my question is, how to tell the workItemManager to execute this workItem.

      What I tried is to call the internalExecuteWorkItem function of the WorkItemManager:

       

      WorkItemManager wiManager = (WorkItemManager) appSess.getKsession().getWorkItemManager();
      wiManager.internalExecuteWorkItem(workItem);
      

       

      but this throws

       

      Exception in thread "main" java.lang.UnsupportedOperationException
      

       

      Any ideas how I can achieve this?