RE: [rules-users] HelloWorld Example for drools4MR3

2007-07-12 Thread Anstis, Michael \(M.\)
Hi Joshua, 

You *should* be able to change assertObject(...) to simply
insert(...).

I am sure examples will be updated at some stage (I know the JBoss
Drools team always welcome community support).

With kind regards,

Mike

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Joshua Jackson
Sent: 12 July 2007 02:19
To: Rules Users List
Subject: Re: [rules-users] HelloWorld Example for drools4MR3

Hi Mike,

Thanks for the reply. Shall I recall this as an not-yet-updated
examples? So what should I use for those example to change
assertObject?

Thanks in advance

On 7/11/07, Anstis, Michael (M.) [EMAIL PROTECTED] wrote:
 Hi Joshua,

 If I recall correctly; assertObject(), modifyObject() and
 retractObject() became insert(), update() and remove()? in 4.0.

 With kind regards,

 Mike


-- 
It's not just about coding, it's a matter of fulfilling you core being

YM!: thejavafreak
Blog: http://joshuajava.wordpress.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] Rule compilation errors under heavy load

2007-07-12 Thread Dean Jones

Hello folks,

I'm experiencing some odd behaviour from Drools (or maybe the Eclipse
compiler) when load-testing my application, and wondered if anyone
else had experienced the same issue. I have a web service which, for
every request, loads in rules from the database, creates a
org.drools.lang.descr.PackageDescr and then uses this to create a
org.drools.rule.Package. The code is something like:

PackageBuilderConfiguration conf = new PackageBuilderConfiguration();
PackageBuilder builder = new PackageBuilder(conf);
PackageDescr packageDescr = new PackageDescr(MyRulebaseName);
populatePackageDescr(packageDescr);
builder.addPackage(packageDescr);
Package _package = builder.getPackage();
return _package;

This code gets run every request. The populatePackageDescr() method
adds imports, globals, functions and rules to the PackageDescr. My
load-test just repeatedly calls the same rulebase, so
populatePackageDescr() will be doing exactly the same thing for each
request. Occasionally (normally once or twice per 100 requests) I get
a rule compilation error (the exact error varies from request to
request) whereas most of the time the same rule compiles fine. This
makes me suspect a thread-safety issue in either the PackageBuilder or
the compiler (I'm using the eclipse compiler).

Initially, I suspected a problem in my
populatePackageDescr(packageDescr) method, but I think I've ruled this
out. There is nothing stateful in this method, and I've tried dumping
the XML representation of the packageDescr immediately after
populating it; it looks fine to me and is exactly the same whether
compilation succeeds or and fails.

Has anyone done this kind of thing successfully under a heavy load?

Thanks,

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


[rules-users] Can't execute rules twice with a second classloader

2007-07-12 Thread Aaron Dixon

I am trying to sequentially perform two rules executions using two
different classloaders in the same VM. I create completely new state
for each execution, yet I still fail on the second execution. I
believe this has to do with some internal static cached state that
JBossRules is maintaining. A snippet of the code and exeception are
shown in this email.

   public void demo() throws Exception {
   // Save original classloader
   ClassLoader original = Thread.currentThread().getContextClassLoader();

   // Create Classloader 1 with parent of original
   FooClassLoader loader1 = new FooClassLoader(original);
   Thread.currentThread().setContextClassLoader(loader1);
   testRules();

   // Success so far...

   // Create Classloader 2 with parent of original
   FooClassLoader loader2 = new FooClassLoader(original);
   Thread.currentThread().setContextClassLoader(loader2);
   testRules();

   // Never make it to here.

   // Restore
   Thread.currentThread().setContextClassLoader(original);
   }

   private void testRules() throws Exception {
   PackageBuilder builder = new PackageBuilder();
   Package pkg = buildPackage(new String[] { Foo.drl }, builder);
   RuleBase base = RuleBaseFactory.newRuleBase();
   base.addPackage(pkg);
   StatelessSession session = base.newStatelessSession();
   final ClassLoader loader =
Thread.currentThread().getContextClassLoader();
   Object inst = loader.loadClass(com.foo.Foo).newInstance();
   session.execute(new Object[] { inst });
   }



Exception in thread main java.lang.ClassCastException:
adixon.prototype.rules.classloader.demo.copy.FooShadowProxy
at 
org.drools.base.adixon.prototype.rules.classloader.demo.copy.Foo$getName.getValue(Unknown
Source)
at 
org.drools.base.ClassFieldExtractor.getValue(ClassFieldExtractor.java:94)
at 
org.drools.base.evaluators.StringFactory$StringEqualEvaluator.evaluate(StringFactory.java:85)
at 
org.drools.rule.LiteralRestriction.isAllowed(LiteralRestriction.java:61)
at 
org.drools.rule.LiteralConstraint.isAllowed(LiteralConstraint.java:82)
at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:121)
at 
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:20)
at 
org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:159)
at org.drools.reteoo.Rete.assertObject(Rete.java:175)
at 
org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:190)
at 
org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:70)
at 
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:772)
at 
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:584)
at 
org.drools.reteoo.ReteooStatelessSession.execute(ReteooStatelessSession.java:63)
at 
adixon.prototype.rules.classloader.demo.copy.Driver.testRules(Driver.java:47)
at 
adixon.prototype.rules.classloader.demo.copy.Driver.go(Driver.java:33)
at 
adixon.prototype.rules.classloader.demo.copy.Driver.main(Driver.java:17)
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Rule compilation errors under heavy load

