在jbpmm

时间:2016-03-28 18:26:10

标签: java drools jbpm bpmn

我正在研究jbpm示例,如下面的教程https://docs.jboss.org/jbpm/v5.3/userguide/ch.quickstarts.html#d0e1137但是我在set user变量中遇到问题脚本任务进程,所以我得到以下消息
    com / innvo / Process_com $ u46 $ innvo $ u46 $ u46 $ Drools_Work_Flow_Example421421234.java(16:701):用户无法解析为变量

 public static void main(String arg[]){

        User user=new User();
        user.setName("123123");
        user.setMail("456456");
        KieServices ks = KieServices.Factory.get();
        KieContainer kContainer = ks.getKieClasspathContainer();
        KieSession kSession = kContainer.newKieSession("ksession-process");
        Map<String, Object> params=new HashMap<String,Object>();
        params.put("user", user);
        kSession.startProcess("com.innvo", params);

  }

脚本任务代码打印用户

 System.out.println(user.getName());

bpmn代码

  <?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" 
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
xmlns:g="http://www.jboss.org/drools/flow/gpd"
xmlns:tns="http://www.jboss.org/drools" xmlns="http://www.jboss.org
/drools" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL
BPMN20.xsd http://www.jboss.org/drools drools.xsd http://www.bpsim.org
/schemas/1.0 bpsim.xsd" id="Definition" 
expressionLanguage="http://www.mvel.org/2.0" 
targetNamespace="http://www.jboss.org/drools" 
typeLanguage="http://www.java.com/javaTypes">
<bpmn2:process id="com.innvo.drools" tns:version="1" 
 tns:packageName="com.innvo.drools" tns:adHoc="false" name="Drools Work 
 Flow Example" isExecutable="true" processType="Private">
 <bpmn2:extensionElements>
    <tns:import name="org.kie.api.runtime.ObjectFilter"/>
  <tns:import name="java.util.ArrayList"/>
  <tns:import name="java.util.List"/>
  <tns:import name="com.innvo.domain.Score"/>
  <tns:import name="org.kie.api.runtime.rule.FactHandle"/>
  <tns:import name="com.innvo.drools.ScoreService"/>
 </bpmn2:extensionElements>
 <bpmn2:startEvent id="_1" name="">
  <bpmn2:outgoing>_1-_jbpm-unique-6</bpmn2:outgoing>
 </bpmn2:startEvent>
 <bpmn2:sequenceFlow id="_1-_jbpm-unique-6" tns:priority="1" name=""
 sourceRef="_1" targetRef="ScriptTask_1"/>
 <bpmn2:scriptTask id="ScriptTask_1" name="Script Task 1" 
 scriptFormat="http://www.java.com/java">
  <bpmn2:incoming>_1-_jbpm-unique-6</bpmn2:incoming>
  <bpmn2:outgoing>SequenceFlow_1</bpmn2:outgoing>
  <bpmn2:script>kcontext.setVariable(&quot;scoreRouteRulefile&quot;,
  &quot;scoreRouteRulefile&quot;);
  System.out.println(scoreRouteRulefile);</bpmn2:script>
 </bpmn2:scriptTask>
 <bpmn2:sequenceFlow id="SequenceFlow_1" tns:priority="1" name=""
 sourceRef="ScriptTask_1" targetRef="_jbpm-unique-6"/>
<bpmn2:endEvent id="_3" name="">
  <bpmn2:incoming>SequenceFlow_2</bpmn2:incoming>
  <bpmn2:terminateEventDefinition id="TerminateEventDefinition_1"/>
</bpmn2:endEvent>
<bpmn2:businessRuleTask id="_jbpm-unique-6" tns:ruleFlowGroup="" 
 g:ruleFlowGroup="Group1" name="rule">
  <bpmn2:incoming>SequenceFlow_1</bpmn2:incoming>
  <bpmn2:outgoing>SequenceFlow_2</bpmn2:outgoing>
  <bpmn2:ioSpecification id="InputOutputSpecification_1">
    <bpmn2:inputSet id="InputSet_1"/>
    <bpmn2:outputSet id="OutputSet_1"/>
  </bpmn2:ioSpecification>
