This is an automated email from the ASF dual-hosted git repository.

tkobayas pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-drools.git


The following commit(s) were added to refs/heads/main by this push:
     new d2886894a3 Added files and dirs for codestart (#6279)
d2886894a3 is described below

commit d2886894a3e30e22f7cb0a09d8b8392bcc6b6424
Author: Paolo Bizzarri <[email protected]>
AuthorDate: Fri Mar 21 02:21:41 2025 +0100

    Added files and dirs for codestart (#6279)
    
    * Added files and dirs for codestart
    
    * Fixed formatting and licencing issues
---
 drools-quarkus-extension/drools-quarkus/pom.xml    | 21 +++++++
 .../quarkus/drools-quarkus-codestart/codestart.yml | 26 +++++++++
 .../java/src/main/java/org/acme/Applicant.java     | 46 +++++++++++++++
 .../java/src/main/java/org/acme/LoanAppDTO.java    | 42 ++++++++++++++
 .../src/main/java/org/acme/LoanApplication.java    | 66 ++++++++++++++++++++++
 .../java/org/acme/LoanApplicationEndPoint.java     | 53 +++++++++++++++++
 .../java/src/main/resources/org/acme/rules.drl     | 62 ++++++++++++++++++++
 .../main/resources/META-INF/quarkus-extension.yaml |  7 ++-
 8 files changed, 322 insertions(+), 1 deletion(-)

diff --git a/drools-quarkus-extension/drools-quarkus/pom.xml 
b/drools-quarkus-extension/drools-quarkus/pom.xml
index fa208fac63..5bf7e4d928 100644
--- a/drools-quarkus-extension/drools-quarkus/pom.xml
+++ b/drools-quarkus-extension/drools-quarkus/pom.xml
@@ -152,6 +152,27 @@
                 <groupId>io.smallrye</groupId>
                 <artifactId>jandex-maven-plugin</artifactId>
             </plugin>
+                     <plugin>
+                       <artifactId>maven-jar-plugin</artifactId>
+                       <executions>
+                         <execution>
+                           <id>generate-codestart-jar</id>
+                           <phase>generate-resources</phase>
+                           <goals>
+                             <goal>jar</goal>
+                           </goals>
+                           <configuration>
+                             
<classesDirectory>${project.basedir}/src/main</classesDirectory>
+                             <includes>
+                               <include>codestarts/**</include>
+                             </includes>
+                             <classifier>codestarts</classifier>
+                             <skipIfEmpty>true</skipIfEmpty>
+                           </configuration>
+                         </execution>
+                       </executions>
+                     </plugin>
+            
         </plugins>
     </build>
 </project>
diff --git 
a/drools-quarkus-extension/drools-quarkus/src/main/codestarts/quarkus/drools-quarkus-codestart/codestart.yml
 
b/drools-quarkus-extension/drools-quarkus/src/main/codestarts/quarkus/drools-quarkus-codestart/codestart.yml
new file mode 100644
index 0000000000..500267a779
--- /dev/null
+++ 
b/drools-quarkus-extension/drools-quarkus/src/main/codestarts/quarkus/drools-quarkus-codestart/codestart.yml
@@ -0,0 +1,26 @@
+ # 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.
+ 
+
+name: quarkus-drools-codestart
+ref: quarkus-drools
+type: code
+tags: extension-codestart
+metadata:
+  title: Quarkus Drool Codestsart
+  description: Start to code with the Quarkus Drool Extension
+  related-guide-section: https://quarkus.io/guides/drools
diff --git 
a/drools-quarkus-extension/drools-quarkus/src/main/codestarts/quarkus/drools-quarkus-codestart/java/src/main/java/org/acme/Applicant.java
 
b/drools-quarkus-extension/drools-quarkus/src/main/codestarts/quarkus/drools-quarkus-codestart/java/src/main/java/org/acme/Applicant.java
new file mode 100644
index 0000000000..4127bf8634
--- /dev/null
+++ 
b/drools-quarkus-extension/drools-quarkus/src/main/codestarts/quarkus/drools-quarkus-codestart/java/src/main/java/org/acme/Applicant.java
@@ -0,0 +1,46 @@
+/**
+ * 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.acme;
+
+public class Applicant {
+       private String name;
+       private int age;
+
+       public Applicant(String name, int age) {
+               this.name = name;
+               this.age = age;
+       }
+
+       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;
+       }
+
+}
\ No newline at end of file
diff --git 
a/drools-quarkus-extension/drools-quarkus/src/main/codestarts/quarkus/drools-quarkus-codestart/java/src/main/java/org/acme/LoanAppDTO.java
 
b/drools-quarkus-extension/drools-quarkus/src/main/codestarts/quarkus/drools-quarkus-codestart/java/src/main/java/org/acme/LoanAppDTO.java
new file mode 100644
index 0000000000..a3d9055d95
--- /dev/null
+++ 
b/drools-quarkus-extension/drools-quarkus/src/main/codestarts/quarkus/drools-quarkus-codestart/java/src/main/java/org/acme/LoanAppDTO.java
@@ -0,0 +1,42 @@
+/**
+ * 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.acme;
+
+import java.util.List;
+
+public class LoanAppDTO {
+       private int maxAmount;
+       private List<LoanApplication> loanApplications;
+
+       public int getMaxAmount() {
+               return maxAmount;
+       }
+
+       public void setMaxAmount(int maxAmount) {
+               this.maxAmount = maxAmount;
+       }
+
+       public List<LoanApplication> getLoanApplications() {
+               return loanApplications;
+       }
+
+       public void setLoanApplications(List<LoanApplication> loanApplications) 
{
+               this.loanApplications = loanApplications;
+       }
+}
\ No newline at end of file
diff --git 
a/drools-quarkus-extension/drools-quarkus/src/main/codestarts/quarkus/drools-quarkus-codestart/java/src/main/java/org/acme/LoanApplication.java
 
b/drools-quarkus-extension/drools-quarkus/src/main/codestarts/quarkus/drools-quarkus-codestart/java/src/main/java/org/acme/LoanApplication.java
new file mode 100644
index 0000000000..f1354f1e0c
--- /dev/null
+++ 
b/drools-quarkus-extension/drools-quarkus/src/main/codestarts/quarkus/drools-quarkus-codestart/java/src/main/java/org/acme/LoanApplication.java
@@ -0,0 +1,66 @@
+/**
+ * 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.acme;
+
+public class LoanApplication {
+    private String id;
+    private Applicant applicant;
+    private int amount;
+    private int deposit;
+    private boolean approved = false;
+
+   public LoanApplication(String id, Applicant applicant, int amount, int 
deposit) {
+       this.id = id;
+       this.applicant = applicant;
+       this.amount = amount;
+       this.deposit = deposit;
+   }
+
+       public Applicant getApplicant() {
+               return applicant;
+       }
+       
+       public void setApplicant(Applicant applicant) {
+               this.applicant = applicant;
+       }
+       
+       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;
+       }
+       
+       public boolean isApproved() {
+               return approved;
+       }
+       
+       public void setApproved(boolean approved) {
+               this.approved = approved;
+       }
+}
\ No newline at end of file
diff --git 
a/drools-quarkus-extension/drools-quarkus/src/main/codestarts/quarkus/drools-quarkus-codestart/java/src/main/java/org/acme/LoanApplicationEndPoint.java
 
b/drools-quarkus-extension/drools-quarkus/src/main/codestarts/quarkus/drools-quarkus-codestart/java/src/main/java/org/acme/LoanApplicationEndPoint.java
new file mode 100644
index 0000000000..36d1405e36
--- /dev/null
+++ 
b/drools-quarkus-extension/drools-quarkus/src/main/codestarts/quarkus/drools-quarkus-codestart/java/src/main/java/org/acme/LoanApplicationEndPoint.java
@@ -0,0 +1,53 @@
+/**
+ * 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.acme;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import jakarta.inject.Inject;
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import org.kie.api.runtime.KieRuntimeBuilder;
+import org.kie.api.runtime.KieSession;
+
+@Path("/find-approved")
+public class LoanApplicationEndPoint {
+
+       @Inject
+       KieRuntimeBuilder kieRuntimeBuilder;
+
+       @POST
+       @Produces("application/json")
+       @Consumes("application/json")
+       public List<LoanApplication> executeQuery(LoanAppDTO loanAppDto) {
+               KieSession session = kieRuntimeBuilder.newKieSession();
+               List<LoanApplication> approvedApplications = new ArrayList<>();
+
+               session.setGlobal("approvedApplications", approvedApplications);
+               session.setGlobal("maxAmount", loanAppDto.getMaxAmount());
+               loanAppDto.getLoanApplications().forEach(session::insert);
+
+               session.fireAllRules();
+               session.dispose();
+               return approvedApplications;
+       }
+}
diff --git 
a/drools-quarkus-extension/drools-quarkus/src/main/codestarts/quarkus/drools-quarkus-codestart/java/src/main/resources/org/acme/rules.drl
 
b/drools-quarkus-extension/drools-quarkus/src/main/codestarts/quarkus/drools-quarkus-codestart/java/src/main/resources/org/acme/rules.drl
new file mode 100644
index 0000000000..9f5ffbcb46
--- /dev/null
+++ 
b/drools-quarkus-extension/drools-quarkus/src/main/codestarts/quarkus/drools-quarkus-codestart/java/src/main/resources/org/acme/rules.drl
@@ -0,0 +1,62 @@
+/**
+ * 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.acme;
+
+import org.acme.Applicant;
+import org.acme.LoanApplication;
+
+global Integer maxAmount;
+global java.util.List approvedApplications;
+
+rule SmallDepositApprove when
+    $l: LoanApplication( applicant.age >= 20, deposit < 1000, amount <= 2000 )
+then
+    modify($l) { setApproved(true) };
+end
+
+rule SmallDepositReject when
+    $l: LoanApplication( applicant.age >= 20, deposit < 1000, amount > 2000 )
+then
+    modify($l) { setApproved(false) };
+end
+
+rule LargeDepositApprove when
+    $l: LoanApplication( applicant.age >= 20, deposit >= 1000, amount <= 
maxAmount )
+then
+    modify($l) { setApproved(true) };
+end
+
+rule LargeDepositReject when
+    $l: LoanApplication( applicant.age >= 20, deposit >= 1000, amount > 
maxAmount )
+then
+    modify($l) { setApproved(false) };
+end
+
+rule NotAdultApplication when
+    $l: LoanApplication( applicant.age < 20 )
+then
+    modify($l) { setApproved(false) };
+end
+
+rule CollectApprovedApplication when
+    $l: LoanApplication( approved )
+then
+    approvedApplications.add($l);
+end
diff --git 
a/drools-quarkus-extension/drools-quarkus/src/main/resources/META-INF/quarkus-extension.yaml
 
b/drools-quarkus-extension/drools-quarkus/src/main/resources/META-INF/quarkus-extension.yaml
index 0ed9233b1d..631157ff62 100644
--- 
a/drools-quarkus-extension/drools-quarkus/src/main/resources/META-INF/quarkus-extension.yaml
+++ 
b/drools-quarkus-extension/drools-quarkus/src/main/resources/META-INF/quarkus-extension.yaml
@@ -29,4 +29,9 @@ metadata:
   guide: "https://quarkus.io/guides/drools";
   categories:
     - "business-automation"
-  status: "stable"
\ No newline at end of file
+  status: "stable"
+  codestart:
+      name: quarkus-drools
+      languages:
+      - "java"
+      artifact: "org.drools:drools-quarkus:codestarts:jar:${project.version}"


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to