KnowledgeBases are not aware of Guvnor, nor are ChangeSets.

If you create a new rule and want to add it to Guvnor you'll need to use a suitable API.

Please look at Guvnor's documentation, in particular the Integration section and REST API.

With kind regards,

Mike

On 7 March 2012 07:12, PC <prakash.3098@gmail.com> wrote:
Hi,
 i am using Guvnor-5.2.0 . Through a simple java client class i wanted to
add
a rule at runtime.

below is the snippet of java code i am using to add a rule.

KnowledgeBase knowledgeBase = createKnowledgeBase();
session = knowledgeBase.newStatefulKnowledgeSession();
logger = KnowledgeRuntimeLoggerFactory.newFileLogger(session,
"log/DroolsSample");
KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);
String ruleDescription = "package com.tcube.atyaf.dto;"+
                                       "import
com.tcube.atyaf.dto.EmployeeDataDTO;" +
                                       "rule \"SimpleDRLRule\""+
                                       " @ID(11003588)"+
                                       " lock-on-active true"+
                                       " salience -11"+
                                       " dialect 'mvel'"+
                                       " when m :
EmployeeDataDTO(empName==\"PC\");"+
                                       " then System.out.println(
\"*************rule executed\");" +
                                       " m.setDesignation( \"Manager
,Additional Duties & Additional hike
!!!\" );"+
                                       " update( m );"+
                                       " end";
byte[] data = ruleDescription.getBytes();

KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(knowledgeBase);
kbuilder.add( ResourceFactory.newClassPathResource("ChangeSet.xml"),
ResourceType.CHANGE_SET );
kbuilder.add( ResourceFactory.newClassPathResource("TestRule.drl"),
ResourceType.DRL);
kbuilder.add(ResourceFactory.newByteArrayResource(data),
ResourceType.DRL);

if(kbuilder.hasErrors()) {
                           System.out.println( kbuilder.getErrors() );
                           return;
                       }
Collection<KnowledgePackage> kpkgs = kbuilder.getKnowledgePackages();
knowledgeBase.addKnowledgePackages( kpkgs );


emp = new EmployeeDataDTO();
emp.setEmpNo(1);
emp.setEmpName("PC");
emp.setAge(29);
emp.setSalary(new BigDecimal("6500"));

session.insert(emp);

session.fireAllRules();

I am getting all the rules executed as per exceptation since it is in the
same session, however the new rules that i have added are not reflected in
Drools-Guvnor UI....

please help me on code for deploying the knowldgeBase/Package(kpkgs) to
Drools-Guvnor UI..

-----
PC
--
View this message in context: http://drools.46999.n3.nabble.com/facing-problems-while-adding-a-Rule-to-DROOLS-using-java-client-tp3806068p3806068.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