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


[rules-users] to retrieve objects from a list using context

2007-03-13 Thread vanitha

hi
i have to retrieve all the objects from a list. And i should also be able to
use a list inside another list.
can i do this using context. is there any other way possible?
-- 
View this message in context: 
http://www.nabble.com/to-retrieve-objects-from-a-list-using-%22context%22-tf3397082.html#a9458384
Sent from the drools - user 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] [rule-users] OR with multiple binding in LHS

2007-03-13 Thread Francesco Campagnola

Hi,

I'd like to write a rule that contains an OR condition in the LHS, to match
the presence in the working memory of an object with particular values of a
specific field.  In the rest of LHS, i need to bind other values of the
specific object matched. Is there a particular sintax to use for the
binding?

For example:

rule orCondition
   when
   myObj : (MyObject(field1 == a) or MyObject(field1 == b))
//correct column

   field2: myObj.getField2 ()// how to correctly get
   field3: myObj.getField3()// those values?
   then
   System.out.println(fields = + field2 + field3);

Thanks in advance, FC.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] trouble with 3.1.0-M1 docs?

2007-03-13 Thread Justine Hlista

I am having trouble reading the 3.1.0-M1 docs/html files in either internet
explorer or firefox.
All I see under the chapter headings are a bunch of empty xi:include
elements.

Is there a plug in needed? Any ideas?

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


[rules-users] dynamically generated classes, drools classloader, and jsr-94

2007-03-13 Thread Martin Schoch
The application I'm working on will use facts which are dynamically
generated classes.  After reading
http://jira.jboss.com/jira/browse/JBRULES-557 I figured out the trick to
get this working was to pass the ClassLoader responsible for the dynamic
classes to drools.  So I set things up something like:

  PackageBuilderConfiguration pbc = new PackageBuilderConfiguration();
  pbc.setCompiler(PackageBuilderConfiguration.JANINO);
 
pbc.setClassLoader(instanceOfDynamicallyGeneratedClass.getClass().getCla
ssLoader());
  PackageBuilder builder = new PackageBuilder(pbc);

Using this approach I am able to execute rules which interact with the
properties of the dynamically generated classes.  The problem I've run
into is that I'd really like to work with the JSR-94 API.  I have two
questions:

1. Is the code I referenced above using the correct approach?  Or am I
already headed down the wrong path?
2. Would passing additional configuration details into the properties
argument of the call
ruleExecutionSetProvider.createRuleExecutionSet(drlStream, properties)
be advisable?  I have created a proof of concept to test this and
included a patch.  Using this approach the application code looks
something like this:

  PackageBuilderConfiguration pbc = new PackageBuilderConfiguration();
  pbc.setCompiler(PackageBuilderConfiguration.JANINO);
 
pbc.setClassLoader(instanceOfDynamicallyGeneratedClass.getClass().getCla
ssLoader());

  Map localProperties = new HashMap();
  localProperties.put(packageBuilderConfiguration, pbc);

  RuleExecutionSet ruleExecutionSet =
ruleExecutionSetProvider.createRuleExecutionSet(drlStream,
localProperties);

Obviously this introduces a JBossRules dependency into my application
code, but I am otherwise able to stick to the JSR-94 APIs.

I have attached a patch to support this new property and welcome
comments on this solution.

Thanks,

Marty Schoch
[EMAIL PROTECTED]



pbc-jsr94.patch
Description: pbc-jsr94.patch
___
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


Re: [rules-users] OR with multiple binding in LHS

2007-03-13 Thread Edson Tirelli


   Francesco,

   You need to be careful when doing that, if you are using 3.0.x version.
   First thing is that both sides of your or must be perfectly 
balanced, i.e., the same classes in the same order. I didn't tried 
that, but I think it works if you simply declare your binding once:


rule orCondition
   when
   myObj : (MyObject(field1 == a, $field2 : field2, $field3 : 
field3) or MyObject(field1 == b))//correct column

   AnotherPattern( attr2 == $field2, attr3 == $field3 )
   then
   System.out.println(fields = + field2 + field3);
end

   This is a workaround for the 3.0.x versions.Try it and let me know plz.

   In 3.1M1 and later, all this is fixed and the correct is to declare 
the variable in all logical branches:


