[jboss-jira] [JBoss JIRA] (DROOLS-5220) Make @watch annotation to also work with oopath
Mario Fusco (Jira)
issues at jboss.org
Fri May 1 11:52:05 EDT 2020
[ https://issues.redhat.com/browse/DROOLS-5220?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Mario Fusco updated DROOLS-5220:
--------------------------------
Sprint: (was: 2020 Week 16-18 (from Apr 13))
> Make @watch annotation to also work with oopath
> ------------------------------------------------
>
> Key: DROOLS-5220
> URL: https://issues.redhat.com/browse/DROOLS-5220
> Project: Drools
> Issue Type: Bug
> Reporter: Mario Fusco
> Assignee: Mario Fusco
> Priority: Major
>
> Property reactivity is currently working on oopath as demostrated by this test case:
> {code}
> @Test
> public void testPropertyReactivityWithOOPath() {
> String str =
> "import " + Person.class.getCanonicalName() + ";" +
> "import " + AdultUnit.class.getCanonicalName() + "\n" +
> "rule Adult @Unit( AdultUnit.class ) when\n" +
> " $p : /persons[name == \"Mario\"]\n" +
> "then\n" +
> " modify($p) { setAge($p.getAge()+1) };\n" +
> "end\n";
> KieContainer kieContainer = getKieContainer( null, str );
> RuleUnitExecutor executor = RuleUnitExecutor.newRuleUnitExecutor( kieContainer );
> Person mario = new Person( "Mario", 45 );
> Person sofia = new Person( "Sofia", 8 );
> DataSource<Person> persons = DataSource.create( mario, sofia );
> AdultUnit unit = new AdultUnit(persons);
> assertEquals(1, executor.run( unit ) );
> assertEquals(46, mario.getAge() );
> }
> {code}
> Conversely what it is not working (it doesn't compile at all) is the use of the @watch annotation like in
> {code}
> @Test
> public void testPropertyReactivityWithOOPathAndWatch() {
> String str =
> "import " + Person.class.getCanonicalName() + ";" +
> "import " + AdultUnit.class.getCanonicalName() + "\n" +
> "rule Adult @Unit( AdultUnit.class ) when\n" +
> " $p : /persons[$age : age, name == \"Mario\"] @watch( !age )\n" +
> "then\n" +
> " modify($p) { setAge($age+1) };\n" +
> "end\n";
> KieContainer kieContainer = getKieContainer( null, str );
> RuleUnitExecutor executor = RuleUnitExecutor.newRuleUnitExecutor( kieContainer );
> Person mario = new Person( "Mario", 45 );
> Person sofia = new Person( "Sofia", 8 );
> DataSource<Person> persons = DataSource.create( mario, sofia );
> AdultUnit unit = new AdultUnit(persons);
> assertEquals(1, executor.run( unit ) );
> assertEquals(46, mario.getAge() );
> }
> {code}
> Of course this can work only on a one-level oopath. It has to be decided what to do (trigger a compile time error?) when trying to use that annotation on a oopath made of 2 or more chunks.
--
This message was sent by Atlassian Jira
(v7.13.8#713008)
More information about the jboss-jira
mailing list