From 30c0952e45128a3fad18bf3da1762cba6f7adb37 Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Mon, 25 Oct 2021 17:47:19 +0900 Subject: [PATCH] [KOGITO-6039] [KOGITO-6040] Vert.X example - Applying Vert.X EventBus to LoanApplication 2 RuleUnits example --- .../README.md | 11 +++ .../multi-ruleunit-quarkus-example.yaml | 20 ++++ multi-ruleunit-quarkus-example-poc02/pom.xml | 92 +++++++++++++++++++ .../org/kie/kogito/examples/Applicant.java | 67 ++++++++++++++ .../examples/ApplicantValidationUnit.java | 41 +++++++++ .../kie/kogito/examples/LoanApplication.java | 82 +++++++++++++++++ .../examples/LoanApplicationMessageCodec.java | 74 +++++++++++++++ .../org/kie/kogito/examples/LoanUnit.java | 41 +++++++++ .../kie/kogito/examples/TwoUnitsEndpoint.java | 53 +++++++++++ .../kie/kogito/examples/TwoUnitsService.java | 64 +++++++++++++ .../java/org/kie/kogito/examples/Util.java | 38 ++++++++ .../src/main/resources/application.properties | 7 ++ .../examples/ApplicantValidationUnit.drl | 44 +++++++++ .../org/kie/kogito/examples/LoanUnit.drl | 51 ++++++++++ .../src/test/resources/application.properties | 5 + 15 files changed, 690 insertions(+) create mode 100644 multi-ruleunit-quarkus-example-poc02/README.md create mode 100644 multi-ruleunit-quarkus-example-poc02/operator/multi-ruleunit-quarkus-example.yaml create mode 100644 multi-ruleunit-quarkus-example-poc02/pom.xml create mode 100644 multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/Applicant.java create mode 100644 multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/ApplicantValidationUnit.java create mode 100644 multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/LoanApplication.java create mode 100644 multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/LoanApplicationMessageCodec.java create mode 100644 multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/LoanUnit.java create mode 100644 multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/TwoUnitsEndpoint.java create mode 100644 multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/TwoUnitsService.java create mode 100644 multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/Util.java create mode 100644 multi-ruleunit-quarkus-example-poc02/src/main/resources/application.properties create mode 100644 multi-ruleunit-quarkus-example-poc02/src/main/resources/org/kie/kogito/examples/ApplicantValidationUnit.drl create mode 100644 multi-ruleunit-quarkus-example-poc02/src/main/resources/org/kie/kogito/examples/LoanUnit.drl create mode 100644 multi-ruleunit-quarkus-example-poc02/src/test/resources/application.properties diff --git a/multi-ruleunit-quarkus-example-poc02/README.md b/multi-ruleunit-quarkus-example-poc02/README.md new file mode 100644 index 0000000000..7a69125190 --- /dev/null +++ b/multi-ruleunit-quarkus-example-poc02/README.md @@ -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} +``` \ No newline at end of file diff --git a/multi-ruleunit-quarkus-example-poc02/operator/multi-ruleunit-quarkus-example.yaml b/multi-ruleunit-quarkus-example-poc02/operator/multi-ruleunit-quarkus-example.yaml new file mode 100644 index 0000000000..d149fd66a7 --- /dev/null +++ b/multi-ruleunit-quarkus-example-poc02/operator/multi-ruleunit-quarkus-example.yaml @@ -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 \ No newline at end of file diff --git a/multi-ruleunit-quarkus-example-poc02/pom.xml b/multi-ruleunit-quarkus-example-poc02/pom.xml new file mode 100644 index 0000000000..14fee679ff --- /dev/null +++ b/multi-ruleunit-quarkus-example-poc02/pom.xml @@ -0,0 +1,92 @@ + + + 4.0.0 + + org.kie.kogito.examples + kogito-examples + 2.0.0-SNAPSHOT + + multi-ruleunit-quarkus-example-poc02 + Kogito Example :: Multiple RuleUnit - Quarkus + + 2.3.0.Final + quarkus-bom + io.quarkus + 2.3.0.Final + + + + + ${quarkus.platform.group-id} + ${quarkus.platform.artifact-id} + ${quarkus.platform.version} + pom + import + + + + + + org.kie.kogito + kogito-quarkus-rules + + + io.quarkus + quarkus-resteasy-jackson + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-resteasy-mutiny + + + io.quarkus + quarkus-arc + + + io.quarkus + quarkus-smallrye-openapi + + + org.kie.kogito + kogito-drools + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + io.quarkus + quarkus-smallrye-health + + + + ${project.artifactId} + + + io.quarkus + quarkus-maven-plugin + ${quarkus-plugin.version} + + + + build + + + + + + + diff --git a/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/Applicant.java b/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/Applicant.java new file mode 100644 index 0000000000..3d8a154d5b --- /dev/null +++ b/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/Applicant.java @@ -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; + } + +} diff --git a/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/ApplicantValidationUnit.java b/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/ApplicantValidationUnit.java new file mode 100644 index 0000000000..08e8a0473f --- /dev/null +++ b/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/ApplicantValidationUnit.java @@ -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 loanApplications; + + public ApplicantValidationUnit() { + this(DataSource.createStore()); + } + + public ApplicantValidationUnit(DataStore loanApplications) { + this.loanApplications = loanApplications; + } + + public DataStore getLoanApplications() { + return loanApplications; + } + + public void setLoanApplications(DataStore loanApplications) { + this.loanApplications = loanApplications; + } +} diff --git a/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/LoanApplication.java b/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/LoanApplication.java new file mode 100644 index 0000000000..4b84e14d1f --- /dev/null +++ b/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/LoanApplication.java @@ -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; + } + +} diff --git a/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/LoanApplicationMessageCodec.java b/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/LoanApplicationMessageCodec.java new file mode 100644 index 0000000000..8f1974289e --- /dev/null +++ b/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/LoanApplicationMessageCodec.java @@ -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 { + + 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() { + }); + } 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; + } + +} diff --git a/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/LoanUnit.java b/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/LoanUnit.java new file mode 100644 index 0000000000..01471b4949 --- /dev/null +++ b/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/LoanUnit.java @@ -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 loanApplications; + + public LoanUnit() { + this(DataSource.createStore()); + } + + public LoanUnit(DataStore loanApplications) { + this.loanApplications = loanApplications; + } + + public DataStore getLoanApplications() { + return loanApplications; + } + + public void setLoanApplications(DataStore loanApplications) { + this.loanApplications = loanApplications; + } +} diff --git a/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/TwoUnitsEndpoint.java b/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/TwoUnitsEndpoint.java new file mode 100644 index 0000000000..cbfad12b80 --- /dev/null +++ b/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/TwoUnitsEndpoint.java @@ -0,0 +1,53 @@ +/* + * 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 javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import io.smallrye.mutiny.Uni; +import io.vertx.mutiny.core.eventbus.EventBus; +import io.vertx.mutiny.core.eventbus.Message; + +@Path("/2units") +public class TwoUnitsEndpoint { + + @Inject + EventBus bus; + + public TwoUnitsEndpoint() { + + } + + @POST() + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Uni executeQuery(org.kie.kogito.examples.ApplicantValidationUnit unitDTO) { + LoanApplication loanApplication = Util.getSingleLoanApplication(unitDTO.getLoanApplications()); + Uni validatedUni = bus. request("applicant-validation", loanApplication) + .onItem() + .transform(Message::body); + LoanApplication validated = validatedUni.await().indefinitely(); + Uni approvedUni = bus. request("loan", validated) + .onItem() + .transform(Message::body); + return approvedUni; + } +} diff --git a/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/TwoUnitsService.java b/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/TwoUnitsService.java new file mode 100644 index 0000000000..8f70e056e7 --- /dev/null +++ b/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/TwoUnitsService.java @@ -0,0 +1,64 @@ +/* + * 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 java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import javax.enterprise.context.ApplicationScoped; + +import org.kie.kogito.rules.DataStore; +import org.kie.kogito.rules.RuleUnit; +import org.kie.kogito.rules.RuleUnitInstance; + +import io.quarkus.vertx.ConsumeEvent; + +@ApplicationScoped +public class TwoUnitsService { + + @javax.inject.Inject + RuleUnit applicantValidationUnit; + + @javax.inject.Inject + RuleUnit loanUnit; + + @ConsumeEvent(value = "applicant-validation") + public LoanApplication applicantValidation(LoanApplication loanApplication) { + System.out.println("Bus : applicant-validation"); + DataStore loanApplications = Util.toDataStore(loanApplication); + ApplicantValidationUnit applicantValidationUnitData = new ApplicantValidationUnit(loanApplications); + RuleUnitInstance applicantValidationUnitInstance = applicantValidationUnit.createInstance(applicantValidationUnitData); + applicantValidationUnitInstance.fire(); + applicantValidationUnitInstance.dispose(); + return loanApplication; + } + + @ConsumeEvent(value = "loan") + public LoanApplication findApproved(LoanApplication loanApplication) { + System.out.println("Bus : loan"); + DataStore loanApplications = Util.toDataStore(loanApplication); + LoanUnit loanUnitData = new LoanUnit(loanApplications); + RuleUnitInstance loanUnitInstance = loanUnit.createInstance(loanUnitData); + List response = loanUnitInstance.executeQuery("FindApproved").stream().map(this::toResult).collect(Collectors.toList()); + loanUnitInstance.dispose(); + return response.isEmpty() ? null : response.get(0); + } + + private LoanApplication toResult(Map tuple) { + return (LoanApplication) tuple.get("$l"); + } +} diff --git a/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/Util.java b/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/Util.java new file mode 100644 index 0000000000..2905835c18 --- /dev/null +++ b/multi-ruleunit-quarkus-example-poc02/src/main/java/org/kie/kogito/examples/Util.java @@ -0,0 +1,38 @@ +/* + * 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 java.util.ArrayList; +import java.util.List; + +import org.kie.kogito.rules.DataObserver; +import org.kie.kogito.rules.DataSource; +import org.kie.kogito.rules.DataStore; + +public class Util { + + public static DataStore toDataStore(LoanApplication loanApplication) { + DataStore loanApplications = DataSource.createStore(); + loanApplications.add(loanApplication); + return loanApplications; + } + + public static LoanApplication getSingleLoanApplication(DataStore loanApplications) { + List list = new ArrayList<>(); + loanApplications.subscribe(DataObserver.of(list::add)); + return list.get(0); + } +} diff --git a/multi-ruleunit-quarkus-example-poc02/src/main/resources/application.properties b/multi-ruleunit-quarkus-example-poc02/src/main/resources/application.properties new file mode 100644 index 0000000000..9557fd6d04 --- /dev/null +++ b/multi-ruleunit-quarkus-example-poc02/src/main/resources/application.properties @@ -0,0 +1,7 @@ +# Packaging +# quarkus.package.type=fast-jar + +quarkus.swagger-ui.always-include=true + +# Maximum Java heap to be used during the native image generation +quarkus.native.native-image-xmx=4g diff --git a/multi-ruleunit-quarkus-example-poc02/src/main/resources/org/kie/kogito/examples/ApplicantValidationUnit.drl b/multi-ruleunit-quarkus-example-poc02/src/main/resources/org/kie/kogito/examples/ApplicantValidationUnit.drl new file mode 100644 index 0000000000..d8bc03c09a --- /dev/null +++ b/multi-ruleunit-quarkus-example-poc02/src/main/resources/org/kie/kogito/examples/ApplicantValidationUnit.drl @@ -0,0 +1,44 @@ +/** + * 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; +unit ApplicantValidationUnit; + +import org.kie.kogito.examples.LoanApplication; + +rule NotAdult +lock-on-active true +when + $l: /loanApplications[ applicant.age < 20 ] +then + Applicant $a = $l.getApplicant(); + $a.setInvalid(true); + modify($l) { setApplicant($a) }; +end + +rule BadCreditScore +lock-on-active true +when + $l: /loanApplications[ applicant.creditScore < 100 ] +then + Applicant $a = $l.getApplicant(); + $a.setInvalid(true); + modify($l) { setApplicant($a) }; +end + +query FindInvalidApplicant + /loanApplications[ $applicant: applicant, applicant.invalid ] +end + diff --git a/multi-ruleunit-quarkus-example-poc02/src/main/resources/org/kie/kogito/examples/LoanUnit.drl b/multi-ruleunit-quarkus-example-poc02/src/main/resources/org/kie/kogito/examples/LoanUnit.drl new file mode 100644 index 0000000000..9952ae3ce5 --- /dev/null +++ b/multi-ruleunit-quarkus-example-poc02/src/main/resources/org/kie/kogito/examples/LoanUnit.drl @@ -0,0 +1,51 @@ +/** + * 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; +unit LoanUnit; + +import org.kie.kogito.examples.LoanApplication; + +rule SmallDepositApprove when + $l: /loanApplications[ !applicant.invalid, deposit < 1000, amount <= 2000 ] +then + modify($l) { setApproved(true) }; +end + +rule SmallDepositReject when + $l: /loanApplications[ !applicant.invalid, deposit < 1000, amount > 2000 ] +then + modify($l) { setApproved(false) }; +end + +rule LargeDepositApprove when + $l: /loanApplications[ !applicant.invalid, deposit >= 1000, amount <= 10000 ] +then + modify($l) { setApproved(true) }; +end + +rule LargeDepositReject when + $l: /loanApplications[ !applicant.invalid, deposit >= 1000, amount > 10000 ] +then + modify($l) { setApproved(false) }; +end + +query FindApproved + $l: /loanApplications[ approved ] +end + +query FindNotApprovedIdAndAmount + /loanApplications[ !approved, $id: id, $amount : amount ] +end diff --git a/multi-ruleunit-quarkus-example-poc02/src/test/resources/application.properties b/multi-ruleunit-quarkus-example-poc02/src/test/resources/application.properties new file mode 100644 index 0000000000..8c5dc5bd35 --- /dev/null +++ b/multi-ruleunit-quarkus-example-poc02/src/test/resources/application.properties @@ -0,0 +1,5 @@ +# Quarkus +quarkus.http.test-port=0 + +# Maximum Java heap to be used during the native image generation +quarkus.native.native-image-xmx=4g