apache / incubator-kie-drools

Drools is a rule engine, DMN engine and complex event processing (CEP) engine for Java.
http://www.drools.org
5.83k stars 2.49k forks source link

exec-model doesn't populate metadata of declared type #6037

Open tkobayas opened 1 month ago

tkobayas commented 1 month ago

For example, if we add this test case to drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/compiler/TypeDeclarationTest.java

    @Test
    public void testTypeDeclarationCustomMetadata() {
        String str = "package org.example.custom; \n" +
                "import " + Date.class.getCanonicalName() + ";\n" +
                "import " + Address.class.getCanonicalName() + ";\n" +
                "\n" +
                "declare Person\n" +
                "    @author( Bob )\n" +
                "    @dateOfCreation( 01-Feb-2009 )\n" +
                "\n" +
                "    name : String @key @maxLength( 30 )\n" +
                "    dateOfBirth : Date\n" +
                "    address : Address\n" +
                "end";

        KieBase kBase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);

        FactType person = kBase.getFactType( "org.example.custom", "Person" );

        Map<String, Object> personMetaData = person.getMetaData();
        System.out.println("== Person Meta Data ==");
        System.out.println(personMetaData);

        FactField field = person.getField( "name" );
        Map<String, Object> nameMetaData = field.getMetaData();
        System.out.println("== name Meta Data ==");
        System.out.println(nameMetaData);
    }

non-exec-model

== Person Meta Data ==
{author=Bob, dateOfCreation=01-Feb-2009}
== name Meta Data ==
{key=null, maxLength=30}

exec-model

== Person Meta Data ==
null
== name Meta Data ==
null
tkobayas commented 1 month ago

Note that the generated class contains the annotation when the annotation is defined as a Java class, which should be the main benefit.

https://kie.zulipchat.com/#narrow/stream/232677-drools/topic/Annotations.20on.20user.20declared.20types.3F/near/455392692

tkobayas commented 1 month ago

lower priority