2007-07-12 Thread Edson Tirelli

  Is it possible for you to provide a test case capable of reproducing the
problem?

  At the same time, I would suggest you to not follow such approach in your
application. Compilation is an extremely heavy process and should not be
done for each request. The ideal approach is to pre-compile (for instance,
we have a contributed ant-task for that) and serialize your rulebase to your
database or filesystem, or at least, compile it only once and cache it at
runtime.

  []s
  Edson

2007/7/12, Dean Jones [EMAIL PROTECTED]:


Hello folks,

I'm experiencing some odd behaviour from Drools (or maybe the Eclipse
compiler) when load-testing my application, and wondered if anyone
else had experienced the same issue. I have a web service which, for
every request, loads in rules from the database, creates a
org.drools.lang.descr.PackageDescr and then uses this to create a
org.drools.rule.Package. The code is something like:

PackageBuilderConfiguration conf = new PackageBuilderConfiguration();
PackageBuilder builder = new PackageBuilder(conf);
PackageDescr packageDescr = new PackageDescr(MyRulebaseName);
populatePackageDescr(packageDescr);
builder.addPackage(packageDescr);
Package _package = builder.getPackage();
return _package;

This code gets run every request. The populatePackageDescr() method
adds imports, globals, functions and rules to the PackageDescr. My
load-test just repeatedly calls the same rulebase, so
populatePackageDescr() will be doing exactly the same thing for each
request. Occasionally (normally once or twice per 100 requests) I get
a rule compilation error (the exact error varies from request to
request) whereas most of the time the same rule compiles fine. This
makes me suspect a thread-safety issue in either the PackageBuilder or
the compiler (I'm using the eclipse compiler).

Initially, I suspected a problem in my
populatePackageDescr(packageDescr) method, but I think I've ruled this
out. There is nothing stateful in this method, and I've tried dumping
the XML representation of the packageDescr immediately after
populating it; it looks fine to me and is exactly the same whether
compilation succeeds or and fails.

Has anyone done this kind of thing successfully under a heavy load?

Thanks,

Dean.
___
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 3529-6000
 Mobile: +55 11 9287-5646
 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] NullPointerException while deleting the rule package

2007-07-12 Thread Edson Tirelli

   This problem was supposed to be fixed in MR3. Can you please provide a
self contained test and attach it to a JIRA so I can investigate and fix?

   Thank you,
 Edson

2007/7/12, Sarika Khamitkar [EMAIL PROTECTED]:


 This is the again regarding the NullPointerException issue. Sorry for
resending this message again. But I would really appreciate a response on
how this can be resolved.

The following is the exception I get while removing a package from the
RuleBase.

java.lang.NullPointerException

at
org.drools.reteoo.CompositeObjectSinkAdapter.removeObjectSink(
CompositeObjectSinkAdapter.java:125)

at org.drools.reteoo.ObjectSource.removeObjectSink(
ObjectSource.java:123)

at org.drools.reteoo.ObjectTypeNode.removeObjectSink(
ObjectTypeNode.java:297)

at org.drools.reteoo.ObjectTypeNode.remove(ObjectTypeNode.java
:232)

at org.drools.reteoo.AlphaNode.remove(AlphaNode.java:187)

at org.drools.reteoo.AlphaNode.remove(AlphaNode.java:187)

at org.drools.reteoo.BetaNode.remove(BetaNode.java:185)

at org.drools.reteoo.BetaNode.remove(BetaNode.java:187)

at org.drools.reteoo.RuleTerminalNode.remove(
RuleTerminalNode.java:439)

at org.drools.reteoo.ReteooBuilder.removeRule(
ReteooBuilder.java:135)

at org.drools.reteoo.ReteooRuleBase.removeRule(
ReteooRuleBase.java:259)

at org.drools.common.AbstractRuleBase.removePackage(
AbstractRuleBase.java:408)

….



This exception has been occurring after I recently switched to 4.0 MR3.



Thanks.




 --