</bpmn2:businessRuleTask>
<bpmn2:sequenceFlow id="SequenceFlow_2" tns:priority="1" name=""
   sourceRef="_jbpm-unique-6" targetRef="_3"/>
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_Process_1" bpmnElement="com.innvo.drools">
  <bpmndi:BPMNShape id="BPMNShape_StartEvent_1" bpmnElement="_1">
    <dc:Bounds height="48.0" width="48.0" x="75.0" y="133.0"/>
  </bpmndi:BPMNShape>
  <bpmndi:BPMNShape id="BPMNShape_EndEvent_1" bpmnElement="_3">
    <dc:Bounds height="48.0" width="48.0" x="590.0" y="133.0"/>
  </bpmndi:BPMNShape>
  <bpmndi:BPMNShape id="BPMNShape_ScriptTask_1"
       bpmnElement="ScriptTask_1">
    <dc:Bounds height="50.0" width="110.0" x="220.0" y="132.0"/>
  </bpmndi:BPMNShape>
  <bpmndi:BPMNShape id="BPMNShape_BusinessRuleTask_1" bpmnElement="_jbpm-
       unique-6">
    <dc:Bounds height="48.0" width="80.0" x="420.0" y="133.0"/>
  </bpmndi:BPMNShape>
  <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_2" bpmnElement="_1-_jbpm-
   unique-6" sourceElement="BPMNShape_StartEvent_1" 
     targetElement="BPMNShape_ScriptTask_1">
    <di:waypoint xsi:type="dc:Point" x="123.0" y="157.0"/>
    <di:waypoint xsi:type="dc:Point" x="216.0" y="157.0"/>
    <di:waypoint xsi:type="dc:Point" x="216.0" y="157.0"/>
    <di:waypoint xsi:type="dc:Point" x="220.0" y="157.0"/>
  </bpmndi:BPMNEdge>
  <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_3" 
  bpmnElement="SequenceFlow_1" sourceElement="BPMNShape_ScriptTask_1"
     targetElement="BPMNShape_BusinessRuleTask_1">
    <di:waypoint xsi:type="dc:Point" x="330.0" y="157.0"/>
    <di:waypoint xsi:type="dc:Point" x="406.0" y="157.0"/>
    <di:waypoint xsi:type="dc:Point" x="406.0" y="157.0"/>
    <di:waypoint xsi:type="dc:Point" x="420.0" y="157.0"/>
  </bpmndi:BPMNEdge>
  <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_4" 
 bpmnElement="SequenceFlow_2"  
    sourceElement="BPMNShape_BusinessRuleTask_1"  
      targetElement="BPMNShape_EndEvent_1">
    <di:waypoint xsi:type="dc:Point" x="500.0" y="157.0"/>
    <di:waypoint xsi:type="dc:Point" x="570.0" y="157.0"/>
    <di:waypoint xsi:type="dc:Point" x="570.0" y="157.0"/>
    <di:waypoint xsi:type="dc:Point" x="590.0" y="157.0"/>
  </bpmndi:BPMNEdge>
 </bpmndi:BPMNPlane>
 </bpmndi:BPMNDiagram>
</bpmn2:definitions>

1 个答案:

答案 0 :(得分:1)

(即使您的流程定义使用User),我也会在我的回复中使用userscoreRouteRulefile

据我所知,您的流程中没有使用名称user和类型User定义的变量。启动流程实例时发送参数不会自动将它们设置为流程变量。 您需要做的是在进程中添加一个变量,其名称与参数user的键名称相同,并且与您传递的对象类型相同(User)。 如果您在jbpm-designer中工作,请单击该过程的背景并转到属性选项板。在那里,您将找到一个属性,它是流程'变量的定义。

希望它有所帮助,