2013-08-29 26 views
0

我是新來的Jbpm,我目前正在建造一個貸款應用程序,我有一個人類有貸款額度。Jbpm - Java:訪問對象的過程和調用這些對象的方法

我傳遞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")); 

問題是每當我嘗試打電話給任何我此的ThOD對象上/嘗試將其轉換爲的人,它如下拋出錯誤:

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這是在「分歧網關」的Person對象中對貸款類型進行分類。誰能幫我?我錯了,我找不到它,謝謝。

回答

0

此:線程「主」java.lang.IllegalArgumentException異常:無法解析知識。 在org.drools.compiler.builder.impl.KnowledgeBuilderImpl.newKnowledgeBase(KnowledgeBuilderImpl.java:79)

意思的東西在你的程序是錯誤的,但你不能共享完整的堆棧跟蹤,因此對我們來說更復雜幫助你。如果你仔細觀察堆棧軌跡,你會發現那裏發生了什麼。

乾杯

+0

這是我唯一的堆棧跟蹤,我已經發布我的代碼爲更好的理解,我想要做的就是我想通過人的對象,要訪問它在網關進行分類貸款請求。 –

1

從理論上講,你應該能夠看到有關編譯過程中出現了什麼問題(在控制檯或更早的堆棧跟蹤)的更多信息。如果不是,請使用kbuilder.getErrors()獲取更多詳細信息。

快速看看這個過程讓我懷疑你是否不應該使用Person類的完全限定名(包括包)?

克里斯