Hi,


I am implementing rules engine into my project, I have been referring the many 
technical resources about jboss drools.
I did implement some set of rules which are much more needed for my project.
All of a sudden after I placed all the rules in the spreadsheet(.xls) file, and 
executed it, it shows me strange exceptions like this below.
It was reading the xls file, creating .drl file, that also we can see, but it 
is showing the errors.
Can anyone help me please on this, I am very much tried, could not able to 
resolve.
I need a clue how to do that.

This is my class, where I will have conditional parameters
package com.dfs.dsa.rules;

public class QuarterlyBonusRules {

private Double attendancePercentage = null;

public Double getAttendancePercentage() {
return attendancePercentage;
}

public void setAttendancePercentage(Double attendancePercentage) {
this.attendancePercentage = attendancePercentage;
}

public int getMinorCollisionDays() {
return minorCollisionDays;
}

public void setMinorCollisionDays(int minorCollisionDays) {
this.minorCollisionDays = minorCollisionDays;
}

public int getMajorCollisionDays() {
return majorCollisionDays;
}

public void setMajorCollisionDays(int majorCollisionDays) {
this.majorCollisionDays = majorCollisionDays;
}

private int minorCollisionDays;
private int majorCollisionDays;
private int bonusAmount = 11;
private boolean violationAssessed = false;

public int getBonusAmount() {
return bonusAmount;
}

public void setBonusAmount(int bonusAmount) {
this.bonusAmount = bonusAmount;
}

public boolean isViolationAssessed() {
return violationAssessed;
}

public void setViolationAssessed(boolean violationAssessed) {
this.violationAssessed = violationAssessed;
}

}

Then I do have one test class to execute the rules

package com.dfs.dsa.rules;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;

import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.decisiontable.InputType;
import org.drools.decisiontable.SpreadsheetCompiler;
import org.drools.event.rule.DebugAgendaEventListener;
import org.drools.event.rule.DebugWorkingMemoryEventListener;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;

/**
 * This class will create a drl file from excel sheet and then execute the
 * rules.
 */
@SuppressWarnings("restriction")
public class QBResult {
public static final void main(final String[] args) {
// Create knowledge builder
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();

// Create drl file from excel sheet
InputStream is = null;
try {
is = new 
FileInputStream("c:/myeclipse/DroolsProject/src/QuarterlyBonusRules.xls");

} catch (FileNotFoundException e) {
e.printStackTrace();
}
// Create compiler class instance
SpreadsheetCompiler sc = new SpreadsheetCompiler();

// Compile the excel to generate the (.drl) file
StringBuffer drl = new StringBuffer(sc.compile(is, InputType.XLS));

// Insert dialect value into drl file
drl.insert(drl.indexOf("DROOLS") + 40, "dialect \"mvel\"" + "\n");

// Check the generated drl file
System.out.println("Generate DRL file is showing below–: ");
System.out.println(drl);

// writing string into a drl file
try {
BufferedWriter out = new BufferedWriter(new FileWriter(
"QuarterlyBonusRules.drl"));
out.write(drl.toString());
out.close();
} catch (IOException e) {
System.out.println("Exception ");
}
// Wait before using the drl file in the next section.
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
kbuilder.add(ResourceFactory.newFileResource(new File(
"QuarterlyBonusRules.drl")), ResourceType.DRL);
if (kbuilder.hasErrors()) {
System.out.println("kbuilder has errors");
System.out.println(kbuilder.getErrors().toString());
}
// get the compiled packages (which are serializable)
final Collection pkgs = kbuilder.getKnowledgePackages();
final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(pkgs);
final StatefulKnowledgeSession ksession = kbase
.newStatefulKnowledgeSession();
ksession.addEventListener(new DebugAgendaEventListener());
ksession.addEventListener(new DebugWorkingMemoryEventListener());
QuarterlyBonusRules qbr = new QuarterlyBonusRules();
qbr.setAttendancePercentage(new Double(0.75));
qbr.setMinorCollisionDays(0);
qbr.setMajorCollisionDays(0);
qbr.setViolationAssessed(false);
ksession.insert(qbr);
ksession.fireAllRules();
ksession.dispose();
System.out.println(qbr.getBonusAmount());
}
}

AFter executing the above program, here I am getting the error, and not able to 
rectify it

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further 
details.
Warning:  Cannot read name ranges for Excel_BuiltIn__FilterDatabase_1 - setting 
to empty
Warning:  Cell at D21 not present - adding a blank
Generate DRL file is showing below–: 
package DROOLS;
//generated from Decision Table
dialect "mvel"
import com.dfs.dsa.rules.QuarterlyBonusRules;
// rule values at B11, header at B6
rule "1"
when
qbr:QuarterlyBonusRules(attendancePercentage>=0.75)
(minorCollisionDays>=0 && minorCollisionDays<=0);
(majorCollisionDays>=0 && majorCollisionDays<=0);
violationAssessed==false;
then
qbr.setBonusAmount(150);
end

// rule values at B12, header at B6
rule "2"
when
qbr:QuarterlyBonusRules(attendancePercentage>=0.56)
(minorCollisionDays>=0 && minorCollisionDays<=90);
(majorCollisionDays>=0 && majorCollisionDays<=90);
violationAssessed==true;
then
qbr.setBonusAmount(0);
end


kbuilder has errors
[9,21]: [ERR 102] Line 9:21 mismatched input '>=' in rule "1"
[20,21]: [ERR 102] Line 20:21 mismatched input '>=' in rule "2"
[0,0]: Parser returned a null Package

==>[ObjectInsertedEventImpl: getFactHandle()=[fact 
0:1:2144330803:2144330803:1:DEFAULT:com.dfs.dsa.rules.QuarterlyBonusRules@7fcfe433],
 getObject()=com.dfs.dsa.rules.QuarterlyBonusRules@7fcfe433, 
getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@23efdc4, 
getPropagationContext()=PropagationContextImpl [activeActivations=0, 
dormantActivations=0, entryPoint=EntryPoint::DEFAULT, factHandle=[fact 
0:1:2144330803:2144330803:1:DEFAULT:com.dfs.dsa.rules.QuarterlyBonusRules@7fcfe433],
 leftTuple=null, originOffset=-1, propagationNumber=4, rule=null, type=0]]
11

Note: the number 11 is the value, it has printed, that I set to the bonus 
amount, but it should not print that value, it should pring 150.

I am here attaching the spread sheet, where I have added all the rules in it.

I appreciate you a lot for the help

Thanks & Regards,
Venkata.

Attachment: QuarterlyBonusRules.xls
Description: MS-Excel spreadsheet

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to