-
1. Re: can Drools API tell me how many rules are using a particular attribute
tkobayashi Feb 5, 2020 8:27 PM (in response to meabhishek80)Drools doesn't have a convenient API for the purpose. You may write a tool using internal APIs but it could be complex and error-prone.
Rather, I think the following approaches would be easier to measure the impact.
A) Simply grep your rules with "Instrument"
B) Comment out the "Instrument" line of "declare FRONTOFFICESYSTEM" and build the rules. You will see build errors so you will see how many / which rules are affected.
-
2. Re: can Drools API tell me how many rules are using a particular attribute
meabhishek80 Feb 5, 2020 11:19 PM (in response to tkobayashi)I agree but that's manual process. I wanted to do it programatically.
I have an application in background where we can define attributes, rules etc. So, if somebody deletes attributes which is already used in any of the rules, i need to stop that and I need to tell back in response that For example Rule1, Rule10 are using this attribute and so you cant delete.
So how to achieve that
-
3. Re: can Drools API tell me how many rules are using a particular attribute
tkobayashi Feb 6, 2020 8:13 PM (in response to meabhishek80)You can build rules and check errors programatically.
KieServices ks = KieServices.Factory.get(); KieFileSystem kfs = ks.newKieFileSystem(); // You can add your DRL files as InputStream here. Existing rules + a modified rule (e.g. where a field of a declared fact is removed) kfs.write("src/main/resources/abc/modelMapping/ruleEngine/Sample.drl", ks.getResources().newInputStreamResource(new FileInputStream(new File("my-src/abc/modelMapping/ruleEngine/Sample.drl")))); // You can add more... // It's just for verification so give it a ReleaseId which is different from your production ReleaseId ReleaseId releaseId = ks.newReleaseId("com.sample", "my-sample-for-verify", "1.0.0"); kfs.generateAndWritePomXML(releaseId); // Build KieBuilder kbuilder = ks.newKieBuilder( kfs ).buildAll(); // Get results including errors Results results = kbuilder.getResults(); if (results.hasMessages(Message.Level.ERROR)) {; List messages = results.getMessages(Message.Level.ERROR); // report the error }
I hope it helps.