rule orCondition
   when
   myObj : (MyObject(field1 == a, $field2 : field2, $field3 : 
field3) or MyObject(field1 == b, $field2 : field2, $field3 : 
field3))//correct column

   AnotherPattern( attr2 == $field2, attr3 == $field3 )
   then
   System.out.println(fields = + field2 + field3);
end

  []s
  Edson


Francesco Campagnola wrote:


Hi,

I'd like to write a rule that contains an OR condition in the LHS, to 
match the presence in the working memory of an object with particular 
values of a specific field.  In the rest of LHS, i need to bind other 
values of the specific object matched. Is there a particular sintax to 
use for the binding?


For example:

rule orCondition
when
myObj : (MyObject(field1 == a) or MyObject(field1 == 
b))//correct column
   
field2: myObj.getField2 ()// how to correctly get

field3: myObj.getField3()// those values?
then
System.out.println(fields = + field2 + field3);

Thanks in advance, FC.



___
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


Re: [rules-users] Shadow fact problem?

2007-03-13 Thread Edson Tirelli


  Mike,

  Yes, that is a shadow fact unwanted side-effect (nice name for a 
bug hm? :) ), but I remember fixing something similar as part of another 
ticket I was working on. Is it possible for you to verify if the problem 
is happening in trunk?

  If it is still hapenning, let me know and I will fix it.

  Thank you,
  Edson

Anstis, Michael (M.) wrote:


Hi,

I am running 3.1-M1 and have (by way of example) two simple rules; A 
and B as follows:-


  *rule* A
  *when*
  $a1 : Attribute ( name == Constants.ATTRIBUTES_A, $pa :
  number )
  $a2 : Attribute ( name == Constants.ATTRIBUTES_B, $nc :
  number )
  $p : Process ( attributesList* contains* $a1,
  attributesList* contains* $a2 )
  *then*
 * double* txy = doSomeMaths($pa, $nc, $p);
  Attribute a =* new* Attribute(Constants.ATTRIBUTES_C, txy);
  $p.addAttribute(a);
 * assertLogical*(a);
 * modify*($p);
  System.out.println(Rule 'A' fired);
  *end*
 
  *rule* B

  *when*
  $a1 : Attribute ( name == Constants.ATTRIBUTES_C, $txy :
  number)
  $p : Process( attributesList* contains* $a1 )
  // -- Line causing rule not to activate


  *then*
 * double* m = doSomeMoreMaths($txy, $p);
  System.out.println(Rule 'B' fired);
  *end*

Process exposes an ArrayList of Attribute objects (each having a 
name\value pair).


When the content of the ArrayList held by Process is added to (Rule 
'A') the next rule (Rule 'B') is not being activated.


Can anybody provide any insight into how best a workaround can be 
engineered?


With kind regards,

Mike



___
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


Re: [rules-users] can't refer to the bound column fields from the LHS?..

2007-03-13 Thread Edson Tirelli


Vlad,

Not yet. We may eventually support that in the future through MVEL 
integration, but right now you can't do it. You can though use a return 
value predicate for that though:


Rule xxx

When

$r1: MyRecord (field1 == “xxx”)

$r2: MyRecord2 (field1 == ( $r1.getField1() ))

Then

System.out.println(“found match: “+$r2+”, “+$r1);

End


I know it was just an illustration example, but always good to 
reinforce: for the above case, the best would be to bind the attribute 
itself, not the fact:


Rule xxx

When

$r1: MyRecord ( $f1 : field1 == “xxx”)

$r2: MyRecord2 ( field1 == $f1 )

Then

System.out.println(“found match: “+$r2+”, “+$r1);

End


[]s
Edson


Olenin, Vladimir (MOH) wrote:


Hi,

I always assumed that one can refer to the properties of the bound 
column in the LHS like this:


MyRecord {

String field1, field2;

}

MyRecord2 {

String field1, field3;

}

Rule xxx

When

$r1: MyRecord (field1 == “xxx”)

$r2: MyRecord2 (field1 == $r1.field1)

Then

System.out.println(“found match: “+$r2+”, “+$r1);

End

Compiler does complain on ‘$r1’ usage in the LHS (as part of 
constraint for MyRecord2 fact), but works OK if used only in RHS. The 
error I’m getting is: “Unable to find class $r1”. “$r1.getField1()” 
doesn’t work either (getting “mismatched token, expecting ‘)’ “ error).


Thanks,

Vlad



___
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


Re: [rules-users] trouble with 3.1.0-M1 docs?

2007-03-13 Thread Edson Tirelli


  Justine,

  Documents are not yet updated to 3.1.
  Although, to read them, you need a docbook reader/editor... for example:

http://www.xmlmind.com/xmleditor/

  []s
  Edson

Justine Hlista wrote:

I am having trouble reading the 3.1.0-M1 docs/html files in either 
internet explorer or firefox.
All I see under the chapter headings are a bunch of empty xi:include 
elements.


Is there a plug in needed? Any ideas?

Thanks,
Justine



___
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


Re: [rules-users] dynamically generated classes, drools classloader, and jsr-94

2007-03-13 Thread Edson Tirelli


  Martin,

  You may find some useful information here:

http://markproctor.blogspot.com/2006/12/dynamically-generated-class-beans-as.html

  Thank you for the patch. I will take a look.

   []s
   Edson


Martin Schoch wrote:


The application I'm working on will use facts which are dynamically
generated classes.  After reading
http://jira.jboss.com/jira/browse/JBRULES-557 I figured out the trick to
get this working was to pass the ClassLoader responsible for the dynamic
classes to drools.  So I set things up something like:

 PackageBuilderConfiguration pbc = new PackageBuilderConfiguration();
 pbc.setCompiler(PackageBuilderConfiguration.JANINO);

pbc.setClassLoader(instanceOfDynamicallyGeneratedClass.getClass().getCla
ssLoader());
 PackageBuilder builder = new PackageBuilder(pbc);

Using this approach I am able to execute rules which interact with the
properties of the dynamically generated classes.  The problem I've run
into is that I'd really like to work with the JSR-94 API.  I have two
questions:

1. Is the code I referenced above using the correct approach?  Or am I
already headed down the wrong path?
2. Would passing additional configuration details into the properties
argument of the call
ruleExecutionSetProvider.createRuleExecutionSet(drlStream, properties)
be advisable?  I have created a proof of concept to test this and
included a patch.  Using this approach the application code looks
something like this:

 PackageBuilderConfiguration pbc = new PackageBuilderConfiguration();
 pbc.setCompiler(PackageBuilderConfiguration.JANINO);

pbc.setClassLoader(instanceOfDynamicallyGeneratedClass.getClass().getCla
ssLoader());

 Map localProperties = new HashMap();
 localProperties.put(packageBuilderConfiguration, pbc);

 RuleExecutionSet ruleExecutionSet =
ruleExecutionSetProvider.createRuleExecutionSet(drlStream,
localProperties);

Obviously this introduces a JBossRules dependency into my application
code, but I am otherwise able to stick to the JSR-94 APIs.

I have attached a patch to support this new property and welcome
comments on this solution.

Thanks,

Marty Schoch
[EMAIL PROTECTED]

 




___
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


Re: [rules-users] SQL inside rules(new to rules )

2007-03-13 Thread Edson Tirelli


  Yes, you can. In RHS just call the helper classes and you are done. 
In LHS you need the from CE (available only in 3.1M1 and later). See 
previous messages to the list for additional info.


  []s
  Edson

Arsene Costin wrote:

Can I use java helper classes (that connect to a database and retrive 
data) inside LHS and RHS in order to achive some business requirements.



Finding fabulous fares is fun.
Let Yahoo! FareChase search your favorite travel sites 
http://farechase.yahoo.com/promo-generic-14795097;_ylc=X3oDMTFtNW45amVpBF9TAzk3NDA3NTg5BF9zAzI3MTk0ODEEcG9zAzEEc2VjA21haWx0YWdsaW5lBHNsawNxMS0wNw-- 
to find flight and hotel bargains.




___
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


[rules-users] Error creating shadow fact for object

2007-03-13 Thread dileep_sivaraman

I am using drools 3.1 MI

I have got a class Message which contains an inner class ProcessRuleDTO
When I try to assert the inner class object directly into memory it gives a
shadow fact error.

The Code Snippet :

ProcessRuleDTO processRuleDTO=message.new ProcessRuleDTO();
workingMemory.assertObject( processRuleDTO );

Error :

org.drools.RuntimeDroolsException: Error creating shadow fact for object:
[EMAIL PROTECTED]
at org.drools.base.ClassObjectType.getShadow(ClassObjectType.java:125)
at 
org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:148)
at org.drools.reteoo.Rete.assertObject(Rete.java:121)
at 
org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:196)
at
org.drools.reteoo.ReteooWorkingMemory.doAssertObject(ReteooWorkingMemory.java:68)
at
org.drools.common.AbstractWorkingMemory.assertObject(AbstractWorkingMemory.java:724)
at
org.drools.common.AbstractWorkingMemory.assertObject(AbstractWorkingMemory.java:543)
at Example.HelloWorldExample.main(HelloWorldExample.java:57)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at org.drools.base.ClassObjectType.getShadow(ClassObjectType.java:123)
... 7 more
Caused by: java.lang.NoSuchMethodError:
com.components.Message$ProcessRuleDTO: method init()V not found
at com.components.Message$ProcessRuleDTOShadowProxy.init(Unknown 
Source)
... 12 more

Can we or not assert an inner class directly in drools?

Thanks
-- 
View this message in context: 
http://www.nabble.com/Error-creating-shadow-fact-for-object-tf3400224.html#a9468586
Sent from the drools - user 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] Problems with rule builder errors

2007-03-13 Thread Dirk Bergstrom
I'm using trunk (revision 10170), and I'm getting an exception when trying to
read errors after calling PackageBuilder.addPackageFromDrl(String, Reader).  The
getErrors() method spits out this exception:

java.lang.ArrayStoreException
at java.lang.System.arraycopy(Native Method)
at java.util.ArrayList.toArray(ArrayList.java:304)
at org.drools.compiler.PackageBuilder.getErrors(PackageBuilder.java:380)

(The docs for toArray say that exception is thrown if one of the members of the
List is the wrong class for the supplied array.)

If I instead call printErrors, I get something more useful:

java.lang.ClassCastException: org.drools.lang.ExpanderException
at 
org.drools.compiler.PackageBuilder.printErrors(PackageBuilder.java:390)

It looks like someone is putting the wrong kind of exception in the error list.

This may be related to some bugs in DSL handling.  I had to comment out all the
blank lines in my DSL file to get it to suppress some other errors, and if I
switch to PackageBuilder.addPackageFromDrl(String), the problem goes away.

-- 
Dirk Bergstrom   [EMAIL PROTECTED]
_
Juniper Networks Inc.,  Computer Geek
Tel: 408.745.3182   Fax: 408.745.8905
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Problem with shadow facts in trunk

2007-03-13 Thread Dirk Bergstrom
I'm using trunk (revision 10170), and I'm getting an error while asserting
objects.  It looks to be reproducible, in that it only happens with particular
instances of one class.  But since it's in a method of a generated class (the
shadow proxy), I don't have a clue how to debug it.  I had a look at the
buildHashCode method in ShadowProxyFactory, but the magic was too thick for me.
 If it helps, the class being shadowed has boolean, float and long attributes,
but no char, short, int, double or list.

Here's the stacktrace:

Exception in thread RLIs Processor java.lang.IncompatibleClassChangeError
at net.juniper.dash.data.RLIRecordShadowProxy.hashCode(Unknown Source)
at java.util.HashMap.put(HashMap.java:418)
at java.util.HashSet.add(HashSet.java:194)
at org.drools.reteoo.CollectNode.assertTuple(CollectNode.java:135)
at org.drools.reteoo.CollectNode.assertObject(CollectNode.java:212)
at
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:20)
at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:145)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:304)
at 
org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:176)
at org.drools.reteoo.Rete.assertObject(Rete.java:121)
at 
org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:196)
at
org.drools.reteoo.ReteooWorkingMemory.doAssertObject(ReteooWorkingMemory.java:68)
at
org.drools.common.AbstractWorkingMemory.assertObject(AbstractWorkingMemory.java:729)
at
org.drools.common.AbstractWorkingMemory.assertObject(AbstractWorkingMemory.java:548)

-- 
Dirk Bergstrom   [EMAIL PROTECTED]
_
Juniper Networks Inc.,  Computer Geek
Tel: 408.745.3182   Fax: 408.745.8905

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