如何从 Guvnor Web 应用程序加载特定规则 (.drl)?

发布于 2024-11-04 23:46:58 字数 1027 浏览 3 评论 0原文

例如,我在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

杀お生予夺 2024-11-11 23:47:01

当我们需要执行特定的 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.

爱的那么颓废 2024-11-11 23:47:01

包和单个资产的 URL 模式是不同的。对于资产(例如 DRL),模式是:

<resource source='http://localhost:9090/drools-guvnor/rest/packages/test/assets/MyRule/source' type='DRL' />

The URL patterns for packages and individual assets is different. For assets (e.g. DRLs) the pattern is:

<resource source='http://localhost:9090/drools-guvnor/rest/packages/test/assets/MyRule/source' type='DRL' />
对你再特殊 2024-11-11 23:47:01

我解决此问题的方法是创建两个不同的包,一个用于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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文