This commit is contained in:
Nicolas Héron 2016-05-20 14:16:10 +02:00
commit 474d3bf5b1
86 changed files with 675 additions and 529 deletions

View file

@ -1,8 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<kbase name="sample" packages="sample">
<ksession name="sample-session"/>
</kbase>
<kbase name="simplesample" packages="simplesample">
<ksession name="simplesample-session"/>
</kbase>
<kbase name="part1" packages="part1">
<ksession name="part1-rules"/>
</kbase>
<kbase name="part2" packages="part2">
<ksession name="part2-rules"/>
</kbase>
<kbase name="part3" packages="part3">
<ksession name="part3-rules"/>
</kbase>
<kbase name="part4" packages="part4">
<ksession name="part4-rules"/>
</kbase>
<kbase name="part5" packages="part5">
<ksession name="part5-rules"/>
</kbase>
<kbase name="part6" packages="part6">
<ksession name="part6-rules"/>
</kbase>
<kbase name="part7" packages="part7">
<ksession name="part7-rules"/>
</kbase>
<kbase name="demo" packages="demo">
<ksession name="demo-rules"/>
</kbase>
<kbase name="demo-global" packages="demo-global">
<ksession name="demo-global-rules"/>
</kbase>
<kbase name="demo-insertupdatedelete" packages="demo-insertupdatedelete">
<ksession name="demo-insertupdatedelete-rules"/>
</kbase>
<kbase name="demo-ruleflow1" packages="demo-ruleflow1">
<ksession name="demo-ruleflow1-rules"/>
</kbase>
<kbase name="demo-ruleflow2" packages="demo-ruleflow2">
<ksession name="demo-ruleflow2-rules"/>
</kbase>
<kbase name="demo-ruleflow3" packages="demo-ruleflow3">
<ksession name="demo-ruleflow3-rules"/>
</kbase>
</kmodule>

View file

@ -1,17 +0,0 @@
package simplesample
import droolscours.Account;
import droolscours.AccountingPeriod;
import droolscours.CashFlow;
import droolscours.util.OutputDisplay;
global OutputDisplay showResults;
rule "Credit Rule"
when
acco: Account( no : accountno )
period : AccountingPeriod(s : startDate , e: endDate )
act : CashFlow( type == CashFlow.CREDIT ,mvtDate >= s && mvtDate <=e ,accountNo ==no)
then
acco.setBalance(acco.getBalance()+act.getAmount());
showResults.showText("The new balance is now "+acco.getBalance());
end

View file

