Skip to content

Commit

Permalink
Merge pull request #44 from rgdoliveira/sync_main
Browse files Browse the repository at this point in the history
Sync main branch with Apache main branch (OSL 1.35 cut-off)
  • Loading branch information
rgdoliveira authored Nov 7, 2024
2 parents 50a7412 + 2720daa commit 5fee7c0
Show file tree
Hide file tree
Showing 27 changed files with 698 additions and 13 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/pr-kogito-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ jobs:
timeout-minutes: 180
strategy:
matrix:
job_name: [ kogito-quarkus-examples, kogito-springboot-examples, serverless-workflow-examples ]
job_name: [ kogito-java-examples, kogito-quarkus-examples, kogito-springboot-examples, serverless-workflow-examples ]
os: [ubuntu-latest]
java-version: [17]
maven-version: ['3.9.6']
include:
- job_name: kogito-java-examples
repository: incubator-kie-kogito-examples
env_KOGITO_EXAMPLES_SUBFOLDER_POM: kogito-java-examples/
- job_name: kogito-quarkus-examples
repository: kogito-examples
env_KOGITO_EXAMPLES_SUBFOLDER_POM: kogito-quarkus-examples/
Expand Down
3 changes: 3 additions & 0 deletions kogito-java-examples/dmn-embedded-mode-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target
settings.xml
.vscode
6 changes: 6 additions & 0 deletions kogito-java-examples/dmn-embedded-mode-example/README.md
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.
112 changes: 112 additions & 0 deletions kogito-java-examples/dmn-embedded-mode-example/pom.xml
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>
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;
}
}
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());
}
}
}
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
+ "]";
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Main-Class: org.kie.kogito.decisions.embedded.DecisionsEmbeddedModeExample
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>
Loading

0 comments on commit 5fee7c0

Please sign in to comment.