|
Hi there,
I have a rule where I would like human-readable rule to have a comma separated list of enum constants in it, however I can't find a way to get this working. DSLR file: import com.test.Report; import com.test.RulesResult; import com.test.State; rule "Test rule" when the received object - state is NEW, MODIFY then #unimportant end DSL file: [*][when]the received object=result : RulesResult();$stm : Report() [*][when]- state is {stateList}=state in (State.{stateList}) Class Report has a property called state which is an enum of type State which has a number of constants including NEW and MODIFY. When I run this I get: org.drools.RuntimeDroolsException: Exception executing predicate ( state == State.NEW || state == MODIFY) As you can see only the first constant is being qualified with the enum class. Can anyone help me with how to do this properly? Thanks, Derek |
|
Hi,
Unless there is another workaround, I think you would have to do it something like this: [*][when]the received object=result : RulesResult();$stm : Report() [*][keyword]NEW=State.NEW [*][keyword]OLD=State.OLD [*][when]- state is {stateList}=state in ({stateList}) Regards, Frank |
|
In reply to this post by dsykes
Regrettably, this is just a string substitution, not caring what it
is, or what comes before or after. -W On 16/05/2012, dsykes <[hidden email]> wrote: > Hi there, > > I have a rule where I would like human-readable rule to have a comma > separated list of enum constants in it, however I can't find a way to get > this working. > > DSLR file: > > import com.test.Report; > import com.test.RulesResult; > import com.test.State; > > rule "Test rule" > when > the received object > - state is NEW, MODIFY > then > #unimportant > end > > DSL file: > > [*][when]the received object=result : RulesResult();$stm : Report() > [*][when]- state is {stateList}=state in (State.{stateList}) > > Class Report has a property called state which is an enum of type State > which has a number of constants including NEW and MODIFY. > > When I run this I get: > > org.drools.RuntimeDroolsException: Exception executing predicate ( state == > State.NEW || state == MODIFY) > > As you can see only the first constant is being qualified with the enum > class. Can anyone help me with how to do this properly? > > Thanks, > Derek > > -- > View this message in context: > http://drools.46999.n3.nabble.com/use-of-enum-with-in-on-LHS-tp3997081.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > _______________________________________________ > rules-users mailing list > [hidden email] > https://lists.jboss.org/mailman/listinfo/rules-users > rules-users mailing list [hidden email] https://lists.jboss.org/mailman/listinfo/rules-users |
|
In reply to this post by FrankVhh
But take care, this replaces *all* occurrences of the words NEW and OLD.
-W On 16/05/2012, FrankVhh <[hidden email]> wrote: > Hi, > > Unless there is another workaround, I think you would have to do it > something like this: > > [*][when]the received object=result : RulesResult();$stm : Report() > [*][keyword]NEW=State.NEW > [*][keyword]OLD=State.OLD > [*][when]- state is {stateList}=state in ({stateList}) > > Regards, > Frank > > -- > View this message in context: > http://drools.46999.n3.nabble.com/use-of-enum-with-in-on-LHS-tp3997081p3997136.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > _______________________________________________ > rules-users mailing list > [hidden email] > https://lists.jboss.org/mailman/listinfo/rules-users > rules-users mailing list [hidden email] https://lists.jboss.org/mailman/listinfo/rules-users |
|
In reply to this post by FrankVhh
Hey Frank,
It's not perfect but it should serve the purpose and is far preferable to the alternatives I was considering. Thanks very much! Cheers, Derek |
|
In reply to this post by dsykes
Another potentiel trick :
In State enum, add a method to build a State list from a list of string enum State { ... static List<State> buildList(String listAsStr) { // well, don't need to detail that ... // ... but think to keep a cache somewhere to avoid unecessary iterations at each rule's evaluation ... } } and in your DSL : [*][when]- state is {stateList}=state in (State.buildList({stateList})) Don't know if it really works, just an idea that could be better than replacing all NEW/OLD strings ... If ot works, it can even be better to handle weird items list in a big string ... _______________________________________________ rules-users mailing list [hidden email] https://lists.jboss.org/mailman/listinfo/rules-users |
| Powered by Nabble | Edit this page |
