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.git


The following commit(s) were added to refs/heads/main by this push:
     new db631d1c24d [incubator-kie#7211] Executable model: DRL @role overrides 
Java @Role (#7251)
db631d1c24d is described below

commit db631d1c24d4a480c2b43b36d22bee201fe93b48
Author: Toshiya Kobayashi <[email protected]>
AuthorDate: Wed Nov 4 18:22:25 2026 +0900

    [incubator-kie#7211] Executable model: DRL @role overrides Java @Role 
(#7251)
---
 .../codegen/execmodel/AlignAnnotationTest.java     | 30 +++++++++++++++++++++-
 .../modelcompiler/util/TypeDeclarationUtil.java    | 10 ++++++--
 2 files changed, 37 insertions(+), 3 deletions(-)

diff --git 
a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/AlignAnnotationTest.java
 
b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/AlignAnnotationTest.java
index c6cdc938de7..6da83c930a8 100644
--- 
a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/AlignAnnotationTest.java
+++ 
b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/AlignAnnotationTest.java
@@ -19,8 +19,10 @@
 package org.drools.model.codegen.execmodel;
 
 import org.drools.base.rule.TypeDeclaration;
+import org.drools.core.common.InternalFactHandle;
 import org.drools.core.impl.InternalRuleBase;
 import org.drools.model.codegen.execmodel.domain.AnnotatedEvent;
+import org.drools.model.codegen.execmodel.domain.Person;
 import org.drools.model.codegen.execmodel.domain.PropertyChangeSupportFact;
 import org.drools.model.codegen.execmodel.domain.PropertyReactiveFact;
 import org.junit.jupiter.params.ParameterizedTest;
@@ -176,12 +178,38 @@ public class AlignAnnotationTest extends BaseModelTest {
     // --- Explicit DRL override — DRL annotation should take precedence over 
Java ---
 
     @ParameterizedTest
-    @MethodSource("parametersStandardOnly")
+    @MethodSource("parameters")
     public void testRoleExplicitOverride(RUN_TYPE runType) {
         TypeDeclaration typeDecl = getTypeDeclaration(runType, 
ANNOTATED_EVENT_OVERRIDE_DRL, AnnotatedEvent.class);
         assertThat(typeDecl.getRole()).isEqualTo(Role.Type.FACT);
     }
 
+    // --- DRL @role on a class without a Java @Role ---
+
+    @ParameterizedTest
+    @MethodSource("parameters")
+    public void testRoleEventDeclaredInDrlOnPlainClass(RUN_TYPE runType) {
+        for (String roleValue : new String[]{"event", "EVENT", 
"Role.Type.EVENT"}) {
+            String drl =
+                    "import " + Person.class.getCanonicalName() + ";\n" +
+                    "declare Person\n" +
+                    "  @role(" + roleValue + ")\n" +
+                    "end\n" +
+                    "rule R when Person() then end\n";
+
+            KieSession ksession = getKieSession(runType, drl);
+            try {
+                TypeDeclaration typeDecl = ((InternalRuleBase) 
ksession.getKieBase()).getTypeDeclaration(Person.class);
+                assertThat(typeDecl.getRole()).as("@role(%s)", 
roleValue).isEqualTo(Role.Type.EVENT);
+
+                InternalFactHandle handle = (InternalFactHandle) 
ksession.insert(new Person("Mario", 40));
+                assertThat(handle.isEvent()).as("@role(%s)", 
roleValue).isTrue();
+            } finally {
+                ksession.dispose();
+            }
+        }
+    }
+
     @ParameterizedTest
     @MethodSource("parameters")
     public void testExpiresExplicitOverride(RUN_TYPE runType) {
diff --git 
a/drools-model/drools-model-compiler/src/main/java/org/drools/modelcompiler/util/TypeDeclarationUtil.java
 
b/drools-model/drools-model-compiler/src/main/java/org/drools/modelcompiler/util/TypeDeclarationUtil.java
index a298feeca50..aa8fc68a898 100644
--- 
a/drools-model/drools-model-compiler/src/main/java/org/drools/modelcompiler/util/TypeDeclarationUtil.java
+++ 
b/drools-model/drools-model-compiler/src/main/java/org/drools/modelcompiler/util/TypeDeclarationUtil.java
@@ -22,6 +22,7 @@ import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 
@@ -68,6 +69,11 @@ public class TypeDeclarationUtil {
         return typeDeclaration;
     }
 
+    // accepts the same forms as the DRL compiler: event, EVENT, 
Role.Type.EVENT
+    private static Role.Type parseRole( String value ) {
+        return Role.Type.valueOf( value.substring( value.lastIndexOf( '.' ) + 
1 ).toUpperCase( Locale.ROOT ) );
+    }
+
     private static void wireMetaTypeAnnotations( TypeMetaData metaType, 
TypeDeclaration typeDeclaration ) {
         ClassDefinition classDef = typeDeclaration.getTypeClassDef();
         for (Map.Entry<String, AnnotationValue[]> ann : 
metaType.getAnnotations().entrySet()) {
@@ -77,8 +83,8 @@ public class TypeDeclarationUtil {
             switch (annotationName) {
                 case "role":
                     for (AnnotationValue annVal : ann.getValue()) {
-                        if (annVal.getKey().equals( "value" ) && 
annVal.getValue().equals( "event" )) {
-                            typeDeclaration.setRole( Role.Type.EVENT );
+                        if (annVal.getKey().equals( "value" )) {
+                            typeDeclaration.setRole( parseRole( 
annVal.getValue().toString() ) );
                         }
                     }
                     break;


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

Reply via email to