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

mariofusco 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 8b8e8b9293 [incubator-kie-drools-6010] Date Between Dates with globals 
Not Triggering for Executable Model (#6011)
8b8e8b9293 is described below

commit 8b8e8b9293e7df2ebecdf25841b0354062ae7315
Author: Toshiya Kobayashi <[email protected]>
AuthorDate: Mon Jul 8 17:53:13 2024 +0900

    [incubator-kie-drools-6010] Date Between Dates with globals Not Triggering 
for Executable Model (#6011)
---
 .../drools/base/rule/accessor/GlobalExtractor.java |  3 +
 .../codegen/execmodel/domain/SimpleDateHolder.java | 44 +++++++++++
 .../execmodel/operators/DateOperatorTest.java      | 87 ++++++++++++++++++++++
 3 files changed, 134 insertions(+)

diff --git 
a/drools-base/src/main/java/org/drools/base/rule/accessor/GlobalExtractor.java 
b/drools-base/src/main/java/org/drools/base/rule/accessor/GlobalExtractor.java
index 5988701cfc..40c3ca72d7 100755
--- 
a/drools-base/src/main/java/org/drools/base/rule/accessor/GlobalExtractor.java
+++ 
b/drools-base/src/main/java/org/drools/base/rule/accessor/GlobalExtractor.java
@@ -132,6 +132,9 @@ public class GlobalExtractor extends 
BaseObjectClassFieldReader
             return false;
         }
         final GlobalExtractor other = (GlobalExtractor) obj;
+        if (!(this.identifier.equals(other.identifier))) {
+            return false;
+        }
         return this.objectType.equals( other.objectType );
     }
 
diff --git 
a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/domain/SimpleDateHolder.java
 
b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/domain/SimpleDateHolder.java
new file mode 100644
index 0000000000..bc95716773
--- /dev/null
+++ 
b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/domain/SimpleDateHolder.java
@@ -0,0 +1,44 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.drools.model.codegen.execmodel.domain;
+
+import java.util.Date;
+
+public class SimpleDateHolder {
+
+    private String id;
+    private final Date date;
+
+    public SimpleDateHolder(String id, Date date) {
+        this.id = id;
+        this.date = date;
+    }
+
+    public Date getDate() {
+        return date;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+}
diff --git 
a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/DateOperatorTest.java
 
b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/DateOperatorTest.java
new file mode 100644
index 0000000000..482bf00567
--- /dev/null
+++ 
b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/DateOperatorTest.java
@@ -0,0 +1,87 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.drools.model.codegen.execmodel.operators;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+
+import org.drools.model.codegen.execmodel.BaseModelTest;
+import org.drools.model.codegen.execmodel.domain.Person;
+import org.drools.model.codegen.execmodel.domain.SimpleDateHolder;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.kie.api.runtime.KieSession;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DateOperatorTest extends BaseModelTest {
+
+    public DateOperatorTest(RUN_TYPE testRunType) {
+        super(testRunType);
+    }
+
+    @Test
+    public void dateBetweenGlobals() throws ParseException {
+        String str =
+                "import " + SimpleDateHolder.class.getCanonicalName() + ";" +
+                        "global java.util.Date $startDate;\n" +
+                        "global java.util.Date $endDate;\n" +
+                        "rule R when\n" +
+                        "  SimpleDateHolder(date > $startDate && date < 
$endDate)\n" +
+                        "then\n" +
+                        "end";
+
+        KieSession ksession = getKieSession(str);
+        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
+        ksession.setGlobal("$startDate", sdf.parse("04/01/2019"));
+        ksession.setGlobal("$endDate", sdf.parse("05/01/2019"));
+
+        SimpleDateHolder holder = new SimpleDateHolder("A", 
sdf.parse("04/15/2019"));
+        ksession.insert(holder);
+        int fired = ksession.fireAllRules();
+
+        assertThat(fired).isEqualTo(1);
+    }
+
+    @Test
+    public void dateBetweenVariables() throws ParseException {
+        String str =
+                "import " + SimpleDateHolder.class.getCanonicalName() + ";" +
+                        "rule R when\n" +
+                        "  SimpleDateHolder(id == \"A\", $startDate : date)\n" 
+
+                        "  SimpleDateHolder(id == \"B\", $endDate : date)\n" +
+                        "  SimpleDateHolder(id == \"C\", date > $startDate && 
date < $endDate)\n" +
+                        "then\n" +
+                        "end";
+
+        KieSession ksession = getKieSession(str);
+        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
+
+        SimpleDateHolder holderA = new SimpleDateHolder("A", 
sdf.parse("04/01/2019"));
+        SimpleDateHolder holderB = new SimpleDateHolder("B", 
sdf.parse("05/01/2019"));
+        SimpleDateHolder holderC = new SimpleDateHolder("C", 
sdf.parse("04/15/2019"));
+
+        ksession.insert(holderA);
+        ksession.insert(holderB);
+        ksession.insert(holderC);
+        int fired = ksession.fireAllRules();
+
+        assertThat(fired).isEqualTo(1);
+    }
+}


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

Reply via email to