Grega Bremec vor 2 Jahren
Commit
ffe5af1409

+ 8 - 0
.gitignore

@@ -0,0 +1,8 @@
+.*.sw?
+.DS_Store
+.classpath
+.project
+.settings/
+.vscode/
+target/
+tmp/

+ 56 - 0
pom.xml

@@ -0,0 +1,56 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>com.redhat.training</groupId>
+  <artifactId>airline-ticket-simple</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+  <properties>
+  	<kie-platform-version>7.59.0.Final-redhat-00010</kie-platform-version>
+  </properties>
+  <dependencyManagement>
+  	<dependencies>
+  		<dependency>
+  			<groupId>org.kie</groupId>
+  			<artifactId>kie-bom</artifactId>
+  			<version>${kie-platform-version}</version>
+  			<type>pom</type>
+  			<scope>import</scope>
+  		</dependency>
+  		<dependency>
+  			<groupId>org.drools</groupId>
+  			<artifactId>drools-bom</artifactId>
+  			<version>${kie-platform-version}</version>
+  			<type>pom</type>
+  			<scope>import</scope>
+  		</dependency>
+  		<dependency>
+  			<groupId>org.jbpm</groupId>
+  			<artifactId>jbpm-bom</artifactId>
+  			<version>${kie-platform-version}</version>
+  			<type>pom</type>
+  			<scope>import</scope>
+  		</dependency>
+  	</dependencies>
+  </dependencyManagement>
+  <dependencies>
+	<dependency>
+		<groupId>org.kie</groupId>
+		<artifactId>kie-api</artifactId>
+	</dependency>
+	<dependency>
+		<groupId>org.drools</groupId>
+		<artifactId>drools-compiler</artifactId>
+	</dependency>
+	<dependency>
+		<groupId>org.drools</groupId>
+		<artifactId>drools-decisiontables</artifactId>
+	</dependency>
+	<dependency>
+		<groupId>org.drools</groupId>
+		<artifactId>drools-mvel</artifactId>
+	</dependency>
+	<dependency>
+		<groupId>org.jbpm</groupId>
+		<artifactId>jbpm-bpmn2</artifactId>
+	</dependency>
+  </dependencies>
+</project>

+ 38 - 0
src/main/java/com/redhat/training/rules/Customer.java

@@ -0,0 +1,38 @@
+package com.redhat.training.rules;
+
+public class Customer {
+	private String name;
+	private LoyaltyLevel loyaltyLevel;
+	private int milesFlown;
+	private int age;
+
+	public String getName() {
+		return name;
+	}
+	public void setName(String name) {
+		this.name = name;
+	}
+	public LoyaltyLevel getLoyaltyLevel() {
+		return loyaltyLevel;
+	}
+	public void setLoyaltyLevel(LoyaltyLevel loyaltyLevel) {
+		this.loyaltyLevel = loyaltyLevel;
+	}
+	public int getMilesFlown() {
+		return milesFlown;
+	}
+	public void setMilesFlown(int milesFlown) {
+		this.milesFlown = milesFlown;
+	}
+	public int getAge() {
+		return age;
+	}
+	public void setAge(int age) {
+		this.age = age;
+	}
+	@Override
+	public String toString() {
+		return "Customer [name=" + name + ", loyaltyLevel=" + loyaltyLevel + ", milesFlown=" + milesFlown + ", age="
+				+ age + "]";
+	}
+}

+ 8 - 0
src/main/java/com/redhat/training/rules/LoyaltyLevel.java

@@ -0,0 +1,8 @@
+package com.redhat.training.rules;
+
+public enum LoyaltyLevel {
+	NONE,
+	BRONZE,
+	SILVER,
+	GOLD;
+}

+ 57 - 0
src/main/java/com/redhat/training/rules/MainApp.java

