Work
This commit is contained in:
parent
ce0f351c9d
commit
c9209dc9a5
105 changed files with 2390 additions and 839 deletions
33
AccountProject/drools-lesson-pojo/drools-lesson-pojo.iml
Normal file
33
AccountProject/drools-lesson-pojo/drools-lesson-pojo.iml
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?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" />
|
||||
</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" />
|
||||
</component>
|
||||
</module>
|
||||
38
AccountProject/drools-lesson-pojo/pom.xml
Normal file
38
AccountProject/drools-lesson-pojo/pom.xml
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?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-lesson-pojo</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>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package droolscours;
|
||||
|
||||
public class Account {
|
||||
private long accountno;
|
||||
private double balance;
|
||||
|
||||
public Account(long accountno, double balance) {
|
||||
super();
|
||||
this.accountno = accountno;
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
public Account() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public long getAccountno() {
|
||||
return accountno;
|
||||
}
|
||||
|
||||
public void setAccountno(long accountno) {
|
||||
this.accountno = accountno;
|
||||
}
|
||||
|
||||
public double getBalance() {
|
||||
return balance;
|
||||
}
|
||||
|
||||
public void setBalance(double balance) {
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
// TODO Auto-generated method stub
|
||||
StringBuffer buff = new StringBuffer();
|
||||
buff.append("-----Account-----)\n");
|
||||
buff.append("Account no " + this.accountno + "\n");
|
||||
buff.append("Balance " + this.balance + "\n");
|
||||
buff.append("-----End Account-)");
|
||||
return buff.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package droolscours;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class AccountingPeriod {
|
||||
private Date startDate;
|
||||
private Date endDate;
|
||||
|
||||
public AccountingPeriod() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public AccountingPeriod(Date startDate, Date endDate) {
|
||||
super();
|
||||
this.startDate = startDate;
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(Date start) {
|
||||
this.startDate = start;
|
||||
}
|
||||
|
||||
public Date getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(Date end) {
|
||||
this.endDate = end;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
// TODO Auto-generated method stub
|
||||
StringBuffer buff = new StringBuffer();
|
||||
buff.append("-----AccountingPeriod-----)\n");
|
||||
if (this.startDate != null) {
|
||||
buff.append("StartDate "
|
||||
+ DateFormat.getDateInstance().format(this.startDate)
|
||||
+ "\n");
|
||||
} else {
|
||||
buff.append("No start date was set\n");
|
||||
}
|
||||
if (this.endDate != null) {
|
||||
buff.append("EndDate "
|
||||
+ DateFormat.getDateInstance().format(this.endDate) + "\n");
|
||||
} else {
|
||||
buff.append("No ens date was set\n");
|
||||
}
|
||||
buff.append("-----End AccountingPeriod -)");
|
||||
return buff.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
package droolscours;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class CashFlow {
|
||||
public static int CREDIT = 1;
|
||||
public static int DEBIT = 2;
|
||||
private Date mvtDate;
|
||||
private double amount;
|
||||
private int type;
|
||||
private long accountNo;
|
||||
|
||||
public CashFlow(Date mvtDate, double amount, int type, long accountNo) {
|
||||
super();
|
||||
this.mvtDate = mvtDate;
|
||||
this.amount = amount;
|
||||
this.type = type;
|
||||
this.accountNo = accountNo;
|
||||
}
|
||||
|
||||
public CashFlow() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public Date getMvtDate() {
|
||||
return mvtDate;
|
||||
}
|
||||
|
||||
public void setMvtDate(Date date) {
|
||||
this.mvtDate = date;
|
||||
}
|
||||
|
||||
public double getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(double amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public long getAccountNo() {
|
||||
return accountNo;
|
||||
}
|
||||
|
||||
public void setAccountNo(long accountNo) {
|
||||
this.accountNo = accountNo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
// TODO Auto-generated method stub
|
||||
StringBuffer buff = new StringBuffer();
|
||||
buff.append("-----CashFlow-----)\n");
|
||||
buff.append("Account no=" + this.accountNo + "\n");
|
||||
if (this.mvtDate != null) {
|
||||
buff.append("Mouvement Date= "
|
||||
+ DateFormat.getDateInstance().format(this.mvtDate)
|
||||
+ "\n");
|
||||
} else {
|
||||
buff.append("No Mouvement date was set\n");
|
||||
}
|
||||
buff.append("Mouvement Amount=" + this.amount + "\n");
|
||||
buff.append("-----CashFlow end--)");
|
||||
return buff.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package droolscours;
|
||||
|
||||
public class Customer {
|
||||
private String name;
|
||||
private String surname;
|
||||
private String country;
|
||||
|
||||
public Customer(String name, String surname, String country) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.surname = surname;
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public Customer() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSurname() {
|
||||
return surname;
|
||||
}
|
||||
|
||||
public void setSurname(String surname) {
|
||||
this.surname = surname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buff = new StringBuffer();
|
||||
buff.append("-----Customer-----)\n");
|
||||
buff.append("Name=" + this.name + "\n");
|
||||
buff.append("Surname Name=" + this.surname + "\n");
|
||||
buff.append("Country=" + this.country + "\n");
|
||||
buff.append("-----Customer end-)");
|
||||
return buff.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package droolscours;
|
||||
|
||||
public class PrivateAccount extends Account {
|
||||
private Customer owner;
|
||||
|
||||
public Customer getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(Customer owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buff = new StringBuffer();
|
||||
buff.append("-----Private Account-)");
|
||||
buff.append(super.toString());
|
||||
if (this.owner != null) {
|
||||
buff.append(this.owner.toString());
|
||||
}
|
||||
buff.append("-----Private Account end-)");
|
||||
return buff.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package droolscours.service;
|
||||
|
||||
import droolscours.Customer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CustomerService {
|
||||
|
||||
public List<Customer> getListCustomer() {
|
||||
List<Customer> result = new ArrayList<Customer>();
|
||||
result.add(new Customer("Héron", "Nicolas", "Fr"));
|
||||
result.add(new Customer("Héron", "James", "GB"));
|
||||
result.add(new Customer("Héron", "Nicolas", "GB"));
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package droolscours.util;
|
||||
|
||||
public class OutputDisplay {
|
||||
public OutputDisplay() {
|
||||
}
|
||||
|
||||
public void showText(String someText) {
|
||||
long time = System.currentTimeMillis();
|
||||
System.out.println("time=" + time + "-" + someText);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package util;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class DateHelper {
|
||||
public static String sFormat = "yyyy-MM-dd";
|
||||
|
||||
public static Date getDate(String sDate) throws Exception {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(sFormat);
|
||||
return sdf.parse(sDate);
|
||||
}
|
||||
|
||||
public static Date getDate(String sDate, String anotherFormat)
|
||||
throws Exception {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(anotherFormat);
|
||||
return sdf.parse(sDate);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
package util;
|
||||
|
||||
import org.kie.api.KieServices;
|
||||
import org.kie.api.event.rule.*;
|
||||
import org.kie.api.runtime.KieContainer;
|
||||
import org.kie.api.runtime.KieSession;
|
||||
import org.kie.api.runtime.StatelessKieSession;
|
||||
|
||||
public class KnowledgeSessionHelper {
|
||||
|
||||
public static KieContainer createRuleBase() {
|
||||
|
||||
KieServices ks = KieServices.Factory.get();
|
||||
KieContainer kieContainer = ks.getKieClasspathContainer();
|
||||
return kieContainer;
|
||||
}
|
||||
|
||||
public static StatelessKieSession getStatelessKnowledgeSession(KieContainer kieContainer, String sessionName) {
|
||||
StatelessKieSession kSession = kieContainer.newStatelessKieSession(sessionName);
|
||||
|
||||
return kSession;
|
||||
}
|
||||
|
||||
public static KieSession getStatefulKnowledgeSession(KieContainer kieContainer, String sessionName) {
|
||||
KieSession kSession = kieContainer.newKieSession(sessionName);
|
||||
|
||||
return kSession;
|
||||
}
|
||||
|
||||
public static KieSession getStatefulKnowledgeSessionWithCallback(
|
||||
KieContainer kieContainer, String sessionName) {
|
||||
KieSession session = getStatefulKnowledgeSession(kieContainer, sessionName);
|
||||
session.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());
|
||||
}
|
||||
});
|
||||
|
||||
session.addEventListener(new AgendaEventListener() {
|
||||
public void matchCreated(MatchCreatedEvent event) {
|
||||
System.out.println("The rule "
|
||||
+ event.getMatch().getRule().getName()
|
||||
+ " can be fired in agenda");
|
||||
}
|
||||
|
||||
public void matchCancelled(MatchCancelledEvent event) {
|
||||
System.out.println("The rule "
|
||||
+ event.getMatch().getRule().getName()
|
||||
+ " cannot b in agenda");
|
||||
}
|
||||
|
||||
public void beforeMatchFired(BeforeMatchFiredEvent event) {
|
||||
System.out.println("The rule "
|
||||
+ event.getMatch().getRule().getName()
|
||||
+ " will be fired");
|
||||
}
|
||||
|
||||
public void afterMatchFired(AfterMatchFiredEvent event) {
|
||||
System.out.println("The rule "
|
||||
+ event.getMatch().getRule().getName()
|
||||
+ " has be fired");
|
||||
}
|
||||
|
||||
public void agendaGroupPopped(AgendaGroupPoppedEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void agendaGroupPushed(AgendaGroupPushedEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void beforeRuleFlowGroupActivated(RuleFlowGroupActivatedEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void afterRuleFlowGroupActivated(RuleFlowGroupActivatedEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void beforeRuleFlowGroupDeactivated(RuleFlowGroupDeactivatedEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void afterRuleFlowGroupDeactivated(RuleFlowGroupDeactivatedEvent event) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue