如何在Drools中从Java API操作指导决策表?

时间:2023-02-07 10:04:14

I have requirement in my project where I need to manipulate Drools guided decision table content (just data not structure) from a custom web based UI.

在我的项目中,我需要从基于Web的自定义UI操作Drools引导的决策表内容(只是数据而不是结构)。

I have searched a lot but I'm not able to find any Java or REST API in Drools which gives access to guided decision table.

我已经搜索了很多但是我无法在Drools中找到任何Java或REST API来访问指导决策表。

Any help would be appreciated.

任何帮助,将不胜感激。

1 个解决方案

#1


3  

I'm assuming you are talking about guided decision tables in the kie-workbench.

我假设您正在讨论kie-workbench中的指导决策表。

As far as I know, there is no public API to manipulate a guided decision table, but there is another thing you can do. Each project in the kie-workbench is in reality a maven project persisted in a local git repository. The good news is that you can actually make a clone of that repository.

据我所知,没有公共API来操纵指导决策表,但还有另一件事你可以做。 kie-workbench中的每个项目实际上都是一个持久存储在本地git存储库中的maven项目。好消息是,您实际上可以复制该存储库。

Once you have a local clone of your project, you can locate the guided decision table you want to modify as a file with .gdst extension.

获得项目的本地克隆后,可以将要修改的指导决策表定位为扩展名为.gdst的文件。

For example, this is the directory structure of the uf-playground sample project coming with the kie-workbench:

例如,这是与kie-workbench一起发布的uf-playground示例项目的目录结构:

如何在Drools中从Java API操作指导决策表?

In the screenshot above you can see a Pricing loans.gdst file. The content of this file is an xml containing both, the structure and the data of the "Pricing loans" guided decision table.

在上面的屏幕截图中,您可以看到Pricing loans.gdst文件。该文件的内容是一个xml,包含“定价贷款”指导决策表的结构和数据。

And here is where things get interesting. If you dig deep down into the kie-workbench code, I'm sure you will find some kind of undocumented and very volatile API to handle these .gdst files. After all, the kie-workbench is actually creating and modifying these files. The challenge here are:

这里是事情变得有趣的地方。如果你深入研究kie-workbench代码,我相信你会发现某种未记录且非常易变的API来处理这些.gdst文件。毕竟,kie-workbench实际上是在创建和修改这些文件。这里面临的挑战是:

  1. Find this API
  2. 找到这个API
  3. Understand this API
  4. 了解此API

Another solution that, from the technical point of view may not be the best, - but that is easier to implement for simple things such as data manipulation - is to parse and modify those .gdst files using an XML library.

另一种解决方案,从技术角度来看可能不是最好的,但是对于诸如数据操作这样的简单事物来说更容易实现 - 是使用XML库解析和修改这些.gdst文件。

Once you are done with the changes you can push them back to the kie-workbench and they will be available for the GUI users.

完成更改后,您可以将它们推回到kie-workbench,它们将可供GUI用户使用。

Of course none of these 2 proposed solutions are ideal. Using an undocumented API that was not meant to be used by third parties and that will certainly change in the future may not sound like a good idea. But manually parsing an XML file whose semantic may probably change on different versions of the kie-workbench also presents some challenges.

当然,这两种提出的解决方案都不是理想的。使用未被第三方使用且未来肯定会改变的未记录的API可能听起来不是一个好主意。但是手动解析其语义可能在kie-workbench的不同版本上发生变化的XML文件也存在一些挑战。

Hope it helps,

希望能帮助到你,

#1


3  

I'm assuming you are talking about guided decision tables in the kie-workbench.

我假设您正在讨论kie-workbench中的指导决策表。

As far as I know, there is no public API to manipulate a guided decision table, but there is another thing you can do. Each project in the kie-workbench is in reality a maven project persisted in a local git repository. The good news is that you can actually make a clone of that repository.

据我所知,没有公共API来操纵指导决策表,但还有另一件事你可以做。 kie-workbench中的每个项目实际上都是一个持久存储在本地git存储库中的maven项目。好消息是,您实际上可以复制该存储库。

Once you have a local clone of your project, you can locate the guided decision table you want to modify as a file with .gdst extension.

获得项目的本地克隆后,可以将要修改的指导决策表定位为扩展名为.gdst的文件。

For example, this is the directory structure of the uf-playground sample project coming with the kie-workbench:

例如,这是与kie-workbench一起发布的uf-playground示例项目的目录结构:

如何在Drools中从Java API操作指导决策表?

In the screenshot above you can see a Pricing loans.gdst file. The content of this file is an xml containing both, the structure and the data of the "Pricing loans" guided decision table.

在上面的屏幕截图中,您可以看到Pricing loans.gdst文件。该文件的内容是一个xml,包含“定价贷款”指导决策表的结构和数据。

And here is where things get interesting. If you dig deep down into the kie-workbench code, I'm sure you will find some kind of undocumented and very volatile API to handle these .gdst files. After all, the kie-workbench is actually creating and modifying these files. The challenge here are:

这里是事情变得有趣的地方。如果你深入研究kie-workbench代码,我相信你会发现某种未记录且非常易变的API来处理这些.gdst文件。毕竟,kie-workbench实际上是在创建和修改这些文件。这里面临的挑战是:

  1. Find this API
  2. 找到这个API
  3. Understand this API
  4. 了解此API

Another solution that, from the technical point of view may not be the best, - but that is easier to implement for simple things such as data manipulation - is to parse and modify those .gdst files using an XML library.

另一种解决方案,从技术角度来看可能不是最好的,但是对于诸如数据操作这样的简单事物来说更容易实现 - 是使用XML库解析和修改这些.gdst文件。

Once you are done with the changes you can push them back to the kie-workbench and they will be available for the GUI users.

完成更改后,您可以将它们推回到kie-workbench,它们将可供GUI用户使用。

Of course none of these 2 proposed solutions are ideal. Using an undocumented API that was not meant to be used by third parties and that will certainly change in the future may not sound like a good idea. But manually parsing an XML file whose semantic may probably change on different versions of the kie-workbench also presents some challenges.

当然,这两种提出的解决方案都不是理想的。使用未被第三方使用且未来肯定会改变的未记录的API可能听起来不是一个好主意。但是手动解析其语义可能在kie-workbench的不同版本上发生变化的XML文件也存在一些挑战。

Hope it helps,

希望能帮助到你,