@@ -0,0 +1,57 @@
+package com.redhat.training.rules;
+
+import org.kie.api.KieServices;
+import org.kie.api.runtime.KieSession;
+
+public class MainApp {
+
+	public static void main(String[] args) {
+		Customer c1 = new Customer();
+		c1.setName("John Doe");
+		c1.setAge(42);
+		c1.setMilesFlown(70000);
+
+		Ticket t1 = new Ticket();
+		t1.setDeparture("LHR");
+		t1.setDestination("LAX");
+		t1.setDistanceMiles(5431);
+		t1.setTravelClass(TravelClass.BUSINESS);
+		t1.setPrice(2500);
+		t1.setCustomer(c1);
+		
+		Customer c2 = new Customer();
+		c2.setName("Jane Doe");
+		c2.setAge(35);
+		c2.setMilesFlown(100000);
+
+		Ticket t2 = new Ticket();
+		t2.setDeparture("JNB");
+		t2.setDestination("FRA");
+		t2.setDistanceMiles(5400);
+		t2.setTravelClass(TravelClass.FIRST);
+		t2.setPrice(5000);
+		t2.setCustomer(c2);
+		
+		System.out.println("Customer:" + c1);
+		System.out.println("Customer:" + c2);
+		System.out.println("Ticket:" + t1);
+		System.out.println("Ticket:" + t2);
+		
+		System.out.println("*********** FIRING RULES **********");
+		KieSession s = KieServices.Factory.get().getKieClasspathContainer().newKieSession();
+		s.insert(c1);
+		s.insert(c2);
+		s.insert(t1);
+		s.insert(t2);
+		s.startProcess("processTicket");
+		s.fireAllRules();
+		s.dispose();
+		System.out.println("*********** RULES FINISHED **********");
+		
+		System.out.println("Customer:" + c1);
+		System.out.println("Customer:" + c2);
+		System.out.println("Ticket:" + t1);
+		System.out.println("Ticket:" + t2);
+	}
+
+}

+ 59 - 0
src/main/java/com/redhat/training/rules/Ticket.java

@@ -0,0 +1,59 @@
+package com.redhat.training.rules;
+
+public class Ticket {
+	private String departure;
+	private String destination;
+	private TravelClass travelClass;
+	private int distanceMiles;
+	private double price;
+	private int discountPercent;
+	private Customer customer;
+	public String getDeparture() {
+		return departure;
+	}
+	public void setDeparture(String departure) {
+		this.departure = departure;
+	}
+	public String getDestination() {
+		return destination;
+	}
+	public void setDestination(String destination) {
+		this.destination = destination;
+	}
+	public TravelClass getTravelClass() {
+		return travelClass;
+	}
+	public void setTravelClass(TravelClass travelClass) {
+		this.travelClass = travelClass;
+	}
+	public int getDistanceMiles() {
+		return distanceMiles;
+	}
+	public void setDistanceMiles(int distanceMiles) {
+		this.distanceMiles = distanceMiles;
+	}
+	public double getPrice() {
+		return price;
+	}
+	public void setPrice(double price) {
+		this.price = price;
+	}
+	public int getDiscountPercent() {
+		return discountPercent;
+	}
+	public void setDiscountPercent(int discountPercent) {
+		this.discountPercent = discountPercent;
+	}
+	public Customer getCustomer() {
+		return customer;
+	}
+	public void setCustomer(Customer customer) {
+		this.customer = customer;
+	}
+	@Override
+	public String toString() {
+		return "Ticket [departure=" + departure + ", destination=" + destination + ", travelClass=" + travelClass
+				+ ", distanceMiles=" + distanceMiles + ", price=" + price + ", discountPercent=" + discountPercent
+				+ "]";
+	}
+}

+ 7 - 0
src/main/java/com/redhat/training/rules/TravelClass.java

@@ -0,0 +1,7 @@
+package com.redhat.training.rules;
+
+public enum TravelClass {
+	ECONOMY,
+	BUSINESS,
+	FIRST;
+}

+ 2 - 0
src/main/resources/META-INF/kmodule.xml

@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<kmodule xmlns="http://www.drools.org/xsd/kmodule" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>

+ 21 - 0
src/main/resources/com/redhat/training/rules/discount.drl

