Re: [rules-users] How to use type-safe enums in rule condition
Just curiosity. On 13/11/2013, Steven Williams stevearoo...@gmail.com wrote: I use something like the following in rules to good effect: Country( this == Country.USA ) Granted, you can add any number of attributes to an enum so that it's just another way of writing a static set of bean objects. But is there a good effect to be had from a pattern that merely ascertains the presence of an enum instance in the Working Memory? Other than this, a pattern like City( country == Country.USA ) doesn't require the insertion of the Country enums. Cheers Wolfgang ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] How to use type-safe enums in rule condition
We use drools for validation rules in our application. Some of these rules are dependent on which CRUD operation is being performed at the time, so as part of our validation aspect we insert a CrudMode enum with the current action (by annotating the advised method). e.g. @Validate(validators = BusinessRulesValidator.class, mode = CREATE) public void create(@DTO SomeDTO incomingDto) In our rules we can then go: CrudMode(this == CrudMode.CREATE) The second way we use it (and this one I don't like so much) is that our validation aspect runs both before and after a method (PRE and POST). We use an agenda-group to to indicate which phase a rule should be included which works fine, however we were finding that some conditions were relatively expensive which had performance implications. Our solution was to also include a ValidationPhase enum as a fact and use that to short-circuit the rules. I reckon there is probably a better way to achieve this however we didn't spend a lot of time thinking about it. cheers Steve --- Steven Williams On Thu, Nov 14, 2013 at 12:40 AM, Wolfgang Laun wolfgang.l...@gmail.comwrote: Just curiosity. On 13/11/2013, Steven Williams stevearoo...@gmail.com wrote: I use something like the following in rules to good effect: Country( this == Country.USA ) Granted, you can add any number of attributes to an enum so that it's just another way of writing a static set of bean objects. But is there a good effect to be had from a pattern that merely ascertains the presence of an enum instance in the Working Memory? Other than this, a pattern like City( country == Country.USA ) doesn't require the insertion of the Country enums. Cheers Wolfgang ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] How to use type-safe enums in rule condition
Hello, I would like to use type-safe enums in my rules. At the moment I have situation like this: public class Country { private String name; // getter/setters } rule Country when Country ( name == USA ) then DO SOMETHING end I would like to have something like this: public enum Country { USA () // list of all countries in the world } and in the rule I would like to do this: rule Country when Country ( name == Country.USA ) then DO SOMETHING end Is that possible? Thanks in advance for your help. -- View this message in context: http://drools.46999.n3.nabble.com/How-to-use-type-safe-enums-in-rule-condition-tp4026739.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] How to use type-safe enums in rule condition
Using the same name for a fact class Country and an enum Country will most certainly not be possible unless you use full class names for disambiguation. And, of course, the name property of fact class Country would have to have the enum type. -W On 12/11/2013, Stephen Masters stephen.mast...@me.com wrote: That rule would work if you added a “name” property to Country. As a general tip on working with countries, always work with their ISO codes, not their names. http://en.wikipedia.org/wiki/ISO_3166-1 … ideally the 2-char codes, which are much more commonly used than the 3-char codes. Feel free to steal this: https://github.com/gratiartis/sctrcd-payment-validation-web/blob/master/src/main/java/com/sctrcd/payments/enums/CountryEnum.java … which sets up all countries with ISO codes and full-text names as enums. Or at least all countries which were included in the ISO spec at the time of writing. Grab it while you can - I’m in the middle of refactoring it into a JPA entity. :) Steve On 12 Nov 2013, at 10:20, droolster quant.co...@gmail.com wrote: Hello, I would like to use type-safe enums in my rules. At the moment I have situation like this: public class Country { private String name; // getter/setters } rule Country when Country ( name == USA ) then DO SOMETHING end I would like to have something like this: public enum Country { USA () // list of all countries in the world } and in the rule I would like to do this: rule Country when Country ( name == Country.USA ) then DO SOMETHING end Is that possible? Thanks in advance for your help. -- View this message in context: http://drools.46999.n3.nabble.com/How-to-use-type-safe-enums-in-rule-condition-tp4026739.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] How to use type-safe enums in rule condition
Thanks Steve for the advice and code! Awesome. -- View this message in context: http://drools.46999.n3.nabble.com/How-to-use-type-safe-enums-in-rule-condition-tp4026739p4026745.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] How to use type-safe enums in rule condition
I use something like the following in rules to good effect: Country( this == Country.USA ) --- Steven Williams On Wed, Nov 13, 2013 at 12:20 AM, droolster quant.co...@gmail.com wrote: Thanks Steve for the advice and code! Awesome. -- View this message in context: http://drools.46999.n3.nabble.com/How-to-use-type-safe-enums-in-rule-condition-tp4026739p4026745.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users