Bug 851310 - Drools cannot resolve functions when argument is a fact type
Summary: Drools cannot resolve functions when argument is a fact type
Keywords:
Status: VERIFIED
Alias: None
Product: JBoss Enterprise BRMS Platform 5
Classification: JBoss
Component: BRM (Guvnor)
Version: BRMS 5.3.1
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ER2
: BRMS 5.3.1 GA
Assignee: Mario Fusco
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-08-23 18:27 UTC by Mario Fusco
Modified: 2023-05-15 19:53 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
The business rules engine could not resolve functions when a declared type was used as an argument for a function and resulted in compilation failure. This has been resolved by loading the Java Class corresponding to the declared type when compiling the function. It is now possible to use a declared type as an argument for a function.
Clone Of:
Environment:
Last Closed:
Type: Bug
Embargoed:


Attachments (Terms of Use)
Repository export (3.06 KB, application/zip)
2012-09-17 11:00 UTC, Tomas Schlosser
no flags Details
Error messages (124.13 KB, image/png)
2012-09-17 14:26 UTC, Tomas Schlosser
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker JBRULES-3562 0 Major Resolved Drools cannot resolve functions when argument is a fact type 2016-04-04 20:55:34 UTC

Description Mario Fusco 2012-08-23 18:27:02 UTC

Comment 1 Tomas Schlosser 2012-09-17 09:27:20 UTC
Tested on brms-standalone-5.3.0 and the problem described in JIRA still occurs.

Comment 3 Mario Fusco 2012-09-17 10:18:08 UTC
This issue should have been fixed only on the 5.3.1.ER1 indeed.
Could you please verify?

Comment 4 Tomas Schlosser 2012-09-17 10:30:08 UTC
I did try with brms-standalone-5.3.1 I just wrote the comment wrong. Sorry about confusion.

Comment 5 Mario Fusco 2012-09-17 10:34:51 UTC
It works for me. Could you please attach the test you used to verify it?

Comment 6 Tomas Schlosser 2012-09-17 11:00:45 UTC
Created attachment 613628 [details]
Repository export

I manually created this repository to verify bug. It is impossible to build the testPackage.

Comment 7 Mario Fusco 2012-09-17 13:51:13 UTC
That repository works for me. Also I added a further unit test in the code base of the 5.3.x branch using exactly the same DRL generated by that repository and it passes without any problem. I am pasting the source code of that test below:

    @Test
    public void testMvelFunctionWithDeclaredTypeArg() {
        // JBRULES-3562
        String rule = "package testPackage\n" +
                "declare Person\n" +
                "name: String\n" +
                "age: Integer\n" +
                "end\n" +
                "\n" +
                "function String PersonToString(Person p) {\n" +
                "String result = \"\";\n" +
                "result = p.getName() + \", age: \" + p.getAge();\n" +
                "return result;\n" +
                "}\n" +
                "\n" +
                "rule \"testRule1\"\n" +
                "dialect \"mvel\"\n" +
                "when\n" +
                "p : Person( )\n" +
                "then\n" +
                "System.out.println(PersonToString(p));\n" +
                "end\n" +
                "\n" +
                "rule 'testRule2'\n" +
                "dialect 'mvel'\n" +
                "when\n" +
                "$p : Person()\n" +
                "then\n" +
                "System.out.println(PersonToString($p));\n" +
                "end";

        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
        kbuilder.add( ResourceFactory.newByteArrayResource(rule.getBytes()), ResourceType.DRL );

        if ( kbuilder.hasErrors() ) {
            fail( kbuilder.getErrors().toString() );
        }

        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
        kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
    }

Comment 8 Tomas Schlosser 2012-09-17 14:26:16 UTC
Created attachment 613683 [details]
Error messages

I tried again with this [1] version of BRMS using these steps:
1) imported repository
2) opened testPackage
3) tried to build

All I got is attached exception (including BRMS version for clarity).

[1] http://jawa05.englab.brq.redhat.com/candidate/BRMS-5.3.1-ER1/brms-p-5.3.1.ER1-standalone.zip

Comment 9 Mario Fusco 2012-09-17 15:06:49 UTC
Sorry, but I am really not able to reproduce this issue- I don't know how to proceed about it.

Comment 10 Tomas Schlosser 2012-09-25 11:22:06 UTC
I had a colleague of mine trying the same thing and we got the exactly same behaviour as I did.
Are you sure, you tried importing the repository into BRMS-5.3.1-ER1? I used the standalone version as it works out of the box, could you please try to download and run the same?

Comment 11 Mario Fusco 2012-09-27 12:08:48 UTC
I reproduced the problem, but now it seems a Guvnor issue, so I talked to Toni and assigned this ticket to him.

Comment 12 Toni Rikkola 2012-09-28 13:52:24 UTC
I managed to isolate what Guvnor does in this unit test:

 @Test
    public void testMvelFunctionWithDeclaredTypeArg2() throws IOException, DroolsParserException {

        String function = "function String getFieldValue(Bean bean) {" +
                "   return bean.getField();" +
                "}";
        String declaredFactType = "declare Bean \n" +
                "   field : String \n" +
                "end \n";
        String rule = "rule R2 \n" +
                "dialect 'mvel'\n" +
                "when \n" +
                "   $bean : Bean( ) \n" +
                "then \n" +
                "   System.out.println( getFieldValue($bean) ); \n" +
                "end";

        PackageBuilder packageBuilder = new PackageBuilder();
        packageBuilder.addPackageFromDrl(new StringReader(declaredFactType));
        packageBuilder.addPackageFromDrl(new StringReader(function));
        packageBuilder.addPackageFromDrl(new StringReader(rule));

        for (KnowledgeBuilderError error : packageBuilder.getErrors()) {
            System.out.println("ERROR:");
            System.out.println(error.getMessage());
        }
        assertFalse(packageBuilder.hasErrors());
    }

Currently the test fails to pass. If the dialect for the Rule R2 is removed it works.

There are few solutions: 

#1 We remove the PackageBuilder from Guvnor and replace it with KnowledgeBuilder. This is a not a small task and will take a week or more.

#2 We make PackageBuilder work with how Guvnor is using it. 

Mario is taking a look at #2. Hopefully there is an easy fix.

Comment 13 Toni Rikkola 2012-09-28 16:52:54 UTC
#2 is not easy.

I have an idea that might work, but the problem is that it will change how Guvnor packages are being built. So there is a possibility that the end result will not be 100% the same as before.

Comment 14 Mario Fusco 2012-09-30 16:56:57 UTC
Thank to the test provided by Toni, I've been able to fix this issue in Drools (no need to change Guvnor). Toni also helped me to check that the attached repository export compiles without error now.

Comment 15 Tomas Schlosser 2012-10-08 11:51:15 UTC
In BRMS-5.3.1-ER2 the problem is gone. Thank you


Note You need to log in before you can comment on or make changes to this bug.