@@ -0,0 +1,21 @@
+package com.redhat.training.rules
+
+rule "Silver Loyalty is 15% Discount"
+	ruleflow-group "discount"
+    when
+    	c: Customer(loyaltyLevel == LoyaltyLevel.SILVER)
+    	t: Ticket(customer == c)
+    then
+    	System.out.println("Setting SILVER discount: 15%");
+    	t.setDiscountPercent(15);
+end
+
+rule "Gold Loyalty is 25% Discount"
+	ruleflow-group "discount"
+    when
+    	c: Customer(loyaltyLevel == LoyaltyLevel.GOLD)
+    	t: Ticket(customer == c)
+    then
+    	System.out.println("Setting GOLD discount: 25%");
+    	t.setDiscountPercent(25);
+end

BIN
src/main/resources/com/redhat/training/rules/loyalty-rules.xlsx


+ 12 - 0
src/main/resources/com/redhat/training/rules/sanity.drl

@@ -0,0 +1,12 @@
+package com.redhat.training.rules
+
+rule "Add Ticket Miles to Customer"
+	ruleflow-group "sanity"
+    when
+		c: Customer()
+		t: Ticket(customer == c)
+    then
+    	System.out.println("Increasing miles from " + c.getMilesFlown() + " by " + t.getDistanceMiles());
+		c.setMilesFlown(c.getMilesFlown() + t.getDistanceMiles());
+		update(c);
+end

+ 179 - 0
src/main/resources/com/redhat/training/rules/ticket-processing.bpmn2