*From:* [EMAIL PROTECTED] [mailto:
[EMAIL PROTECTED] *On Behalf Of *Sarika Khamitkar
*Sent:* Wednesday, July 11, 2007 6:31 PM
*To:* rules-users@lists.jboss.org
*Subject:* [rules-users] NullPointerException while deleting the rule
package



Sorry for resending the message. This is an urgent issue and if anybody
has encountered this problem, can you please let me know how it can be
resolved?



If I have over 3 packages in the RuleBase and I try to remove one of those
packages, then I get a NullPointerException.



Thanks.




 --

*From:* [EMAIL PROTECTED] [mailto:
[EMAIL PROTECTED] *On Behalf Of *Sarika Khamitkar
*Sent:* Wednesday, July 11, 2007 3:34 PM
*To:* rules-users@lists.jboss.org
*Subject:* [rules-users] NullPointerException while deleting the rule
package



Hi,



I am trying a remove a rule from the RuleBase using the following syntax
and get a NullPointerException:

ruleBase.removePackage(rule2392016206);



Before removing the package, I am iterating through all the packages in
the ruleBase and I can see this package name in the list. I am not sure why
this exception is being thrown then.

I am using 4.0 MR3.



Has this feature changed since 3.0.6?



Thanks.



Sarika









___
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 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 3529-6000
 Mobile: +55 11 9287-5646
 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] Rule compilation errors under heavy load

2007-07-12 Thread Dean Jones

Hi Edson,

On 7/12/07, Edson Tirelli [EMAIL PROTECTED] wrote:


   Is it possible for you to provide a test case capable of reproducing the
problem?


I've written a quick test case, which is attached. When numberOfThreads==1,
everything compiles okay. When numberOfThreads==100, I get function
compilation errors and CompileExceptions from mvel. Clearly there is
nothing shared between these threads as a new test class is created
per thread. If you synchronise the calls to addPackage() and
getPackage() using the class monitor i.e.

synchronized (DroolsLoadTest.class) {
builder.addPackage(packageDescr);
builder.getPackage();
}

then the problems go away. Hope this helps.



   At the same time, I would suggest you to not follow such approach in your
application. Compilation is an extremely heavy process and should not be
done for each request. The ideal approach is to pre-compile (for instance,
we have a contributed ant-task for that) and serialize your rulebase to your
database or filesystem, or at least, compile it only once and cache it at
runtime.


That's very sensible advice. Our situation is slightly different as
users are allowed to change the rules used by a running service, so we
need to reflect any changes when a new request comes in. We are
planning to apply caching if performance is an issue, but we were
trying to assess performance of application under load when this
thread safety issue arose.

Thanks for your help,

Dean.
import org.drools.compiler.DroolsError;
import org.drools.compiler.PackageBuilderConfiguration;
import org.drools.compiler.PackageBuilderErrors;
import org.drools.lang.descr.FunctionDescr;
import org.drools.lang.descr.ImportDescr;
import org.drools.lang.descr.PackageDescr;

public class DroolsLoadTest {

	public DroolsLoadTest() {
	}
	
	public void runTest() {
PackageBuilderConfiguration packageBuilderConfig = new PackageBuilderConfiguration();
org.drools.compiler.PackageBuilder builder = new org.drools.compiler.PackageBuilder(packageBuilderConfig);
PackageDescr packageDescr = new PackageDescr(MyRulebase);
		addImports(packageDescr);
		addFunctions(packageDescr);
		builder.addPackage(packageDescr);
 		builder.getPackage();
   	if (builder.hasErrors()) {
   		PackageBuilderErrors errors = builder.getErrors();
   		for (DroolsError error : errors.getErrors()) {
   			System.out.println(ERROR:  + error.getMessage());
   		}
		}
	}
	
	private void addImports(PackageDescr packageDescr) {
		packageDescr.addImport(new ImportDescr(java.util.List));
		packageDescr.addImport(new ImportDescr(java.util.ArrayList));
		packageDescr.addImport(new ImportDescr(java.util.LinkedList));
		packageDescr.addImport(new ImportDescr(java.util.Set));
		packageDescr.addImport(new ImportDescr(java.util.HashSet));
		packageDescr.addImport(new ImportDescr(java.util.SortedSet));
		packageDescr.addImport(new ImportDescr(java.util.TreeSet));
	}
	
	private void addFunctions(PackageDescr packageDescr) {
		FunctionDescr functionDescr = new FunctionDescr(foo, void);
		functionDescr.addParameter(String, arg1);
		String body = 
			Set myHashSet = new HashSet(); +
			myHashSet.add(arg1); + 
			List myArrayList = new ArrayList(); +
			myArrayList.add(arg1); +
		  List myLinkedList = new LinkedList(); +
		  myLinkedList.add(arg1); +
		  Set myTreeSet = new TreeSet(); +
			myTreeSet.add(arg1);;
		functionDescr.setText(body);
		packageDescr.addFunction(functionDescr);
	}
	
	public static void main(String[] args) {
int numberOfThreads = 100;
Thread[] threads = new Thread[numberOfThreads];
for (int i = 0; i  numberOfThreads; i++) {
Thread testThread = new Thread() {
public void run() {
DroolsLoadTest test = new DroolsLoadTest();
test.runTest();
try {
	Thread.sleep(10);
} catch (InterruptedException e) {
	e.printStackTrace();
} 
}
};
threads[i] = testThread;
testThread.start();
}
	}
}
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Examples moving

2007-07-12 Thread Fernando Meyer

Hi peeps,

	Just to be consistence, the drools-example directory now contains  
examples projects and not an eclipse project anymore:


trunk
  -drools-examples
-drools-examples-drl
-drools-examples-brms
-drools-examples-*  

Im about to add a xml test project and improve brms examples.

Let me know if something isn't working fine.

Regards

Fernando Meyer
Software Engineer - JBoss Rules Core Developer
Office:   +55 11 3124-6000
Mobile: +55 11 8524-1298
JBoss, a division of Red Hat @ www.jboss.com

GPG: 47C0 F16E 0387 F4DF 7EBC  8E3C 7AF1 8D55 AB29 DA3A


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


[rules-users] how to create local variable

2007-07-12 Thread Manukyan, Sergey

Folks,

 

I have a rule where I am repeating part of it twice :
($cs.getSuppCode().substring(4, 6)), and I would like to replace it with
variable... how can I do that? The solution with in doesn't worl
because it is a java code needed to perform calculations for
variable.

 

Please see the rule below:

 

rule SupplierView: Headquarter Supplier Code should end on 25 or 30.

  when

$cs : SupplierView(corporate == true)

eval($cs.getSuppCode().substring(4, 6) == 25 ||
$cs.getSuppCode().substring(4, 6) == 30) 

  then

ValidationErrorFacade.getInstance().registerError($cs, new
ValidationError(Headquarter Supplier Code should end on 25 or 30.));

end

 

 

Thanks,

 

-Sergey

 

 

 

 



**
** LEGAL DISCLAIMER **
**

This E-mail message and any attachments may contain 
legally privileged, confidential or proprietary 
information. If you are not the intended recipient(s),
or the employee or agent responsible for delivery of 
this message to the intended recipient(s), you are 
hereby notified that any dissemination, distribution 
or copying of this E-mail message is strictly 
prohibited. If you have received this message in 
error, please immediately notify the sender and 
delete this E-mail message from your computer.___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Re: Using JDK dynamic proxies as facts

2007-07-12 Thread Chris West

OK, I just solved my own problem.  My proxy had no package, since the jdk
based proxy is only in a package if it has at least 1 non public interface,
according to the javadoc.

The suspect code beginning on line 333 is:

   String pkgName = cls.getPackage().getName();
   if ( org.drools.reteoo.equals( pkgName ) ||
org.drools.base.equals(
pkgName ) ) {
   // We don't shadow internal classes
   this.shadowEnabled = false;
   return;
   }

The getPackage() method returns null.  In this case, it would be good if
JBoss Rules handled the null and went on to shadow the object anyway, since
it is obviously not in the org.drools packages.

Now I'll continue trying to build a test case for my original problem.

Shall I enter a JIRA for this issue?

Thanks,
-Chris West

On 7/12/07, Chris West [EMAIL PROTECTED] wrote:


Hello,

I'm trying to use objects that are generated as dynamic proxies (through
the java.lang.reflect.Proxy class) as facts in JBoss Rules 4.0 MR3.  My
project was using CGLib to generate proxies, and they were working just fine
in 3.0.6.  However, when I tried 4.0, the CGLib based proxies seemed to
have a final method that kept the proxies from being proxied as shadow
facts.  So I rewrote my code to try to use JDK based proxies, and version
4.0 MR3 accepts them and apparently creates shadow facts, but now my rules
don't fire correctly.

