Setting a Flow Variable from a Rule
by Todd Pagni
How do you set a flow variable (not global) from inside a rule so it is
available for nodes that follow the rule execution? I cannot seem to
find this in the doc.
Previously I had a Person() fact that was also passed into the flow as a
variable, when I modified the fact Person() object it was reflected in
the flow variable, but the latest snapshot seems to have broken this so
I am looking for alternatives.
Thanks,
Todd
16 years, 4 months
"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 :-)
16 years, 4 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.
16 years, 4 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
16 years, 4 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.
16 years, 4 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.
16 years, 4 months