AnsweredAssumed Answered

can't access to bpm_package childrens in a ExecutionListener

Question asked by jpmerlin on Nov 5, 2014
Latest reply on Nov 5, 2014 by jpmerlin
Hi,

I'm with Alfresco community 4.2.c and activiti 5.10-alf.20121114.

I have a problem when i want to access to bpm_package content in a executionListener.
I've got a NPE on org.alfresco.repo.jscript.ScriptNode.getChildren() function.
I have not this problem with a taskListener.

Here is a simple process for test :


<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="myProcess" name="My process" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="endevent1">
      <extensionElements>
        <activiti:executionListener event="take" class="fr.rsi.whi.bpm.taskListener.TestExecutionListener"></activiti:executionListener>
      </extensionElements>
    </sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
    <bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="80.0" y="150.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="220.0" y="150.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="115.0" y="167.0"></omgdi:waypoint>
        <omgdi:waypoint x="220.0" y="167.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>


Here is my ExecutionListener :


public class TestExecutionListener implements ExecutionListener {
   
   private static Log logger = LogFactory.getLog(TestExecutionListener.class);
   
   @Override
   public void notify(DelegateExecution execution) throws Exception {
      ActivitiScriptNode  bpm_package = (ActivitiScriptNode) execution.getVariable("bpm_package");
      if (bpm_package == null){
         logger.error("le bpm_package is null");
      } else {
      Scriptable childrens = bpm_package.getChildren();
      if (childrens == null){
         logger.error(" bpm_package.getChildren() is null");
      }else {
         
         ScriptNode firstChild = (ScriptNode) childrens.get(0, null);
      
         String noderef = firstChild.getStoreType()+"://"+firstChild.getStoreId()+"/"+firstChild.getId();
         logger.error("Noderef first child : " + noderef);
      }

   }

   }
}


Here is the stacktrace :


Caused by: java.lang.NullPointerException
        at org.mozilla.javascript.ScriptableObject.getTopLevelScope(ScriptableObject.java:1483)
        at org.mozilla.javascript.ScriptRuntime.setObjectProtoAndParent(ScriptRuntime.java:3106)
        at org.mozilla.javascript.Context.newArray(Context.java:1547)
        at org.alfresco.repo.jscript.ScriptNode.getChildren(ScriptNode.java:439)
        at fr.rsi.whi.bpm.taskListener.TestExecutionListener.notify(TestExecutionListener.java:21)


Outcomes