forked from apache/incubator-kie-kogito-examples
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from rgdoliveira/sync_main
Sync main branch with Apache main branch (OSL 1.35 cut-off)
- Loading branch information
Showing
27 changed files
with
698 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
target | ||
settings.xml | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# decisions-embedded-mode-example | ||
|
||
Is an example of running DMN decisions using plain java. This is an example decision for approving and declining the loan application. Please notice, the decision is only example that do not cover all cases from the banking domain. | ||
|
||
## Execute | ||
Simply run the main class `org.kie.kogito.decisions.embedded.DecisionsEmbeddedModeExample` either from the IDE or your command line. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.kie.kogito.decisions.embedded</groupId> | ||
<artifactId>dmn-embedded-mode-example</artifactId> | ||
<name>Kogito Example :: DMN Embedded Mode</name> | ||
<version>999-SNAPSHOT</version> | ||
<packaging>kjar</packaging> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<exec.mainClass>org.kie.kogito.decisions.embedded.DecisionsEmbeddedModeExample</exec.mainClass> | ||
|
||
<version.org.kie.kogito>999-SNAPSHOT</version.org.kie.kogito> | ||
<version.org.drools>999-SNAPSHOT</version.org.drools> | ||
<version.org.drools>999-SNAPSHOT</version.org.drools> | ||
<version.kogito.bom>999-SNAPSHOT</version.kogito.bom> | ||
<version.org.kie>999-SNAPSHOT</version.org.kie> | ||
|
||
<version.org.slf4j>2.0.13</version.org.slf4j> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools-bom</artifactId> | ||
<version>${version.org.drools}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.kie.kogito</groupId> | ||
<artifactId>kogito-bom</artifactId> | ||
<version>${version.kogito.bom}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools-compiler</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools-model-compiler</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.kie</groupId> | ||
<artifactId>kie-dmn-core</artifactId> | ||
<version>${version.org.kie}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools-xml-support</artifactId> | ||
</dependency> | ||
|
||
<!-- Logging --> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>${version.org.slf4j}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
<version>${version.org.slf4j}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.kie</groupId> | ||
<artifactId>kie-maven-plugin</artifactId> | ||
<version>${version.org.kie}</version> | ||
<extensions>true</extensions> | ||
<configuration> | ||
<validateDMN>disable</validateDMN> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
30 changes: 30 additions & 0 deletions
30
.../dmn-embedded-mode-example/src/main/java/org/kie/kogito/decisions/embedded/Applicant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.kie.kogito.decisions.embedded; | ||
|
||
public class Applicant { | ||
private String id; | ||
private int age; | ||
|
||
public Applicant() { | ||
} | ||
|
||
public Applicant(String id, int age) { | ||
this.id = id; | ||
this.age = age; | ||
} | ||
|
||
public int getAge() { | ||
return age; | ||
} | ||
|
||
public void setAge(int age) { | ||
this.age = age; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...example/src/main/java/org/kie/kogito/decisions/embedded/DecisionsEmbeddedModeExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.kie.kogito.decisions.embedded; | ||
|
||
import org.kie.api.KieServices; | ||
import org.kie.api.runtime.KieContainer; | ||
import org.kie.api.runtime.KieRuntimeFactory; | ||
import org.kie.dmn.api.core.DMNContext; | ||
import org.kie.dmn.api.core.DMNDecisionResult; | ||
import org.kie.dmn.api.core.DMNModel; | ||
import org.kie.dmn.api.core.DMNResult; | ||
import org.kie.dmn.api.core.DMNRuntime; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class DecisionsEmbeddedModeExample { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(DecisionsEmbeddedModeExample.class); | ||
|
||
public static void main(String[] args) { | ||
|
||
KieServices kieServices = KieServices.Factory.get(); | ||
KieContainer kieContainer = kieServices.getKieClasspathContainer(); | ||
|
||
logger.info("-----> Now we execute DMN <-----"); | ||
|
||
DMNRuntime dmnRuntime = KieRuntimeFactory.of(kieContainer.getKieBase()).get(DMNRuntime.class); | ||
|
||
String namespace = "https://kie.org/dmn/_C83DFD16-A42A-46BE-A843-370444580E0F"; | ||
String modelName = "loan-application-age-limit"; | ||
|
||
DMNModel dmnModel = dmnRuntime.getModel(namespace, modelName); | ||
|
||
DMNContext dmnContext = dmnRuntime.newContext(); | ||
dmnContext.set("Applicant", new Applicant("#0001", 20)); | ||
dmnContext.set("Application", new LoanApplication("#0001")); | ||
DMNResult dmnResult = dmnRuntime.evaluateAll(dmnModel, dmnContext); | ||
|
||
for (DMNDecisionResult dr : dmnResult.getDecisionResults()) { | ||
logger.info( | ||
"Decision: '" + dr.getDecisionName() + "', " + | ||
"Result: " + dr.getResult()); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...mbedded-mode-example/src/main/java/org/kie/kogito/decisions/embedded/LoanApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.kie.kogito.decisions.embedded; | ||
|
||
public class LoanApplication { | ||
private String applicantId; | ||
private String explanation; | ||
private boolean approved; | ||
|
||
public LoanApplication() { | ||
} | ||
|
||
public LoanApplication(String applicantId) { | ||
this.applicantId = applicantId; | ||
} | ||
|
||
public LoanApplication(String applicantId, String explanation, boolean approved) { | ||
this.applicantId = applicantId; | ||
this.explanation = explanation; | ||
this.approved = approved; | ||
} | ||
|
||
public String getExplanation() { | ||
return explanation; | ||
} | ||
|
||
public void setExplanation(String explanation) { | ||
this.explanation = explanation; | ||
} | ||
|
||
public boolean isApproved() { | ||
return approved; | ||
} | ||
|
||
public void setApproved(boolean approved) { | ||
this.approved = approved; | ||
} | ||
|
||
public String getApplicantId() { | ||
return applicantId; | ||
} | ||
|
||
public void setApplicantId(String applicantId) { | ||
this.applicantId = applicantId; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "LoanApplication [applicantId=" + applicantId + ", explanation=" + explanation + ", approved=" + approved | ||
+ "]"; | ||
} | ||
|
||
|
||
} |
1 change: 1 addition & 0 deletions
1
kogito-java-examples/dmn-embedded-mode-example/src/main/resources/META-INF/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Main-Class: org.kie.kogito.decisions.embedded.DecisionsEmbeddedModeExample |
5 changes: 5 additions & 0 deletions
5
kogito-java-examples/dmn-embedded-mode-example/src/main/resources/META-INF/kmodule.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<kmodule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://www.drools.org/xsd/kmodule"> | ||
|
||
</kmodule> |
Oops, something went wrong.