1
votes

I have a code, where I am inserting some parameters within the process(Jbpm) and then starting the process and also I am adding an EventListener(which extends DefaultProcessEventListener) to the knowledge session

KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); 

Map<String, Object> input = new HashMap<String, Object>();
input.put("payload", payloadObject);
input.put("caseNo", caseNoString);

EventListner listner = new EventListner();
ksession.addEventListener(listner);
ksession.startProcess(strategyName,input);

Now I want the input map within the Listner class

public class EventListner extends DefaultProcessEventListener{

@Override
public void afterProcessStarted(ProcessStartedEvent startEvent) {
    //NEEDED HERE
}

@Override
public void afterProcessCompleted(ProcessCompletedEvent arg0) {
    //NEEDED HERE
}

How...??? Need help

1

1 Answers

0
votes

I just happened to be working on this same problem. Here is my code that I got working

public void afterNodeLeft(ProcessNodeLeftEvent event) {
    RuleFlowProcessInstance rfpi = (RuleFlowProcessInstance)event.getProcessInstance();
    RuleFlowProcess rfp = rfpi.getRuleFlowProcess();
    VariableScope scope = rfp.getVariableScope();
    for(Variable var : scope.getVariables()) {
        Object obj = rfpi.getVariable(var.getName());
        String value = null;
        if (obj != null) {
            value = obj.toString();
        }
        System.out.printf("\tVariable name: %s, Value: %s%n",var.getName(),value);
    }
}

I found that if you try to access the variables directly through process the result is always null. Accessing process variables through the ProcessInstance appears to work.