繁体   English   中英

Jbpm-Java:使用进程访问对象并在这些对象上调用方法

[英]Jbpm - Java : Accessing objects withing process and calling methods on these objects

我是Jbpm的新手,当前正在构建贷款申请,我的个人类具有贷款金额。

我正在使用Map in Process将Person对象作为参数传递,如下所示:

KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
        kBuilder.add(ResourceFactory.newClassPathResource("bpmn/sampleProcess.bpmn"),ResourceType.BPMN2 );

        KieBase kBase = kBuilder.newKnowledgeBase();

        KieSession kSession = kBase.newKieSession();

        // PROCESS PARAMETERS ::: Process Level Variables with Process Scope
        Map<String,Object> params = new HashMap<>();

        //Creating a Person who applies to loan.
        Person p = new Person();
        p.setName("Ayushya K Devmurari");
        p.setUniqueId("A007");
        p.setLoanAmmount(5_00_000.00);
        p.setIncome(2_40_000.00);

        // setting parameter in Map
        params.put("Applicant1", p);

        //Starting the process.
        kSession.startProcess("com.discusit.loanapplication", params);       

        kSession.dispose();

这是我的流程图的链接:

http://tinypic.com/view.php?pic=2pza22o&s=5

我可以在启动脚本中访问人员对象,代码如下:

System.out.println("Person is :::"+kcontext.getVariable("Applicant1"));

问题是,每当我尝试在此对象上调用任何方法/尝试将其强制转换为Person时,都会引发如下错误:

Exception in thread "main" java.lang.IllegalArgumentException: Could not parse knowledge.
    at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.newKnowledgeBase(KnowledgeBuilderImpl.java:79)
    at com.discusit.loanapplication.main.MainClass.main(MainClass.java:23)

这是我的.bpmn文件:

<?xml version="1.0" encoding="UTF-8"?> 
<definitions id="Definition"
             targetNamespace="http://www.jboss.org/drools"
             typeLanguage="http://www.java.com/javaTypes"
             expressionLanguage="http://www.mvel.org/2.0"
             xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"
             xmlns:g="http://www.jboss.org/drools/flow/gpd"
             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:tns="http://www.jboss.org/drools">

  <itemDefinition id="_personItem" structureRef="Person" />
  <itemDefinition id="_amountItem" structureRef="Float" />

  <process processType="Private" isExecutable="true" id="com.discusit.loanapplication" name="Sample Process" tns:packageName="defaultPackage" >

    <!-- process variables -->
    <property id="person" itemSubjectRef="_personItem"/>
    <property id="amount" itemSubjectRef="_amountItem"/>

    <!-- nodes -->
    <startEvent id="_1"  isInterrupting="true"/>
    <endEvent id="_16" name="End" >
        <terminateEventDefinition />
    </endEvent>
    <exclusiveGateway id="_3" name="Gateway" gatewayDirection="Diverging" />
    <scriptTask id="_18" name="Starting" scriptFormat="http://www.java.com/java" >
      <script>System.out.println("Process initialization...");
System.out.println("Person Object "+kcontext.getVariable("Applicant1"));
</script>
    </scriptTask>
    <scriptTask id="_4" name="Low Amount" scriptFormat="http://www.java.com/java" >
      <script>

System.out.println("Amount is Low :::::::");
</script>
    </scriptTask>
    <scriptTask id="_5" name="Medium Amount" scriptFormat="http://www.java.com/java" >
      <script>System.out.println("Amount is medium :::::");
</script>
    </scriptTask>
    <scriptTask id="_6" name="High Amount" scriptFormat="http://www.java.com/java" >
      <script>System.out.println("Amount is HIGH :::::::::");</script>
    </scriptTask>
    <parallelGateway id="_22" name="Gateway" gatewayDirection="Converging" />

    <!-- connections -->
    <sequenceFlow id="_22-_16" sourceRef="_22" targetRef="_16" />
    <sequenceFlow id="_18-_3" sourceRef="_18" targetRef="_3" />
    <sequenceFlow id="_1-_18" sourceRef="_1" targetRef="_18" />
    <sequenceFlow id="_3-_4" sourceRef="_3" targetRef="_4" name="low" tns:priority="1" >
      <conditionExpression xsi:type="tFormalExpression" language="http://www.java.com/java" >return false;</conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="_3-_5" sourceRef="_3" targetRef="_5" name="medium" tns:priority="1" >
      <conditionExpression xsi:type="tFormalExpression" language="http://www.java.com/java" >return false;</conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="_3-_6" sourceRef="_3" targetRef="_6" name="high" tns:priority="1" >
      <conditionExpression xsi:type="tFormalExpression" language="http://www.java.com/java" >return true;</conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="_5-_22" sourceRef="_5" targetRef="_22" />
    <sequenceFlow id="_6-_22" sourceRef="_6" targetRef="_22" />
    <sequenceFlow id="_4-_22" sourceRef="_4" targetRef="_22" />

  </process>

  <bpmndi:BPMNDiagram>
    <bpmndi:BPMNPlane bpmnElement="com.discusit.loanapplication" >
      <bpmndi:BPMNShape bpmnElement="_1" >
        <dc:Bounds x="265" y="57" width="48" height="48" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_16" >
        <dc:Bounds x="265" y="558" width="48" height="48" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_3" >
        <dc:Bounds x="263" y="223" width="48" height="48" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_18" >
        <dc:Bounds x="248" y="134" width="80" height="48" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_4" >
        <dc:Bounds x="21" y="356" width="132" height="48" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_5" >
        <dc:Bounds x="217" y="355" width="142" height="48" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_6" >
        <dc:Bounds x="475" y="346" width="132" height="48" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_22" >
        <dc:Bounds x="264" y="462" width="48" height="48" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="_22-_16" >
        <di:waypoint x="288" y="486" />
        <di:waypoint x="289" y="582" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_18-_3" >
        <di:waypoint x="288" y="158" />
        <di:waypoint x="287" y="247" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_1-_18" >
        <di:waypoint x="289" y="81" />
        <di:waypoint x="288" y="158" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_3-_4" >
        <di:waypoint x="287" y="247" />
        <di:waypoint x="87" y="380" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_3-_5" >
        <di:waypoint x="287" y="247" />
        <di:waypoint x="288" y="379" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_3-_6" >
        <di:waypoint x="287" y="247" />
        <di:waypoint x="541" y="370" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_5-_22" >
        <di:waypoint x="288" y="379" />
        <di:waypoint x="288" y="486" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_6-_22" >
        <di:waypoint x="541" y="370" />
        <di:waypoint x="288" y="486" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_4-_22" >
        <di:waypoint x="87" y="380" />
        <di:waypoint x="288" y="486" />
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>

</definitions>

我想要做的是访问“分歧网关”上“人”对象内的loanAmount,以对贷款类型进行分类。 谁能帮我? 我哪里出错了,我找不到它,谢谢。

从理论上讲,您应该能够查看有关编译期间出了什么问题的更多信息(在控制台中或更早的堆栈跟踪中)。 如果没有,请使用kbuilder.getErrors()获得更多详细信息。

快速浏览一下过程使我想知道您是否不应该为Person类等使用完全限定的名称(包括软件包)?

克里斯

这:线程“主”中的异常java.lang.IllegalArgumentException:无法解析知识。 在org.drools.compiler.builder.impl.KnowledgeBuilderImpl.newKnowledgeBase(KnowledgeBuilderImpl.java:79)

意味着您的过程中有问题,但是您没有共享完整的堆栈跟踪,因此对于我们来说,帮助您变得更加复杂。.如果您仔细查看堆栈跟踪,您将了解发生了什么。

干杯

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM