Re: [rules-users] Getting validation errors

2007-03-13 Thread Marcus Ilgner

Hi Mike,

On 3/13/07, Mike Dougherty [EMAIL PROTECTED] wrote:

Hello,

I am using JBoss Rules to validate entities before storing them in the
database. I therefore need a way to inform the calling code that the entity
which was asserted failed verification. The only way I have been able to
find that works is to assert an exception from within the rule file. For
example:

rule user is 'miked'
  when
identity : Identity( username == miked )
  then
assertLogical(new IllegalStateException(Entity failed verification.));
end

Then in the Java that fires the rule, I have:

workingMemory.fireAllRules();
for(Iterator i = workingMemory.getObjects(Exception.class).iterator();
i.hasNext(); ) {
System.out.println(Exception: +i.next());
}

Which seems to be working OK. But I wanted to see if maybe there is a better
way to accomplish what I need.

Thanks for you help.
Mike



My approach would be to derive all objects that will be validated from
a superclass, e.g. ValidatedObject, which provides a boolean property
validated.
Then you can set this property in your rules and later on display
warning/error messages for those objects that failed validation.

Best regards
Marcus
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Getting validation errors

2007-03-13 Thread Edson Tirelli

  Mike

  What I usually see is that you have a fact or attribute where you can 
set the result of your validation:


rule user is miked
when
   $id : Identity( usename == miked )
   $p : Permission( id == $id )
then
   $p.deny();
end

  In your application you asserted the Permission object, so you have 
it's handle and just check the result:


if( permission.isDenied() ) {
   // do something
}

  Another way would be to use call back, setting the callback instance 
as a global:


global org.sample.PermissionManager permission;

rule user is miked
when
   $id : Identity( usename == miked )
then
   permission.deny( $id );
end

  []s
  Edson

Mike Dougherty wrote:


Hello,

I am using JBoss Rules to validate entities before storing them in the 
database. I therefore need a way to inform the calling code that the 
entity which was asserted failed verification. The only way I have 
been able to find that works is to assert an exception from within the 
rule file. For example:


rule user is 'miked'
  when
identity : Identity( username == miked )
  then
assertLogical(new IllegalStateException(Entity failed 
verification.));

end

Then in the Java that fires the rule, I have:

workingMemory.fireAllRules();
for(Iterator i = workingMemory.getObjects(Exception.class).iterator(); 
i.hasNext(); ) {

System.out.println(Exception: +i.next());
}

Which seems to be working OK. But I wanted to see if maybe there is a 
better way to accomplish what I need.


Thanks for you help.
Mike


--
*
Mike Dougherty
[EMAIL PROTECTED] mailto:[EMAIL PROTECTED]
858.232.3635

http://www.google.com/talk/
*





___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
 




--
Edson Tirelli
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3124-6000
Mobile: +55 11 9218-4151
JBoss, a division of Red Hat @ www.jboss.com


___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users