接收 Drools 逻辑撤销事件的通知
我有一个用于执行数据模型验证的知识库。来自 UI 的修改事件被异步发布到一个单独的线程,该线程更新知识库并触发规则。验证错误会触发错误对象的逻辑插入。我可以收集这些并将事件异步发布回 UI 线程。然而,为了更容易地保持 UI 最新,我还想在用户修复错误时发布一个事件 - 即当错误对象从知识库中撤回时。
对于如何做到这一点,我有两个想法,但我都不喜欢:
我可以从程序代码中监听工作记忆事件,但这会违反知识库中验证功能的封装。
或者,我可以插入一个与错误对象的逻辑插入配对的标志对象,并编写一个规则来检测未配对的标志,收回它们,并触发“错误已修复”事件。
是否有一种干净且简单的方法来激活基于如上所述的错误对象的逻辑撤消的规则?
I have a knowledge base for performing validation of my data model. Modification events from the UI are posted asynchronously to a separate thread that updates the knowledge base and fires the rules. Validation errors trigger a logical insert of an error object. I can collect these and post events asynchronously back to the UI thread. However, to make it easier to keep the UI up-to-date, I also want to post an event when the user fixes an error – i.e. when an error object is retracted from the knowledge base.
I have two ideas for how to do this, neither of which I like:
I could listen to working memory events from procedural code, but that would violate the encapsulation of the validation functionality within the knowledge base.
Alternately, I could insert a flag object paired with my logical insertion of an error object and write a rule that detects un-paired flags, retracts them, and fires the "error fixed" event.
Is there a clean and simple way to activate a rule based on the logical retraction of an error object as described above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
自我回答,以便我稍后可以链接到此内容并找出是否有更好的方法。
这是我最终采取的方法:
当触发验证规则时,insertLogical一个具有代表验证错误的唯一id的对象(例如ValidationMessage)。
ValidationMessage 有一个属性“标记”,默认为 false。
定义一个在存在未标记的 ValidationMessage 时触发的规则。在 RHS 中,标记消息并对全局事件处理程序进行 onAssert 调用。插入与 ValidationMessage 具有相同 id 的第二个对象(例如 ValidationMessageFlag)。
定义一个规则,当不存在相应的 ValidationMessage(具有相同 id 的情况)时,该规则会在 ValidationMessageFlag 存在时触发。在 RHS 中,在全局事件处理程序中调用 onRetract。收回 ValidationMessageFlag。
Self-answering so that I can link to this later and find out if there is a better way to do it.
Here's the approach I wound up taking:
When a validation rule is triggered, insertLogical an object with a unique id representing the validation error (e.g. ValidationMessage).
ValidationMessage has a property "flagged", which defaults to false.
Define a rule that triggers on existence of unmarked ValidationMessages. In the RHS, mark the message and make an onAssert call to a global event handler. Insert a second object (e.g. ValidationMessageFlag) with the same id as the ValidationMessage.
Define a rule that triggers on existence of a ValidationMessageFlag, when no corresponding ValidationMessage (with the same id exists). In the RHS, call onRetract in the global event handler. Retract the ValidationMessageFlag.