@@ -0,0 +1,179 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<bpmn2:definitions xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:bpsim="http://www.bpsim.org/schemas/1.0" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:drools="http://www.jboss.org/drools" xmlns:xsi="xsi" id="_ic0z4OouEDqmQv_npA3Sew" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd http://www.jboss.org/drools drools.xsd http://www.bpsim.org/schemas/1.0 bpsim.xsd http://www.omg.org/spec/DD/20100524/DC DC.xsd http://www.omg.org/spec/DD/20100524/DI DI.xsd " exporter="jBPM Process Modeler" exporterVersion="2.0" targetNamespace="http://www.omg.org/bpmn20">
+  <bpmn2:itemDefinition id="__8FA30527-0154-4D40-9194-0D8DDB10D56F_namespaceInputXItem" structureRef="java.lang.String"/>
+  <bpmn2:itemDefinition id="__8FA30527-0154-4D40-9194-0D8DDB10D56F_modelInputXItem" structureRef="java.lang.String"/>
+  <bpmn2:itemDefinition id="__8FA30527-0154-4D40-9194-0D8DDB10D56F_decisionInputXItem" structureRef="java.lang.String"/>
+  <bpmn2:itemDefinition id="__77839E76-5C5B-47A6-A6C4-19A002783744_namespaceInputXItem" structureRef="java.lang.String"/>
+  <bpmn2:itemDefinition id="__77839E76-5C5B-47A6-A6C4-19A002783744_modelInputXItem" structureRef="java.lang.String"/>
+  <bpmn2:itemDefinition id="__77839E76-5C5B-47A6-A6C4-19A002783744_decisionInputXItem" structureRef="java.lang.String"/>
+  <bpmn2:itemDefinition id="__C99FFBCC-5EC8-4F46-8D20-B764C27B552F_namespaceInputXItem" structureRef="java.lang.String"/>
+  <bpmn2:itemDefinition id="__C99FFBCC-5EC8-4F46-8D20-B764C27B552F_modelInputXItem" structureRef="java.lang.String"/>
+  <bpmn2:itemDefinition id="__C99FFBCC-5EC8-4F46-8D20-B764C27B552F_decisionInputXItem" structureRef="java.lang.String"/>
+  <bpmn2:collaboration id="_79DC6814-EF64-42E8-A295-C67E34FB9816" name="Default Collaboration">
+    <bpmn2:participant id="_98A4FA78-871C-4258-89F9-0CA875A8D03E" name="Pool Participant" processRef="processTicket"/>
+  </bpmn2:collaboration>
+  <bpmn2:process id="processTicket" drools:packageName="com.redhat.training.rules" drools:version="1.0" drools:adHoc="false" name="ticket-processing" isExecutable="true" processType="Public">
+    <bpmn2:sequenceFlow id="_71A04A0C-E4A0-4E1F-B1DF-1670444DFCB3" sourceRef="_C99FFBCC-5EC8-4F46-8D20-B764C27B552F" targetRef="_6996926E-F83D-411A-A6D8-531B36856985">
+      <bpmn2:extensionElements>
+        <drools:metaData name="isAutoConnection.target">
+          <drools:metaValue><![CDATA[true]]></drools:metaValue>
+        </drools:metaData>
+      </bpmn2:extensionElements>
+    </bpmn2:sequenceFlow>
+    <bpmn2:sequenceFlow id="_940099C8-D7AB-4C47-B637-635ADBBE1DAE" sourceRef="_77839E76-5C5B-47A6-A6C4-19A002783744" targetRef="_C99FFBCC-5EC8-4F46-8D20-B764C27B552F"/>
+    <bpmn2:sequenceFlow id="_BEEC9DB5-3B66-4ABB-A435-8BD6C63AA5B5" sourceRef="_8FA30527-0154-4D40-9194-0D8DDB10D56F" targetRef="_77839E76-5C5B-47A6-A6C4-19A002783744">
+      <bpmn2:extensionElements>
+        <drools:metaData name="isAutoConnection.target">
+          <drools:metaValue><![CDATA[true]]></drools:metaValue>
+        </drools:metaData>
+      </bpmn2:extensionElements>
+    </bpmn2:sequenceFlow>
+    <bpmn2:sequenceFlow id="_87BBD7D5-BF5F-4609-9909-08D681E3F205" sourceRef="_8C33E05A-8FF6-4632-93F6-E7D0F7EE8F7A" targetRef="_8FA30527-0154-4D40-9194-0D8DDB10D56F"/>
+    <bpmn2:endEvent id="_6996926E-F83D-411A-A6D8-531B36856985">
+      <bpmn2:incoming>_71A04A0C-E4A0-4E1F-B1DF-1670444DFCB3</bpmn2:incoming>
+    </bpmn2:endEvent>
+    <bpmn2:businessRuleTask id="_C99FFBCC-5EC8-4F46-8D20-B764C27B552F" drools:ruleFlowGroup="discount" name="Discount Rules" implementation="http://www.jboss.org/drools/rule">
+      <bpmn2:extensionElements>
+        <drools:metaData name="elementname">
+          <drools:metaValue><![CDATA[Discount Rules]]></drools:metaValue>
+        </drools:metaData>
+      </bpmn2:extensionElements>
+      <bpmn2:incoming>_940099C8-D7AB-4C47-B637-635ADBBE1DAE</bpmn2:incoming>
+      <bpmn2:outgoing>_71A04A0C-E4A0-4E1F-B1DF-1670444DFCB3</bpmn2:outgoing>
+    </bpmn2:businessRuleTask>
+    <bpmn2:businessRuleTask id="_77839E76-5C5B-47A6-A6C4-19A002783744" drools:ruleFlowGroup="loyalty" name="Loyalty Rules" implementation="http://www.jboss.org/drools/rule">
+      <bpmn2:extensionElements>
+        <drools:metaData name="elementname">
+          <drools:metaValue><![CDATA[Loyalty Rules]]></drools:metaValue>
+        </drools:metaData>
+      </bpmn2:extensionElements>
+      <bpmn2:incoming>_BEEC9DB5-3B66-4ABB-A435-8BD6C63AA5B5</bpmn2:incoming>
+      <bpmn2:outgoing>_940099C8-D7AB-4C47-B637-635ADBBE1DAE</bpmn2:outgoing>
+    </bpmn2:businessRuleTask>
+    <bpmn2:businessRuleTask id="_8FA30527-0154-4D40-9194-0D8DDB10D56F" drools:ruleFlowGroup="sanity" name="Sanity Rules" implementation="http://www.jboss.org/drools/rule">
+      <bpmn2:extensionElements>
+        <drools:metaData name="elementname">
+          <drools:metaValue><![CDATA[Sanity Rules]]></drools:metaValue>
+        </drools:metaData>
+      </bpmn2:extensionElements>
+      <bpmn2:incoming>_87BBD7D5-BF5F-4609-9909-08D681E3F205</bpmn2:incoming>
+      <bpmn2:outgoing>_BEEC9DB5-3B66-4ABB-A435-8BD6C63AA5B5</bpmn2:outgoing>
+    </bpmn2:businessRuleTask>
+    <bpmn2:startEvent id="_8C33E05A-8FF6-4632-93F6-E7D0F7EE8F7A">
+      <bpmn2:outgoing>_87BBD7D5-BF5F-4609-9909-08D681E3F205</bpmn2:outgoing>
+    </bpmn2:startEvent>
+  </bpmn2:process>
+  <bpmndi:BPMNDiagram>
+    <bpmndi:BPMNPlane bpmnElement="processTicket">
+      <bpmndi:BPMNShape id="shape__8C33E05A-8FF6-4632-93F6-E7D0F7EE8F7A" bpmnElement="_8C33E05A-8FF6-4632-93F6-E7D0F7EE8F7A">
+        <dc:Bounds height="56" width="56" x="138" y="149"/>
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="shape__8FA30527-0154-4D40-9194-0D8DDB10D56F" bpmnElement="_8FA30527-0154-4D40-9194-0D8DDB10D56F">
+        <dc:Bounds height="102" width="154" x="274" y="126"/>
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="shape__77839E76-5C5B-47A6-A6C4-19A002783744" bpmnElement="_77839E76-5C5B-47A6-A6C4-19A002783744">
+        <dc:Bounds height="102" width="154" x="544" y="126"/>
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="shape__C99FFBCC-5EC8-4F46-8D20-B764C27B552F" bpmnElement="_C99FFBCC-5EC8-4F46-8D20-B764C27B552F">
+        <dc:Bounds height="102" width="154" x="778" y="126"/>
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="shape__6996926E-F83D-411A-A6D8-531B36856985" bpmnElement="_6996926E-F83D-411A-A6D8-531B36856985">
+        <dc:Bounds height="56" width="56" x="1025" y="149"/>
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNEdge id="edge_shape__8C33E05A-8FF6-4632-93F6-E7D0F7EE8F7A_to_shape__8FA30527-0154-4D40-9194-0D8DDB10D56F" bpmnElement="_87BBD7D5-BF5F-4609-9909-08D681E3F205">
+        <di:waypoint x="166" y="177"/>
+        <di:waypoint x="351" y="177"/>
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="edge_shape__8FA30527-0154-4D40-9194-0D8DDB10D56F_to_shape__77839E76-5C5B-47A6-A6C4-19A002783744" bpmnElement="_BEEC9DB5-3B66-4ABB-A435-8BD6C63AA5B5">
+        <di:waypoint x="351" y="177"/>
+        <di:waypoint x="621" y="126"/>
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="edge_shape__77839E76-5C5B-47A6-A6C4-19A002783744_to_shape__C99FFBCC-5EC8-4F46-8D20-B764C27B552F" bpmnElement="_940099C8-D7AB-4C47-B637-635ADBBE1DAE">
+        <di:waypoint x="621" y="177"/>
+        <di:waypoint x="855" y="177"/>
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="edge_shape__C99FFBCC-5EC8-4F46-8D20-B764C27B552F_to_shape__6996926E-F83D-411A-A6D8-531B36856985" bpmnElement="_71A04A0C-E4A0-4E1F-B1DF-1670444DFCB3">
+        <di:waypoint x="855" y="177"/>
+        <di:waypoint x="1102" y="149"/>
+      </bpmndi:BPMNEdge>
+    </bpmndi:BPMNPlane>
+  </bpmndi:BPMNDiagram>
+  <bpmn2:relationship type="BPSimData">
+    <bpmn2:extensionElements>
+      <bpsim:BPSimData>
+        <bpsim:Scenario id="default" name="Simulationscenario">
+          <bpsim:ScenarioParameters/>
+          <bpsim:ElementParameters elementRef="_8C33E05A-8FF6-4632-93F6-E7D0F7EE8F7A">
+            <bpsim:TimeParameters>
+              <bpsim:ProcessingTime>
+                <bpsim:NormalDistribution mean="0" standardDeviation="0"/>
+              </bpsim:ProcessingTime>
+            </bpsim:TimeParameters>
+          </bpsim:ElementParameters>
+          <bpsim:ElementParameters elementRef="_8FA30527-0154-4D40-9194-0D8DDB10D56F">
+            <bpsim:TimeParameters>
+              <bpsim:ProcessingTime>
+                <bpsim:NormalDistribution mean="0" standardDeviation="0"/>
+              </bpsim:ProcessingTime>
+            </bpsim:TimeParameters>
+            <bpsim:ResourceParameters>
+              <bpsim:Availability>
+                <bpsim:FloatingParameter value="0"/>
+              </bpsim:Availability>
+              <bpsim:Quantity>
+                <bpsim:FloatingParameter value="0"/>
+              </bpsim:Quantity>
+            </bpsim:ResourceParameters>
+            <bpsim:CostParameters>
+              <bpsim:UnitCost>
+                <bpsim:FloatingParameter value="0"/>
+              </bpsim:UnitCost>
+            </bpsim:CostParameters>
+          </bpsim:ElementParameters>
+          <bpsim:ElementParameters elementRef="_77839E76-5C5B-47A6-A6C4-19A002783744">
+            <bpsim:TimeParameters>
+              <bpsim:ProcessingTime>
+                <bpsim:NormalDistribution mean="0" standardDeviation="0"/>
+              </bpsim:ProcessingTime>
+            </bpsim:TimeParameters>
+            <bpsim:ResourceParameters>
+              <bpsim:Availability>
+                <bpsim:FloatingParameter value="0"/>
+              </bpsim:Availability>
+              <bpsim:Quantity>
+                <bpsim:FloatingParameter value="0"/>
+              </bpsim:Quantity>
+            </bpsim:ResourceParameters>
+            <bpsim:CostParameters>
+              <bpsim:UnitCost>
+                <bpsim:FloatingParameter value="0"/>
+              </bpsim:UnitCost>
+            </bpsim:CostParameters>
+          </bpsim:ElementParameters>
+          <bpsim:ElementParameters elementRef="_C99FFBCC-5EC8-4F46-8D20-B764C27B552F">
+            <bpsim:TimeParameters>
+              <bpsim:ProcessingTime>
+                <bpsim:NormalDistribution mean="0" standardDeviation="0"/>
+              </bpsim:ProcessingTime>
+            </bpsim:TimeParameters>
+            <bpsim:ResourceParameters>
+              <bpsim:Availability>
+                <bpsim:FloatingParameter value="0"/>
+              </bpsim:Availability>
+              <bpsim:Quantity>
+                <bpsim:FloatingParameter value="0"/>
+              </bpsim:Quantity>
+            </bpsim:ResourceParameters>
+            <bpsim:CostParameters>
+              <bpsim:UnitCost>
+                <bpsim:FloatingParameter value="0"/>
+              </bpsim:UnitCost>
+            </bpsim:CostParameters>
+          </bpsim:ElementParameters>
+        </bpsim:Scenario>
+      </bpsim:BPSimData>
+    </bpmn2:extensionElements>
+    <bpmn2:source>_ic0z4OouEDqmQv_npA3Sew</bpmn2:source>
+    <bpmn2:target>_ic0z4OouEDqmQv_npA3Sew</bpmn2:target>
+  </bpmn2:relationship>
+</bpmn2:definitions>