Work
This commit is contained in:
parent
ce0f351c9d
commit
c9209dc9a5
105 changed files with 2390 additions and 839 deletions
35
AccountProject/drools-lesson1/drools-lesson1.iml
Normal file
35
AccountProject/drools-lesson1/drools-lesson1.iml
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/../../drools-lesson1/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: org.drools:drools-compiler:6.4.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.drools:drools-core:6.4.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.kie:kie-internal:6.4.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.antlr:antlr-runtime:3.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mvel:mvel2:2.2.8.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.thoughtworks.xstream:xstream:1.4.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: xmlpull:xmlpull:1.1.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: xpp3:xpp3_min:1.1.4c" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.protobuf:protobuf-java:2.6.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jdt.core.compiler:ecj:3.5.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jbpm:jbpm-bpmn2:6.4.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jbpm:jbpm-flow-builder:6.4.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jbpm:jbpm-flow:6.4.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: joda-time:joda-time:2.2" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.kie:kie-api:6.4.0.Final" level="project" />
|
||||
<orderEntry type="module" module-name="drools-lesson-pojo" />
|
||||
</component>
|
||||
</module>
|
||||
43
AccountProject/drools-lesson1/pom.xml
Normal file
43
AccountProject/drools-lesson1/pom.xml
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>AccountProject</artifactId>
|
||||
<groupId>com.pymma-software.droolscourse</groupId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>drools-lesson1</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.drools</groupId>
|
||||
<artifactId>drools-compiler</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jdt.core.compiler</groupId>
|
||||
<artifactId>ecj</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jbpm</groupId>
|
||||
<artifactId>jbpm-bpmn2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.kie</groupId>
|
||||
<artifactId>kie-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pymma-software.droolscourse</groupId>
|
||||
<artifactId>drools-lesson-pojo</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
|
||||
|
||||
<kbase name="lesson1" packages="lesson1">
|
||||
<ksession name="lesson1-session"/>
|
||||
</kbase>
|
||||
|
||||
</kmodule>
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
//#created on: 30 oct. 2010
|
||||
package cours
|
||||
|
||||
//list any import classes here.
|
||||
import droolscours.Account;
|
||||
import droolscours.Customer;
|
||||
import droolscours.AccountingPeriod;
|
||||
import droolscours.PrivateAccount;
|
||||
import droolscours.CashFlow;
|
||||
import droolscours.util.OutputDisplay;
|
||||
|
||||
//declare any global variables here
|
||||
|
||||
|
||||
global OutputDisplay showResult;
|
||||
|
||||
rule "Your First Rule"
|
||||
|
||||
when
|
||||
Account( )
|
||||
then
|
||||
System.out.println("The bank account exists");
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
rule "Your First Rule revisited with Global"
|
||||
|
||||
when
|
||||
Customer()
|
||||
then
|
||||
showResult.showText("A customer exists");
|
||||
|
||||
end
|
||||
|
||||
rule "Your First Rule revisited AccountingPeriod"
|
||||
|
||||
when
|
||||
CashFlow( )
|
||||
then
|
||||
showResult.showText("The CashFlow exists, inserting an accounting Period");
|
||||
AccountingPeriod newPeriod = new AccountingPeriod();
|
||||
insert (newPeriod);
|
||||
end
|
||||
|
||||
rule "Rule on AccountingPeriod that are inserting"
|
||||
when
|
||||
AccountingPeriod ()
|
||||
then
|
||||
showResult.showText("Accounting period exists");
|
||||
end
|
||||
|
|
@ -0,0 +1,163 @@
|
|||
package droolscours;
|
||||
|
||||
import droolscours.util.OutputDisplay;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.kie.api.event.rule.ObjectDeletedEvent;
|
||||
import org.kie.api.event.rule.ObjectInsertedEvent;
|
||||
import org.kie.api.event.rule.ObjectUpdatedEvent;
|
||||
import org.kie.api.event.rule.RuleRuntimeEventListener;
|
||||
import org.kie.api.runtime.KieContainer;
|
||||
import org.kie.api.runtime.KieSession;
|
||||
import org.kie.api.runtime.StatelessKieSession;
|
||||
import org.kie.api.runtime.rule.FactHandle;
|
||||
import util.KnowledgeSessionHelper;
|
||||
|
||||
|
||||
public class Testlesson1 {
|
||||
static KieContainer kieContainer;
|
||||
StatelessKieSession sessionStateless = null;
|
||||
KieSession sessionStatefull = null;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
kieContainer = KnowledgeSessionHelper.createRuleBase();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRuleOneFactWithoutFact() {
|
||||
sessionStatefull = KnowledgeSessionHelper
|
||||
.getStatefulKnowledgeSession(kieContainer, "lesson1-session");
|
||||
sessionStatefull.fireAllRules();
|
||||
System.out.println("Did you see something ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRuleOneFactWithFact() {
|
||||
sessionStatefull = KnowledgeSessionHelper
|
||||
.getStatefulKnowledgeSession(kieContainer, "lesson1-session");
|
||||
Account a = new Account();
|
||||
sessionStatefull.insert(a);
|
||||
sessionStatefull.fireAllRules();
|
||||
System.out.println("So you saw something ;)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRuleOneFactWithFactAndUsageOfGlobal() {
|
||||
sessionStatefull = KnowledgeSessionHelper
|
||||
.getStatefulKnowledgeSession(kieContainer, "lesson1-session");
|
||||
Customer a = new Customer();
|
||||
OutputDisplay display = new OutputDisplay();
|
||||
|
||||
sessionStatefull.setGlobal("showResult", display);
|
||||
sessionStatefull.insert(a);
|
||||
|
||||
sessionStatefull.fireAllRules();
|
||||
System.out.println("So you saw something ;)");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRuleOneFactWithFactAndUsageOfGlobalAndCallBack() {
|
||||
sessionStatefull = KnowledgeSessionHelper
|
||||
.getStatefulKnowledgeSession(kieContainer, "lesson1-session");
|
||||
sessionStatefull.addEventListener(new RuleRuntimeEventListener() {
|
||||
public void objectInserted(ObjectInsertedEvent event) {
|
||||
System.out.println("Object inserted \n"
|
||||
+ event.getObject().toString());
|
||||
}
|
||||
|
||||
public void objectUpdated(ObjectUpdatedEvent event) {
|
||||
System.out.println("Object was updated \n"
|
||||
+ "new Content \n" + event.getObject().toString());
|
||||
}
|
||||
|
||||
public void objectDeleted(ObjectDeletedEvent event) {
|
||||
System.out.println("Object retracted \n"
|
||||
+ event.getOldObject().toString());
|
||||
}
|
||||
});
|
||||
Customer a = new Customer();
|
||||
a.setName("Heron");
|
||||
FactHandle handlea = sessionStatefull.insert(a);
|
||||
a.setSurname("Nicolas");
|
||||
sessionStatefull.update(handlea, a);
|
||||
sessionStatefull.delete(handlea);
|
||||
sessionStatefull.fireAllRules();
|
||||
System.out.println("So you saw something ;)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRuleOneFactFireConditionStep1() {
|
||||
sessionStatefull = KnowledgeSessionHelper
|
||||
.getStatefulKnowledgeSession(kieContainer, "lesson1-session");
|
||||
Account a = new Account();
|
||||
FactHandle handlea = sessionStatefull.insert(a);
|
||||
System.out.println("First fireAllRules");
|
||||
sessionStatefull.fireAllRules();
|
||||
System.out.println("Second fireAllRules");
|
||||
sessionStatefull.fireAllRules();
|
||||
System.out.println("Did A rule be fired");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRuleOneFactFireConditionStep2() {
|
||||
sessionStatefull = KnowledgeSessionHelper
|
||||
.getStatefulKnowledgeSession(kieContainer, "lesson1-session");
|
||||
Account a = new Account();
|
||||
FactHandle handlea = sessionStatefull.insert(a);
|
||||
System.out.println("First fireAllRules");
|
||||
sessionStatefull.fireAllRules();
|
||||
System.out.println("Updating fact");
|
||||
sessionStatefull.update(handlea, a);
|
||||
System.out.println("Second fireAllRules");
|
||||
sessionStatefull.fireAllRules();
|
||||
System.out.println("Did A rule be fired");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRuleOneFactThatInsertObject() {
|
||||
sessionStatefull = KnowledgeSessionHelper
|
||||
.getStatefulKnowledgeSession(kieContainer, "lesson1-session");
|
||||
|
||||
OutputDisplay display = new OutputDisplay();
|
||||
sessionStatefull.setGlobal("showResult", display);
|
||||
|
||||
sessionStatefull.addEventListener(new RuleRuntimeEventListener() {
|
||||
public void objectInserted(ObjectInsertedEvent event) {
|
||||
System.out.println("Object inserted \n"
|
||||
+ event.getObject().toString());
|
||||
}
|
||||
|
||||
public void objectUpdated(ObjectUpdatedEvent event) {
|
||||
System.out.println("Object was updated \n"
|
||||
+ "new Content \n" + event.getObject().toString());
|
||||
}
|
||||
|
||||
public void objectDeleted(ObjectDeletedEvent event) {
|
||||
System.out.println("Object retracted \n"
|
||||
+ event.getOldObject().toString());
|
||||
}
|
||||
});
|
||||
CashFlow a = new CashFlow();
|
||||
FactHandle handlea = sessionStatefull.insert(a);
|
||||
sessionStatefull.fireAllRules();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRuleOneFactWithFactAndAllCallbacks() {
|
||||
sessionStatefull = KnowledgeSessionHelper
|
||||
.getStatefulKnowledgeSessionWithCallback(kieContainer, "lesson1-session");
|
||||
OutputDisplay display = new OutputDisplay();
|
||||
sessionStatefull.setGlobal("showResult", display);
|
||||
Account a = new Account();
|
||||
sessionStatefull.insert(a);
|
||||
sessionStatefull.fireAllRules();
|
||||
CashFlow b = new CashFlow();
|
||||
FactHandle handlea = sessionStatefull.insert(b);
|
||||
sessionStatefull.fireAllRules();
|
||||
System.out.println("So you saw something ;)");
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue