Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO-NOT-MERGE] [KOGITO-6039] [KOGITO-6040] Vert.X example #952

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions multi-ruleunit-quarkus-example-poc02/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### Single loan application test

```sh
curl -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"loanApplications":[{"id":"ABC10002","amount":500,"deposit":100,"applicant":{"age":25,"name":"Paul","creditScore":200}}]}' http://localhost:8080/2units
```

Currently this poc02 takes only one loanApplication request because TwoUnitsService takes one LoanApplication object. This is more looks like a reactive use case. Of course we can improve TwoUnitsEndpoint to iterate LoanApplication objects but I leave it for simplicity now.

```json
{"id":"ABC10002","applicant":{"name":"Paul","age":25,"creditScore":200,"invalid":false},"amount":500,"deposit":100,"approved":true}
```
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
92 changes: 92 additions & 0 deletions multi-ruleunit-quarkus-example-poc02/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?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-poc02</artifactId>
<name>Kogito Example :: Multiple RuleUnit - 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-resteasy-mutiny</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,67 @@
/*
* 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 boolean invalid = false; // false by default

public Applicant() {
}

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

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 boolean isInvalid() {
return invalid;
}

public void setInvalid(boolean invalid) {
this.invalid = invalid;
}

}
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 ApplicantValidationUnit implements RuleUnitData {

private DataStore<LoanApplication> loanApplications;

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

public ApplicantValidationUnit(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,82 @@
/*
* 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, boolean approved) {
super();
this.id = id;
this.applicant = applicant;
this.amount = amount;
this.deposit = deposit;
this.approved = approved;
}

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;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2021 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 com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.vertx.core.buffer.Buffer;
import io.vertx.core.eventbus.MessageCodec;

public class LoanApplicationMessageCodec implements MessageCodec<LoanApplication, LoanApplication> {

private static ObjectMapper objectMapper = new ObjectMapper();

@Override
public void encodeToWire(Buffer buffer, LoanApplication loanApplication) {
String jsonStr;
try {
jsonStr = objectMapper.writeValueAsString(loanApplication);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}

buffer.appendInt(jsonStr.getBytes().length);
buffer.appendString(jsonStr);
}

@Override
public LoanApplication decodeFromWire(int position, Buffer buffer) {
int _pos = position;
int length = buffer.getInt(_pos);

String jsonStr = buffer.getString(_pos += 4, _pos += length);

LoanApplication loanApplication;
try {
loanApplication = objectMapper.readValue(jsonStr, new TypeReference<LoanApplication>() {
});
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return loanApplication;
}

@Override
public LoanApplication transform(LoanApplication loanApplication) {
return loanApplication;
}

@Override
public String name() {
return this.getClass().getSimpleName();
}

@Override
public byte systemCodecID() {
return -1;
}

}
Loading