我如何 return 从规则到 bpm 流程的 loanApplication 对象?
How do I return the loanApplication object from a rule to the bpm process?
我正在使用 drools(kie-wb 网络界面),我有一个 bpm 流程,它接受一个 loanApplication 和 returns 带有更新数据的 loanApplication(目标)。但是当我尝试这样做时,我被退回了。
"Unable to create response: [LoanApplicationReviewer.LoanApplicationReview:21 - Age Knockout:1] -- [LoanApplicationReviewer.LoanApplicationReview:21 - Age Knockout:1] -- null"
我的数据模型:
public class LoanApplication implements java.io.Serializable {
static final long serialVersionUID = 1L;
private java.lang.Integer id;
private java.lang.Integer age;
private boolean accepted = true;
private java.util.List<java.lang.String> knockoutReasons = new java.util.ArrayList<java.lang.String>();
public LoanApplication() {
}
public java.lang.Integer getId() {
return this.id;
}
public void setId(java.lang.Integer id) {
this.id = id;
}
public java.lang.Integer getAge() {
return this.age;
}
public void setAge(java.lang.Integer age) {
this.age = age;
}
public boolean isAccepted() {
return this.accepted;
}
public void setAccepted(boolean accepted) {
this.accepted = accepted;
}
public java.util.List<java.lang.String> getKnockoutReasons() {
return this.knockoutReasons;
}
public void setKnockoutReasons(
java.util.List<java.lang.String> knockoutReasons) {
this.knockoutReasons = knockoutReasons;
}
public void addKnockoutReason(String knockoutReason) {
if (this.knockoutReasons == null) {
this.knockoutReasons = new java.util.ArrayList<java.lang.String>();
}
this.knockoutReasons.add(knockoutReason);
}
public String toString() {
return "loanApplicationResponse::[accepted=" + this.accepted
+ ",knockoutReasons="
+ this.knockoutReasons.toString() + "]";
}
public LoanApplication(java.lang.Integer id, java.lang.Integer age,
boolean accepted, java.util.List
knockoutReasons) {
this.id = id;
this.age = age;
this.accepted = accepted;
this.knockoutReasons = knockoutReasons;
}
}
我的规则是:
package com.xyz.loanapplicationreviewer;
import com.xyz.loanapplicationreviewer.LoanApplication;
import org.kie.api.runtime.process.WorkflowProcessInstance;
rule 'age less than 30 do not accept'
ruleflow-group 'ageKnockoutGroup'
dialect "mvel"
when
$process : WorkflowProcessInstance();
$loanApp : LoanApplication() from (LoanApplication)$process.getVariable("loanApplication");
eval ($loanApp.getAge() < 30);
then
$loanApp.setAccepted(false);
$loanApp.addKnockoutReason("age under 30");
((WorkflowProcessInstance)kcontext.getKnowledgeRuntime().getProcessInstance($process.getId())).setVariable("loanApplication", $loanApp);
System.out.println("Age less than 30 knockout");
end
我在业务规则步骤中添加了一个入口脚本来填写流程实例,如下所示:
kcontext.getKnowledgeRuntime().insert(kcontext.getProcessInstance());
我也填写了我期望的数据分配。它似乎获取了数据,因为当我创建一个新实例并从表单 运行 它具有数据并执行规则时,仅从使用 swagger 的其余界面我得到上述错误。
看了很久之后;
看来我必须稍微修改一下我的请求才能变成:
{
"loanApplication" : {
"com.xyz.abc.LoanApplication" : {
"id" : 1,
"age": 1,
"accepted" : true
}
}
}
此外,我不得不将规则更改为:
rule 'age less than 30 do not accept'
ruleflow-group 'ageKnockoutGroup'
dialect "mvel"
when
loanApplication : LoanApplication(age < 30);
//process : WorkflowProcessInstance();
//loanApp : LoanApplication() from (LoanApplication)process.getVariable("loanApplication");
//eval (loanApp.getAge() < 30);
then
loanApplication.setAccepted(false);
loanApplication.addKnockoutReason("age under 30");
System.out.println("in then less than 30 with loanApp:" + loanApplication.toString());
String knockoutReasonFact = "age under 30";
boolean acceptedFact = false;
insert(knockoutReasonFact);
insert(acceptedFact);
update(loanApplication);
end
使用所有相同的端点,我最终得到了预期的响应。我刚刚结束了跟踪业务中心是如何调用我的 drools/jbpm 流程并对其进行镜像的。
我正在使用 drools(kie-wb 网络界面),我有一个 bpm 流程,它接受一个 loanApplication 和 returns 带有更新数据的 loanApplication(目标)。但是当我尝试这样做时,我被退回了。
"Unable to create response: [LoanApplicationReviewer.LoanApplicationReview:21 - Age Knockout:1] -- [LoanApplicationReviewer.LoanApplicationReview:21 - Age Knockout:1] -- null"
我的数据模型:
public class LoanApplication implements java.io.Serializable {
static final long serialVersionUID = 1L;
private java.lang.Integer id;
private java.lang.Integer age;
private boolean accepted = true;
private java.util.List<java.lang.String> knockoutReasons = new java.util.ArrayList<java.lang.String>();
public LoanApplication() {
}
public java.lang.Integer getId() {
return this.id;
}
public void setId(java.lang.Integer id) {
this.id = id;
}
public java.lang.Integer getAge() {
return this.age;
}
public void setAge(java.lang.Integer age) {
this.age = age;
}
public boolean isAccepted() {
return this.accepted;
}
public void setAccepted(boolean accepted) {
this.accepted = accepted;
}
public java.util.List<java.lang.String> getKnockoutReasons() {
return this.knockoutReasons;
}
public void setKnockoutReasons(
java.util.List<java.lang.String> knockoutReasons) {
this.knockoutReasons = knockoutReasons;
}
public void addKnockoutReason(String knockoutReason) {
if (this.knockoutReasons == null) {
this.knockoutReasons = new java.util.ArrayList<java.lang.String>();
}
this.knockoutReasons.add(knockoutReason);
}
public String toString() {
return "loanApplicationResponse::[accepted=" + this.accepted
+ ",knockoutReasons="
+ this.knockoutReasons.toString() + "]";
}
public LoanApplication(java.lang.Integer id, java.lang.Integer age,
boolean accepted, java.util.List
knockoutReasons) {
this.id = id;
this.age = age;
this.accepted = accepted;
this.knockoutReasons = knockoutReasons;
}
}
我的规则是:
package com.xyz.loanapplicationreviewer;
import com.xyz.loanapplicationreviewer.LoanApplication;
import org.kie.api.runtime.process.WorkflowProcessInstance;
rule 'age less than 30 do not accept'
ruleflow-group 'ageKnockoutGroup'
dialect "mvel"
when
$process : WorkflowProcessInstance();
$loanApp : LoanApplication() from (LoanApplication)$process.getVariable("loanApplication");
eval ($loanApp.getAge() < 30);
then
$loanApp.setAccepted(false);
$loanApp.addKnockoutReason("age under 30");
((WorkflowProcessInstance)kcontext.getKnowledgeRuntime().getProcessInstance($process.getId())).setVariable("loanApplication", $loanApp);
System.out.println("Age less than 30 knockout");
end
我在业务规则步骤中添加了一个入口脚本来填写流程实例,如下所示:
kcontext.getKnowledgeRuntime().insert(kcontext.getProcessInstance());
我也填写了我期望的数据分配。它似乎获取了数据,因为当我创建一个新实例并从表单 运行 它具有数据并执行规则时,仅从使用 swagger 的其余界面我得到上述错误。
看了很久之后;
看来我必须稍微修改一下我的请求才能变成:
{
"loanApplication" : {
"com.xyz.abc.LoanApplication" : {
"id" : 1,
"age": 1,
"accepted" : true
}
}
}
此外,我不得不将规则更改为:
rule 'age less than 30 do not accept'
ruleflow-group 'ageKnockoutGroup'
dialect "mvel"
when
loanApplication : LoanApplication(age < 30);
//process : WorkflowProcessInstance();
//loanApp : LoanApplication() from (LoanApplication)process.getVariable("loanApplication");
//eval (loanApp.getAge() < 30);
then
loanApplication.setAccepted(false);
loanApplication.addKnockoutReason("age under 30");
System.out.println("in then less than 30 with loanApp:" + loanApplication.toString());
String knockoutReasonFact = "age under 30";
boolean acceptedFact = false;
insert(knockoutReasonFact);
insert(acceptedFact);
update(loanApplication);
end
使用所有相同的端点,我最终得到了预期的响应。我刚刚结束了跟踪业务中心是如何调用我的 drools/jbpm 流程并对其进行镜像的。