diff --git a/README.md b/README.md new file mode 100644 index 0000000..8aca092 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Quick Loan Bank Apps - demo + +## Description + +This demo showcases [Kogito](https://kogito.kie.org/) and [Quarkus](https://quarkus.io/) feautres for Cloud Native Business Automation Applications. diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..2b5e725 --- /dev/null +++ b/pom.xml @@ -0,0 +1,56 @@ + + + + 4.0.0 + + com.redhat.demo.qlb + qlb-apps + 1.0 + pom + + Quick Loan Bank Apps + Quick Loan Bank demo showcasing Kogito and Quarkus feautres for Cloud Native Business Automation Applications + + + ../packages/qlb-react-app + 1.4.1.Final + 0.10.1 + v11.6.0 + 6.10.3 + v1.19.1 + 1.9.1 + 2.22.1 + 3.8.1 + 3.1.0 + UTF-8 + 11 + + + + + + + org.kie.kogito + kogito-bom + ${kogito.version} + pom + import + + + + io.quarkus + quarkus-bom + ${quarkus.version} + pom + import + + + + + + + qlb-loan-preapproval-dmn + qlb-ui + + + \ No newline at end of file diff --git a/qlb-loan-preapproval-dmn/README.md b/qlb-loan-preapproval-dmn/README.md new file mode 100644 index 0000000..8984968 --- /dev/null +++ b/qlb-loan-preapproval-dmn/README.md @@ -0,0 +1,135 @@ +# Quick Loan Bank - Loan Pre-Approval DMN on Kogito Decision Service + +DMN implementation of qlb loan application demo. +Demonstrates DMN on Kogito capabilities, including REST interface code generation. + +## Decision Service definition + +![DMN model](docs/loan-preapproval_dmn.png) + +## Installing and Running + +### Prerequisites + +You will need: + +- Java 11+ installed +- Environment variable JAVA_HOME set accordingly +- Maven 3.6.2+ installed + +When using native image compilation, you will also need: + +- [GraalVM 19.3.1](https://github.com/oracle/graal/releases/tag/vm-19.3.1) installed +- Environment variable GRAALVM_HOME set accordingly +- Note that GraalVM native image compilation typically requires other packages (glibc-devel, zlib-devel and gcc) to be installed too. You also need 'native-image' installed in GraalVM (using 'gu install native-image'). Please refer to [GraalVM installation documentation](https://www.graalvm.org/docs/reference-manual/aot-compilation/#prerequisites) for more details. + +### Compile and Run in Local Dev Mode + +``` +mvn clean compile quarkus:dev +``` + +### Package and Run in JVM mode + +``` +mvn clean package +java -jar target/kjt-qlb-loan-preapproval-dmn-1.0-runner.jar +``` + +or on Windows + +``` +mvn clean package +java -jar target\kjt-qlb-loan-preapproval-dmn-1.0-runner.jar +``` + +### Package and Run using Local Native Image + +Note that this requires GRAALVM_HOME to point to a valid GraalVM installation + +``` +mvn clean package -Pnative +``` + +To run the generated native executable, generated in `target/`, execute + +``` +./target/kjt-qlb-loan-preapproval-dmn-1.0-runner +``` + +Note: This does not yet work on Windows, GraalVM and Quarkus should be rolling out support for Windows soon. + +## OpenAPI (Swagger) documentation + +The exposed service [OpenAPI specification](https://swagger.io/docs/specification) is generated at +[/docs/openapi.json](http://localhost:8081/docs/openapi.json). + +You can visualize and interact with the generated specification using the embbeded [Swagger UI](http://localhost:8081/swagger-ui) or importing the generated specification file on [Swagger Editor](https://editor.swagger.io). + +In addition client application can be easily generated from the swagger definition to interact with this service. + +## Demo Usage + +Once the service is up and running, you can use the following example to interact with the service. + +### POST /loan-preapproval + +Returns check QLB loan pre-approval + +Given inputs: + +```json +{ + "Applicant": { + "Monthly Income": 4000, + "Credit Score": 300, + "Name": "Lucien Bramard", + "Age": 16 + }, + "Loan": { + "Amount": 300000, + "Duration": 20 + } +} +``` + +Curl command (using the JSON object above): + +```sh +curl -X POST "http://localhost:8081/loan-preapproval" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"Applicant\":{\"Monthly Income\":4000,\"Credit Score\":300,\"Name\":\"Lucien Bramard\",\"Age\":16},\"Loan\":{\"Amount\":300000,\"Duration\":20}}" +``` + +or on Windows: + +```sh +curl -X POST "http://localhost:8081/loan-preapproval" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"Applicant\":{\"Monthly Income\":4000,\"Credit Score\":300,\"Name\":\"Lucien Bramard\",\"Age\":16},\"Loan\":{\"Amount\":300000,\"Duration\":20}}" +``` + +As response, pre-approval result is returned. + +Example response: + +```json +{ + "Pre Approval": { + "Rejection Reasons": [ + "Non eligible age", + "High debt ratio (31.68%)", + "Insufficient credit score (min required is 500)" + ], + "Result": false + }, + "Interest Rate": 1.39, + "Loan": { + "Amount": 300000, + "Duration": 20 + }, + "Debt Ratio": "function Debt Ratio( loanAmount, loanDuration, interestRate, monthlyIncome )", + "Applicant": { + "Monthly Income": 4000, + "Age": 16, + "Credit Score": 300, + "Name": "Lucien Bramard" + } +} +``` diff --git a/qlb-loan-preapproval-dmn/docs/loan-preapproval_dmn.png b/qlb-loan-preapproval-dmn/docs/loan-preapproval_dmn.png new file mode 100644 index 0000000..f6b132e Binary files /dev/null and b/qlb-loan-preapproval-dmn/docs/loan-preapproval_dmn.png differ diff --git a/qlb-loan-preapproval-dmn/pom.xml b/qlb-loan-preapproval-dmn/pom.xml new file mode 100644 index 0000000..79da67d --- /dev/null +++ b/qlb-loan-preapproval-dmn/pom.xml @@ -0,0 +1,119 @@ + + + + 4.0.0 + + + com.redhat.demo.qlb + qlb-apps + 1.0 + + + qlb-loan-preapproval-dmn + + Quick Loan Bank :: preapproval DMN Decision Service + DMN implementation of qlb loan pre-approval demo. + + + + + org.kie.kogito + kogito-quarkus + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-resteasy-jackson + + + io.quarkus + quarkus-smallrye-openapi + + + io.quarkus + quarkus-arc + + + + org.kie.kogito + kogito-scenario-simulation + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${compiler.plugin.version} + + ${maven.compiler.release} + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.plugin.version} + + + + io.quarkus + quarkus-maven-plugin + ${quarkus.version} + + + + build + + + + + + + + + + + + native + + + + io.quarkus + quarkus-maven-plugin + + + + native-image + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + ${surefire.plugin.version} + + + + + + + + \ No newline at end of file diff --git a/qlb-loan-preapproval-dmn/src/main/resources/application.properties b/qlb-loan-preapproval-dmn/src/main/resources/application.properties new file mode 100644 index 0000000..2b3f427 --- /dev/null +++ b/qlb-loan-preapproval-dmn/src/main/resources/application.properties @@ -0,0 +1,30 @@ +# +# 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. +# + +#https://quarkus.io/guides/openapi-swaggerui +# Configure the http port +quarkus.http.port=8081 + +quarkus.http.cors=true + +# Configure the log level +quarkus.log.level=INFO +quarkus.log.console.level=INFO + +quarkus.smallrye-openapi.path=/docs/openapi.json +quarkus.swagger-ui.always-include=true + +kogito.service.url=http://localhost:8081 \ No newline at end of file diff --git a/qlb-loan-preapproval-dmn/src/main/resources/com/redhat/demo/qlb/loan-preapproval.dmn b/qlb-loan-preapproval-dmn/src/main/resources/com/redhat/demo/qlb/loan-preapproval.dmn new file mode 100644 index 0000000..5a93955 --- /dev/null +++ b/qlb-loan-preapproval-dmn/src/main/resources/com/redhat/demo/qlb/loan-preapproval.dmn @@ -0,0 +1,796 @@ + + + + + string + + + number + + [250..900] + + + + number + + + number + + + + + number + + + number + + 7, 10, 12, 15, 20, 25 + + + + + + boolean + + + string + + + + + + + + + + + + + + + + Loan.Amount + + + + + Loan.Duration + + + + + + + < 300000 + + + 7 + + + 0.47 + + + + + + + + [300000..600000] + + + 7 + + + 0.70 + + + + + + + + > 600000 + + + 7 + + + 0.98 + + + + + + + + < 300000 + + + 10 + + + 0.72 + + + + + + + + [300000..600000] + + + 10 + + + 0.90 + + + + + + + + > 600000 + + + 10 + + + 1.10 + + + + + + + + < 300000 + + + 12 + + + 0.87 + + + + + + + + [300000..600000] + + + 12 + + + 1.06 + + + + + + + + > 600000 + + + 12 + + + 1.31 + + + + + + + + < 300000 + + + 15 + + + 1.06 + + + + + + + + [300000..600000] + + + 15 + + + 1.20 + + + + + + + + > 600000 + + + 15 + + + 1.45 + + + + + + + + < 300000 + + + 20 + + + 1.25 + + + + + + + + [300000..600000] + + + 20 + + + 1.39 + + + + + + + + > 600000 + + + 20 + + + 1.65 + + + + + + + + < 300000 + + + 25 + + + 1.45 + + + + + + + + [300000..600000] + + + 25 + + + 1.65 + + + + + + + + > 600000 + + + 25 + + + 1.85 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Applicant.Age + + + + + true + + + + + "" + + + + + + not( [18 .. 70] ) + + + false + + + "Non eligible age" + + + + + + + + + + + + Debt Ratio + + + + + Loan.Amount + + + + + + Loan.Duration + + + + + + Interest Rate + + + + + + Applicant.Monthly Income + + + + + + + + + + Debt Ratio + + + + + true + + + + + "" + + + + + + > 30 + + + false + + + "High debt ratio (" + string(decimal(Debt Ratio,2)) + "%)" + + + + + + + + + + + + + Loan.Amount + + + + + true + + + + + "" + + + + + + < 1000 + + + false + + + "Loan amount too low (min is 1000)" + + + + + + + + > 1000000 + + + false + + + "Loan amount too high (max is 1000000)" + + + + + + + + + + + + + Loan.Amount + + + + + Applicant.Credit Score + + + + + true + + + + + "" + + + + + + - + + + < 300 + + + false + + + "Insufficient credit score (min required is 300)" + + + + + + + + [100000..300000) + + + < 400 + + + false + + + "Insufficient credit score (min required is 400)" + + + + + + + + [300000..400000) + + + < 500 + + + false + + + "Insufficient credit score (min required is 500)" + + + + + + + + [400000..500000) + + + < 600 + + + false + + + "Insufficient credit score (min required is 600)" + + + + + + + + [500000..1000000] + + + < 700 + + + false + + + "Insufficient credit score (min required is 700)" + + + + + + + + + + + all (Applicant Eligibility Check.Result , Debt Ratio Check.Result , Loan Amount Check.Result , Credit Score Check.Result ) + + + + + + union(Applicant Eligibility Check.Rejection Reasons, Debt Ratio Check.Rejection Reasons, Loan Amount Check.Rejection Reasons,Credit Score Check.Rejection Reasons) + + + + + {"Result" : Result , "Rejection Reasons" : Rejection Reasons[item != ""] } + + + + + + + + + + + + + + + + + ( ( interestRate * loanAmount / 100 ) + loanAmount ) / ( loanDuration * 12 ) + + + + + ( Monthly Repayment / monthlyIncome ) * 100 + + + + + + + + + + + + + + + 50 + 154 + 178 + 100 + 100 + + + 50 + 227 + 1104 + + + 50 + 182 + 100 + 228 + 524 + + + 50 + 159 + 875 + + + + 875 + + + 875 + + + 875 + + + 875 + + + 50 + 100 + 100 + 639 + 195 + + + 50 + 159 + 100 + 331 + 444 + + + 50 + 146 + 155 + 100 + 401 + 232 + + + 1104 + + + 1104 + + + 1104 + + + 50 + 180 + 707 + + + 707 + + + 707 + + + 50 + 957 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/qlb-loan-preapproval-dmn/src/test/java/testscenario/KogitoScenarioJunitActivatorTest.java b/qlb-loan-preapproval-dmn/src/test/java/testscenario/KogitoScenarioJunitActivatorTest.java new file mode 100644 index 0000000..5061ebe --- /dev/null +++ b/qlb-loan-preapproval-dmn/src/test/java/testscenario/KogitoScenarioJunitActivatorTest.java @@ -0,0 +1,11 @@ +package testscenario; + +/** + * KogitoJunitActivator is a custom JUnit runner that enables the execution of + * Test Scenario files (*.scesim). This activator class, when executed, will + * load all scesim files available in the project and run them. Each row of the + * scenario will generate a test JUnit result. + */ +@org.junit.runner.RunWith(org.kogito.scenariosimulation.runner.KogitoJunitActivator.class) +public class KogitoScenarioJunitActivatorTest { +} \ No newline at end of file diff --git a/qlb-loan-preapproval-dmn/src/test/resources/com/redhat/demo/qlb/loan-preapproval-test.scesim b/qlb-loan-preapproval-dmn/src/test/resources/com/redhat/demo/qlb/loan-preapproval-test.scesim new file mode 100644 index 0000000..83fbcfc --- /dev/null +++ b/qlb-loan-preapproval-dmn/src/test/resources/com/redhat/demo/qlb/loan-preapproval-test.scesim @@ -0,0 +1,563 @@ + + + + + + + + Index + OTHER + + + # + java.lang.Integer + + java.lang.Integer + # + 70 + NOT_EXPRESSION + + + + + Description + OTHER + + + Scenario description + java.lang.String + + java.lang.String + Scenario description + 300 + NOT_EXPRESSION + + + + + Applicant + + + Credit Score + + + + 1|2 + GIVEN + + + Applicant + Applicant + + number + Applicant + Credit Score + + 114 + NOT_EXPRESSION + + + + + Applicant + + + Age + + + + 1|3 + GIVEN + + + Applicant + Applicant + + number + Applicant + Age + + 114 + NOT_EXPRESSION + + + + + Applicant + + + Monthly Income + + + + 1|4 + GIVEN + + + Applicant + Applicant + + number + Applicant + Monthly Income + + 114 + NOT_EXPRESSION + + + + + Loan + + + Amount + + + + 1|5 + GIVEN + + + Loan + Loan + + number + Loan + Amount + + 114 + NOT_EXPRESSION + + + + + Loan + + + Duration + + + + 1|6 + GIVEN + + + Loan + Loan + + number + Loan + Duration + + 114 + NOT_EXPRESSION + + + + + Interest Rate + + + + 1|7 + EXPECT + + + Interest Rate + Interest Rate + + number + Interest Rate + value + + 114 + NOT_EXPRESSION + + + + + Pre Approval + + + Result + + + + 1|8 + EXPECT + + + Pre Approval + Pre Approval + + boolean + Pre Approval + Result + + 114 + NOT_EXPRESSION + + + + + + + + + Scenario description + java.lang.String + + + Description + OTHER + + Too large loan amount + + + + Applicant + Applicant + + + 1|2 + GIVEN + + 700 + + + + Applicant + Applicant + + + 1|3 + GIVEN + + 18 + + + + Applicant + Applicant + + + 1|4 + GIVEN + + 3000 + + + + Loan + Loan + + + 1|5 + GIVEN + + 2000000 + + + + Loan + Loan + + + 1|6 + GIVEN + + 7 + + + + Interest Rate + Interest Rate + + + 1|7 + EXPECT + + 0.98 + + + + Pre Approval + Pre Approval + + + 1|8 + EXPECT + + false + + + + # + java.lang.Integer + + + Index + OTHER + + 1 + + + + + + + + Scenario description + java.lang.String + + + Description + OTHER + + Underaged applicant + + + + Applicant + Applicant + + + 1|2 + GIVEN + + 700 + + + + Applicant + Applicant + + + 1|3 + GIVEN + + 17 + + + + Applicant + Applicant + + + 1|4 + GIVEN + + 3000 + + + + Loan + Loan + + + 1|5 + GIVEN + + 100000 + + + + Loan + Loan + + + 1|6 + GIVEN + + 7 + + + + Interest Rate + Interest Rate + + + 1|7 + EXPECT + + 0.47 + + + + Pre Approval + Pre Approval + + + 1|8 + EXPECT + + false + + + + # + java.lang.Integer + + + Index + OTHER + + 2 + + + + + + + + Scenario description + java.lang.String + + + Description + OTHER + + Too low loan amount + + + + Applicant + Applicant + + + 1|2 + GIVEN + + 700 + + + + Applicant + Applicant + + + 1|3 + GIVEN + + 18 + + + + Applicant + Applicant + + + 1|4 + GIVEN + + 3000 + + + + Loan + Loan + + + 1|5 + GIVEN + + 500 + + + + Loan + Loan + + + 1|6 + GIVEN + + 7 + + + + Interest Rate + Interest Rate + + + 1|7 + EXPECT + + 0.47 + + + + Pre Approval + Pre Approval + + + 1|8 + EXPECT + + false + + + + # + java.lang.Integer + + + Index + OTHER + + 3 + + + + + + + + + + + + 1|1 + GIVEN + + + Empty + java.lang.Void + + java.lang.Void + INSTANCE 1 + PROPERTY 1 + 114 + NOT_EXPRESSION + + + + + + + + + Empty + java.lang.Void + + + 1|1 + GIVEN + + + + + + + + src/main/resources/com/redhat/demo/qlb/loan-preapproval.dmn + DMN + http://www.qlb.com/dmn/_96E3B174-69BB-4689-A66B-3A8DAA10D45D + loan-preapproval + false + false + + + + + \ No newline at end of file diff --git a/qlb-ui/README.md b/qlb-ui/README.md index c4e8c0e..4c1e842 100644 --- a/qlb-ui/README.md +++ b/qlb-ui/README.md @@ -1,8 +1,8 @@ # QLB UI -This project use Vert.x and Quarkus, to render a React Application +This project use [Vert.x](https://quarkus.io/guides/vertx) and [Quarkus](https://quarkus.io/) , to render a React Application -If you want to learn more about Quarkus, please visit its website: https://quarkus.io/ . +![DMN model](docs/loan-preapproval_dmn.png) ## Running the application in dev mode @@ -31,6 +31,12 @@ The application is now runnable using: java -jar target/qlb-ui-1.0-runner.jar ``` +Open [http://localhost:8082](http://localhost:8082) to view it in the browser. + +![QLB home](docs/qlb-ui-home.png) + +![QLB pre-approval](docs/qlb-ui-preapproval.png) + ## Creating a native executable You can create a native executable using: diff --git a/qlb-ui/docs/qlb-ui-home.png b/qlb-ui/docs/qlb-ui-home.png new file mode 100644 index 0000000..6f18028 Binary files /dev/null and b/qlb-ui/docs/qlb-ui-home.png differ diff --git a/qlb-ui/docs/qlb-ui-preapproval.png b/qlb-ui/docs/qlb-ui-preapproval.png new file mode 100644 index 0000000..06ae169 Binary files /dev/null and b/qlb-ui/docs/qlb-ui-preapproval.png differ diff --git a/qlb-ui/pom.xml b/qlb-ui/pom.xml index 96702b7..fd3bceb 100644 --- a/qlb-ui/pom.xml +++ b/qlb-ui/pom.xml @@ -1,57 +1,21 @@ - 4.0.0 - Quick Loan Bank :: User interface + + com.redhat.demo.qlb + qlb-apps + 1.0 + - com.redhat.demo.qlb qlb-ui - 1.0 + Quick Loan Bank :: User interface User interface for the qlb demo. - - ../packages/qlb-react-app - 1.4.1.Final - 0.10.1 - v11.6.0 - 6.10.3 - v1.19.1 - 1.9.1 - 2.22.1 - 3.8.1 - 3.1.0 - UTF-8 - 11 - - - - - - - org.kie.kogito - kogito-bom - ${kogito.version} - pom - import - - - io.quarkus - quarkus-bom - ${quarkus.version} - pom - import - - - - + io.quarkus quarkus-vertx-web @@ -73,9 +37,10 @@ - + + org.apache.maven.plugins maven-compiler-plugin @@ -84,6 +49,7 @@ ${maven.compiler.release} + io.quarkus quarkus-maven-plugin @@ -99,6 +65,7 @@ + org.apache.maven.plugins maven-surefire-plugin @@ -109,15 +76,17 @@ + com.github.eirslett frontend-maven-plugin - ${version.frontend.plugin} + ${frontend.plugin.version} ${path.to.frontend.app} + org.apache.maven.plugins @@ -142,9 +111,12 @@ + + + native @@ -176,6 +148,7 @@ native +