aspose file tools*
The moose likes Other Open Source Projects and the fly likes Using Drools I am not able to run rules from .pkg resources. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Using Drools I am not able to run rules from .pkg resources." Watch "Using Drools I am not able to run rules from .pkg resources." New topic
Author

Using Drools I am not able to run rules from .pkg resources.

kalpana vankadari
Greenhorn

Joined: Jul 17, 2013
Posts: 1
I am not able to run rules from .pkg resources.

Knowledgesession is getting populated with package and rules inside the packages but when I am firing ksession.fireAllRules(); no rules are getting executed.
I am not able to run rules from .pkg resources.



Below is my program

final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

// Use this line if calling rule defined using guvnor package
org.drools.io.impl.UrlResource urlResource;
try {
urlResource = (org.drools.io.impl.UrlResource) org.drools.io.ResourceFactory
.newUrlResource(new java.net.URL("http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/OBSPOC/OBSSNAP/OBSPOC_OBSSNAP.pkg"));


urlResource.setBasicAuthentication("enabled");
urlResource.setUsername("admin");
urlResource.setPassword("admin");
kbuilder.add(urlResource,ResourceType.PKG);
}
catch (MalformedURLException e) {
System.out.println("malformed URL");
e.printStackTrace();
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// create the knowledge base
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();




// Check the builder for errors
if (kbuilder.hasErrors()) {
System.out.println(kbuilder.getErrors().toString() + "********");
throw new RuntimeException("Unable to compile the rule file.");
}else{
System.out.println(".....Rule File is Read Successfully....");
}

// get the compiled packages (which are serializable)
final Collection pkgs = kbuilder
.getKnowledgePackages();

// add the packages to a knowledgebase (deploy the knowledge packages).
// final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(pkgs);


final StatefulKnowledgeSession ksession = kbase
.newStatefulKnowledgeSession();

ksession.addEventListener(new DebugAgendaEventListener());
ksession.addEventListener(new DebugWorkingMemoryEventListener());

EmployeeMap employeeMap = new EmployeeMap();
employeeMap.setEmployeeCountry("INDIA");
employeeMap.setEmployeeID(1);
employeeMap.setEmployeeName("USERP");

ksession.insert(employeeMap);
ksession.fireAllRules();


ksession.dispose();
Suresh Mahalingam
Greenhorn

Joined: Dec 05, 2013
Posts: 1
Hi Kalpana,
The issue has been resolved, I have tried different way and got the solution. Please try the below code.

org.drools.io.impl.UrlResource urlResource;
try {
urlResource = (org.drools.io.impl.UrlResource) org.drools.io.ResourceFactory
.newUrlResource(new java.net.URL("http://localhost:8080/guvnor-5.5.0.Final-jboss-as-7.0/rest/packages/com.xxx.xxx.drools/binary"));
urlResource.setBasicAuthentication("enabled");
urlResource.setUsername("admin");
urlResource.setPassword("admin");
kbuilder.add(urlResource,ResourceType.PKG);
}
catch (MalformedURLException e) {
System.out.println("malformed URL");
e.printStackTrace();
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Pankaj Patro
Ranch Hand

Joined: Apr 20, 2005
Posts: 35
Hi,

need to run same (.PKG) in Drools 6.0.0 version, could you help me on APIs, as I am very new to Drools.


Thanks & Regards,
Pankaj Patro
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using Drools I am not able to run rules from .pkg resources.