Re: [rules-users] How to write Drools rule basing on a changed property?
Yes, that is a Map base approach I am thinking. Now more questions: global Map oldObjectContext WHEN $person: Person() eval(((Person)oldObjectContext[$name]).jobTitle == $person.name) THEN Q1: without eval, the compiler will report error Q2: without type cast, the compiler will also report error Any suggestion how we can make it easier? Thanks... -- View this message in context: http://drools.46999.n3.nabble.com/How-to-write-Drools-rule-basing-on-a-changed-property-tp3492926p3493956.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 write Drools rule basing on a changed property?
It seems that this is more of a technical problem on the Java side: how to register the fact that a certain property of an element has changed. You'll need somthing like a "clone" method. The old version of Person need and should not remain in Working Memory, but a simple wrapper fact referencing to the cloned Person object (not a fact!) would be required. Then you might do Person( $adress: adress ) Wrapper( $person: person, eval( $adress != $person.getAddress() ) ) -W On 9 November 2011 09:57, kapokfly wrote: > Thanks, when I am saying person address is changed, our app only concerns > about its initial value and its final value, any change in the middle, we > don't care. > > Examples: > person.address.address1 starts with 'my addr1' > > later a couple of changes were made, say its final value is 'my addr1', > we treat it as no change and no middle rules should be fired. > > Even for the 2 objects approach, how I can write the rules to get the old > and new object matched correctly? > > They are both Person instances without any identity to tell which one is > the > old which one is the new one, unless I enable some kinds of map/or list in > the rule and one structure to host only new objects and the other one hosts > only the old values? > > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/How-to-write-Drools-rule-basing-on-a-changed-property-tp3492926p3492979.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 write Drools rule basing on a changed property?
Thanks, when I am saying person address is changed, our app only concerns about its initial value and its final value, any change in the middle, we don't care. Examples: person.address.address1 starts with 'my addr1' later a couple of changes were made, say its final value is 'my addr1', we treat it as no change and no middle rules should be fired. Even for the 2 objects approach, how I can write the rules to get the old and new object matched correctly? They are both Person instances without any identity to tell which one is the old which one is the new one, unless I enable some kinds of map/or list in the rule and one structure to host only new objects and the other one hosts only the old values? -- View this message in context: http://drools.46999.n3.nabble.com/How-to-write-Drools-rule-basing-on-a-changed-property-tp3492926p3492979.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 write Drools rule basing on a changed property?
The agent that is responsible for the address change must take care to provide information about what it does. This could be done by creating an UpdateEvent fact referencing the Person fact and indicating the attribute (address). Or a listener reacts to the change and insert the UpdateEvent fact. Or you follow your "ideally-we-should-have-2" idea. -W On 9 November 2011 09:29, kapokfly wrote: > Requirement: > > 1) > Rule > When > Person.address.address1 is changed > THEN > > 2) Ideally we should have 2 objects, 1 for the old person instance, the > other for the new person instance so contextually the LHS equals to > oldPerson.address.address1 != newPerson.address.address1. > > A properties change listener might not be the best solution as it might > span > multiple calls and the property change could be done on the web layer which > is out of the JBoss Drools knowledge session. > > Ivan > > -- > View this message in context: > http://drools.46999.n3.nabble.com/How-to-write-Drools-rule-basing-on-a-changed-property-tp3492926p3492926.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
[rules-users] How to write Drools rule basing on a changed property?
Requirement: 1) Rule When Person.address.address1 is changed THEN 2) Ideally we should have 2 objects, 1 for the old person instance, the other for the new person instance so contextually the LHS equals to oldPerson.address.address1 != newPerson.address.address1. A properties change listener might not be the best solution as it might span multiple calls and the property change could be done on the web layer which is out of the JBoss Drools knowledge session. Ivan -- View this message in context: http://drools.46999.n3.nabble.com/How-to-write-Drools-rule-basing-on-a-changed-property-tp3492926p3492926.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