So, in an attempt to create a simple program to illustrate the problem, I
ran into a different problem.  The attached eclipse project illustrates this
problem.

The error is:

java.lang.NullPointerException
at org.drools.reteoo.Rete$ObjectTypeConf.init(Rete.java:333)
at org.drools.reteoo.Rete.assertObject(Rete.java:152)
at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java
:190)
at org.drools.reteoo.ReteooWorkingMemory.doInsert(
ReteooWorkingMemory.java:70)
at org.drools.common.AbstractWorkingMemory.insert(
AbstractWorkingMemory.java:772)
at org.drools.common.AbstractWorkingMemory.insert (
AbstractWorkingMemory.java:584)
at com.sample.DroolsTest.main(DroolsTest.java:42)

Has anyone successfully used JDK based dynamic proxies as facts?

Thanks,
-Chris West


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


Re: [rules-users] Using JDK dynamic proxies as facts

2007-07-12 Thread Edson Tirelli

  Chris,

  It seems like a bug to me. May I ask you please to open a JIRA and attach
your project?
  We are trying to fix final bugs for MR4 and keeping all of them in JIRA
will avoid us to miss anyone...

  Thanks

  []s
  Edson


2007/7/12, Chris West [EMAIL PROTECTED]:


Hello,

I'm trying to use objects that are generated as dynamic proxies (through
the java.lang.reflect.Proxy class) as facts in JBoss Rules 4.0 MR3.  My
project was using CGLib to generate proxies, and they were working just fine
in 3.0.6.  However, when I tried 4.0, the CGLib based proxies seemed to
have a final method that kept the proxies from being proxied as shadow
facts.  So I rewrote my code to try to use JDK based proxies, and version
4.0 MR3 accepts them and apparently creates shadow facts, but now my rules
don't fire correctly.

