-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[incubator-kie-issues#1209] Implemented scesim rules springboot example
- Loading branch information
Gabriele-Cardosi
committed
May 16, 2024
1 parent
ef03557
commit 19022fb
Showing
17 changed files
with
783 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...-legacy-scesim-quarkus-example/src/test/java/testscenario/ScenarioJunitActivatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
package testscenario; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
/** | ||
* Do not remove this file | ||
*/ | ||
@QuarkusTest | ||
@org.junit.runner.RunWith(org.drools.scenariosimulation.backend.runner.ScenarioJunitActivator.class) | ||
public class ScenarioJunitActivatorTest { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
kogito-springboot-examples/rules-legacy-scesim-springboot-example/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# RuleUnit + Spring Boot example | ||
|
||
## Description | ||
|
||
A simple rule service to validate `Hello` fact. | ||
|
||
An injectable KieRuntimeBuilder is generated, so you can create Drools v7 KieBase and KieSession out of it. | ||
|
||
## Installing and Running | ||
|
||
### Prerequisites | ||
|
||
You will need: | ||
- Java 11+ installed | ||
- Environment variable JAVA_HOME set accordingly | ||
- Maven 3.8.6+ installed | ||
|
||
### Compile and Run | ||
|
||
```sh | ||
mvn clean compile spring-boot:run | ||
``` | ||
|
||
### Package and Run | ||
|
||
```sh | ||
mvn clean package | ||
java -jar target/ruleunit-springboot-example.jar | ||
``` | ||
|
||
## OpenAPI (Swagger) documentation | ||
[Specification at swagger.io](https://swagger.io/docs/specification/about/) | ||
|
||
You can take a look at the [OpenAPI definition](http://localhost:8080/v3/api-docs) - automatically generated and included in this service - to determine all available operations exposed by this service. For easy readability you can visualize the OpenAPI definition file using a UI tool like for example available [Swagger UI](https://editor.swagger.io). | ||
|
||
In addition, various clients to interact with this service can be easily generated using this OpenAPI definition. | ||
|
||
## Example Usage | ||
|
||
Once the service is up and running, you can use the following examples to interact with the service. | ||
|
||
### POST /find-approved | ||
|
||
Returns approved Hello from the given fact: | ||
|
||
```sh | ||
curl -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"approved":false, "greeting":"foo"}' http://localhost:8080/find-approved | ||
``` | ||
or on windows | ||
|
||
```sh | ||
curl -X POST -H "Accept: application/json" -H "Content-Type: application/json" -d "{\"approved\":false, \"greeting\":\"foo\"}" http://localhost:8080/find-approved | ||
``` | ||
|
||
As response the modified Hello is returned. | ||
|
||
Example response: | ||
|
||
```json | ||
{"greeting":"foo","approved":true} | ||
``` | ||
|
||
Returns denied Hello from the given fact: | ||
|
||
```sh | ||
curl -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"approved":false, "greeting":"bar"}' http://localhost:8080/find-approved | ||
``` | ||
or on windows | ||
|
||
```sh | ||
curl -X POST -H "Accept: application/json" -H "Content-Type: application/json" -d "{\"approved\":false, \"greeting\":\"bar\"}" http://localhost:8080/find-approved | ||
``` | ||
|
||
As response the modified Hello is returned. | ||
|
||
Example response: | ||
|
||
```json | ||
{"greeting":"bar","approved":false} | ||
``` |
115 changes: 115 additions & 0 deletions
115
kogito-springboot-examples/rules-legacy-scesim-springboot-example/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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 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> | ||
|
||
<parent> | ||
<groupId>org.kie.kogito.examples</groupId> | ||
<artifactId>kogito-springboot-examples</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>rules-legacy-scesim-springboot-example</artifactId> | ||
<name>Kogito Example :: Rules Legacy API HELLO - Spring Boot</name> | ||
|
||
<properties> | ||
<version.org.kie.kogito>999-SNAPSHOT</version.org.kie.kogito> | ||
<kogito.bom.version>999-SNAPSHOT</kogito.bom.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.kie.kogito</groupId> | ||
<artifactId>kogito-spring-boot-bom</artifactId> | ||
<version>${kogito.bom.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools-xml-support</artifactId> | ||
<version>${version.org.kie.kogito}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools-rules-spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<!-- test related --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- SCESIM --> | ||
<dependency> | ||
<groupId>org.kie.kogito</groupId> | ||
<artifactId>kogito-scenario-simulation</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools-xml-support</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>${project.artifactId}</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.kie.kogito</groupId> | ||
<artifactId>kogito-maven-plugin</artifactId> | ||
<version>${version.org.kie.kogito}</version> | ||
<extensions>true</extensions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
41 changes: 41 additions & 0 deletions
41
...les/rules-legacy-scesim-springboot-example/src/main/java/org/kie/kogito/legacy/Hello.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.kie.kogito.legacy; | ||
|
||
/** | ||
* This class was automatically generated by the data modeler tool. | ||
*/ | ||
|
||
public class Hello implements java.io.Serializable { | ||
|
||
static final long serialVersionUID = 1L; | ||
|
||
@org.kie.api.definition.type.Label("Greeting") | ||
private java.lang.String greeting; | ||
|
||
@org.kie.api.definition.type.Label(value = "Approved") | ||
private java.lang.Boolean approved; | ||
|
||
public Hello() { | ||
} | ||
|
||
public java.lang.String getGreeting() { | ||
return this.greeting; | ||
} | ||
|
||
public void setGreeting(java.lang.String greeting) { | ||
this.greeting = greeting; | ||
} | ||
|
||
public java.lang.Boolean getApproved() { | ||
return this.approved; | ||
} | ||
|
||
public void setApproved(java.lang.Boolean approved) { | ||
this.approved = approved; | ||
} | ||
|
||
public Hello(java.lang.String greeting, java.lang.Boolean approved) { | ||
this.greeting = greeting; | ||
this.approved = approved; | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...s-legacy-scesim-springboot-example/src/main/java/org/kie/kogito/legacy/HelloEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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.legacy; | ||
|
||
import org.kie.api.runtime.KieRuntimeBuilder; | ||
import org.kie.api.runtime.KieSession; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/find-approved") | ||
public class HelloEndpoint { | ||
|
||
private final KieRuntimeBuilder kieRuntimeBuilder; | ||
|
||
public HelloEndpoint(KieRuntimeBuilder kieRuntimeBuilder) { | ||
this.kieRuntimeBuilder = kieRuntimeBuilder; | ||
} | ||
|
||
@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) | ||
public Hello executeQuery(@RequestBody(required = true) Hello hello) { | ||
KieSession session = kieRuntimeBuilder.newKieSession(); | ||
|
||
session.insert(hello); | ||
session.fireAllRules(); | ||
|
||
return hello; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...m-springboot-example/src/main/java/org/kie/kogito/legacy/KogitoSpringbootApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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.legacy; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication(scanBasePackages = { "org.kie.kogito.**", "org.drools.**" }) | ||
public class KogitoSpringbootApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(KogitoSpringbootApplication.class, args); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...s/rules-legacy-scesim-springboot-example/src/main/java/org/kie/kogito/legacy/Message.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.kie.kogito.legacy; | ||
|
||
/** | ||
* This class was automatically generated by the data modeler tool. | ||
*/ | ||
|
||
public class Message implements java.io.Serializable { | ||
|
||
static final long serialVersionUID = 1L; | ||
|
||
public Message() { | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
...t-examples/rules-legacy-scesim-springboot-example/src/main/resources/META-INF/kmodule.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<kmodule xmlns="http://www.drools.org/xsd/kmodule"> | ||
|
||
<!-- <kbase name="HelloRuleKB" packages="org.kie.kogito.legacy" default="true">--> | ||
<!-- <ksession name="HelloRule" type="stateful" default="true"/>--> | ||
<!-- </kbase>--> | ||
</kmodule> |
Oops, something went wrong.