Until now, if you wanted to create or edit rule assets in Drools you needed to enter Guvnor and work inside it. When Drools 5.2 sees the light of the day, there will be a new way: to embed Guvnor’s editors in your applications.
Guvnor provides a set of editors to author rules in different ways. According to rule’s format a specialized editor is used. Some of the supported formats are: brl (guided editor), drl (plain editor), dsl (dsl editor), template (guided editor) and decision table (decision table editor).
Since now, the only way to use these editor was using guvnor. But with Drools 5.2 you could embed any of these editors in your own application just like if they were standalone applications.
The standalone version of Guvnor’s Editors lets you to use just the editor window inside your applications. In order to be able to invoke a Editor instance from an external application, Guvnor must be running: Standalone Editor is just a part of Guvnor and not a different application.
So the first step is to have Guvnor deployed and running in a web/application server.
Using the standalone version of Guvnor’s Editor you can create or edit assets only inside existing categories and packages. You must configure at least one category and package with a valid model inside Guvnor to start working with this feature.
Depending on the parameters used to invoke the Editor, you can use it in 3 different ways: BRL Edition Mode, Edition of Existing Assets Mode and Create New Asset Mode.
BRL Edition Mode is used if you want to use BRL code in your application. You can provide multiple BRL sources to the Editor, each of them will be converted to a temporal RuleAsset (a Guvnor’s internal representation) and displayed in a separate editor.
The parameters involved in this mode are:
Parameter Name | Explanation | Allow multiple values | Example |
packageName | The name of the package used to hold the created assets. The package must exist in Guvnor. | false | mortgages |
categoryName | Each rule must have at least one category. The created rules will belong to this category. The category must exist in Guvnor | false | Home Mortgage |
brlSource | The BRL source used by the editor. You can pass multiple brlSource parameters for multiple rules. | true | <rule> <name> Bankruptcy history </name> <modelVersion> 1.0 </modelVersion> <attributes> … </attributes> <lhs> … </lhs> <rhs> … </rhs> </rule> |
All the assets created when using this mode are temporal. They are never going to be persisted in Guvnor. The purpose of this mode is to use just the Guided Editor and not Guvnor. You can provide one or more initial brls, work on them using the Guided Editor and then retrieve the modified source. Every time you want to edit a rule, you must provide its brl code.
You can use this mode if you want to use the Standalone Editor for edit assets that already exist inside Guvnor.
When editing existing assets, you will be able to save the changes in Guvnor as well as get the DRL and BRL code of them.
The parameters involved in this mode are:
Parameter Name | Explanation | Allow multiple values | Example |
assetsUUIDs | The asset’s UUID. Use multiple parameters for specify multiple assets. | true | 968c9b3c-bc19-40ba-bb38-44435956ccee |
The asset’s UUID could be found using Guvnor (we are working on a way to get this information using Guvnor’s REST API).
When using this mode, you can edit assets from different types: like rules and decision tables.
You can use this mode if you want to start a new asset from scratch. Assets created using this mode could be persisted inside Guvnor using the “Save all Changes” button. At this moment, you can only create one asset at a time using this mode.
The parameters involved in this mode are:
Parameter Name | Explanation | Allow multiple values | Example |
packageName | The name of the package used to hold the created asset. The package must exist in Guvnor. | false | mortgages |
categoryName | The created rule will belong to this category. The category must exist in Guvnor | false | Home Mortgage |
createNewAsset | Flag indicating that we want to start a new rule from the scratch | false | true false |
assetName | The name for the asset to be created | false | New Rule |
assetFormat | The format of the asset to be created. The format identifies the editor to be used. | false | brl (default) drl dsl gdst template And possibly any value defined in org.drools.guvnor.client.common.AssetFormats |
When you edit or create rules in BRL format (using the Guided Editor), you can choose which part of the rules would be visible (LHS, RHS and Attributes). You can specify this using 3 different HTTP parameters:
Parameter Name | Explanation | Allow multiple values | Example |
hideRuleLHS | Should the LHS of the rules be hidden? | false | true false |
hideRuleRHS | Should the RHS of the rules be hidden? | false | true false |
hideRuleAttributes | Should the Attributes of the rules be hidden? | false | true false |
When you edit or create rules in BRL format (using the Guided Editor), you can define a subset of the Fact Types defined in the rule’s package. When authoring the rule, you will only see the Fact Types defined in that subset. This is the same concept as Working-Sets. In fact, a Working-Set will be created and applied on-the-fly using the provided subset.
If you want to define this set of Fact Types you could use this parameter:
Parameter Name | Explanation | Allow multiple values | Example |
validFactType | The name of a valid Fact Type. This is just the class name and not the fqn. | true | Bankruptcy ApplicationLoan |
After the Editor is open, you can interact with it using JavaScript.
The Editor defines a JavaScript object in the Window where it is rendered. This object looks like this:
var guvnorEditorObject = { getDRL: function (callbackFunction), getBRL: function (callbackFunction), registerAfterSaveAndCloseButtonCallbackFunction: function (callbackFunction), registerAfterCancelButtonCallbackFunction: function (callbackFunction), getAssetsUUIDs: function() }
The window.guvnorEditorObject defines 5 functions that you can use to interact with it. getDRL() and getBRL() receive a callback function as parameter. This function will receive a String containing the DRL or BRL of the rules you are editing.
The next 2 functions are for register callbacks for “Save”, “Done” and “Cancel” buttons. These callback functions don’t accept any parameter.
The last function is ised to retrieve the UUIDs of the assets you are editing. This is very useful when you are creating a new rule asset and you don’t know the UUID of it.
If you want to create rules in your applications using Guvnor’s Editors you can embed them in your applications now.
To invoke an Editor instance you need to perform a HTTP Request to /standaloneEditorServlet URL. According to the parameters passed, you could use Guvnor’s Editors in 3 different ways.When you need to interact with Guvnor’s Editor, you can use a JavaScript object defined in the window/frame where it is open.
If you want to try this feature, you need to get the latest snapshot of Guvnor 5.2 version.
I also have created the following files to test all the functionalities while I was developing them. You can use them if you want to make a quick test, or to see how your applications should interact with Guvnor’s Editors.
You could download them and change the ACTION attribute of the form they have.
Very nice…
This is a great idea.
Thanks Edson.
Sorry, I meant thank Estaban – nice work man.
Thanks to Edson for fusion 🙂
Not Able to download Guvnor 5.2. please let me know location from where i can download.
5.2 FINAL is not yet available. If you want to start playing around with this feature, you can get the nightly builds from: http://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/target/
Pingback: Integrate Oryx Designer and Guvnor in your own applications « Tihomir Surdilovic
hmm, sorry! I can’t get this working for me. I’m running Guvnor 5.2.0M2. On the same server I put a little hmtl-file (like assetEditor.html) defining nothing then a single key-value-pair (assetsUUIDs and uuidOfAnExistingAsset) inside the form-tag and sends it against the standaloneEditorServlet of Guvnor. After invoking the redirect to StandalonEditor.html is ok, but the url shows not the asset-uuid and it throws a 500-error 😦 any suggestions?
Are you getting any stacktrace in Server’s output console?
Hi,
yeah, it gives me a Nullpointer-Exception in StandaloneEditorServiceImplementation where the server tries to handle the clientName-String from the request. In your example you do not provide the option “client” within the Post-Form. After adding this option, it works like a charme. You can find my solution in the trackback above.
Pingback: Standalone-Editor für Drools-Guvnor - Christoph Burmeister
How about rule validation? That would be a nice menu option to have
Yes, I was thinking about adding rule validation and verification options to standalone BRL Editor.
Not in my priority list yet 🙂 But you know, contributions are always welcomed!
Hi All,
1)In the above file “brlEditor.html” the url at the end
127.0.0.1:9997 what it (9997) represents exactly.
and when i running this i am getting gwt plugin required..
2) can anybody tell me is it possible or not : in guvnor console when i create a new package ( or) rule after immadeiatly when i click save button i want to call a java class is it possible……
Thanks in Advance…
1) 9997 is the port. You have to adapt the url to match your guvnor instance.
2) It is possible. What you have to do is to register a callback in the Save and Close button in js using “registerAfterSaveAndCloseButtonCallbackFunction()”. Using that function you can register your own function to do whatever you want after the user press the “Save and Close” button.
Thanks for your valuable suggestion Esteban.But where to write js registerAfterSaveAndCloseButtonCallBackFunction()??In the guvnor itself?
Please suggest me.
I have a question for you first: Are you using Guvnor’s UI or are you creating your own application that uses Guvnor’s editors? This post is about the latter. If you want to use Guvnor instead of your custom application, then you will need to modify Guvnor’s code in order to achieve what you need.
Hi Esteban,
can u give an idea how to achieve my requirement:
i have a java class when i compile that class the packages & rules which i was created in Guvnor console is storing in DB.
when i add a new Package (or) rule in guvnor even i have to compile that java class then only newly added package & rules are storing in Db.
in guvnor when i create a new package ( or) rule after immadeiatly when i click save button i want to call a java class is it possible……
Thanks in Advance…
You can achieve part of what you are looking for (execute custom code after a rule is created/modified) only if you are using Rule Editor inside your own application. If you are using Guvnor (I mean, accessing Guvnor through your browser) to do this, then there is no way to do what you need. You will need to modify Guvnor’s source code.
Best Regards,
Hi Estaban,
I am looking for a way to call a method for Guvnor, Decision Table Guided Editors. Is it possible in the current version? All I see are setting values for fields.
Thanks in Advance
Unfortunately, the current version doesn’t support the required functionality. The embedded editor is treated as a generic editor, so there is no way to invoke specific methods of a specific editor type.
Best Regards,