So, in an attempt to create a simple program to illustrate the problem, I
ran into a different problem.  The attached eclipse project illustrates this
problem.

The error is:

java.lang.NullPointerException
at org.drools.reteoo.Rete$ObjectTypeConf.init(Rete.java:333)
at org.drools.reteoo.Rete.assertObject(Rete.java:152)
at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java
:190)
at org.drools.reteoo.ReteooWorkingMemory.doInsert(
ReteooWorkingMemory.java:70)
at org.drools.common.AbstractWorkingMemory.insert(
AbstractWorkingMemory.java:772)
at org.drools.common.AbstractWorkingMemory.insert (
AbstractWorkingMemory.java:584)
at com.sample.DroolsTest.main(DroolsTest.java:42)

Has anyone successfully used JDK based dynamic proxies as facts?

Thanks,
-Chris West

___
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 3529-6000
 Mobile: +55 11 9287-5646
 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] how to create local variable

2007-07-12 Thread Edson Tirelli

   It is not possible to assign the result of an arbitrary method call to a
variable right now. So, your best option is probably to do (please note the
use of inline-eval):

*rule* SupplierView: Headquarter Supplier Code should end on 25 or 30.

 *when*

   $cs : SupplierView(corporate == *true,* eval( suppCode.substring(4,
6).equals( 25 ) || suppCode.substring(4, 6).equals( 30 ) ) )

 *then*

   ValidationErrorFacade.getInstance().registerError($cs,
*new*ValidationError(Headquarter
Supplier Code should end on 25 or 30.));

*end*

   A more clean solution is to use matches operator. If your rule states
that Supplier Code must END with 25 or 30, you can do:

*rule* SupplierView: Headquarter Supplier Code should end on 25 or 30.

 *when*

   $cs : SupplierView(corporate == *true,* suppCode matches .*25 ||
matches .*30 )

 *then*

   ValidationErrorFacade.getInstance().registerError($cs,
*new*ValidationError(Headquarter
Supplier Code should end on 25 or 30.));

*end*

   Hope it helps.

   []s
   Edson


2007/7/12, Manukyan, Sergey [EMAIL PROTECTED]:


 Folks,



I have a rule where I am repeating part of it twice : 
($cs.getSuppCode().substring(4,
6)), and I would like to replace it with variable… how can I do that? The
solution with in doesn't worl because it is a java code needed to perform
calculations for variable…..



Please see the rule below:

* *

*rule* SupplierView: Headquarter Supplier Code should end on 25 or 30.

  *when*

$cs : SupplierView(corporate == *true*)

*eval*($cs.getSuppCode().substring(4, 6) == 25 ||
$cs.getSuppCode().substring(4, 6) == 30)

  *then*

ValidationErrorFacade.getInstance().registerError($cs, 
*new*ValidationError(Headquarter
Supplier Code should end on 25 or 30.));

*end*





Thanks,



-Sergey








 **
** LEGAL DISCLAIMER **
**

This E-mail message and any attachments may contain
legally privileged, confidential or proprietary
information. If you are not the intended recipient(s),
or the employee or agent responsible for delivery of
this message to the intended recipient(s), you are
hereby notified that any dissemination, distribution
or copying of this E-mail message is strictly
prohibited. If you have received this message in
error, please immediately notify the sender and
delete this E-mail message from your computer.

___
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 3529-6000
 Mobile: +55 11 9287-5646
 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] Re: Using JDK dynamic proxies as facts

2007-07-12 Thread Edson Tirelli

  Please!

  Thank you for providing the solution.

  []s
  Edson

2007/7/12, Chris West [EMAIL PROTECTED]:


OK, I just solved my own problem.  My proxy had no package, since the jdk
based proxy is only in a package if it has at least 1 non public interface,
according to the javadoc.

