Skip to content

Commit

Permalink
adding parent project and dmn decision service
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachid Snoussi committed May 20, 2020
1 parent e9d3c76 commit e672a14
Show file tree
Hide file tree
Showing 13 changed files with 1,744 additions and 47 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
56 changes: 56 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.redhat.demo.qlb</groupId>
<artifactId>qlb-apps</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<name>Quick Loan Bank Apps</name>
<description>Quick Loan Bank demo showcasing Kogito and Quarkus feautres for Cloud Native Business Automation Applications</description>

<properties>
<path.to.frontend.app>../packages/qlb-react-app</path.to.frontend.app>
<quarkus.version>1.4.1.Final</quarkus.version>
<kogito.version>0.10.1</kogito.version>
<version.node>v11.6.0</version.node>
<version.npm>6.10.3</version.npm>
<version.yarn>v1.19.1</version.yarn>
<frontend.plugin.version>1.9.1</frontend.plugin.version>
<surefire.plugin.version>2.22.1</surefire.plugin.version>
<compiler.plugin.version>3.8.1</compiler.plugin.version>
<resources.plugin.version>3.1.0</resources.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
</properties>

<dependencyManagement>
<dependencies>

<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-bom</artifactId>
<version>${kogito.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${quarkus.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

</dependencies>
</dependencyManagement>

<modules>
<module>qlb-loan-preapproval-dmn</module>
<module>qlb-ui</module>
</modules>

</project>
135 changes: 135 additions & 0 deletions qlb-loan-preapproval-dmn/README.md
Original file line number Diff line number Diff line change
@@ -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"
}
}
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
119 changes: 119 additions & 0 deletions qlb-loan-preapproval-dmn/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?xml version="1.0" encoding="UTF-8" ?>
<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>

<parent>
<groupId>com.redhat.demo.qlb</groupId>
<artifactId>qlb-apps</artifactId>
<version>1.0</version>
</parent>

<artifactId>qlb-loan-preapproval-dmn</artifactId>

<name>Quick Loan Bank :: preapproval DMN Decision Service</name>
<description>DMN implementation of qlb loan pre-approval demo.</description>

<dependencies>

<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-quarkus</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>

<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-scenario-simulation</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>

</dependencies>

<build>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler.plugin.version}</version>
<configuration>
<release>${maven.compiler.release}</release>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
</plugin>

<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.version}</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>

<profiles>

<profile>
<id>native</id>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>native-image</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire.plugin.version}</version>
</plugin>
</plugins>
</build>
</profile>

</profiles>

</project>
30 changes: 30 additions & 0 deletions qlb-loan-preapproval-dmn/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit e672a14

Please sign in to comment.