Re: [rules-users] drools 6 equivalent of addKnowledgePackages
I head previously read that but didn't spot the bit that mentions creating from a drl defined as a String. I take it this can be done from KieFileSystem. String rules = ... KieFileSystem kfs = kieServices.newKieFileSystem(); kfs.write(kieServices.getResources().newReaderResource(new StringReader(rules))); This throws an exception complaining that the resource doesn't have a source or target path set. Is there a way to push a dynamically created drl into this without writing it to disk first? -- View this message in context: http://drools.46999.n3.nabble.com/drools-6-equivalent-of-addKnowledgePackages-tp4027044p4027059.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] drools 6 equivalent of addKnowledgePackages
The KIEFileSystem is an in-memory filesystem, so what you are doing is correct. You will have to set at least two more properties of the resource: 1) the sourcePath - e.g. foo/myRule.drl will eventually place the rule file in the virtual src/main/resources/foo folder, where it will be picked up by the builder 2) the resource type, e.g. ResourceType.DRL Unfortunately, the API-based, incremental build process in 6.0 final has a few issues and may not always work as expected. It is being fixed even now, but you may have to rebuild and update your full virtual jar every time you want to modify the knowledge base. See the test class IncrementalCompilationTest in the source code and the drools examples, and feel free to ask for more clarifications Best Davide On 12/03/2013 01:25 AM, pmander wrote: I head previously read that but didn't spot the bit that mentions creating from a drl defined as a String. I take it this can be done from KieFileSystem. String rules = ... KieFileSystem kfs = kieServices.newKieFileSystem(); kfs.write(kieServices.getResources().newReaderResource(new StringReader(rules))); This throws an exception complaining that the resource doesn't have a source or target path set. Is there a way to push a dynamically created drl into this without writing it to disk first? -- View this message in context: http://drools.46999.n3.nabble.com/drools-6-equivalent-of-addKnowledgePackages-tp4027044p4027059.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] drools 6 equivalent of addKnowledgePackages
There are several different ways of doing it, but here is a snippet to help creating an in-memory kjar with default kbases and ksessions: public static byte[] createKJar(KieServices ks, ReleaseId releaseId, String pom, String... drls) { KieFileSystem kfs = ks.newKieFileSystem(); if( pom != null ) { kfs.write(pom.xml, pom); } else { kfs.generateAndWritePomXML(releaseId); } KieResources kr = KieServices.getResources(); for (int i = 0; i drls.length; i++) { if (drls[i] != null) { kfs.write( kr.newByteArrayResource( drls[i].getBytes() ).setSourcePath(my/pkg/drl+i+.drl) ); } } KieBuilder kb = ks.newKieBuilder(kfs).buildAll(); if( kb.getResults().hasMessages( org.kie.api.builder.Message.Level.ERROR ) ) { for( org.kie.api.builder.Message result : kb.getResults().getMessages() ) { System.out.println(result.getText()); } return null; } InternalKieModule kieModule = (InternalKieModule) ks.getRepository() .getKieModule(releaseId); byte[] jar = kieModule.getBytes(); return jar; } Please note that you usually don't need the byte[] back, so you can ignore everything after the last 3 lines of the code. Also, the error check in the snippet is just printing to sysout. You should handle this accordingly in your application. Hope it helps. Edson On Tue, Dec 3, 2013 at 3:25 AM, pmander paul.s.man...@gmail.com wrote: I head previously read that but didn't spot the bit that mentions creating from a drl defined as a String. I take it this can be done from KieFileSystem. String rules = ... KieFileSystem kfs = kieServices.newKieFileSystem(); kfs.write(kieServices.getResources().newReaderResource(new StringReader(rules))); This throws an exception complaining that the resource doesn't have a source or target path set. Is there a way to push a dynamically created drl into this without writing it to disk first? -- View this message in context: http://drools.46999.n3.nabble.com/drools-6-equivalent-of-addKnowledgePackages-tp4027044p4027059.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users -- Edson Tirelli Principal Software Engineer Red Hat Business Systems and Intelligence Group ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] drools 6 equivalent of addKnowledgePackages
Just doing some investigation of the drools 6 release. We dynamically build our rules and use some thing like the following to bring them into a stateful session: KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder(); builder.add(ResourceFactory.newReaderResource(new StringReader( compiledRules)), ResourceType.DRL); KnowledgeBuilderErrors errors = builder.getErrors(); kbase.addKnowledgePackages(builder.getKnowledgePackages()); This appears to be deprecated but there is no indication in the javadoc for what the alternative is. -- View this message in context: http://drools.46999.n3.nabble.com/drools-6-equivalent-of-addKnowledgePackages-tp4027044.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] drools 6 equivalent of addKnowledgePackages
I’ve sent a few emails on this now. See docs: http://docs.jboss.org/drools/release/6.0.0.Final/drools-docs/html/KIEChapter.html 4.2.2.4. Defining a KieModule programmatically 4.2.5.9. Programaticaly build a Simple KieModule with Defaults 4.2.5.10. Programaticaly build a KieModule using Meta Models Mark On 2 Dec 2013, at 17:38, pmander paul.s.man...@gmail.com wrote: Just doing some investigation of the drools 6 release. We dynamically build our rules and use some thing like the following to bring them into a stateful session: KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder(); builder.add(ResourceFactory.newReaderResource(new StringReader( compiledRules)), ResourceType.DRL); KnowledgeBuilderErrors errors = builder.getErrors(); kbase.addKnowledgePackages(builder.getKnowledgePackages()); This appears to be deprecated but there is no indication in the javadoc for what the alternative is. -- View this message in context: http://drools.46999.n3.nabble.com/drools-6-equivalent-of-addKnowledgePackages-tp4027044.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users