The suspect code beginning on line 333 is:

String pkgName = cls.getPackage().getName();
if ( org.drools.reteoo.equals( pkgName ) || 
org.drools.base.equals(
pkgName ) ) {
// We don't shadow internal classes
this.shadowEnabled = false;
return;
}

The getPackage() method returns null.  In this case, it would be good if
JBoss Rules handled the null and went on to shadow the object anyway, since
it is obviously not in the org.drools packages.

Now I'll continue trying to build a test case for my original problem.

Shall I enter a JIRA for this issue?

Thanks,
-Chris West

On 7/12/07, Chris West [EMAIL PROTECTED] wrote:

 Hello,

 I'm trying to use objects that are generated as dynamic proxies (through
 the java.lang.reflect.Proxy class) as facts in JBoss Rules 4.0 MR3.  My
 project was using CGLib to generate proxies, and they were working just fine
 in 3.0.6.  However, when I tried 4.0, the CGLib based proxies seemed to
 have a final method that kept the proxies from being proxied as shadow
 facts.  So I rewrote my code to try to use JDK based proxies, and version
 4.0 MR3 accepts them and apparently creates shadow facts, but now my
 rules don't fire correctly.

 So, in an attempt to create a simple program to illustrate the problem,
 I ran into a different problem.  The attached eclipse project illustrates
 this problem.

 The error is:

 java.lang.NullPointerException
 at org.drools.reteoo.Rete$ObjectTypeConf.init(Rete.java:333)
 at org.drools.reteoo.Rete.assertObject(Rete.java:152)
 at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java
 :190)
 at org.drools.reteoo.ReteooWorkingMemory.doInsert(
 ReteooWorkingMemory.java:70)
 at org.drools.common.AbstractWorkingMemory.insert(
 AbstractWorkingMemory.java:772)
 at org.drools.common.AbstractWorkingMemory.insert (
 AbstractWorkingMemory.java:584)
 at com.sample.DroolsTest.main(DroolsTest.java:42)

 Has anyone successfully used JDK based dynamic proxies as facts?

 Thanks,
 -Chris West



___
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 3529-6000
 Mobile: +55 11 9287-5646
 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] how to create local variable

2007-07-12 Thread Manukyan, Sergey
Thank you Edson,

 

I liked the solution with matches, it is much cleaner 

 

-Sergey

 

 



From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Edson Tirelli
Sent: Thursday, July 12, 2007 4:19 PM
To: Rules Users List
Subject: Re: [rules-users] how to create local variable

 


It is not possible to assign the result of an arbitrary method call
to a variable right now. So, your best option is probably to do (please
note the use of inline-eval):

rule SupplierView: Headquarter Supplier Code should end on 25 or 30.

  when

$cs : SupplierView(corporate == true, eval(
suppCode.substring(4, 6).equals( 25 ) || suppCode.substring(4,
6).equals( 30 ) ) )

  then

ValidationErrorFacade.getInstance().registerError($cs, new
ValidationError(Headquarter Supplier Code should end on 25 or 30.));

end


A more clean solution is to use matches operator. If your rule
states that Supplier Code must END with 25 or 30, you can do: 

rule SupplierView: Headquarter Supplier Code should end on 25 or 30.

  when

$cs : SupplierView(corporate == true, suppCode matches
.*25 || matches .*30 )

  then

ValidationErrorFacade.getInstance().registerError($cs, new
ValidationError(Headquarter Supplier Code should end on 25 or 30.));

end


Hope it helps.

[]s
Edson



2007/7/12, Manukyan, Sergey  [EMAIL PROTECTED]:

Folks,

 

I have a rule where I am repeating part of it twice :
($cs.getSuppCode().substring(4, 6)), and I would like to replace it with
variable... how can I do that? The solution with in doesn't worl
because it is a java code needed to perform calculations for
variable.

 

Please see the rule below:

 

rule SupplierView: Headquarter Supplier Code should end on 25 or 30.

  when

$cs : SupplierView(corporate == true)

eval($cs.getSuppCode().substring(4, 6) == 25 ||
$cs.getSuppCode().substring(4, 6) == 30) 

  then

ValidationErrorFacade.getInstance().registerError($cs, new
ValidationError(Headquarter Supplier Code should end on 25 or 30.));

end

 

 

Thanks,

 

-Sergey

 

 

 

 

**
** LEGAL DISCLAIMER **
**

This E-mail message and any attachments may contain 
legally privileged, confidential or proprietary 
information. If you are not the intended recipient(s),
or the employee or agent responsible for delivery of 
this message to the intended recipient(s), you are 
hereby notified that any dissemination, distribution 
or copying of this E-mail message is strictly 
prohibited. If you have received this message in 
error, please immediately notify the sender and 
delete this E-mail message from your computer.


