[rules-users] how to import function in drl file on guvnor

Stephen Masters stephen.masters at me.com
Wed Sep 5 06:34:53 EDT 2012


Hi Avneesh (guessing your name from your email address),

I'm curious what you're actually trying to do. Especially as you refer to "companyDivision" as a rule and as a function in different parts of your email.

If you intend to apply a function to all objects, is there any reason for it to be a guided rule in Guvnor? As Mike mentions, you could create a free-format DRL "technical rule" exactly as you wrote it below. It's perfectly fine to mix the two up. Some rules suit management by a 'business' person within a guided editor and others suit being hard-coded by a developer.

With the example you provide, it looks like you're trying to clone a fact when it is inserted and call a function using the cloned fact as an argument.

If you have a guided rule or decision table which inserts a fact, and you wish to apply a rule/function to the fact after being processed by the first rule, you can do things like set a flag on that fact or insert a new fact type, which the technical free-form DRL rule matches.

As a very trivial example:
	when
		$company: CompanyBean(!companyDivisionValidated)
	then
		companyDivision($company);

Steve

On 5 Sep 2012, at 10:02, Michael Anstis <michael.anstis at gmail.com> wrote:

> Forwarded to mailing list.
> 
> You would have to consider use of free-format DRL in this scenario.
> 
> ---------- Forwarded message ----------
> From: <avneesh.sisodia at intelegencia.com>
> Date: 4 September 2012 12:33
> Subject: how to import function in drl file on guvnor
> To: michael.anstis at gmail.com
> 
> 
> Hello mantis,
> I am very new in drools and guvnor users. I have a problem during making rules. I want to use my predefined functions in rule execution.
> Suppose I have a rule "companyDivision" and i want to import it into my rule file like this:
> 
> package com.exp.test
> 
> import com.abc.bean.CompanyBean
> import function
>         com.abc.util.Validation.companyDivision;
> 
> rule "CompanyInfo"
>         dialect "mvel"
>         when
>                 CompanyBean( businessType == "ABC" , insuranceProgram == "XYZ" )
>         then
>                 CompanyBean fact0 = new CompanyBean();
>                 fact0.setBusinessType( "ABC" );
>                 fact0.setInsuranceProgram( "XYZ" );
>                 companyDivision(fact0 );
> end
> 
> 
> How I can do this.
> I am doing following steps to c\generate rules::
> 1. creating com.exp.test package
> 2. uploading jar(model) file which included all pojo files of application
> 3. creating "CompanyInfo" rule
> 
> rule file generated by guvnor is like this:::
> 
> package com.exp.test
> 
> import com.abc.bean.CompanyBean
> 
> 
> rule "CompanyInfo"
>         dialect "mvel"
>         when
>                 CompanyBean( businessType == "ABC" , insuranceProgram == "XYZ" )
>         then
>                 CompanyBean fact0 = new CompanyBean();
>                 fact0.setBusinessType( "ABC" );
>                 fact0.setInsuranceProgram( "XYZ" );
>                 insert(fact0 );
> end
> 
> I have only two options there 1. insert and 2. insert logically.
> but on place of insert and insert logically I want to use "companyDivision" function.
> Please guys tell me how it is possible.
> Thanks
> 
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20120905/2e58cd25/attachment.html 


More information about the rules-users mailing list