@ -1,6 +1,5 @@
package droolscours;
import droolscours.util.OutputDisplay;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@ -11,24 +10,25 @@ 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.omg.CORBA.portable.OutputStream;
import util.DateHelper;
import util.KnowledgeSessionHelper;
public class PremierEssai {
StatelessKieSession sessionStateless = null;
KieSession sessionStatefull = null;
static KieContainer kieContainer;
StatelessKieSession sessionStateless = null;
KieSession sessionStatefull = null;
@BeforeClass
public static void beforeClass(){
kieContainer=KnowledgeSessionHelper.createRuleBase();
public static void beforeClass() {
kieContainer = KnowledgeSessionHelper.createRuleBase();
}
@Test
public void testSimple() throws Exception {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSession(kieContainer,"simplesample-session");
.getStatefulKnowledgeSession(kieContainer, "simplesample-session");
sessionStatefull.addEventListener(new RuleRuntimeEventListener() {
public void objectInserted(ObjectInsertedEvent event) {
System.out.println("Object inserted \n"
@ -45,8 +45,6 @@ public class PremierEssai {
+ event.getOldObject().toString());
}
});
OutputDisplay showResult = new OutputDisplay();
sessionStatefull.setGlobal("showResults",showResult);
Account account = new Account();
account.setAccountno(1);
sessionStatefull.insert(account);

View file

@ -0,0 +1,73 @@
package droolscours;
import droolscours.util.OutputDisplay;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import util.KnowledgeSessionHelper;
public class TestRuleFlow {
static KieContainer kieContainer;
KieSession sessionStatefull = null;
@BeforeClass
public static void beforeClass() {
kieContainer = KnowledgeSessionHelper.createRuleBase();
}
@Before
public void setUp() throws Exception {
System.out.println("------------Before------------");
}
@After
public void tearDown() throws Exception {
System.out.println("------------Après ------------");
}
@Test
public void testdeuxFait1() {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSession(kieContainer, "demo-ruleflow1-rules");
OutputDisplay display = new OutputDisplay();
sessionStatefull.setGlobal("showResult", display);
Account a = new Account();
sessionStatefull.insert(a);
AccountingPeriod period = new AccountingPeriod();
sessionStatefull.insert(period);
sessionStatefull.startProcess("RF1");
sessionStatefull.fireAllRules();
}
@Test
public void testdeuxFait2() {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSession(kieContainer, "demo-ruleflow2-rules");
OutputDisplay display = new OutputDisplay();
sessionStatefull.setGlobal("showResult", display);
Account a = new Account();
sessionStatefull.insert(a);
AccountingPeriod period = new AccountingPeriod();
sessionStatefull.insert(period);
sessionStatefull.fireAllRules();
}
@Test
public void testdeuxFait3() {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSession(kieContainer, "demo-ruleflow3-rules");
OutputDisplay display = new OutputDisplay();
sessionStatefull.setGlobal("showResult", display);
Account a = new Account();
a.setBalance(1500);
sessionStatefull.insert(a);
AccountingPeriod period = new AccountingPeriod();
sessionStatefull.insert(period);
sessionStatefull.fireAllRules();
}
}

View file

@ -0,0 +1,256 @@
package droolscours;
import droolscours.service.CustomerService;
import droolscours.util.OutputDisplay;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.rule.FactHandle;
import util.DateHelper;
import util.KnowledgeSessionHelper;
public class Testlanguage {
static KieContainer kieContainer;
KieSession sessionStatefull = null;
@BeforeClass
public static void beforeClass() {
kieContainer = KnowledgeSessionHelper.createRuleBase();
}
@Before
public void setUp() throws Exception {
System.out.println("------------Before------------");
}
@After
public void tearDown() throws Exception {
System.out.println("------------Après ------------");
}
@Test
public void testdeuxFait1() {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSessionWithCallback(kieContainer, "part1-rules");
OutputDisplay display = new OutputDisplay();
sessionStatefull.setGlobal("showResult", display);
Account a = new Account();
sessionStatefull.insert(a);
AccountingPeriod period = new AccountingPeriod();
sessionStatefull.insert(period);
sessionStatefull.fireAllRules();
}
@Test
public void testdeuxFait2() throws Exception {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSessionWithCallback(kieContainer, "part1-rules");
OutputDisplay display = new OutputDisplay();
sessionStatefull.setGlobal("showResult", display);
Account a = new Account();
a.setAccountno(1);
a.setBalance(0);
sessionStatefull.insert(a);
CashFlow cash1 = new CashFlow();
cash1.setAccountNo(1);
cash1.setAmount(1000);
cash1.setMvtDate(DateHelper.getDate("2010-01-15"));
cash1.setType(CashFlow.CREDIT);
sessionStatefull.insert(cash1);
sessionStatefull.fireAllRules();
Assert.assertTrue(a.getBalance()==1000);
}
@Test
public void testdeuxFait3() throws Exception {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSessionWithCallback(kieContainer, "part1-rules");
OutputDisplay display = new OutputDisplay();
sessionStatefull.setGlobal("showResult", display);
Account a = new Account();
a.setAccountno(1);
a.setBalance(0);
sessionStatefull.insert(a);
CashFlow cash1 = new CashFlow();
cash1.setAccountNo(1);
cash1.setAmount(1000);
cash1.setMvtDate(DateHelper.getDate("2010-01-15"));
cash1.setType(CashFlow.CREDIT);
sessionStatefull.insert(cash1);
CashFlow cash2 = new CashFlow();
cash2.setAccountNo(2);
cash2.setAmount(1000);
cash2.setMvtDate(DateHelper.getDate("2010-01-15"));
cash2.setType(CashFlow.CREDIT);
sessionStatefull.insert(cash2);
sessionStatefull.fireAllRules();
Assert.assertTrue(a.getBalance()==1000);
}
@Test
public void testdeuxFait4() throws Exception {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSessionWithCallback(kieContainer, "part2-rules");
OutputDisplay display = new OutputDisplay();
sessionStatefull.setGlobal("showResult", display);
Account a = new Account();
a.setAccountno(1);
a.setBalance(0);
sessionStatefull.insert(a);
CashFlow cash1 = new CashFlow();
cash1.setAccountNo(1);
cash1.setAmount(1000);
cash1.setMvtDate(DateHelper.getDate("2010-01-15"));
cash1.setType(CashFlow.CREDIT);
sessionStatefull.insert(cash1);
CashFlow cash2 = new CashFlow();
cash2.setAccountNo(1);
cash2.setAmount(500);
cash2.setMvtDate(DateHelper.getDate("2010-02-15"));
cash2.setType(CashFlow.DEBIT);
sessionStatefull.insert(cash2);
CashFlow cash3 = new CashFlow();
cash3.setAccountNo(1);
cash3.setAmount(1000);
cash3.setMvtDate(DateHelper.getDate("2010-04-15"));
cash3.setType(CashFlow.CREDIT);
sessionStatefull.insert(cash3);
AccountingPeriod period = new AccountingPeriod();
period.setStartDate(DateHelper.getDate("2010-01-01"));
period.setEndDate(DateHelper.getDate("2010-03-31"));
sessionStatefull.insert(period);
sessionStatefull.fireAllRules();
Assert.assertTrue(a.getBalance()==500);
}
@Test
public void testdeuxFait5() throws Exception {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSessionWithCallback(kieContainer, "part3-rules");
OutputDisplay display = new OutputDisplay();
sessionStatefull.setGlobal("showResult", display);
Customer customer = new Customer();
customer.setName("Héron");
customer.setSurname("Nicolas");
PrivateAccount pAccount = new PrivateAccount();
pAccount.setOwner(customer);
sessionStatefull.insert(pAccount);
sessionStatefull.fireAllRules();
}
@Test
public void testdeuxFait6() throws Exception {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSessionWithCallback(kieContainer, "part3-rules");
OutputDisplay display = new OutputDisplay();
sessionStatefull.setGlobal("showResult", display);
Customer customer = new Customer();
customer.setName("Héron");
customer.setSurname("Nicolas");
customer.setCountry("GB");
sessionStatefull.insert(customer);
PrivateAccount pAccount = new PrivateAccount();
pAccount.setOwner(customer);
sessionStatefull.insert(pAccount);
sessionStatefull.fireAllRules();
}
@Test
public void testdeuxFait7() throws Exception {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSessionWithCallback(kieContainer, "part3-rules");
OutputDisplay display = new OutputDisplay();
sessionStatefull.setGlobal("showResult", display);
Account pAccount = new Account();
sessionStatefull.insert(pAccount);
sessionStatefull.fireAllRules();
}
@Test
public void testdeuxFait8() throws Exception {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSessionWithCallback(kieContainer, "part3-rules");
OutputDisplay display = new OutputDisplay();
sessionStatefull.setGlobal("showResult", display);
Account pAccount = new Account();
sessionStatefull.insert(pAccount);
sessionStatefull.fireAllRules();
}
@Test
public void testdeuxFait9() throws Exception {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSessionWithCallback(kieContainer, "part4-rules");
OutputDisplay display = new OutputDisplay();
sessionStatefull.setGlobal("showResult", display);
Account a = new Account();
a.setAccountno(1);
a.setBalance(0);
sessionStatefull.insert(a);
CashFlow cash1 = new CashFlow();
cash1.setAccountNo(1);
cash1.setAmount(1000);
cash1.setMvtDate(DateHelper.getDate("2010-01-15"));
cash1.setType(CashFlow.CREDIT);
sessionStatefull.insert(cash1);
CashFlow cash2 = new CashFlow();
cash2.setAccountNo(1);
cash2.setAmount(500);
cash2.setMvtDate(DateHelper.getDate("2010-02-15"));
cash2.setType(CashFlow.DEBIT);
sessionStatefull.insert(cash2);
Account a2 = new Account();
a2.setAccountno(2);
a2.setBalance(0);
sessionStatefull.insert(a2);
CashFlow cash3 = new CashFlow();
cash3.setAccountNo(2);
cash3.setAmount(1000);
cash3.setMvtDate(DateHelper.getDate("2010-04-15"));
cash3.setType(CashFlow.CREDIT);
sessionStatefull.insert(cash3);
sessionStatefull.fireAllRules();
}
@Test
public void testdeuxFait10() throws Exception {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSessionWithCallback(kieContainer, "part5-rules");
OutputDisplay display = new OutputDisplay();
sessionStatefull.setGlobal("showResult", display);
sessionStatefull.setGlobal("serviceCustomer", new CustomerService());
Customer c = new Customer("Héron","Nicolas","A");
sessionStatefull.insert(c);
sessionStatefull.fireAllRules();
}
@Test
public void testdeuxFait11() throws Exception {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSessionWithCallback(kieContainer, "part6-rules");
OutputDisplay display = new OutputDisplay();
sessionStatefull.setGlobal("showResult", display);
Account a = new Account();
a.setAccountno(1);
a.setBalance(0);
sessionStatefull.insert(a);
sessionStatefull.insert(new CashFlow(DateHelper.getDate("2010-01-15"),1000,CashFlow.CREDIT,1));
sessionStatefull.insert(new CashFlow(DateHelper.getDate("2010-02-15"),500,CashFlow.DEBIT,1));
sessionStatefull.insert(new CashFlow(DateHelper.getDate("2010-04-15"),1000,CashFlow.CREDIT,1));
sessionStatefull.insert(new AccountingPeriod(DateHelper.getDate("2010-01-01"),DateHelper.getDate("2010-31-31")));
sessionStatefull.fireAllRules();
}
@Test
public void testdeuxFait12() throws Exception {
sessionStatefull = KnowledgeSessionHelper
.getStatefulKnowledgeSessionWithCallback(kieContainer, "part7-rules");
OutputDisplay display = new OutputDisplay();
sessionStatefull.setGlobal("showResult", display);
sessionStatefull.insert(new Account(1,0));
FactHandle fa = sessionStatefull.insert(new CashFlow(DateHelper.getDate("2010-01-15"), 1000, CashFlow.CREDIT, 1));
sessionStatefull.insert(new CashFlow(DateHelper.getDate("2010-02-15"),500,CashFlow.DEBIT,1));
sessionStatefull.insert(new CashFlow(DateHelper.getDate("2010-04-15"),1000,CashFlow.CREDIT,1));
sessionStatefull.insert(new AccountingPeriod(DateHelper.getDate("2010-01-01"),DateHelper.getDate("2010-12-31")));
sessionStatefull.fireAllRules();
sessionStatefull.delete(fa);
sessionStatefull.fireAllRules();
}
}

View file

@ -0,0 +1,22 @@
//#created on: 30 oct. 2010
package cours
//list any import classes here.
import droolscours.Account;
import droolscours.util.OutputDisplay;
//#declare any global variables here
global OutputDisplay showResult;
rule "Your First Rule revisited"
when
Account( )
then
showResult.showText("Le compte existe donc déjà");
end

View file

@ -0,0 +1,23 @@
//#created on: 30 oct. 2010
package cours
//#list any import classes here.
import droolscours.Account;
import droolscours.AccountingPeriod;
import droolscours.util.OutputDisplay;
//#declare any global variables here
global OutputDisplay showResult;
rule "Your First Rule revisited"
when
Account( )
then
showResult.showText("Le compte existe donc déjà");
AccountingPeriod newPeriod = new AccountingPeriod();
insert (newPeriod);
end
rule "Rule on Period"
when
AccountingPeriod ()
then
showResult.showText("Période de compte existe");
end

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://drools.org/drools-5.0/process"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd"
type="RuleFlow" name="RuleFlow1" id="RF1" package-name="cours" >
<header>
</header>
<nodes>
<start id="1" name="Start" x="62" y="79" width="80" height="40" />
<ruleSet id="2" name="Verify" x="162" y="77" width="80" height="40" ruleFlowGroup="Group1" />
<ruleSet id="3" name="Calculation" x="267" y="77" width="80" height="40" ruleFlowGroup="Group2" />
<end id="4" name="End" x="372" y="77" width="80" height="40" />
</nodes>
<connections>
<connection from="1" to="2" />
<connection from="2" to="3" />
<connection from="3" to="4" />
</connections>
</process>

View file

@ -0,0 +1,32 @@
//#created on: 30 oct. 2010
package cours
//#list any import classes here.
import droolscours.Account;
import droolscours.AccountingPeriod;
import droolscours.CashFlow;
import droolscours.util.OutputDisplay;
//#declare any global variables here
global OutputDisplay showResult;
rule "Account group1"
ruleflow-group "Group1"
when
Account( )
then
showResult.showText("Account in Group1");
end
rule "Account group2"
ruleflow-group "Group2"
when
Account( )
then
showResult.showText("Account in Group2");
end

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://drools.org/drools-5.0/process"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd"
type="RuleFlow" name="RuleFlow2" id="RF2" package-name="cours" >
<header>
</header>
<nodes>
<start id="1" name="Start" x="62" y="79" width="80" height="40" />
<ruleSet id="2" name="Verify" x="162" y="77" width="80" height="40" ruleFlowGroup="Group1" />
<ruleSet id="3" name="Calculation" x="267" y="77" width="80" height="40" ruleFlowGroup="Group2" />
<end id="4" name="End" x="372" y="77" width="80" height="40" />
</nodes>
<connections>
<connection from="1" to="2" />
<connection from="2" to="3" />
<connection from="3" to="4" />
</connections>
</process>

View file

@ -0,0 +1,38 @@
//#created on: 30 oct. 2010
package cours
//#list any import classes here.
import droolscours.Account;
import droolscours.AccountingPeriod;
import droolscours.CashFlow;
import droolscours.util.OutputDisplay;
//#declare any global variables here
global OutputDisplay showResult;
rule "start process"
when
then
kcontext.getKieRuntime().startProcess("RF2");
end
rule "Account group1"
ruleflow-group "Group1"
when
Account( )
then
showResult.showText("Account in Group1");
end
rule "Account group2"
ruleflow-group "Group2"
when
Account( )
then
showResult.showText("Account in Group2");
end

View file

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://drools.org/drools-5.0/process"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd"
type="RuleFlow" name="RuleFlow3" id="RF2" package-name="cours" >
<header>
<imports>
<import name="droolscours.Account" />
</imports>
</header>
<nodes>
<start id="1" name="Start" x="27" y="78" width="80" height="40" />
<ruleSet id="2" name="Calculate2" x="264" y="135" width="80" height="40" ruleFlowGroup="Group2" />
<ruleSet id="3" name="Calculate1" x="266" y="28" width="80" height="40" ruleFlowGroup="Group1" />
<end id="4" name="End" x="487" y="85" width="80" height="40" />
<join id="6" name="Join" x="357" y="91" width="80" height="40" type="2" />
<split id="7" name="Split" x="131" y="93" width="80" height="40" type="3" >
<constraints>
<constraint toNodeId="2" toType="DROOLS_DEFAULT" name="constraint" priority="1" type="rule" dialect="mvel" >Account(balance &lt;= 1000 )</constraint>
<constraint toNodeId="3" toType="DROOLS_DEFAULT" name="constraint" priority="1" type="rule" dialect="mvel" >Account(balance &gt; 1000 )</constraint>
</constraints>
</split>
</nodes>
<connections>
<connection from="7" to="2" />
<connection from="7" to="3" />
<connection from="6" to="4" />
<connection from="3" to="6" />
<connection from="2" to="6" />
<connection from="1" to="7" />
</connections>
</process>

View file

@ -0,0 +1,37 @@
//#created on: 30 oct. 2010
package cours
//#list any import classes here.
import droolscours.Account;
import droolscours.AccountingPeriod;
import droolscours.CashFlow;
import droolscours.util.OutputDisplay;
//#declare any global variables here
global OutputDisplay showResult;
rule "start process"
when
then
kcontext.getKieRuntime().startProcess("RF3");
end
rule "Account group1"
ruleflow-group "Group1"
when
Account(balance > 0 )
then
showResult.showText("Account in Group1 > 1000 ");
end
rule "Account group2"
ruleflow-group "Group2"
when
Account( )
then
showResult.showText("Account in Group2 < 1000");
end

View file

@ -0,0 +1,21 @@
//#created on: 30 oct. 2010
package cours
//list any import classes here.
import droolscours.Account;
import droolscours.util.OutputDisplay;
//declare any global variables here
global OutputDisplay showResult;
rule "Your First Rule"
when
Account( )
then
System.out.println("Le compte existe");
end

View file

@ -0,0 +1,34 @@
//#created on: 30 oct. 2010
package cours
//#list any import classes here.
import droolscours.Account;
import droolscours.AccountingPeriod;
import droolscours.CashFlow;
import droolscours.util.OutputDisplay;
//#declare any global variables here
global OutputDisplay showResult;
rule "Account and accounting period both exist"
when
Account( )
AccountingPeriod( )
then
showResult.showText("Un compte est un accountingperiod existe");
end
rule "Credit rule"
when
$cash :CashFlow( $no : accountNo ,type == CashFlow.CREDIT )
$acc : Account(accountno ==$no )
then
$acc.setBalance($acc.getBalance()+$cash.getAmount());
showResult.showText("le compte no "+$no+ " a maintenant une valeur de "+$acc.getBalance());
end

View file

@ -0,0 +1,32 @@
//#created on: 30 oct. 2010
package cours
import droolscours.Account;
import droolscours.AccountingPeriod;
import droolscours.CashFlow;
import droolscours.util.OutputDisplay;
global OutputDisplay showResult;
rule "Credit rule"
when
$cash :CashFlow( $aDate : mvtDate, $no : accountNo ,type == CashFlow.CREDIT )
$acc : Account(accountno ==$no )
$period : AccountingPeriod( startDate <= $aDate && endDate >= $aDate)
then
$acc.setBalance($acc.getBalance()+$cash.getAmount());
showResult.showText("le compte no "+$no+ " a maintenant une valeur de "+$acc.getBalance());
end
rule "Debit rule"
when
$cash :CashFlow( $aDate : mvtDate, $no : accountNo ,type == CashFlow.DEBIT )
$acc : Account(accountno ==$no )
$period : AccountingPeriod( startDate <= $aDate && endDate >= $aDate)
then
$acc.setBalance($acc.getBalance()-$cash.getAmount());
showResult.showText("le compte no "+$no+ " a maintenant une valeur de "+$acc.getBalance());
end

View file

@ -0,0 +1,51 @@
//#created on: 30 oct. 2010
package cours
//#list any import classes here.
import droolscours.Account;
import droolscours.AccountingPeriod;
import droolscours.CashFlow;
import droolscours.PrivateAccount;
import droolscours.Customer;
import droolscours.util.OutputDisplay;
//#declare any global variables here
global OutputDisplay showResult;
rule "Le cashFlow est du crédit ou du débit"
when
$cash :CashFlow(type in ( CashFlow.DEBIT,CashFlow.CREDIT) )
then
showResult.showText("Cash Flow est un crédit ou un débit");
end
rule "Accessor"
when
$cash :PrivateAccount( owner.name =="Héron" )
then
showResult.showText("Account is owned by Héron");
end
rule "infixAnd"
when
( $c1 : Customer ( country=="GB") and PrivateAccount( owner==$c1))
or
( $c1 : Customer (country=="US") and PrivateAccount( owner==$c1))
then
showResult.showText("Person lives in GB or US");
end
rule "no customer"
when
not Customer( )
then
showResult.showText("No customer");
end
rule "Exists"
when
exists Account( )
then
showResult.showText("Account exists");
end

View file

@ -0,0 +1,32 @@
//#created on: 30 oct. 2010
package cours
//#list any import classes here.
import droolscours.Account;
import droolscours.AccountingPeriod;
import droolscours.CashFlow;
import droolscours.PrivateAccount;
import droolscours.Customer;
import droolscours.util.OutputDisplay;
//#declare any global variables here
global OutputDisplay showResult;
rule "ForAll"
when
forall ( Account( $no : accountno )
CashFlow( accountNo == $no)
)
then
showResult.showText("All mouvements concerns all account ");
end
rule "ForAll2"
when
Account( $no : accountno )
CashFlow( accountNo == $no)
then
showResult.showText("All mouvements concerns only one account ");
end

View file

@ -0,0 +1,22 @@
//#created on: 30 oct. 2010
package cours
//#list any import classes here.
import droolscours.Account;
import droolscours.AccountingPeriod;
import droolscours.CashFlow;
import droolscours.PrivateAccount;
import droolscours.Customer;
import droolscours.service.CustomerService;
import droolscours.util.OutputDisplay;
//#declare any global variables here
global OutputDisplay showResult;
global CustomerService serviceCustomer;
rule "ForAll"
when
$c : Customer()
$cc : Customer(name ==$c.name,surname==$c.surname,country !=$c.country) from serviceCustomer.getListCustomer();
then
showResult.showText("Found same customer in 2 countries");
end

View file

@ -0,0 +1,42 @@
//#created on: 30 oct. 2010
package cours
//#list any import classes here.
import droolscours.Account;
import droolscours.AccountingPeriod;
import droolscours.CashFlow;
import droolscours.PrivateAccount;
import droolscours.Customer;
import droolscours.service.CustomerService;
import java.util.ArrayList;
import droolscours.util.OutputDisplay;
//#declare any global variables here
global OutputDisplay showResult;
global CustomerService serviceCustomer;
rule "More then 2 CashFlow Line"
when
$c : Account( $acc : accountno )
$p : AccountingPeriod ($sDate : startDate ,$eDate : endDate )
$number : ArrayList(size >= 2 )
from collect( CashFlow( mvtDate >= $sDate && mvtDate <= $eDate,accountNo == $acc ) )
then
showResult.showText("Found more than 2 CashFlow Lines");
showResult.showText("<<<<<<<<<<");
for (Object ff : $number){
showResult.showText(ff.toString());
}
showResult.showText(">>>>>>>>>>>>>>>>");
end
rule "Numbers of CashFlow Line"
when
$c : Account( $acc : accountno )
$p : AccountingPeriod ($sDate : startDate ,$eDate : endDate )
$number : ArrayList( )
from collect( CashFlow( mvtDate >= $sDate && mvtDate <= $eDate,accountNo == $acc ) )
then
showResult.showText("Found "+$number+" more than 2 CashFlow Lines");
end

View file

@ -0,0 +1,38 @@
//#created on: 30 oct. 2010
package cours
//#list any import classes here.
import droolscours.Account;
import droolscours.AccountingPeriod;
import droolscours.CashFlow;
import droolscours.PrivateAccount;
import droolscours.Customer;
import droolscours.service.CustomerService;
import java.util.ArrayList;
import droolscours.util.OutputDisplay;
//#declare any global variables here
global OutputDisplay showResult;
global CustomerService serviceCustomer;
rule "Credit and Debit Rule"
when
$c : Account( $acc : accountno )
$p : AccountingPeriod ($sDate : startDate ,$eDate : endDate )
$totalCredit : Number( doubleValue > 100 )
from accumulate( CashFlow( type ==CashFlow.CREDIT,$value : amount, mvtDate >= $sDate && mvtDate <= $eDate,accountNo == $acc ),
init( double total = 0; ),
action( total += $value; ),
reverse( total -= $value; ),
result( total ) )
$totalDebit : Number( doubleValue > 100 )
from accumulate( CashFlow( type ==CashFlow.DEBIT,$value : amount, mvtDate >= $sDate && mvtDate <= $eDate,accountNo == $acc ),
init( double total = 0; ),
action( total += $value; ),
reverse( total -= $value; ),
result( total ) )
then
showResult.showText(" Found "+$totalCredit+" as a credit");
showResult.showText(" Found "+$totalDebit+" as a debit");
end

View file

@ -0,0 +1,15 @@
package com.sample
import droolscours.Account;
import droolscours.AccountingPeriod;
import droolscours.CashFlow;
rule "Credit Rule"
when
acc: Account( no : accountno )
period : AccountingPeriod(s : startDate , e: endDate )
act : CashFlow( type == CashFlow.CREDIT ,mvtDate >= s && mvtDate <=e ,accountNo ==no)
then
acc.setBalance(acc.getBalance()+act.getAmount());
end

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<kbase name="simplesample" packages="simplesample">
<ksession name="simplesample-session"/>
</kbase>
</kmodule>

View file

@ -1,17 +0,0 @@
package simplesample
import droolscours.Account;
import droolscours.AccountingPeriod;
import droolscours.CashFlow;
import droolscours.util.OutputDisplay;
global OutputDisplay showResults;
rule "Credit Rule"
when
acco: Account( no : accountno )
period : AccountingPeriod(s : startDate , e: endDate )
act : CashFlow( type == CashFlow.CREDIT ,mvtDate >= s && mvtDate <=e ,accountNo ==no)
then
acco.setBalance(acco.getBalance()+act.getAmount());
showResults.showText("The new balance is now "+acco.getBalance());
end

View file

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<javadocOptions>
<docletArtifacts>
<docletArtifact/>
</docletArtifacts>
<tagletArtifacts>
<tagletArtifact/>
</tagletArtifacts>
<javadocResourcesDirectory>src/main/javadoc</javadocResourcesDirectory>
</javadocOptions>

View file

@ -1,5 +0,0 @@
#Generated by Maven
#Thu May 12 17:05:58 CEST 2016
version=2.0-SNAPSHOT
groupId=com.pymma-software.droolscourse
artifactId=drools-lesson1

View file

@ -1,2 +0,0 @@
droolscours/PremierEssai.class
droolscours/PremierEssai$1.class

View file

@ -1 +0,0 @@
/Users/nheron/workspace-chtiJBUG/chtijbug-6.3/droolscourse/AccountProject/drools-lesson1/src/test/java/droolscours/PremierEssai.java