[rules-users] Problem with existing drl and dsl from drools 3

Edson Tirelli tirelli at post.com
Tue Sep 4 13:59:17 EDT 2007


   Paul,

   My advice for you is rename your rules file from .drl to .dslr. This way,
the IDE plugin will correctly open it with the DSLR editor and you have a
"tab" in the lower part of the editor where you can see the DRL preview.
Looking at the preview, it will be easy for you to see the problems.
   Also, seems you are using a lot of top-level eval(), and that is bad. In
4.0 we have increased the expressiveness of the language and you can avoid
most of them now. I suggest you update your mappings for such syntax.

   []s
   Edson

2007/9/4, Paul Smith <paul.t.smith at gmail.com>:
>
> Forgive me if this one comes through a second time but I seem to be having
> a few difficulties getting my mails to go through.
>
> Hi Guys,
>
> I've decided to bite the bullet and try and move up to 4.01 but I'm having
> trouble getting the rules to compile. I have the following drl
>
> /*******************
> Code type rules
> ********************/
> package au.com.codeprotechnology.online.ejb3.logic.common
>
> import au.com.codeprotechnology.online.bi.exception.ValidationError
> import
> au.com.codeprotechnology.online.ejb3.logic.constants.CodeTypeConstants
> import au.com.codeprotechnology.online.persistence.ejb.core.CodeType
>
> expander common.dsl
>
> rule "Code type is mandatory"
>
>     when
>         The code types type is null or empty
>     then
>         Send the message that the code types type is mandatory
> end
>
> rule "Long name is mandatory"
>
>     when
>         The code types long name is null or empty
>     then
>         Send the message that the code types long name is mandatory
>
> end
>
> rule "Short name is mandatory"
>
>     when
>         The code types short name is null or empty
>     then
>         Send the message that the code types short name is mandatory
>
> end
>
> rule "Short name too long"
>
>     when
>         The short name for the code type is too long
>     then
>         Send the message that the code types short name is too long
>
> end
>
> rule "Sort order is mandatory"
>
>     when
>         The code types sort order is null or zero
>     then
>         Send the message that the code types sort order is mandatory
>
> end
>
>
> With the corresponding dsl
>
> #Common domain specific language.
> [when]The code types type=$obj : CodeType(val : codeType)
> [when]The code types long name=$obj : CodeType(val : longName)
> [when]The code types short name=$obj : CodeType(val : shortName)
> [when]The short name for the code type is too long=$obj : CodeType(val :
> shortName -> (val != null && val.trim().length() >
> CodeTypeConstants.MAX_SHORT_NAME_LENGTH))
> [when]The code types sort order=$obj : CodeType(val : sortOrder)
> [when]The documentation text=$obj : Documentation(val : documentationText)
> [when]The documentation type is null=$obj : Documentation(val : type ->
> (val == null))
> [when]is null or empty=eval(val == null || val.trim ().length() == 0);
> [when]is null or zero=eval(val == null || val.longValue() == 0);
> [when]is not null=eval($obj != null);
> [when]is not numeric=eval(!isNumeric(val));
> [when]is not a valid expiry date=eval(!isValidExpiry(val));
> [when]length is greater than {len}=eval(val.length() > {len});
> [when]length is less than {len}=eval(val.length() < {len});
> [then]Print the message '{msg}'=System.out.println("{msg}");
> [then]Send the message that the code types type is
> mandatory=$obj.addValidationError(new ValidationError(
> CodeTypeConstants.MSG_KEY_CODE_TYPE_MANDATORY,
> CodeTypeConstants.MSG_CODE_TYPE_MANDATORY));
> [then]Send the message that the code types long name is
> mandatory=$obj.addValidationError(new ValidationError(
> CodeTypeConstants.MSG_KEY_LONG_NAME_MANDATORY,
> CodeTypeConstants.MSG_LONG_NAME_MANDATORY));
> [then]Send the message that the code types short name is
> mandatory=$obj.addValidationError(new ValidationError(
> CodeTypeConstants.MSG_KEY_SHORT_NAME_MANDATORY ,
> CodeTypeConstants.MSG_SHORT_NAME_MANDATORY));
> [then]Send the message that the code types short name is too
> long=$obj.addValidationError(new ValidationError(
> CodeTypeConstants.MSG_KEY_SHORT_NAME_TOO_LONG,
> CodeTypeConstants.MSG_SHORT_NAME_TOO_LONG ));
> [then]Send the message that the code types sort order is
> mandatory=$obj.addValidationError(new ValidationError(
> CodeTypeConstants.MSG_KEY_SORT_ORDER_MANDATORY,
> CodeTypeConstants.MSG_SORT_ORDER_MANDATORY));
> [then]Send the message that the documentation text is
> mandatory=$obj.addValidationError(new ValidationError(
> DocumentationConstants.MSG_KEY_TEXT_MANDATORY,
> DocumentationConstants.MSG_TEXT_MANDATORY));
> [then]Send the message that the documentation type is
> mandatory=$obj.addValidationError(new ValidationError(
> DocumentationConstants.MSG_KEY_TYPE_MANDATORY ,
> DocumentationConstants.MSG_TYPE_MANDATORY));
>
> But I keep getting the following errors when trying to build the package
>
> unknown:14:36 Unexpected token 'val'
> unknown:14:60 Unexpected token ')'
> unknown:14:61 Unexpected token '.'
> unknown:14:71 mismatched token: [@106,457:458='==',<75>,14:71]; expecting
> type THEN
> unknown:23:36 Unexpected token 'val'
> unknown:23:60 Unexpected token ')'
> unknown:23:61 Unexpected token '.'
> unknown:23:71 mismatched token: [@171,723:724='==',<75>,23:71]; expecting
> type THEN
> unknown:33:37 Unexpected token 'val'
> unknown:33:61 Unexpected token ')'
> unknown:33:62 Unexpected token '.'
> unknown:33:72 mismatched token: [@236,995:996='==',<75>,33:72]; expecting
> type THEN
> unknown:53:37 Unexpected token 'val'
> unknown:53:66 Unexpected token ')'
> unknown:53:68 Unexpected token '=='
>
> These are the errors from PackageBuilder. Used to work fine with 3 and I
> can't see any drastic differences between this and your examples in the
> documentation.
>
>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>


-- 
  Edson Tirelli
  Software Engineer - JBoss Rules Core Developer
  Office: +55 11 3529-6000
  Mobile: +55 11 9287-5646
  JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070904/534ba396/attachment.html 


More information about the rules-users mailing list