Ant Build of PKG with Declared Types
by TroyL
I am attempting to build a PKG utilizing an Ant Script. My DRL includes two
declared types. When the declared types have only one field the PKG will
compile but when the declared types have more than one field I get an error
stating that a class of that name was already found on the class path :
specifically the error states:
[compiler] Duplicate type definition. A class with the name XXXXXXX was
found in the classpath while trying to redefine the fields in the declare
statement. Fields can only be defined for non-existing classes.
My ant script:
<?xml version="1.0" encoding="UTF-8" ?>
<project default="rules">
<property name="projectPath" value="" />
<property name="droolsPath"
value="C:/Users/266571/Documents/drools-distribution-5.2.0.Final/binaries"
/>
<property name="eclipsePath"
value="C:/Users/266571/Documents/eclipse/plugins" />
<path id="drools.classpath">
<pathelement location="${droolsPath}/drools-ant-5.2.0.FINAL.jar" />
<pathelement location="${droolsPath}/drools-api-5.2.0.jar" />
<pathelement location="${droolsPath}/drools-core-5.2.0.FINAL.jar" />
<pathelement location="${droolsPath}/drools-compiler-5.2.0.FINAL.jar" />
<pathelement location="${droolsPath}/antlr-runtime-3.3.jar" />
<pathelement location="${droolsPath}/mvel2-2.0.19.jar" />
<pathelement location="${droolsPath}/knowledge-api-5.2.0.Final.jar" />
<pathelement
location="${eclipsePath}/org.eclipse.jdt.core_3.6.2.v_A76_R36x.jar" />
</path>
<path id="model.classpath">
<pathelement location="bin" />
</path>
<taskdef name="compiler" classpathref="drools.classpath"
classname="org.drools.contrib.DroolsCompilerAntTask" />
<target name="rules" >
<compiler
srcdir="${projectPath}src/rules"
tofile="${projectPath}src/rules/rules.pkg"
binformat="package"
classpathref="model.classpath" >
<include name="supportObjects.drl" />
</compiler>
</target>
</project>
My DRL:
package gov.ssa.codedObjects
import gov.ssa.codedObjects.SupportObjectsCollection;
declare SecondaryBrain
name : String
id : int
end
declare ICDCode
code : String
name : String
end
global SupportObjectsCollection supportObjectsList;
rule "Evaluate Coded Object"
when
$codedObject : CodedObject(code == 191.0)
then
SecondaryBrain brain = new SecondaryBrain();
brain.setName("Brain Tumor, Cerebrum");
insert (brain);
end
rule "Evaluate Coded Object Malignent"
when
$codedObject : CodedObject(code == "239.6" || code == "C71.9", $code :
code)
then
ICDCode code = new ICDCode();
code.setCode($code);
code.setName("Neoplasm of uspecified nature of the Brain");
insert(code);
end
rule "Add Brain Neoplasm to List"
when
$code : ICDCode(code == "239.6" || code == "C71.9")
then
supportObjectsList.addToSupportObjects($code);
end
rule "Megaduodenum"
when
$codedObject : CodedObject(code == "537.3" || code == "K59.3", $code :
code)
then
ICDCode code = new ICDCode();
code.setCode($code);
code.setName("Megaduodenum");
insert(code);
end
rule "Add Megaduodenum to List"
when
$code : ICDCode(code == "537.3" || code == "K59.3")
then
supportObjectsList.addToSupportObjects($code);
end
Any suggestions would be helpful.
--
View this message in context: http://drools.46999.n3.nabble.com/Ant-Build-of-PKG-with-Declared-Types-tp...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 3 months
Facing an inconsistent error executing rules during runtime
by S_Kumar_P@DELLTEAM.com
Hi,
I am getting an error at inconsistent intervals while executing one scheduled task, which uses rules, in Websphere AS. Below is the error trace,
[9/22/11 8:57:59:316 CDT] 0000004d SystemErr R Caused by: java.lang.ClassNotFoundException: autoclassification.Rule_10___10_Auto_Classification_0DefaultConsequenceInvoker
at java.lang.Class.forNameImpl(Native Method)
at java.lang.Class.forName(Class.java:163)
at org.drools.rule.DroolsCompositeClassLoader.loadClass(DroolsCompositeClassLoader.java:91)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at org.drools.rule.JavaDialectRuntimeData.wire(JavaDialectRuntimeData.java:312)
at org.drools.rule.JavaDialectRuntimeData.reload(JavaDialectRuntimeData.java:379)
at org.drools.rule.JavaDialectRuntimeData.onBeforeExecute(JavaDialectRuntimeData.java:139)
at org.drools.rule.DialectRuntimeRegistry.onBeforeExecute(DialectRuntimeRegistry.java:132)
at org.drools.compiler.PackageBuilder.reloadAll(PackageBuilder.java:683)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:641)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:266)
at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:458)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:28)
at com.dell.compliance.middleware.ruleengine.RuleEngine.fire(RuleEngine.java:43)
The rules are:
package autoclassification;
import com.dell.compliance.middleware.business.Part;
import java.util.Map;
function boolean like(String masterData, String transData) {
boolean result = false;
if (masterData == null) {
return result;
}
if (transData != null && transData.trim().length() > 0) {
if (transData.trim().startsWith('%')
&& !transData.trim().endsWith('%')) {
result = masterData.endsWith(removeChar(transData));
}
else if (!transData.trim().startsWith('%')
&& transData.trim().endsWith('%')) {
result = masterData.startsWith(removeChar(transData));
}
else if (transData.trim().startsWith('%')
&& transData.trim().endsWith('%')) {
result = masterData.contains(removeChar(transData));
} else {
result = masterData.equals(transData);
}
}
return result;
}
function String removeChar(String transData) {
String str = transData.replaceAll('%', '');
return str;
}
function boolean validateTechAttribute(Map taMap, String attrNames, String attrVals) {
boolean result = false;
if (attrNames == null || attrVals == null) {
return true;
}
if(taMap == null){
return false;
}
String[] attrs = attrNames.split('[|]');
String[] values = attrVals.split('[|]');
String attr = null;
String value = null;
String attrVal = null;
for (int i = 0; i < attrs.length; i++) {
attr = attrs[i] != null ? attrs[i].trim().toUpperCase() : '';
value = values[i] != null ? values[i].trim().toUpperCase() : '';
if (taMap.containsKey(attr)) {
attrVal = (String) taMap.get(attr);
result = like(attrVal, value);
if(result==false){
return result;
}
} else {
return false;
}
}
return result;
}
rule '2 - 2_Auto Classification'
when
part : Part(eval (like(partType,'Hard Drive (NBK)')) , eval (like(partClass,'Drive,Hard')) , eval (validateTechAttribute(techAttrList,'Placement|Encrypted Drive','Internal|No')))
then
part.setPartDesc('HARD DRIVE-INTERNAL');
update(part);
drools.getWorkingMemory().clearAgenda();
end
rule '3 - 3_Auto Classification'
when
part : Part(eval (like(partType,'Hard Drive (NBK)')) , eval (like(partClass,'Drive,Hard')) , eval (validateTechAttribute(techAttrList,'Placement|Encrypted Drive','Internal|Yes')))
then
part.setPartDesc('HARD DRIVE-INTERNAL-ENCRYPTED');
update(part);
drools.getWorkingMemory().clearAgenda();
end
--
--
--
rule '9 - 9_Auto Classification'
when
part : Part(eval (like(partType,'Card,Network')) , eval (like(partClass,'CARD,NETWORK')) , eval (validateTechAttribute(techAttrList,'Wireless |SWIncludesEncryption','no|Yes')))
then
part.setPartDesc('POPULATED PCB-NETWORK-ADAPTER-ENCRYPTED');
update(part);
drools.getWorkingMemory().clearAgenda();
end
rule '10 - 10_Auto Classification'
when
part : Part(eval (like(partType,'Card,Wireless')) , eval (like(partClass,'CARD,NETWORK')) , eval (validateTechAttribute(techAttrList,'Wireless |SWIncludesEncryption','yes|Yes')))
then
part.setPartDesc('POPULATED PCB-NETWORK WIRELESS WLAN');
update(part);
drools.getWorkingMemory().clearAgenda();
end
And the Code loading rules is in RuleEngine.java as:
public void fire(byte[] rules, Object obj) {
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
// this will parse and compile in one step
kbuilder.add(ResourceFactory.newByteArrayResource(rules),ResourceType.DRL);
// Check the builder for errors
if (kbuilder.hasErrors()) {
System.out.println(kbuilder.getErrors().toString());
throw new RuntimeException("Unable to compile drl.");
}
// get the compiled packages (which are serializable)
final Collection<KnowledgePackage> pkgs = kbuilder.getKnowledgePackages();
// add the packages to a knowledgebase (deploy the knowledge packages).
final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(pkgs);
final StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
ksession.addEventListener(new DebugAgendaEventListener());
ksession.addEventListener(new DebugWorkingMemoryEventListener());
// setup the audit logging
//KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "log/drools.log");
ksession.insert(obj);
ksession.fireAllRules();
//logger.close();
ksession.dispose();
}
We used Drools 5.1,
Please help me resolve as soon as possible.
Thanks & Regards
Santhosh
13 years, 3 months
Exception in Banking Tutorial in Drools expert guide...
by Manohar Kokkula
Hi,
I am trying to execute Banking Tutorial Example given in Drools expert(
http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-expert/ht...
),but im getting following error,
Exception in thread "main" java.lang.ClassCastException:
java.util.ArrayList cannot be cast to org.hibernate.mapping.Collection
at com.sample.RuleRunner.runRules(RuleRunner.java:32)
at com.sample.Example1.main(Example1.java:5)
And when i try to resolve this i am getting another error:
java.lang.ArrayIndexOutOfBoundsException: 0
at com.code.RuleRunner.runRules(RuleRunner.java:45)
at com.code.Example1.main(Example1.java:5)
Code snippet :
for (int i=0; i <=facts.length;i++)
{
System.out.println("222");
Object fact = facts[i]; //The error is for this line of
code
System.out.println( "Inserting fact: " + fact );
ksession.insert(fact);
System.out.println("333");
}
could any body help me on this.
Manohar Kokkula
Mailto: manohar.kokkula(a)tcs.com
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you
13 years, 3 months
persisted stateful sessions and knowledge base changes
by Jordi Alvarez
Hello, I am working for an organization for which we have adopted
Drools flow as the BPM solution. We are making use also of Drools
Expert, which results in a nice combination.
We have stateful sessions persisted in a database in order to record
the state of long-time running processes (which are the goal of our
BPM).
In order to make changes to the knowledge-base associated to the
stateful sessions that we have, we always redeploy the whole system
(ear application + rules + process definitions).
This is where we have the problem. Depending on the changes performed
to the database, the system is not able to reload the persisted
sessions (the change could be for example a change in the condition of
a rule). This results in problems and stack traces similar to the
following one:
[...]
Caused by: java.lang.RuntimeException: Unable to load session snapshot
at org.drools.persistence.session.JPASessionMarshallingHelper.loadSnapshot(JPASessionMarshallingHelper.java:96)
at org.drools.persistence.session.SingleSessionCommandService.initKsession(SingleSessionCommandService.java:196)
at org.drools.persistence.session.SingleSessionCommandService.<init>(SingleSessionCommandService.java:159)
... 95 more
Caused by: java.lang.ClassCastException: org.drools.reteoo.ObjectTypeNode
at org.drools.marshalling.impl.InputMarshaller.readRightTuple(InputMarshaller.java:401)
at org.drools.marshalling.impl.InputMarshaller.readRightTuples(InputMarshaller.java:391)
at org.drools.marshalling.impl.InputMarshaller.readFactHandles(InputMarshaller.java:326)
at org.drools.marshalling.impl.InputMarshaller.readSession(InputMarshaller.java:205)
at org.drools.marshalling.impl.DefaultMarshaller.unmarshall(DefaultMarshaller.java:91)
at org.drools.persistence.session.JPASessionMarshallingHelper.loadSnapshot(JPASessionMarshallingHelper.java:91)
... 97 more
According to some posts, if we were using the knowledge agent we could
update the already loaded sessions, which would allow to migrate
in-memory sessions from the old database to the new database:
http://drools.46999.n3.nabble.com/Dynamic-updates-of-stateful-sessions-td...
http://stackoverflow.com/questions/4368148/is-it-possible-to-add-a-new-ru...
Nevertheless, we absolutely need a way to migrate persisted sessions
from the old database to the new one. Even in the situation in which
we would allow hot modification of the knowledge base, we cannot have
all the stateful sessions loaded in memory when this would happen.
Is there any facility provided by Drools Expert/Flow that allows to
perform this operations easily? Is there a way/configuration to
load/save sessions without the need to store/retrieve the rete-tree
(and instead recomputing it), which seems to be the problem for these
situations.
Many thanks in advance,
Jordi Alvarez
13 years, 3 months
Persistence of events
by Maciej Prochniak
Hello,
Is it possible to persist events (from drools fusion) with default jpa
mechanism? When I try to do this 'just like that' I get exception
like
org.drools.common.DefaultFactHandle incompatible with
org.drools.common.EventFactHandle
It seems that session marshaller is not really aware of certain objects
being events, not facts.
The code I try is more or less like:
UserTransaction ut = ...
StatefulKnowledgeSession session = JPAKnowledgeService
.newStatefulKnowledgeSession(kbase, null, env);
ut.begin()
session.insert(e1);
ut.commit();
StatefulKnowledgeSession sessionPersisted =
JPAKnowledgeService.loadStatefulKnowledgeSession( session.getId(),
kbase, null, env );
ut.begin()
sessionPersisted.insert(e2); (*) <- fails
ut.commit();
When I use session instead of sessionPersisted - it works fine, when
e2 is a fact, not an event - it also works
I know that it may be awkward to persist events which have time
limitations, but I want to use time limits in rules which are like few
days - so I want to have some persistence in case of server shutdown.
I would be grateful for any comment,
br,
maciek prochniak
13 years, 3 months
accumulate function
by pamerida
Hi everyone,
I have this scenario:
I have assserted a few elements of the type "SegmentGroup8" into the working
memory, this SegmentGroup8 class have inside a list called private
List<ControlTotal> cnt;
What I need to achieve is to perform a "sum" of one of the fields called
c6066 inside the ControlTotal for all the SegmentGroup8 asserted into the
WM...
I would like to use the accumulate functions but I really dont know how, any
help would be appreciated, thanks in advance...
the classes code is the following...
public class SegmentGroup8
implements Serializable
{
private List<ControlTotal> cnt;
private List<MonetaryAmount> moa;
public List<ControlTotal> getCnt() {
return cnt;
}
public void setCnt(List<ControlTotal> cnt) {
this.cnt = cnt;
}
......
}
public class ControlTotal extends Segment
implements Serializable
{
private String c6069;
private String c6066;
........
public String getC6069() {
return c6069;
}
public void setC6069(String c6069) {
this.c6069 = c6069;
}
public String getC6066() {
return c6066;
}
public void setC6066(String c6066) {
this.c6066 = c6066;
}
.........
}
--
View this message in context: http://drools.46999.n3.nabble.com/accumulate-function-tp3353507p3353507.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 3 months
rules for promotional offers
by Sandeep Bandela
Hi,
I am new to rules engine, after going through the examples shipped
(shopping.drl, petstore.drl)
I am trying to implement promotional discounting using drools 5.2.0 final,
stateful session. assume cart has all the items that customer wants to buy,
I am trying to bundle them together with the existing offers
rule "Buy X units of Product A and Get Y units of Product B Free"
dialect "java"
when
$itemsA : ArrayList( size >= 2) from collect( CartItem( getProductId()
== "A", !isProcessed()))
$itemsB : ArrayList( size >= 1) from collect( CartItem( getProductId()
== "B", !isProcessed()))
then
// current scenario buy 2*A and get 1*B
int x = 2;
int y = 1;
for(int i=0 ; i < x ; i++){
CartItem $ci = (CartItem) $itemsA.get(i);
// modify($ci){setProcessed(true) ... } dosent work
$ci.setProcessed(true);
$ci.setItemDiscount(0.0);
$ci.setBundleId(bundler.getId());
}
for(int i=0 ; i < y ; i++){
CartItem $ci = (CartItem) $itemsB.get(i);
$ci.setProcessed(true);
$ci.setItemDiscount($ci.getPrice());
$ci.setBundleId(bundler.getId());
}
// global counter to identify bundled items
bundler.increment();
end
the above rule calculates only for 1 set of offer i.e first 2*A & 1*B are
considered, rest in the cart are not bundled.
if customer buys 4*A + 2*B it dosent consider it. am I missing anything? is
this the right way to do it?
any feedback is appreciated.
--
Regards,
Sandeep Bandela.
13 years, 3 months
questions about Drools Fusion perfomance
by Murilo Lima
Hi,
I am planning to use Drools Fusion in a monitoring application, but I have
some performance and fault-tolerance issues.
The idea is to monitor if some measurements are within a parameter defined
on a baseline. The baselines themselves are calculated based on previous
measurements. For example, I want to monitor if a measurement is close to
the average of previous measurements at the same weekday.
My worry is that the volume of measurements is very high, and I need the
average of the measurements over a long period of time. Clearly, I see that
it would be better to use the average of the whole set of measurements
(instead of the average of a sliding window, or setting an expiration for
the events) and calculate the averages in an online fashion, so as not to
keep the measurements in memory. I want to know if Drools Fusion accumulate
functions work that way, or if I need to retract the events myself.
Another question is: if, for some reason, I have to stop the monitoring
application, will Drools Fusion automatically keep track of its internal
state? In the previous example, would I have to provide myself a way to save
the averages on disk, or Drools Fusion would take care of it? I didn't see
anything like that on the documentation.
Thanks for any help,
Murilo
--
View this message in context: http://drools.46999.n3.nabble.com/questions-about-Drools-Fusion-perfomanc...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 3 months