将对象传递给 DROOLS
Pass object to DROOLS
我对 DROOLS 还很陌生。
我正在使用 Activiti-Explorer,我需要 DROOLS 来做决策。我创建了 class 的实例对象并添加了从 API.
获取的数据
LoanApplicant loanApplicant = new LoanApplicant();
loanApplicant.setUserID(obj.getJSONObject("data").getJSONObject("ownership_details").getInt("user_id"));
loanApplicant.setApplicantName(obj.getJSONObject("data").getJSONObject("ownership_details").getString("name"));
同样,我在 class 对象中设置了更多字段,然后将其设置为 Java 将变量 arg0 委托给 Activiti 内存
arg0.setVariable("loanApplication", loanApplicant);
同样,由于进一步需要 DROOLS 决策输出,我创建了一个输出 java 文件来记录其决策。
输出java文件:RulesOutput.java:-
private String testValue = null;
public String getTestValue(){
return this.getTestValue();
}
public void setTestValue(String testValue){
this.testValue = testValue;
}
与 loanApplicant 类似,我已将此 class 设置到内存中:
arg0.setVariable("RulesOutput", new RulesOutput());
现在我将这些字段从 Process BPMN Diagram 传递到 Drools Task Work Step。
这是我的 DROOLS .drl 文件:
import com.LOS.*;
rule "FLS_1"
when
$loanApplication : loanApplication(age >= 20 && age < 60)
$rulesOutput : RulesOutput (isApproved == false || isApproved == true)
then
rulesOutput.setAgeScore(100);
结束
现在问题:
尽管我已将所有必需的对象传递给 DROOLS,但我得到 Unable to resolve ObjectType
。
错误日志:
06:39:47,288 [http-bio-8480-exec-15] INFO org.activiti.engine.impl.bpmn.deployer.BpmnDeployer - Processing resource RuleSet_1.drl
06:39:47,288 [http-bio-8480-exec-15] INFO org.activiti.engine.impl.bpmn.deployer.BpmnDeployer - Processing resource LOS_1.bpmn20.xml'
06:39:47,645 [http-bio-8480-exec-15] INFO org.activiti.engine.impl.rules.RulesDeployer - Processing resource RuleSet_1.drl
06:39:47,702 [http-bio-8480-exec-15] INFO org.activiti.engine.impl.rules.RulesDeployer - Processing resource LOS_1.bpmn20.xml
06:39:47,704 [http-bio-8480-exec-15] ERROR org.drools.compiler.builder.impl.KnowledgeBuilderImpl - Unable to resolve ObjectType '$loanApplication' : [Rule name='FLS_1']
06:39:47,704 [http-bio-8480-exec-15] ERROR org.drools.compiler.builder.impl.KnowledgeBuilderImpl - Unable to resolve ObjectType '$RulesOutput' : [Rule name='FLS_1']
06:39:47,704 [http-bio-8480-exec-15] ERROR org.drools.compiler.builder.impl.KnowledgeBuilderImpl - Rule Compilation error : [Rule name='FLS_1']
[http-bio-8480-exec-15] INFO org.activiti.engine.impl.bpmn.deployer.BpmnDeployer - Processing resource RuleSet_1.drl
[http-bio-8480-exec-15] INFO org.activiti.engine.impl.bpmn.deployer.BpmnDeployer - Processing resource LOS_1.bpmn20.xml
[http-bio-8480-exec-15] INFO org.activiti.engine.impl.rules.RulesDeployer - Processing resource RuleSet_1.drl
[http-bio-8480-exec-15] INFO org.activiti.engine.impl.rules.RulesDeployer - Processing resource LOS_1.bpmn20.xml
[http-bio-8480-exec-15] ERROR org.drools.compiler.builder.impl.KnowledgeBuilderImpl - Unable to resolve ObjectType '$loanApplication' : [Rule name='FLS_1']
[http-bio-8480-exec-15] ERROR org.drools.compiler.builder.impl.KnowledgeBuilderImpl - Unable to resolve ObjectType '$RulesOutput' : [Rule name='FLS_1']
[http-bio-8480-exec-15] ERROR org.drools.compiler.builder.impl.KnowledgeBuilderImpl - Rule Compilation error : [Rule name='FLS_1']
com/LOS/Rule_FLS_1842423443.java (7:323) : \RulesOutput cannot be resolved
我被困在这里差不多2天了。欢迎提出任何建议。
import com.LOS.*;
如果 loanApplication 和 RulesOutput 在包 com.LOS.approc.dao 中,您必须使用
import com.LOS.approc.dao.*;
尽管通常首选单独进口。 (谈到风格:你应该坚持约定,并使用大写首字母 class 名称。
$loanApplication : loanApplication(age >= 20 && age < 60)
如果不需要引用这个对象,绑定($loanApplication:
)可以省略。
$rulesOutput : RulesOutput (isApproved == false || isApproved == true)
then
rulesOutput.setAgeScore(100); ## missing dollar
如果您使用 $rulesOutput
作为绑定变量的名称,则必须坚持使用该名称。 $
是变量 (Java) 名称的一部分,而不是宏扩展运算符,正如您在尝试 ${loanApplication}
和 ${Rules}
时所说的那样。
我对 DROOLS 还很陌生。 我正在使用 Activiti-Explorer,我需要 DROOLS 来做决策。我创建了 class 的实例对象并添加了从 API.
获取的数据LoanApplicant loanApplicant = new LoanApplicant();
loanApplicant.setUserID(obj.getJSONObject("data").getJSONObject("ownership_details").getInt("user_id"));
loanApplicant.setApplicantName(obj.getJSONObject("data").getJSONObject("ownership_details").getString("name"));
同样,我在 class 对象中设置了更多字段,然后将其设置为 Java 将变量 arg0 委托给 Activiti 内存
arg0.setVariable("loanApplication", loanApplicant);
同样,由于进一步需要 DROOLS 决策输出,我创建了一个输出 java 文件来记录其决策。
输出java文件:RulesOutput.java:-
private String testValue = null;
public String getTestValue(){
return this.getTestValue();
}
public void setTestValue(String testValue){
this.testValue = testValue;
}
与 loanApplicant 类似,我已将此 class 设置到内存中:
arg0.setVariable("RulesOutput", new RulesOutput());
现在我将这些字段从 Process BPMN Diagram 传递到 Drools Task Work Step。
这是我的 DROOLS .drl 文件:
import com.LOS.*;
rule "FLS_1"
when
$loanApplication : loanApplication(age >= 20 && age < 60)
$rulesOutput : RulesOutput (isApproved == false || isApproved == true)
then
rulesOutput.setAgeScore(100);
结束
现在问题:
尽管我已将所有必需的对象传递给 DROOLS,但我得到 Unable to resolve ObjectType
。
错误日志:
06:39:47,288 [http-bio-8480-exec-15] INFO org.activiti.engine.impl.bpmn.deployer.BpmnDeployer - Processing resource RuleSet_1.drl
06:39:47,288 [http-bio-8480-exec-15] INFO org.activiti.engine.impl.bpmn.deployer.BpmnDeployer - Processing resource LOS_1.bpmn20.xml'
06:39:47,645 [http-bio-8480-exec-15] INFO org.activiti.engine.impl.rules.RulesDeployer - Processing resource RuleSet_1.drl
06:39:47,702 [http-bio-8480-exec-15] INFO org.activiti.engine.impl.rules.RulesDeployer - Processing resource LOS_1.bpmn20.xml
06:39:47,704 [http-bio-8480-exec-15] ERROR org.drools.compiler.builder.impl.KnowledgeBuilderImpl - Unable to resolve ObjectType '$loanApplication' : [Rule name='FLS_1']
06:39:47,704 [http-bio-8480-exec-15] ERROR org.drools.compiler.builder.impl.KnowledgeBuilderImpl - Unable to resolve ObjectType '$RulesOutput' : [Rule name='FLS_1']
06:39:47,704 [http-bio-8480-exec-15] ERROR org.drools.compiler.builder.impl.KnowledgeBuilderImpl - Rule Compilation error : [Rule name='FLS_1']
[http-bio-8480-exec-15] INFO org.activiti.engine.impl.bpmn.deployer.BpmnDeployer - Processing resource RuleSet_1.drl
[http-bio-8480-exec-15] INFO org.activiti.engine.impl.bpmn.deployer.BpmnDeployer - Processing resource LOS_1.bpmn20.xml
[http-bio-8480-exec-15] INFO org.activiti.engine.impl.rules.RulesDeployer - Processing resource RuleSet_1.drl
[http-bio-8480-exec-15] INFO org.activiti.engine.impl.rules.RulesDeployer - Processing resource LOS_1.bpmn20.xml
[http-bio-8480-exec-15] ERROR org.drools.compiler.builder.impl.KnowledgeBuilderImpl - Unable to resolve ObjectType '$loanApplication' : [Rule name='FLS_1']
[http-bio-8480-exec-15] ERROR org.drools.compiler.builder.impl.KnowledgeBuilderImpl - Unable to resolve ObjectType '$RulesOutput' : [Rule name='FLS_1']
[http-bio-8480-exec-15] ERROR org.drools.compiler.builder.impl.KnowledgeBuilderImpl - Rule Compilation error : [Rule name='FLS_1']
com/LOS/Rule_FLS_1842423443.java (7:323) : \RulesOutput cannot be resolved
我被困在这里差不多2天了。欢迎提出任何建议。
import com.LOS.*;
如果 loanApplication 和 RulesOutput 在包 com.LOS.approc.dao 中,您必须使用
import com.LOS.approc.dao.*;
尽管通常首选单独进口。 (谈到风格:你应该坚持约定,并使用大写首字母 class 名称。
$loanApplication : loanApplication(age >= 20 && age < 60)
如果不需要引用这个对象,绑定($loanApplication:
)可以省略。
$rulesOutput : RulesOutput (isApproved == false || isApproved == true)
then
rulesOutput.setAgeScore(100); ## missing dollar
如果您使用 $rulesOutput
作为绑定变量的名称,则必须坚持使用该名称。 $
是变量 (Java) 名称的一部分,而不是宏扩展运算符,正如您在尝试 ${loanApplication}
和 ${Rules}
时所说的那样。