Skip to content

Commit

Permalink
[KOGITO-6039] Example: Compare RuleUnit coordination to KieBase compo…
Browse files Browse the repository at this point in the history
…sition

- Demonstrates a problem where we want composition (= like kbase includes)
  • Loading branch information
tkobayas committed Oct 25, 2021
1 parent 326bb48 commit ec03f77
Show file tree
Hide file tree
Showing 12 changed files with 604 additions and 0 deletions.
29 changes: 29 additions & 0 deletions multi-ruleunit-quarkus-example-poc03/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
### POST /2units

Custom REST endpoint to execute CommonUnit and LoanUnit. Then reply with "FindApproved" query.


1st example)

```sh
curl -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"loanApplications":[{"id":"ABC10001","amount":5000,"deposit":3000,"applicant":{"age":45,"name":"John","creditScore":1000,"occupationCode":"1021","previousOccupationCode":"1025"}}]}' http://localhost:8080/2units
```

This loan application is approved.

response:

```json
[{"id":"ABC10001","applicant":{"name":"John","age":45,"creditScore":1000,"occupationCode":"1021","previousOccupationCode":"1025","occupationCategory":"A"},"amount":5000,"deposit":3000,"approved":true}]
```

2nd example)

```sh
curl -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"loanApplications":[{"id":"ABC10002","amount":5000,"deposit":3000,"applicant":{"age":43,"name":"Paul","creditScore":1000,"occupationCode":null,"previousOccupationCode":"2099"}}]}' http://localhost:8080/2units
```

This loan application is expected to be approved because rule "LargeDepositWithoutCurrentOccupation" in LoanUnit should trigger rule "occupationCategoryA2" in CommonUnit in case of "kbase composition". However, this example is "RuleUnit orchestration" so CommonUnit -> LoanUnit is executed sequentially. So "occupationCategoryA2" is not triggered.



Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: app.kiegroup.org/v1beta1
kind: KogitoBuild
metadata:
name: multi-ruleunit-quarkus-example
spec:
type: RemoteSource
#env:
# env can be used to set variables during build
#- name: MY_CUSTOM_ENV
# value: "my value"
gitSource:
contextDir: multi-ruleunit-quarkus-example
uri: 'https://github.com/kiegroup/kogito-examples'
# set your maven nexus repository to speed up the build time
#mavenMirrorURL:
---
apiVersion: app.kiegroup.org/v1beta1
kind: KogitoRuntime
metadata:
name: multi-ruleunit-quarkus-example
86 changes: 86 additions & 0 deletions multi-ruleunit-quarkus-example-poc03/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.kie.kogito.examples</groupId>
<artifactId>kogito-examples</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>multi-ruleunit-quarkus-example-poc03</artifactId>
<name>Kogito Example :: Multiple RuleUnit PoC 03 - Quarkus</name>
<properties>
<quarkus-plugin.version>2.3.0.Final</quarkus-plugin.version>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>2.3.0.Final</quarkus.platform.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>${quarkus.platform.artifact-id}</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-quarkus-rules</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-drools</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-health</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2020 Red Hat, Inc. and/or its affiliates.
*
* Licensed 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.
*/
package org.kie.kogito.examples;

public class Applicant {

private String name;
private int age;
private int creditScore;
private String occupationCode;
private String previousOccupationCode;
private String occupationCategory = null; // calculated by common rules

public Applicant() {
}

public Applicant(String name, int age, int creditScore, String occupationCode, String previousOccupationCode) {
super();
this.name = name;
this.age = age;
this.creditScore = creditScore;
this.occupationCode = occupationCode;
this.previousOccupationCode = previousOccupationCode;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public int getCreditScore() {
return creditScore;
}

public void setCreditScore(int creditScore) {
this.creditScore = creditScore;
}

public String getOccupationCode() {
return occupationCode;
}

public void setOccupationCode(String occupationCode) {
this.occupationCode = occupationCode;
}

public String getPreviousOccupationCode() {
return previousOccupationCode;
}

public void setPreviousOccupationCode(String previousOccupationCode) {
this.previousOccupationCode = previousOccupationCode;
}

public String getOccupationCategory() {
return occupationCategory;
}

public void setOccupationCategory(String occupationCategory) {
this.occupationCategory = occupationCategory;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2020 Red Hat, Inc. and/or its affiliates.
*
* Licensed 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.
*/
package org.kie.kogito.examples;

import org.kie.kogito.rules.DataSource;
import org.kie.kogito.rules.DataStore;
import org.kie.kogito.rules.RuleUnitData;

public class CommonUnit implements RuleUnitData {

private DataStore<LoanApplication> loanApplications;

public CommonUnit() {
this(DataSource.createStore());
}

public CommonUnit(DataStore<LoanApplication> loanApplications) {
this.loanApplications = loanApplications;
}

public DataStore<LoanApplication> getLoanApplications() {
return loanApplications;
}

public void setLoanApplications(DataStore<LoanApplication> loanApplications) {
this.loanApplications = loanApplications;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright 2020 Red Hat, Inc. and/or its affiliates.
*
* Licensed 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.
*/
package org.kie.kogito.examples;

public class LoanApplication {

private String id;

private Applicant applicant;

private int amount;

private int deposit;

private boolean approved = false; // false by default

public LoanApplication() {
}

public LoanApplication(String id, Applicant applicant, int amount, int deposit) {
super();
this.id = id;
this.applicant = applicant;
this.amount = amount;
this.deposit = deposit;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public Applicant getApplicant() {
return applicant;
}

public void setApplicant(Applicant applicant) {
this.applicant = applicant;
}

public boolean isApproved() {
return approved;
}

public void setApproved(boolean approved) {
this.approved = approved;
}

public int getAmount() {
return amount;
}

public void setAmount(int amount) {
this.amount = amount;
}

public int getDeposit() {
return deposit;
}

public void setDeposit(int deposit) {
this.deposit = deposit;
}

@Override
public String toString() {
return "LoanApplication [id=" + id + ", applicant=" + applicant + ", amount=" + amount + ", deposit=" + deposit + ", approved=" + approved + "]";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2020 Red Hat, Inc. and/or its affiliates.
*
* Licensed 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.
*/
package org.kie.kogito.examples;

import org.kie.kogito.rules.DataSource;
import org.kie.kogito.rules.DataStore;
import org.kie.kogito.rules.RuleUnitData;

public class LoanUnit implements RuleUnitData {

private DataStore<LoanApplication> loanApplications;

public LoanUnit() {
this(DataSource.createStore());
}

public LoanUnit(DataStore<LoanApplication> loanApplications) {
this.loanApplications = loanApplications;
}

public DataStore<LoanApplication> getLoanApplications() {
return loanApplications;
}

public void setLoanApplications(DataStore<LoanApplication> loanApplications) {
this.loanApplications = loanApplications;
}
}
Loading

0 comments on commit ec03f77

Please sign in to comment.