KnowledgeBases are not aware of Guvnor, nor are ChangeSets.<br><br>If you create a new rule and want to add it to Guvnor you'll need to use a suitable API.<br><br>Please look at Guvnor's documentation, in particular the Integration section and REST API.<br>
<br>With kind regards,<br><br>Mike<br><br><div class="gmail_quote">On 7 March 2012 07:12, PC <span dir="ltr"><<a href="mailto:prakash.3098@gmail.com">prakash.3098@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
i am using Guvnor-5.2.0 . Through a simple java client class i wanted to<br>
add<br>
a rule at runtime.<br>
<br>
below is the snippet of java code i am using to add a rule.<br>
<br>
KnowledgeBase knowledgeBase = createKnowledgeBase();<br>
session = knowledgeBase.newStatefulKnowledgeSession();<br>
logger = KnowledgeRuntimeLoggerFactory.newFileLogger(session,<br>
"log/DroolsSample");<br>
KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);<br>
String ruleDescription = "package com.tcube.atyaf.dto;"+<br>
"import<br>
com.tcube.atyaf.dto.EmployeeDataDTO;" +<br>
"rule \"SimpleDRLRule\""+<br>
" @ID(11003588)"+<br>
" lock-on-active true"+<br>
" salience -11"+<br>
" dialect 'mvel'"+<br>
" when m :<br>
EmployeeDataDTO(empName==\"PC\");"+<br>
" then System.out.println(<br>
\"*************rule executed\");" +<br>
" m.setDesignation( \"Manager<br>
,Additional Duties & Additional hike<br>
!!!\" );"+<br>
" update( m );"+<br>
" end";<br>
byte[] data = ruleDescription.getBytes();<br>
<br>
KnowledgeBuilder kbuilder =<br>
KnowledgeBuilderFactory.newKnowledgeBuilder(knowledgeBase);<br>
kbuilder.add( ResourceFactory.newClassPathResource("ChangeSet.xml"),<br>
ResourceType.CHANGE_SET );<br>
kbuilder.add( ResourceFactory.newClassPathResource("TestRule.drl"),<br>
ResourceType.DRL);<br>
kbuilder.add(ResourceFactory.newByteArrayResource(data),<br>
ResourceType.DRL);<br>
<br>
if(kbuilder.hasErrors()) {<br>
System.out.println( kbuilder.getErrors() );<br>
return;<br>
}<br>
Collection<KnowledgePackage> kpkgs = kbuilder.getKnowledgePackages();<br>
knowledgeBase.addKnowledgePackages( kpkgs );<br>
<br>
<br>
emp = new EmployeeDataDTO();<br>
emp.setEmpNo(1);<br>
emp.setEmpName("PC");<br>
emp.setAge(29);<br>
emp.setSalary(new BigDecimal("6500"));<br>
<br>
session.insert(emp);<br>
<br>
session.fireAllRules();<br>
<br>
I am getting all the rules executed as per exceptation since it is in the<br>
same session, however the new rules that i have added are not reflected in<br>
Drools-Guvnor UI....<br>
<br>
please help me on code for deploying the knowldgeBase/Package(kpkgs) to<br>
Drools-Guvnor UI..<br>
<br>
-----<br>
PC<br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/facing-problems-while-adding-a-Rule-to-DROOLS-using-java-client-tp3806068p3806068.html" target="_blank">http://drools.46999.n3.nabble.com/facing-problems-while-adding-a-Rule-to-DROOLS-using-java-client-tp3806068p3806068.html</a><br>
Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote></div><br>