"from" keyword in Excel tables
by Bernd Rücker
Hey guys.
I currently set up an excel table to capture some rules. I face one
problem and I am not sure if and how that is possible.
I want to include this in the rule:
$o : Order (...)
Customer (status=x) from customerService.getCustomer(
$o.getCustomerId() )
The status=x shall be filled by a column in the table. But how can I
include the from stuff in excel (best without using the pattern stuff,
since it is marked experimental)? Any idea?
Thanks a lot and cheers
Bernd
P.S: IS there a collection of different problem patterns and their
translation to decision tables available somewhere? That would be really
helpful :-)
14 years, 11 months
KnowledgeAgent exception while trying to deserialize KnowledgeDefinitionsPackage
by HonorGod
I am getting the following error while accessing decision tables that were
uploaded in Guvnor -
java.lang.RuntimeException: KnowledgeAgent exception while trying to
deserialize KnowledgeDefinitionsPackage
at
org.drools.agent.impl.KnowledgeAgentImpl.rebuildResources(KnowledgeAgentImpl.java:418)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:120)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:109)
at
com.barcap.efg.fine.drools.rules.CorporateActionRecommendationService.getSession(CorporateActionRecommendationService.java:153)
at
com.barcap.efg.fine.drools.rules.CorporateActionRecommendationService.init(CorporateActionRecommendationService.java:120)
at
com.barcap.efg.fine.drools.rules.CorporateActionRecommendationService.run(CorporateActionRecommendationService.java:50)
at
com.barcap.efg.fine.farm.launcher.FarmAppLauncher.main(FarmAppLauncher.java:184)
Caused by: java.io.FileNotFoundException:
http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/packages/Cor...
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown
Source)
at org.drools.io.impl.UrlResource.getInputStream(UrlResource.java:76)
at
org.drools.agent.impl.KnowledgeAgentImpl.rebuildResources(KnowledgeAgentImpl.java:407)
... 6 more
----------------
Java Code
private StatefulKnowledgeSession getSession() {
LogUtil.caRecommendationLogger.info("Getting session for Rules
Engine ...");
// Set the interval on the ResourceChangeScannerService if you are
to use it
// and default of 60s is not desirable.
final ResourceChangeScannerConfiguration sconf =
ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
// set the disk scanning interval to 30s, default is 60s
sconf.setProperty("drools.resource.scanner.interval", "30");
ResourceFactory.getResourceChangeScannerService().configure(sconf);
knowledgeBaseFromDecisionTable =
KnowledgeBaseFactory.newKnowledgeBase();
final KnowledgeAgentConfiguration aconf =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
// we want to scan directories, not just files, turning this on
turns on file
// scanning
aconf.setProperty("drools.agent.scanDirectories", "true");
// resource changes results in a new instance of the KnowledgeBase
being
// built, this cannot currently be set to false for incremental
building
aconf.setProperty("drools.agent.newInstance", "true");
final KnowledgeAgent kagent =
KnowledgeAgentFactory.newKnowledgeAgent("kagent",
knowledgeBaseFromDecisionTable, aconf);
kagent.applyChangeSet(ResourceFactory.newClassPathResource("changeset.xml"));
//kagent.applyChangeSet(ResourceFactory.newFileResource("c:/changeset.xml"));
return kagent.getKnowledgeBase().newStatefulKnowledgeSession();
}
-----------------
changeset.xml
<?xml version="1.0" encoding="UTF-8"?>
<change-set xmlns='http://drools.org/drools-5.0/change-set'
xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'
xs:schemaLocation='http://drools.org/drools-5.0/change-set
drools-change-set-5.0.xsd'>
<add>
<resource
source='http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/packages/Cor...'
type='PKG' />
</add>
</change-set>
Please help.
Thanks!
--
View this message in context: http://n3.nabble.com/KnowledgeAgent-exception-while-trying-to-deserialize...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 11 months
Class loading problem when registering a knowledge package
by Szabolcs Bárdy
Hi All,
my question would be the following:
There is a class called DroolsStreamUtils, which is used throughout
the drools core library in order to read in contents of a knowledge
package from an input stream. The class has the following method:
public static Object streamIn(InputStream in, ClassLoader
classLoader, boolean compressed)
throws IOException, ClassNotFoundException {
if (compressed)
in = new GZIPInputStream(in);
return new DroolsObjectInputStream(in).readObject();
}
It creates a DroolsObjectInputStream to read in the object, but it
does not uses the specified class loader to create
DroolsObjectInputStream instance. The DroolsObjectInputStream is
created the with the folloing constructor:
public DroolsObjectInputStream(InputStream inputStream) throws IOException {
this( inputStream,
null );
}
public DroolsObjectInputStream(InputStream inputStream,
ClassLoader classLoader) throws IOException {
super( inputStream );
if ( classLoader == null ) {
classLoader = Thread.currentThread().getContextClassLoader();
if ( classLoader == null ) {
classLoader = getClass().getClassLoader();
}
}
this.classLoader = classLoader;
this.parentClassLoader = classLoader;
}
Why can I specify a ClassLoader for DroolsStreamUtils if it is not used?
This causes us the following problem:
We are using Drools in a web application. We are planning to use
Guvnor as our rule repository. We have loaded the rules into the
repository and trying to use a KnowledgeAgent with a changeset xml to
obtain the package built by Guvnor. When the KnowledgeAgent is trying
to build the KnowlegeBase, it fails with a ClassCastException, as it
does not find the drools libraries on the class path. The
KnowledgeAgent uses the above written DroolsStreamUtils to read in the
package contents, and it uses a wrong class loader.
The same problem occurs if I am trying to use a KnowledgeBuilder to
register the package: .
knowledgeBuilder.add(ResourceFactory.newUrlResource("http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/com...."),
ResourceType.PKG);
I can specify a ClassLoader for the KnowledgeBuilder, however it has
no effect, since the following code is used by the KnowledgeBuilder to
register the package:
if ( ResourceType.PKG.equals( type )) {
InputStream is = resource.getInputStream();
Package pkg = (Package) DroolsStreamUtils.streamIn( is );
is.close();
addPackage( pkg );
}
As the DroolsStreamUtils won't use the class loader specified for the
KnowledgeBuilder, this approach fails as well.
If I read in the package with my own code, creating a
DroolsObjectInputStream with the correct class loader, everything
works fine.
Am I doing something wrong?
Cheers,
Szabolcs
14 years, 11 months
Checking multiple null values
by f.cima
Hi.
I have a bean which has some properties; p1, p2 ... px.
I would like to write a rule in a decision table that tests if some of these
parameters are null.
I wrote it in this way:
+---------------+---------------+---------------+
|CONDITION |CONDITION |CONDITION |
|myBean:Bean |
|$param == null |$param == null |$param == null |
|Rule1 |Rule2 |Rule3 |
|p1 |p2 | |
|p1 |p2 |p3 |
|p4 | | |
+---------------+---------------+---------------+
I would like to avoid writing n columns. It is possible to write such a rule
using only one column?
Regards
Fabiano
--
View this message in context: http://n3.nabble.com/Checking-multiple-null-values-tp120674p120674.html
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 11 months
Infinite loop when re-activating rules
by orchid
Hi All,
I have a question about avoiding infinite loop, not using 'no-loop' or
'lock-active' since I want to re-activate rules. Suppose I have one complex
class C and a chain of rules in which Rule2 checks the result of Rule1, Rule
3 checks the result of rule 2, etc... In the last rule ("Rule5") I want to
modify the class instance and re-activate the rules.
rule "Rule1"
when
$c:C(/*some conditions*/)
then
modify ($c){addRule("Rule1")}
end
rule "Rule2"
when
$c:C(rules contains "Rule1" && /*few more conditions*/)
then
modify ($c){addRule("Rule2")}
end
...
...
...
rule "Rule5"
when
$c:C(rules contains "Rule4" && /*few more conditions*/)
then
modify ($c){changeAttribute("...")}
end
In order to avoid infinite loop I added 'lock-on-active' to Rule1, and
'no-loop true' to the rest rules. But, then the rules are not re-activated
as a result of Rule5. How can I cause re-activation of the rules. I hope I
was clear enough :))
Thanks in advance !!!
--
View this message in context: http://n3.nabble.com/Infinite-loop-when-re-activating-rules-tp123918p1239...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 11 months
Drools 5.0 concat string in matches of regular expression
by Lukas Svoboda
How can I get drools 5.0.1 compiled if I have regular expression matches part
concat from static text + dynamic string?
See example:
onBlackList : ArrayList( size > 0 )
from collect( BlacklistItemDRL( blacklistItemType matches
"MAIL_DOMAIN" && customer.currentContactInformation.partyEmailAddress.email
matches (".*@" + blacklistItemValue + ".*") )
from blackList.getItems())
Problem is when I'm trying to do email matches (".*@" + blacklistItemValue +
".*"), which worked in drools 4.0.7 but can't be compiled now in 5.0.1
Is there any way how to use in matches part of reg exp dynamic property
value plus static string?
Thanks,
Lukas
--
View this message in context: http://n3.nabble.com/Drools-5-0-concat-string-in-matches-of-regular-expre...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 11 months
Re: [rules-users] KnowledgeAgent not reloading KnowledgeBase
by Pritam
It's working now. The key was to provide a change-set location to
KnowledgeAgent and make the agent itself singleton in the app.
public static KnowledgeBase getKnowledgeBase()
throws DroolsParserException, IOException {
// hold a static reference in class
if(agent != null) {
return agent.getKnowledgeBase();
}
ResourceChangeScannerConfiguration sconf =
ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
sconf.setProperty("drools.resource.scanner.interval", "5");
ResourceFactory.getResourceChangeScannerService().configure(sconf);
ResourceFactory.getResourceChangeScannerService().start();
ResourceFactory.getResourceChangeNotifierService().start();
agent = KnowledgeAgentFactory.newKnowledgeAgent("myagent");
agent.applyChangeSet(ResourceFactory.newFileResource("<path>\\change-set.xml"));
return agent.getKnowledgeBase();
}
<change-set xmlns='http://drools.org/drools-5.0/change-set'
xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'
xs:schemaLocation='http://drools.org/drools-5.0/change-set.xsd' >
<add>
<resource source='file:<path>/rules/' type='DRL' />
</add>
</change-set>
faruk wrote:
>
> Hi all,
>
> i have same problem with my code. And i implement both cases: with path to
> chage-set file and with xml string as You suggests.
>
> I both cases, i have same situation: logs says me that rules are
> rebuilded, but when i fire rules, i have next situation:
>
> with statefull session, no rules are fired after update
> with stateless session, same rules are fired.
>
> I make rules without conditions.
>
--
View this message in context: http://n3.nabble.com/KnowledgeAgent-not-reloading-KnowledgeBase-tp121401p...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 11 months
KnowledgeAgent not reloading KnowledgeBase
by Pritam
Before I ask the problem, here's the design I currently have:
Our "site" (webapp) has 100 pages. While rendering each page, the rule
engine is called for filtering the page contents. We have 100 drl files
(corresponding to each page). Since creating of a KnowledgeBase is
expensive, I'm using a KnowledgeAgent.getKnowledeBase() since the javadocs
mentions it as "it loads, caches, reloads knowledgeBase."
However after using the sample code given, a change in the rule file is not
reloading the knowledgeBase automatically. Note that I cache the
knowledgeAgent since I need one agent per knowledge base (is there a better
way to manage multiple drl files in one knowledge base and agent?)
Is something wrong with the below code?
// ruleFile is a complete file path on server
public static KnowledgeBase createKnowledgeBaseFromAgent(String ruleFile)
throws DroolsParserException, IOException {
ResourceChangeScannerConfiguration sconf = ResourceFactory
.getResourceChangeScannerService()
.newResourceChangeScannerConfiguration();
// static map of knowledgeAgents
if (knowledgeAgents.containsKey(ruleFile)) {
return
((KnowledgeAgent)knowledgeAgents.get(ruleFile)).getKnowledgeBase();
}
sconf.setProperty("drools.resource.scanner.interval", "5");
ResourceFactory.getResourceChangeScannerService().configure(sconf);
KnowledgeBase knowledgeBase = createKnowledgeBase(ruleFile);
ResourceFactory.getResourceChangeScannerService().start();
ResourceFactory.getResourceChangeNotifierService().start();
KnowledgeAgentConfiguration conf =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
conf.setProperty("drools.agent.scanDirectories", "true");
final KnowledgeAgent agent =
KnowledgeAgentFactory.newKnowledgeAgent(
"my agent", knowledgeBase, conf);
// agent.applyChangeSet(ResourceFactory.newFileResource(ruleFile));
setKnowledgeAgent(ruleFile, agent);
return agent.getKnowledgeBase();
}
public static KnowledgeBase createKnowledgeBase(
KnowledgeBaseConfiguration config,
KnowledgeBuilderConfiguration knowledgeBuilderConfig,
String ruleFile) throws DroolsParserException, IOException {
// else, create a knowledgeBase
KnowledgeBuilder knowledgeBuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(knowledgeBuilderConfig);
knowledgeBuilder.add(ResourceFactory.newFileResource(ruleFile),
ResourceType.DRL);
if (knowledgeBuilder.hasErrors()) {
throw new RuntimeException(knowledgeBuilder.getErrors().toString());
}
KnowledgeBase knowledgeBase =
KnowledgeBaseFactory.newKnowledgeBase(config);
knowledgeBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());
return knowledgeBase;
}
I commented out
agent.applyChangeSet(ResourceFactory.newFileResource(ruleFile));
since I get a NPE
java.lang.NullPointerException
at
org.drools.agent.impl.KnowledgeAgentImpl.processChangeSet(KnowledgeAgentImpl.java:135)
Pl suggest
--
View this message in context: http://n3.nabble.com/KnowledgeAgent-not-reloading-KnowledgeBase-tp121401p...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 11 months