Copilot commented on code in PR #2203: URL: https://github.com/apache/incubator-kie-kogito-examples/pull/2203#discussion_r3091836252
########## kogito-springboot-examples/process-decisions-rules-springboot-yaml/README.md: ########## @@ -0,0 +1,316 @@ +# Process with Decisions Integration through Business Rule Task + +## Description + +This is an example project that shows the usage of decisions within processes. Decisions can be expressed in different domains or assets, such as DMN and DRL. +The focus here is to show how to integrate decisions in an embedded way using Business Rule Task where they must be deployed together with the process, in the same application. All assets(bpmn, dmn, drl) must be under the [resources](src/main/resources/). + +This example covers the following items: + +* DMN to define a decision service +* DRL to define rules decision service +* How to integrate the process with decisions using Business Rule Task + +### The Traffic Process example: + +It is based on the traffic violation evaluation process, where it is required to fetch Driver information, and based on this, it is first performed the license validation to check if the driver has a valid license (using a RuleUnit in a DRL) after the license validation it is then executed the violation evaluation defined as a DMN decision and following, it is checked in the process if the output contains information whether the driver was suspended or not, completing the process. + +#### Process using Business Rule Task + + + +This is a declarative approach, it does not require to have any extra implementation, the interaction with decisions is executed out-of-the-box by the engine. The information needed to execute the decision evaluation should be set in the Data Assignments in the Business Rule Task. + +The BPMN file where this process is declared is [traffic-rules-dmn.bpmn](src/main/resources/traffic-rules-dmn.bpmn). + +--- + +* #### Process Properties +<img src="docs/images/process-properties-embedded.png" width=300/> + +These are the properties defined for the process, the most important one in this section to pay attention is the ID because it is used in the REST endpoint generation referring to the path to interact with this process. + +* #### Proces Variables + +The variables used in the process itself, but the focus in this example are the classes that are used to define the POJOs to interact the process with decisions, that are the [Violation](src/main/java/org/kie/kogito/traffic/Violation.java), [Driver](src/main/java/org/kie/kogito/traffic/Driver.java), [Fine](src/main/java/org/kie/kogito/traffic/Fine.java). + +<img src="docs/images/process-variables-embedded.png" width=300/> + +**Mapping data from Process to/from DMN** + +It is important to mention DMN for instance can define the Data Type in its structure, but we can align all attributes names in a Java class that is used as process variables, in case the attribute names contain spaces or are not following java conventions we can use [Jackson](https://github.com/FasterXML/jackson) annotations to make the process variable POJOs aligned with DMN data types, for instance in the [Violation](src/main/java/org/kie/kogito/traffic/Violation.java) class, where it is mapped the `speedLimit` attribute as `Speed Limit` using `@JsonProperty` annotation, in this case, this attribute from the process variable with Violation can be seamlessly integrated Violation Data Type defined in DMN. + +**Violation Data Type in DMN** + +<img src="docs/images/violation-dmn-data-types.png" width=600/> + + +* #### Get Driver Task + +Fetch for driver information, in this implementation it is just mocking a result, that simply fill with an expired license date in case the `driverId` is an odd number and with a valid date in case of an even number. In a real use case, it could be performing an external call to a service or a database to get this information. + +The service task implementation is done in the [DriverService](src/main/java/org/kie/kogito/traffic/DriverService.java) class. + +In the data assignment the input is the `driverId` and output is the `driver` variable, filled with all driver information. + +* #### License Validation Task (DRL) + +Represents the task to do the call to the DRL service. + +<img src="docs/images/license-validation-drl-businessrule.png" width=150/> + +The properties to be set are mainly the `Rule Language`that should be set as `DRL` and the `Rule Flow Group` with `unit:` + `[the FQCN of the Rule Unit Data class]`, in this case [org.kie.kogito.traffic.LicenseValidationService](src/main/java/org/kie/kogito/traffic/LicenseValidationService.java). + +<img src="docs/images/license-validation-dmn-businessrule-properties.png" width=300/> + +The input and output mapping for this task is just the driver variable that is filled with license validation information. + + + + +* #### Traffic Violation Task (DMN) +Similar to the License Validation Task, but it represents the task to do the call to the DMN service. + +<img src="docs/images/traffic-violation-dmn-businessrule.png" width=150/> + +The properties to be set are mainly the `Rule Language`that should be set as `DMN` and the `Namespace` and `DMN Model Name` must be set with the values defined in in the DMN, in this case [TrafficViolation.dmn](src/main/resources/TrafficViolation.dmn). + +<img src="docs/images/traffic-violation-dmn-businessrule-properties.png" width=300/> + +The input for this task is the `Driver` and `Violation` variables, and the outputs are the `Suspended` and `Fine`. + + + + +* #### Suspended Task +Just an example task where it could be performed any action based on the condition in which the driver is suspended. In the current implementation, it is just logging the information in the console. + + +* #### Not Suspended Task +Just an example task where it could be performed any action based on the condition in which the driver is **not** suspended. In the current implementation, it is just logging the information in the console. + +## Decisions + +### License Validation - Rule Unit + +This decision consistis in rules which are evaluated to check if a driver's license is expired or not according to the expiration date and thus populating the result in the information in the driver variable. + +The DRL file where this Rule Unit is declared is [LicenseValidationService.drl](src/main/resources/LicenseValidationService.drl) and the the Java class that contains the Rule Unit Data is [LicenseValidationService](src/main/java/org/kie/kogito/traffic/LicenseValidationService.java). + +### Traffic Violation - DMN + +This decision consists in a DMN that basically checks if a driver is suspended or not according to the violation and current driver points in its license. + + + +The DMN file where this decision is declared is [TrafficViolation.dmn](src/main/resources/TrafficViolation.dmn) + + +## Build and run + +### Prerequisites + +You will need: + - Java 11+ installed + - Environment variable JAVA_HOME set accordingly + - Maven 3.9.11+ installed + +### Compile and Run in Local Dev Mode + +```sh +mvn clean spring-boot:run +``` + +### Package and Run in JVM mode + +```sh +mvn clean package +java -jar target/process-decisions-springboot.jar +``` + +or on windows + +```sh +mvn clean package +java -jar target\process-decisions-springboot.jar +``` Review Comment: The build instructions use a jar name that doesn't match this module's artifactId/finalName ("process-decisions-springboot.jar"). Update the command to reference the jar produced by this module (e.g., "process-decisions-rules-springboot-yaml.jar"). ########## kogito-springboot-examples/process-decisions-rules-springboot-yaml/README.md: ########## @@ -0,0 +1,316 @@ +# Process with Decisions Integration through Business Rule Task + +## Description + +This is an example project that shows the usage of decisions within processes. Decisions can be expressed in different domains or assets, such as DMN and DRL. +The focus here is to show how to integrate decisions in an embedded way using Business Rule Task where they must be deployed together with the process, in the same application. All assets(bpmn, dmn, drl) must be under the [resources](src/main/resources/). + +This example covers the following items: + +* DMN to define a decision service +* DRL to define rules decision service +* How to integrate the process with decisions using Business Rule Task + +### The Traffic Process example: + +It is based on the traffic violation evaluation process, where it is required to fetch Driver information, and based on this, it is first performed the license validation to check if the driver has a valid license (using a RuleUnit in a DRL) after the license validation it is then executed the violation evaluation defined as a DMN decision and following, it is checked in the process if the output contains information whether the driver was suspended or not, completing the process. + +#### Process using Business Rule Task + + + +This is a declarative approach, it does not require to have any extra implementation, the interaction with decisions is executed out-of-the-box by the engine. The information needed to execute the decision evaluation should be set in the Data Assignments in the Business Rule Task. + +The BPMN file where this process is declared is [traffic-rules-dmn.bpmn](src/main/resources/traffic-rules-dmn.bpmn). + +--- + +* #### Process Properties +<img src="docs/images/process-properties-embedded.png" width=300/> + +These are the properties defined for the process, the most important one in this section to pay attention is the ID because it is used in the REST endpoint generation referring to the path to interact with this process. + +* #### Proces Variables + +The variables used in the process itself, but the focus in this example are the classes that are used to define the POJOs to interact the process with decisions, that are the [Violation](src/main/java/org/kie/kogito/traffic/Violation.java), [Driver](src/main/java/org/kie/kogito/traffic/Driver.java), [Fine](src/main/java/org/kie/kogito/traffic/Fine.java). + +<img src="docs/images/process-variables-embedded.png" width=300/> + +**Mapping data from Process to/from DMN** + +It is important to mention DMN for instance can define the Data Type in its structure, but we can align all attributes names in a Java class that is used as process variables, in case the attribute names contain spaces or are not following java conventions we can use [Jackson](https://github.com/FasterXML/jackson) annotations to make the process variable POJOs aligned with DMN data types, for instance in the [Violation](src/main/java/org/kie/kogito/traffic/Violation.java) class, where it is mapped the `speedLimit` attribute as `Speed Limit` using `@JsonProperty` annotation, in this case, this attribute from the process variable with Violation can be seamlessly integrated Violation Data Type defined in DMN. + +**Violation Data Type in DMN** + +<img src="docs/images/violation-dmn-data-types.png" width=600/> + + +* #### Get Driver Task + +Fetch for driver information, in this implementation it is just mocking a result, that simply fill with an expired license date in case the `driverId` is an odd number and with a valid date in case of an even number. In a real use case, it could be performing an external call to a service or a database to get this information. + +The service task implementation is done in the [DriverService](src/main/java/org/kie/kogito/traffic/DriverService.java) class. + +In the data assignment the input is the `driverId` and output is the `driver` variable, filled with all driver information. + +* #### License Validation Task (DRL) + +Represents the task to do the call to the DRL service. + +<img src="docs/images/license-validation-drl-businessrule.png" width=150/> + +The properties to be set are mainly the `Rule Language`that should be set as `DRL` and the `Rule Flow Group` with `unit:` + `[the FQCN of the Rule Unit Data class]`, in this case [org.kie.kogito.traffic.LicenseValidationService](src/main/java/org/kie/kogito/traffic/LicenseValidationService.java). + +<img src="docs/images/license-validation-dmn-businessrule-properties.png" width=300/> + +The input and output mapping for this task is just the driver variable that is filled with license validation information. + + + + +* #### Traffic Violation Task (DMN) +Similar to the License Validation Task, but it represents the task to do the call to the DMN service. + +<img src="docs/images/traffic-violation-dmn-businessrule.png" width=150/> + +The properties to be set are mainly the `Rule Language`that should be set as `DMN` and the `Namespace` and `DMN Model Name` must be set with the values defined in in the DMN, in this case [TrafficViolation.dmn](src/main/resources/TrafficViolation.dmn). + +<img src="docs/images/traffic-violation-dmn-businessrule-properties.png" width=300/> + +The input for this task is the `Driver` and `Violation` variables, and the outputs are the `Suspended` and `Fine`. + + + + +* #### Suspended Task +Just an example task where it could be performed any action based on the condition in which the driver is suspended. In the current implementation, it is just logging the information in the console. + + +* #### Not Suspended Task +Just an example task where it could be performed any action based on the condition in which the driver is **not** suspended. In the current implementation, it is just logging the information in the console. + +## Decisions + +### License Validation - Rule Unit + +This decision consistis in rules which are evaluated to check if a driver's license is expired or not according to the expiration date and thus populating the result in the information in the driver variable. Review Comment: Typo: "consistis" should be "consists". ```suggestion This decision consists in rules which are evaluated to check if a driver's license is expired or not according to the expiration date and thus populating the result in the information in the driver variable. ``` ########## kogito-springboot-examples/process-decisions-rules-springboot-yaml/src/test/java/org.kie.kogito.traffic/TrafficProcessIT.java: ########## @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.traffic; + +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.server.LocalServerPort; + +import io.restassured.RestAssured; +import io.restassured.http.ContentType; +import io.restassured.response.ValidatableResponse; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = KogitoApplication.class) +public class TrafficProcessIT { + + public static final BigDecimal SPEED_LIMIT = new BigDecimal(100); + + static { + RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(); + } + + @LocalServerPort + int randomServerPort; + + @BeforeEach + public void setup() { + RestAssured.port = randomServerPort; + } + + @Test + public void testTrafficViolationEmbeddedDecisionOnQuarkus() { Review Comment: Test method name references Quarkus, but this is a Spring Boot example/module. Renaming the test to reflect Spring Boot (or removing the platform reference) would avoid confusion in reports and IDE test runners. ```suggestion public void testTrafficViolationEmbeddedDecisionOnSpringBoot() { ``` ########## kogito-springboot-examples/process-decisions-rules-springboot-yaml/README.md: ########## @@ -0,0 +1,316 @@ +# Process with Decisions Integration through Business Rule Task + +## Description + +This is an example project that shows the usage of decisions within processes. Decisions can be expressed in different domains or assets, such as DMN and DRL. +The focus here is to show how to integrate decisions in an embedded way using Business Rule Task where they must be deployed together with the process, in the same application. All assets(bpmn, dmn, drl) must be under the [resources](src/main/resources/). + +This example covers the following items: + +* DMN to define a decision service +* DRL to define rules decision service +* How to integrate the process with decisions using Business Rule Task + +### The Traffic Process example: + +It is based on the traffic violation evaluation process, where it is required to fetch Driver information, and based on this, it is first performed the license validation to check if the driver has a valid license (using a RuleUnit in a DRL) after the license validation it is then executed the violation evaluation defined as a DMN decision and following, it is checked in the process if the output contains information whether the driver was suspended or not, completing the process. + +#### Process using Business Rule Task + + + +This is a declarative approach, it does not require to have any extra implementation, the interaction with decisions is executed out-of-the-box by the engine. The information needed to execute the decision evaluation should be set in the Data Assignments in the Business Rule Task. + +The BPMN file where this process is declared is [traffic-rules-dmn.bpmn](src/main/resources/traffic-rules-dmn.bpmn). + +--- + +* #### Process Properties +<img src="docs/images/process-properties-embedded.png" width=300/> + +These are the properties defined for the process, the most important one in this section to pay attention is the ID because it is used in the REST endpoint generation referring to the path to interact with this process. + +* #### Proces Variables Review Comment: Section header has a typo: "Proces Variables" should be "Process Variables". ```suggestion * #### Process Variables ``` ########## kogito-springboot-examples/process-decisions-rules-springboot-yaml/README.md: ########## @@ -0,0 +1,316 @@ +# Process with Decisions Integration through Business Rule Task + +## Description + +This is an example project that shows the usage of decisions within processes. Decisions can be expressed in different domains or assets, such as DMN and DRL. +The focus here is to show how to integrate decisions in an embedded way using Business Rule Task where they must be deployed together with the process, in the same application. All assets(bpmn, dmn, drl) must be under the [resources](src/main/resources/). + +This example covers the following items: + +* DMN to define a decision service +* DRL to define rules decision service +* How to integrate the process with decisions using Business Rule Task + +### The Traffic Process example: + +It is based on the traffic violation evaluation process, where it is required to fetch Driver information, and based on this, it is first performed the license validation to check if the driver has a valid license (using a RuleUnit in a DRL) after the license validation it is then executed the violation evaluation defined as a DMN decision and following, it is checked in the process if the output contains information whether the driver was suspended or not, completing the process. + +#### Process using Business Rule Task + + + +This is a declarative approach, it does not require to have any extra implementation, the interaction with decisions is executed out-of-the-box by the engine. The information needed to execute the decision evaluation should be set in the Data Assignments in the Business Rule Task. + +The BPMN file where this process is declared is [traffic-rules-dmn.bpmn](src/main/resources/traffic-rules-dmn.bpmn). + +--- + +* #### Process Properties +<img src="docs/images/process-properties-embedded.png" width=300/> + +These are the properties defined for the process, the most important one in this section to pay attention is the ID because it is used in the REST endpoint generation referring to the path to interact with this process. + +* #### Proces Variables + +The variables used in the process itself, but the focus in this example are the classes that are used to define the POJOs to interact the process with decisions, that are the [Violation](src/main/java/org/kie/kogito/traffic/Violation.java), [Driver](src/main/java/org/kie/kogito/traffic/Driver.java), [Fine](src/main/java/org/kie/kogito/traffic/Fine.java). + +<img src="docs/images/process-variables-embedded.png" width=300/> + +**Mapping data from Process to/from DMN** + +It is important to mention DMN for instance can define the Data Type in its structure, but we can align all attributes names in a Java class that is used as process variables, in case the attribute names contain spaces or are not following java conventions we can use [Jackson](https://github.com/FasterXML/jackson) annotations to make the process variable POJOs aligned with DMN data types, for instance in the [Violation](src/main/java/org/kie/kogito/traffic/Violation.java) class, where it is mapped the `speedLimit` attribute as `Speed Limit` using `@JsonProperty` annotation, in this case, this attribute from the process variable with Violation can be seamlessly integrated Violation Data Type defined in DMN. + +**Violation Data Type in DMN** + +<img src="docs/images/violation-dmn-data-types.png" width=600/> + + +* #### Get Driver Task + +Fetch for driver information, in this implementation it is just mocking a result, that simply fill with an expired license date in case the `driverId` is an odd number and with a valid date in case of an even number. In a real use case, it could be performing an external call to a service or a database to get this information. Review Comment: This description says driverId odd/even controls license expiration, but the implementation parses driverId as "{days}-{points}" and uses the days value to compute licenseExpiration. The README should describe the actual format/behavior. ```suggestion Fetch for driver information. In this implementation it mocks a result by parsing the `driverId` using the `{days}-{points}` format and using the `days` value to compute the driver's license expiration date. In a real use case, it could be performing an external call to a service or a database to get this information. ``` ########## kogito-springboot-examples/process-decisions-rules-springboot-yaml/README.md: ########## @@ -0,0 +1,316 @@ +# Process with Decisions Integration through Business Rule Task + +## Description + +This is an example project that shows the usage of decisions within processes. Decisions can be expressed in different domains or assets, such as DMN and DRL. +The focus here is to show how to integrate decisions in an embedded way using Business Rule Task where they must be deployed together with the process, in the same application. All assets(bpmn, dmn, drl) must be under the [resources](src/main/resources/). + +This example covers the following items: + +* DMN to define a decision service +* DRL to define rules decision service +* How to integrate the process with decisions using Business Rule Task + +### The Traffic Process example: + +It is based on the traffic violation evaluation process, where it is required to fetch Driver information, and based on this, it is first performed the license validation to check if the driver has a valid license (using a RuleUnit in a DRL) after the license validation it is then executed the violation evaluation defined as a DMN decision and following, it is checked in the process if the output contains information whether the driver was suspended or not, completing the process. + +#### Process using Business Rule Task + + + +This is a declarative approach, it does not require to have any extra implementation, the interaction with decisions is executed out-of-the-box by the engine. The information needed to execute the decision evaluation should be set in the Data Assignments in the Business Rule Task. + +The BPMN file where this process is declared is [traffic-rules-dmn.bpmn](src/main/resources/traffic-rules-dmn.bpmn). + +--- + +* #### Process Properties +<img src="docs/images/process-properties-embedded.png" width=300/> + +These are the properties defined for the process, the most important one in this section to pay attention is the ID because it is used in the REST endpoint generation referring to the path to interact with this process. + +* #### Proces Variables + +The variables used in the process itself, but the focus in this example are the classes that are used to define the POJOs to interact the process with decisions, that are the [Violation](src/main/java/org/kie/kogito/traffic/Violation.java), [Driver](src/main/java/org/kie/kogito/traffic/Driver.java), [Fine](src/main/java/org/kie/kogito/traffic/Fine.java). + +<img src="docs/images/process-variables-embedded.png" width=300/> + +**Mapping data from Process to/from DMN** + +It is important to mention DMN for instance can define the Data Type in its structure, but we can align all attributes names in a Java class that is used as process variables, in case the attribute names contain spaces or are not following java conventions we can use [Jackson](https://github.com/FasterXML/jackson) annotations to make the process variable POJOs aligned with DMN data types, for instance in the [Violation](src/main/java/org/kie/kogito/traffic/Violation.java) class, where it is mapped the `speedLimit` attribute as `Speed Limit` using `@JsonProperty` annotation, in this case, this attribute from the process variable with Violation can be seamlessly integrated Violation Data Type defined in DMN. + +**Violation Data Type in DMN** + +<img src="docs/images/violation-dmn-data-types.png" width=600/> + + +* #### Get Driver Task + +Fetch for driver information, in this implementation it is just mocking a result, that simply fill with an expired license date in case the `driverId` is an odd number and with a valid date in case of an even number. In a real use case, it could be performing an external call to a service or a database to get this information. + +The service task implementation is done in the [DriverService](src/main/java/org/kie/kogito/traffic/DriverService.java) class. + +In the data assignment the input is the `driverId` and output is the `driver` variable, filled with all driver information. + +* #### License Validation Task (DRL) + +Represents the task to do the call to the DRL service. + +<img src="docs/images/license-validation-drl-businessrule.png" width=150/> + +The properties to be set are mainly the `Rule Language`that should be set as `DRL` and the `Rule Flow Group` with `unit:` + `[the FQCN of the Rule Unit Data class]`, in this case [org.kie.kogito.traffic.LicenseValidationService](src/main/java/org/kie/kogito/traffic/LicenseValidationService.java). Review Comment: The referenced Rule Unit Data FQCN and link are incorrect for this module. The LicenseValidationService class is in the "org.kie.kogito.traffic.licensevalidation" package, so the README should point to that FQCN and file path. ```suggestion The properties to be set are mainly the `Rule Language`that should be set as `DRL` and the `Rule Flow Group` with `unit:` + `[the FQCN of the Rule Unit Data class]`, in this case [org.kie.kogito.traffic.licensevalidation.LicenseValidationService](src/main/java/org/kie/kogito/traffic/licensevalidation/LicenseValidationService.java). ``` ########## kogito-springboot-examples/process-decisions-rules-springboot-yaml/README.md: ########## @@ -0,0 +1,316 @@ +# Process with Decisions Integration through Business Rule Task + +## Description + +This is an example project that shows the usage of decisions within processes. Decisions can be expressed in different domains or assets, such as DMN and DRL. +The focus here is to show how to integrate decisions in an embedded way using Business Rule Task where they must be deployed together with the process, in the same application. All assets(bpmn, dmn, drl) must be under the [resources](src/main/resources/). + +This example covers the following items: + +* DMN to define a decision service +* DRL to define rules decision service +* How to integrate the process with decisions using Business Rule Task + +### The Traffic Process example: + +It is based on the traffic violation evaluation process, where it is required to fetch Driver information, and based on this, it is first performed the license validation to check if the driver has a valid license (using a RuleUnit in a DRL) after the license validation it is then executed the violation evaluation defined as a DMN decision and following, it is checked in the process if the output contains information whether the driver was suspended or not, completing the process. + +#### Process using Business Rule Task + + + +This is a declarative approach, it does not require to have any extra implementation, the interaction with decisions is executed out-of-the-box by the engine. The information needed to execute the decision evaluation should be set in the Data Assignments in the Business Rule Task. + +The BPMN file where this process is declared is [traffic-rules-dmn.bpmn](src/main/resources/traffic-rules-dmn.bpmn). + +--- + +* #### Process Properties +<img src="docs/images/process-properties-embedded.png" width=300/> + +These are the properties defined for the process, the most important one in this section to pay attention is the ID because it is used in the REST endpoint generation referring to the path to interact with this process. + +* #### Proces Variables + +The variables used in the process itself, but the focus in this example are the classes that are used to define the POJOs to interact the process with decisions, that are the [Violation](src/main/java/org/kie/kogito/traffic/Violation.java), [Driver](src/main/java/org/kie/kogito/traffic/Driver.java), [Fine](src/main/java/org/kie/kogito/traffic/Fine.java). Review Comment: The README links to a Driver class path that doesn't exist in this module. The Driver POJO is under the licensevalidation package, so the link should be updated to the correct file path. ```suggestion The variables used in the process itself, but the focus in this example are the classes that are used to define the POJOs to interact the process with decisions, that are the [Violation](src/main/java/org/kie/kogito/traffic/Violation.java), [Driver](src/main/java/org/kie/kogito/traffic/licensevalidation/Driver.java), [Fine](src/main/java/org/kie/kogito/traffic/Fine.java). ``` ########## kogito-springboot-examples/process-decisions-rules-springboot-yaml/pom.xml: ########## @@ -0,0 +1,119 @@ +<?xml version="1.0"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you 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. + +--> +<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-springboot-examples</artifactId> + <version>999-SNAPSHOT</version> + </parent> + <artifactId>process-decisions-rules-springboot-yaml</artifactId> + <name>Kogito Example :: Process :: Decisions :: Rules :: Spring Boot :: YaML</name> + <description>Process with DRL, DMN and DRL integration - Spring Boot - YaML configuration</description> Review Comment: "YaML" is inconsistently capitalized; standard capitalization is "YAML" (also used by Spring Boot docs). Consider updating the name/description accordingly. ```suggestion <name>Kogito Example :: Process :: Decisions :: Rules :: Spring Boot :: YAML</name> <description>Process with DRL, DMN and DRL integration - Spring Boot - YAML configuration</description> ``` ########## kogito-springboot-examples/process-decisions-rules-springboot-yaml/README.md: ########## @@ -0,0 +1,316 @@ +# Process with Decisions Integration through Business Rule Task + +## Description + +This is an example project that shows the usage of decisions within processes. Decisions can be expressed in different domains or assets, such as DMN and DRL. +The focus here is to show how to integrate decisions in an embedded way using Business Rule Task where they must be deployed together with the process, in the same application. All assets(bpmn, dmn, drl) must be under the [resources](src/main/resources/). + +This example covers the following items: + +* DMN to define a decision service +* DRL to define rules decision service +* How to integrate the process with decisions using Business Rule Task + +### The Traffic Process example: + +It is based on the traffic violation evaluation process, where it is required to fetch Driver information, and based on this, it is first performed the license validation to check if the driver has a valid license (using a RuleUnit in a DRL) after the license validation it is then executed the violation evaluation defined as a DMN decision and following, it is checked in the process if the output contains information whether the driver was suspended or not, completing the process. + +#### Process using Business Rule Task + + + +This is a declarative approach, it does not require to have any extra implementation, the interaction with decisions is executed out-of-the-box by the engine. The information needed to execute the decision evaluation should be set in the Data Assignments in the Business Rule Task. + +The BPMN file where this process is declared is [traffic-rules-dmn.bpmn](src/main/resources/traffic-rules-dmn.bpmn). + +--- + +* #### Process Properties +<img src="docs/images/process-properties-embedded.png" width=300/> + +These are the properties defined for the process, the most important one in this section to pay attention is the ID because it is used in the REST endpoint generation referring to the path to interact with this process. + +* #### Proces Variables + +The variables used in the process itself, but the focus in this example are the classes that are used to define the POJOs to interact the process with decisions, that are the [Violation](src/main/java/org/kie/kogito/traffic/Violation.java), [Driver](src/main/java/org/kie/kogito/traffic/Driver.java), [Fine](src/main/java/org/kie/kogito/traffic/Fine.java). + +<img src="docs/images/process-variables-embedded.png" width=300/> + +**Mapping data from Process to/from DMN** + +It is important to mention DMN for instance can define the Data Type in its structure, but we can align all attributes names in a Java class that is used as process variables, in case the attribute names contain spaces or are not following java conventions we can use [Jackson](https://github.com/FasterXML/jackson) annotations to make the process variable POJOs aligned with DMN data types, for instance in the [Violation](src/main/java/org/kie/kogito/traffic/Violation.java) class, where it is mapped the `speedLimit` attribute as `Speed Limit` using `@JsonProperty` annotation, in this case, this attribute from the process variable with Violation can be seamlessly integrated Violation Data Type defined in DMN. + +**Violation Data Type in DMN** + +<img src="docs/images/violation-dmn-data-types.png" width=600/> + + +* #### Get Driver Task + +Fetch for driver information, in this implementation it is just mocking a result, that simply fill with an expired license date in case the `driverId` is an odd number and with a valid date in case of an even number. In a real use case, it could be performing an external call to a service or a database to get this information. + +The service task implementation is done in the [DriverService](src/main/java/org/kie/kogito/traffic/DriverService.java) class. + +In the data assignment the input is the `driverId` and output is the `driver` variable, filled with all driver information. + +* #### License Validation Task (DRL) + +Represents the task to do the call to the DRL service. + +<img src="docs/images/license-validation-drl-businessrule.png" width=150/> + +The properties to be set are mainly the `Rule Language`that should be set as `DRL` and the `Rule Flow Group` with `unit:` + `[the FQCN of the Rule Unit Data class]`, in this case [org.kie.kogito.traffic.LicenseValidationService](src/main/java/org/kie/kogito/traffic/LicenseValidationService.java). + +<img src="docs/images/license-validation-dmn-businessrule-properties.png" width=300/> + +The input and output mapping for this task is just the driver variable that is filled with license validation information. + + + + +* #### Traffic Violation Task (DMN) +Similar to the License Validation Task, but it represents the task to do the call to the DMN service. + +<img src="docs/images/traffic-violation-dmn-businessrule.png" width=150/> + +The properties to be set are mainly the `Rule Language`that should be set as `DMN` and the `Namespace` and `DMN Model Name` must be set with the values defined in in the DMN, in this case [TrafficViolation.dmn](src/main/resources/TrafficViolation.dmn). + +<img src="docs/images/traffic-violation-dmn-businessrule-properties.png" width=300/> + +The input for this task is the `Driver` and `Violation` variables, and the outputs are the `Suspended` and `Fine`. + + + + +* #### Suspended Task +Just an example task where it could be performed any action based on the condition in which the driver is suspended. In the current implementation, it is just logging the information in the console. + + +* #### Not Suspended Task +Just an example task where it could be performed any action based on the condition in which the driver is **not** suspended. In the current implementation, it is just logging the information in the console. + +## Decisions + +### License Validation - Rule Unit + +This decision consistis in rules which are evaluated to check if a driver's license is expired or not according to the expiration date and thus populating the result in the information in the driver variable. + +The DRL file where this Rule Unit is declared is [LicenseValidationService.drl](src/main/resources/LicenseValidationService.drl) and the the Java class that contains the Rule Unit Data is [LicenseValidationService](src/main/java/org/kie/kogito/traffic/LicenseValidationService.java). Review Comment: This sentence has a duplicated word ("and the the Java class"). Remove the extra "the" for readability. ```suggestion The DRL file where this Rule Unit is declared is [LicenseValidationService.drl](src/main/resources/LicenseValidationService.drl) and the Java class that contains the Rule Unit Data is [LicenseValidationService](src/main/java/org/kie/kogito/traffic/LicenseValidationService.java). ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
