【发布时间】:2020-08-31 13:00:36
【问题描述】:
我有一个这样的口水定义类型
package referee.security.category;
declare AskedQuestions
question : String
answer : Boolean
end
和我的 java 文件中相同类型的 Java 类。它没有发送给流口水,因为我不知道我应该在哪里提供参考。
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class AskedQuestions{
private String question;
private boolean answer;
}
我有许多规则,我正在尝试按照此方法将值设置为定义类型中的 question 和 answer 变量。
rule "Threat: Public Readable -- QRF_1.4 [not true]"
agenda-group "evaluate attack category"
dialect "mvel"
when
$q1: QRiskFactor(this == QRiskFactor.QRF1_S4_PUBLIC_READABLE)
Application($rf : riskFactors[QRiskFactor.QRF1_S4_PUBLIC_READABLE.value], $rf!.factor != "true")
then
insert(FlagQuestion.QRF_1_ASK_FLAG);
AskedQuestions $askedQuestions=new AskedQuestions(question:$q1,answer:true);//if i do this way, I get an error defined below
/* if i follow this approach, it also throws the error.
AskedQuestions $askedQuestions=new AskedQuestions();
$askedQuestions.setQuestion($q1);
$askedQuestions.setAnswer(false);
insert($askedQuestions);*/
我必须将值设置为已定义的类型变量,然后在 Java 中获取所有插入的对象并从中生成 JSON。 这是我得到的错误
Unable to Analyse Expression drools.insert(FlagQuestion.QRF_1_ASK_FLAG);
AskedQuestions $askedQuestions=new AskedQuestions(question:$q1,answer:true);
/* $askedQuestions.setQuestion($q1);
$askedQuestions.setAnswer(false);
insert($askedQuestions);*/;
[Error: unable to resolve method using strict-mode:
org.drools.core.spi.KnowledgeHelper.question()]
[Near : {... =new AskedQuestions(question:$q1,answer:true); ....}]
我可能做错了什么?我在这个 repo 中没有找到任何对此的引用,并且本书提供了here。任何帮助将非常感激。非常感谢
【问题讨论】:
-
为什么要在 Drools 中重新定义模型?为什么不直接导入您的 Java 类并使用它呢?