___
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 3529-6000
  Mobile: +55 11 9287-5646
  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] Compilation Error in Drools

2007-07-12 Thread McShiv

Hi All,

I used the following code in the dsl file. 

DSL:

[when] Check whether the name is present as {studName} = $stud :
Student(name = {studName});
[then] Set the Error Code {errorCode} = String string = $stud.getName();
Error(errorCode, string);

DRL:

package com.policy;
expander StudendProgram.dsl;
import java.util.Iterator;
import com.class.Student;
import com.class.Error;

   rule StudendProgram_1
   
when
Check whether the name is present as Stephen 
then
Set the Error Code 88
end


When I try to run this program I got the following error.

   Caused by: org.drools.rule.InvalidRulePackage: Rule Compilation error
File com/policy/Rule_SpeCodeSpeValProdPlan12_0.java, Line 12, Column 176:
Unexpected token . in primary 

When I remove the Line $stud.getName(); in the then part and set the error
code alone its working fine. The . inbetween $stud and getName() may be
the problem. But I don't know the solution for this. 

Any suggessions on this.

Thanks,
McShiv
-- 
View this message in context: 
http://www.nabble.com/Compilation-Error-in-Drools-tf4071029.html#a11569413
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


Re: [rules-users] Complex validation logic for hierarchies with Drools

2007-07-12 Thread Edson Tirelli

  Oleg,

  As I mentioned to you, it is perfectly fine and easy to use the rules
engine to validate your object tree as long as you instruct your users that
they must write structured rules. What I mean is: as much as DSL templates
allow you to write rules that resemble natural language, it is not really
natural language. The main advice is to group objects and attributes
together. So, instead of writing the rule as:

3. ServiceDescription contained inside ClientService with type BRONZE
should has status ACCEPTED

  They need to write the rule as:

3. If there is a ClientService whose type is BRONZE and a
ServiceDescription contained inside it whose status is different of
ACCEPTED then report error

  As you can see, all the constraints/attributes are listed right after
each object type. The above rule can be translated to:

rule 3. Validate status for BRONZE
when
   There is a ClientService
   - whose type is BRONZE
   There is a ServiceDescription
   - contained inside it
   - whose status is different of ACCEPTED
then
   report error
end

  As you can see, the rule definition is very close to the actual rule, if
you take the appropriate care when writing it, having the
attribute/constraints right after each object type.
  Now, the DSL mapping will transform the above rule into:

rule 3. Validate status for BRONZE
when
   cs : ClientService( type == BRONZE )
   sd : ServiceDescription( this memberOf cs.children, status != ACCEPTED
)
then
   # report error
end

  When you try to extrapolate the above example to your real business
example, to make your DSL template completely generic, you may find the need
to explain to your users the concept of variable though.
  So, what he would do is actually name each of your objects. Example
(replace X and Y for any identifier that makes sense for the user):

3. If there is a ClientService named X whose type is BRONZE and a
ServiceDescription name Y contained inside X whose status is different of
ACCEPTED then report error

  If the user names each object, it will be much easier to write generic
templates, since your rule would become:

rule 3. Validate status for BRONZE
when
   There is a ClientService named X
   - whose type is BRONZE
   There is a ServiceDescription named Y
   - contained inside X
   - whose status is different of ACCEPTED
then
   report error
end

  And the DSL would translate that to:

rule 3. Validate status for BRONZE
when
   X : ClientService( type == BRONZE )
   Y : ServiceDescription( this memberOf X.children, status != ACCEPTED )
then
   # report error
end

  I don't think that it is too hard to explain to users that they need to
name each of his objects and this adds a great flexibility to the rules when
adding constraints between objects of the same type.

  The final (and hardest) problem you will face is that you mentioned that
your objects may be any level deep inside each other and you want to
abstract that from users. In this case I see only 2 options:

1. The first option is do what you are already doing and create a helper
function that goes deep a hierarchy checking for the existence of the
relationship.

2. The second option is to create a relationship object that will flatten
your tree structure transforming it in a pure relational structure. This is
a very common solution used in databases that do not support hierarchy
queries. The idea is that you create an object with attributes parent, child
and optionally the level (distance) between each other, and you assert a
copy of it for each related object in your object hierarchy (in
computational theory we call this set of objects the result of the
transitive closure calculation). The result is really a trade-off between
memory and query time. You need to check if for your use case, the
performance gains and expressiveness flexibility pays off the memory cost.

   Hope it helps.

   []s
   Edson

2007/7/12, Oleg Yavorsky [EMAIL PROTECTED]:


Hi.

I've got a lot of domain objects represented as instances of classes
generated from XSD using Castor. My goal is to implement validation
framework for whole tree which contains complex when  conditions (see
bellow). Furthermore, rules definitions should be very easy for
unexperienced user to change so I need DSL.

