如何从 Guvnor Web 应用程序加载特定规则 (.drl)?
例如,我在Guvnor中添加了两条规则(rule1.drl和rule2.drl)。
通常我可以通过创建一个changeset.xml来检索这些规则,例如:
<change-set ...>
<add>
<resource source='http://localhost/guvnor/org.drools.guvnor.Guvnor/package/name/LATEST.drl' type='DRL' basicAuthentication="enabled" username="username" password="password" />
</add>
</change-set>
并通过代码加载changeset.xml:
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent("Test Agent", kaconf);
kagent.applyChangeSet(ResourceFactory.newClassPathResource("changeset.xml"));
knowledgeBase = kagent.getKnowledgeBase();
但是我如何才能只检索特定的规则?例如rule2.drl
当然我可以将changeset.xml中的url更改为
<resource source='http://localhost/guvnor/org.drools.guvnor.Guvnor/package/name/LATEST/rule2.drl' type='DRL' basicAuthentication="enabled" username="username" password="password" />
但我发现响应文件缺少包名称和所有导入语句,例如:
package com.packname;
import namespace.EntityA;
For example, I have added two rules (rule1.drl and rule2.drl) in Guvnor.
Normally I can retrieve those rules combined by creating a changeset.xml like:
<change-set ...>
<add>
<resource source='http://localhost/guvnor/org.drools.guvnor.Guvnor/package/name/LATEST.drl' type='DRL' basicAuthentication="enabled" username="username" password="password" />
</add>
</change-set>
And load the changeset.xml by codes:
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent("Test Agent", kaconf);
kagent.applyChangeSet(ResourceFactory.newClassPathResource("changeset.xml"));
knowledgeBase = kagent.getKnowledgeBase();
But how I can retrieve specific rule only? e.g. rule2.drl
Of course I can change the url in changeset.xml to
<resource source='http://localhost/guvnor/org.drools.guvnor.Guvnor/package/name/LATEST/rule2.drl' type='DRL' basicAuthentication="enabled" username="username" password="password" />
But I found that the response file miss the package name and all the import statements, for example:
package com.packname;
import namespace.EntityA;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当我们需要执行特定的 drl 包时,我们为每个包/快照使用不同的变更集。
如果规则相关,请使用不同的 pojo 来分隔规则,因为您知道管理员会从一个大 .drl 中的包中编译所有规则,如果您有一百个规则然后结束并使用迭代它,这可能会很慢不同的 pojo 实例。
When we need to execute especific drl package we use diferent changeset for each package/snapshot.
If the rules are related use different pojos for separate the rule, because you know the guvnor compile all your rules from a package in one big .drl, this could be slow if you have a hundred of rule-then-end's and iterate it with different pojo instances.
包和单个资产的 URL 模式是不同的。对于资产(例如 DRL),模式是:
The URL patterns for packages and individual assets is different. For assets (e.g. DRLs) the pattern is:
我解决此问题的方法是创建两个不同的包,一个用于rule1.drl,另一个用于rule2.drl。所以我的程序通过两个不同的变更集读取这两个规则。
My workaround to this problem is to create two different packages, one for rule1.drl and one for rule2.drl. So my program read these two rule by two different changeset.