Now I use reflection to assert whole tree of objects to working memory
along with additional context information (like stack of parents associated
with particular object). Then I use eval() in LHS to call boolean functions
which performs checks in plain Java to see if object in particular context.
But I think that this is ugly approach and it doesn't solve other cases. I'm
new to Drools but something tells me that it can give me more elegant
solution for such problems.

Here is an example of possible hierarchy (used XSD to better represent
it). Make note that in production case similar hierarchy is more complex and
has a lot of objects. Sorry, but I don't know how to format it in email.

?xml version=1.0 encoding=UTF-8?
schema 

Re: [rules-users] Compilation Error in Drools

2007-07-12 Thread Edson Tirelli

  Best way to investigate this is to expand your DSL to the DRL to check
how the expansion is working.

   DrlParser parser = new DrlParser();
   String expanded = parser.getExpandedDRL( drlSourceString, dslReader
);

  Check what is wrong in the expanded DRL. I see your map has an error:

$stud : Student(name == {studName})

  The comparison must be made with '==' as above instead of '=' as in your
template. But I don't know if that is the only problem.

  []s
  Edson

2007/7/12, McShiv [EMAIL PROTECTED]:



Hi All,

I used the following code in the dsl file.

DSL:

[when] Check whether the name is present as {studName} = $stud :
Student(name = {studName});
[then] Set the Error Code {errorCode} = String string =
$stud.getName();
Error(errorCode, string);

DRL:

package com.policy;
expander StudendProgram.dsl;
import java.util.Iterator;
import com.class.Student;
import com.class.Error;

   rule StudendProgram_1

when
Check whether the name is present as Stephen
then
Set the Error Code 88
end


When I try to run this program I got the following error.

   Caused by: org.drools.rule.InvalidRulePackage: Rule Compilation error
File com/policy/Rule_SpeCodeSpeValProdPlan12_0.java, Line 12, Column 176:
Unexpected token . in primary

When I remove the Line $stud.getName(); in the then part and set the
error
code alone its working fine. The . inbetween $stud and getName() may be
the problem. But I don't know the solution for this.

Any suggessions on this.

Thanks,
McShiv
--
View this message in context:
http://www.nabble.com/Compilation-Error-in-Drools-tf4071029.html#a11569413
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





--
 Edson Tirelli
 Software Engineer - JBoss Rules Core Developer
 Office: +55 11 3529-6000
 Mobile: +55 11 9287-5646
 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] Problem opening several views in 4.0 MR3 Eclipse

2007-07-12 Thread Eric Miles
When I attempt to open several views (Working Memory, Agenda, Global,
etc) within an JBoss Rules enabled Eclipse, I receive the following
error:

java.lang.NoClassDefFoundError:
org/eclipse/debug/internal/ui/contexts/provisional/IDebugContextListener
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at
org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:161)
at
org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:501)
at
org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:471)
at
org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:430)
at
org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:413)
at
org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:189)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.findLocalClass(BundleLoader.java:340)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:408)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:369)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:357)
at
org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:83)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at
org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:161)
at
org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:501)
at
org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:471)
at
org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:430)
at
org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:413)
at
org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:189)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.findLocalClass(BundleLoader.java:340)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:408)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:369)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:357)
at
org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:83)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at
org.eclipse.osgi.framework.internal.core.BundleLoader.loadClass(BundleLoader.java:289)
at
org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:227)
at
org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1269)
at
org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:160)
at
org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:788)
at
org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243)
at
org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:51)
at
org.eclipse.ui.internal.WorkbenchPlugin.createExtension(WorkbenchPlugin.java:235)
at
org.eclipse.ui.internal.registry.ViewDescriptor.createView(ViewDescriptor.java:69)
at
org.eclipse.ui.internal.ViewReference.createPartHelper(ViewReference.java:327)
at
org.eclipse.ui.internal.ViewReference.createPart(ViewReference.java:227)
at
org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:592)
at org.eclipse.ui.internal.Perspective.showView(Perspective.java:2077)
at
org.eclipse.ui.internal.WorkbenchPage.busyShowView(WorkbenchPage.java:1018)
at org.eclipse.ui.internal.WorkbenchPage.access
$18(WorkbenchPage.java:999)
at org.eclipse.ui.internal.WorkbenchPage
$19.run(WorkbenchPage.java:3666)
at
org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
at
org.eclipse.ui.internal.WorkbenchPage.showView(WorkbenchPage.java:3663)
at
org.eclipse.ui.internal.WorkbenchPage.showView(WorkbenchPage.java:3639)
at
org.eclipse.ui.handlers.ShowViewHandler.openView(ShowViewHandler.java:165)
at