Importing Rules as Object into KnowledgeBuilder
by Bojan Janisch
Hello everyone,
is there a way to import Rules as Objects into the Knowledgebase? So far I've seen, Drools supports only Bytearray, Files and InputStream as Rule Resources.
Greetings
Bojan
12 years, 11 months
Fetch Packages using REST api --> KnowledgeBuilder
by Charles Moulliard
Hi,
Using the following code, I can fetch the packages from Guvnor using Rest
API (source) but How can I next create a KnowledgeBuilder based on the
source of Packages retrieved ?
My idea is to use ResourceFactory.
// Fetch Packages from Guvnor
URL url = new URL("
http://127.0.0.1:8080/guvnor.war/rest/packages/mortgages/source");
HttpURLConnection connection = (HttpURLConnection)
url.openConnection();
connection.setRequestProperty("Authorization",
"Basic " + new
Base64().encodeToString(("admin:admin".getBytes())));
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", MediaType.WILDCARD);
connection.connect();
System.out.println("ResponseCode: " + connection.getResponseCode());
System.out.println("MediaType: " + connection.getContentType());
String packages = IOUtils.toString(connection.getInputStream());
InputStream is = connection.getInputStream();
Regards,
--
Charles Moulliard
Apache Committer / Sr. Enterprise Architect (RedHat)
Twitter : @cmoulliard | Blog : http://cmoulliard.blogspot.com
12 years, 11 months
facing problem in KnowledgeAgent
by himansh
Hi,
I am new in guvnor, please help me
my code are bellow
package com.sample;
import org.drools.KnowledgeBase;
import org.drools.RuleBase;
import org.drools.WorkingMemory;
import org.drools.agent.KnowledgeAgent;
import org.drools.agent.KnowledgeAgentFactory;
import org.drools.agent.RuleAgent;
import org.drools.definition.KnowledgePackage;
import org.drools.definition.type.FactType;
import org.drools.runtime.StatefulKnowledgeSession;
@SuppressWarnings("restriction")
public class DroolDemo {
/**
* @param args
* @throws IllegalAccessException
* @throws InstantiationException
*/
public static void main(String[] args) throws
InstantiationException,
IllegalAccessException {
KnowledgeAgent ruleAgent =
KnowledgeAgentFactory.newKnowledgeAgent("/Guvnor.properties");
System.out.println(ruleAgent.getKnowledgeBase().getFactType("org.sample","NumberTest"));
KnowledgeBase ruleBase = ruleAgent.getKnowledgeBase();
System.out.println(ruleBase.getFactType("org.sample","NumberTest"));
FactType factType =
ruleBase.getFactType("org.sample","NumberTest");
Object obj = factType.newInstance();
factType.set(obj, "numberone", 2);
factType.set(obj, "numbertwo", 1);
StatefulKnowledgeSession workingMemory =
ruleBase.newStatefulKnowledgeSession();
workingMemory.insert(obj);
workingMemory.fireAllRules();
System.out.println(factType.get(obj, "message"));
}
}
======================================================
Guvnor.properties:
url=http://localhost:8080/guvnor/org.drools.guvnor.Guvnor/package/org.sample/testSnapShort2
enableBasicAuthentication=true
username=admin
password=admin
name=drooltest
======================================================
Output:
null
null
Exception in thread "main" java.lang.NullPointerException
at com.sample.DroolDemo.main(DroolDemo.java:34)
======================================================
please help me
thanks,
Him
--
View this message in context: http://drools.46999.n3.nabble.com/facing-problem-in-KnowledgeAgent-tp4023...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 11 months
Open review request for e-book
by Jeremy Ary
Hi all,
I've been given the opportunity to offer a limited number of copies of my
new Instant Drools Starter e-book from Packt Publishing free to interested
parties in return for a blog or consumer review on sellers such as Amazon.
I wanted to offer this to the mailing list community as there are several
loyal members and insightful minds that I'd like to offer to first as a way
of saying thanks for all the help both past and future.
If you're interested, please *EMAIL ME at jeremy.ary(a)gmail.com*. *PLEASE* *DO
NOT reply here in-thread*, as I do not wish to abuse this forum and flood
the list with replies.
More info on book: http://www.packtpub.com/getting-started-with-drools/book
Thanks for your time,
Jeremy Ary
12 years, 11 months
Fusion: Custom Temporal Operators?
by burmanator
Is it possible to create custom temporal operators?
I want to create something like:
$eventA : EventA( this afterStart[3m30s,4m] $eventB)
which would be evaluated as
3m30s <= $eventA.startTimestamp - $eventB.startTimestamp <= 4m
or
$eventA : EventA( this during2 $eventB)
where
$eventB.startTimestamp <= $eventA.startTimestamp<= $eventA.endTimestamp <=
$eventB.endTimestamp
as well as create various others.
--
View this message in context: http://drools.46999.n3.nabble.com/Fusion-Custom-Temporal-Operators-tp4023...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 11 months
Strange error using Drools + Spring + DecisionTable
by Charles Moulliard
Hi,
When I try to instantiate an Excel Decision Table using Drools + Spring
(kresource), I get this error :
REMARK: the file is the same as we have in Drools Unit Test (decision-table)
Error :
Caused by: java.lang.IllegalArgumentException: Your InputStream was neither
an OLE2 stream, nor an OOXML stream
at
org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:75)
at
org.drools.decisiontable.parser.xls.ExcelParser.parseFile(ExcelParser.java:75)
at
org.drools.decisiontable.SpreadsheetCompiler.compile(SpreadsheetCompiler.java:93)
at
org.drools.decisiontable.SpreadsheetCompiler.compile(SpreadsheetCompiler.java:72)
at
org.drools.decisiontable.DecisionTableProviderImpl.compileStream(DecisionTableProviderImpl.java:37)
at
org.drools.decisiontable.DecisionTableProviderImpl.loadFromInputStream(DecisionTableProviderImpl.java:20)
at
org.drools.compiler.compiler.DecisionTableFactory.loadFromInputStream(DecisionTableFactory.java:15)
at
org.drools.compiler.compiler.PackageBuilder.decisionTableToPackageDescr(PackageBuilder.java:460)
at
org.drools.compiler.compiler.PackageBuilder.addPackageFromDecisionTable(PackageBuilder.java:454)
at
org.drools.compiler.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:684)
at
org.drools.compiler.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:51)
at
org.drools.compiler.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:40)
at
org.drools.container.spring.beans.KnowledgeBaseBeanFactory.afterPropertiesSet(KnowledgeBaseBeanFactory.java:110)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
Config :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:drools="http://drools.org/schema/drools-spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://drools.org/schema/drools-spring
http://drools.org/schema/drools-spring.xsd">
<drools:grid-node id="node1"/>
<drools:kbase id="kbase1" node="node1">
<drools:configuration>
<drools:mbeans enabled="true"/>
</drools:configuration>
<drools:resources>
<drools:resource type="DTABLE"
source="classpath:data/IntegrationExampleTest.xls"/>
</drools:resources>
</drools:kbase>
<drools:ksession id="ksession1"
type="stateless"
name="ksession1"
kbase="kbase1"
node="node1"/>
</beans>
Regards,
--
Charles Moulliard
Apache Committer / Sr. Enterprise Architect (RedHat)
Twitter : @cmoulliard | Blog : http://cmoulliard.blogspot.com
12 years, 11 months
Does KnowledgeRuntimeLogger work with persistence?
by dunnlow
I am using Drools 5.5 with persistence. If I create a session like:
ksession = kbase.newStatefulKnowledgeSession(null,env);
My logger works as expected:
KnowledgeRuntimeLogger klogger =
KnowledgeRuntimeLogger.newFileLogger(ksession,"run")
HOWEVER, if I create the ksession like:
ksession =
JPAKnowledgeService.newStatefulKnowledgeSession(kbase,null,env)
my klogger file (run.log) is never created.
Is this expected? Is there a way to get a runtime log using persistence?
Thanks!
--
View this message in context: http://drools.46999.n3.nabble.com/Does-KnowledgeRuntimeLogger-work-with-p...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 11 months
Rule triggering problem with Drools
by JuaneGaragorri
Hi everyone,
I'm relatively new at rule development and I'm having a problem tryin' to
implement one in particular.
I need to capture some events that they've got the same AttributeA and got
more than 9 AttributeB Objects (excluding one type in particular) in one or
more events.
*Model:*
Class Event {
Long id;
AttributeA attributeA;
List<AttributeB> listAttributeB;
Date timestamp;
Long duration;
}
Class AttributeA {
Long id;
double doubleValue;
String name;
}
Class AttributeB {
Long id;
String name;
String someString;
Boolean flag;
}
class AttributeBMock {
//it doesn't have any of "one_type_of_attB"
public List<AttributeB> getTenAttributeB() {
return Arrays.asList(new AttributeB(000001L, 23.4, "random_string_1"),
new AttributeB(000006L, 38.9, "random_string_2"),
new AttributeB(000005L, 35.2, "random_string_3"),
new AttributeB(000003L, 32.5, "random_string_4"),
new AttributeB(000006L, 32.5, "random_string_5"),
new AttributeB(000007L, 23.4, "random_string_6"),
new AttributeB(0000012L, 23.4, "random_string_7"),
new AttributeB(000015L, 44.4, "random_string_8"),
new AttributeB(000010L, 87.0, "random_string_9"),
new AttributeB(000010L, 87.0, "random_string_10"));
}
}
-----------------------------------------------------------------------------------
*Test:*
public void someMethod() {
SessionPseudoClock clock = (SessionPseudoClock) ruleEngine.getClock();
clock.advanceTime(10, TimeUnit.SECONDS);
//Just with this insertion i get the ArrayOutOfBounds exception
ruleEngine.addEvent(new Purchase(123456L,new AttributeA(),
AttributeBMock.getTenAttributeB(),new Date(clock.getCurrentTime(),0L));
Assert.assertTrue("The rule hasn't been fired", Assert.assertFalse("The rule
hasn't been fired",
ruleEngine.getEventListener().getExecutedRulesNames().containsAll(EXPECTED_RULES_NAMES));
}
-------------------------------------------------------------------------------------------------------
*Rule:*
when
$event: event($attributeA : attributeA, attributeA.flag == true,
$listAttributeB : listAttributeB) from entry-point "some_entry_point"
$quantity: List() from collect($attributeB : attributeB(name !=
'one_type_of_attB') from $listAttributeB)
Number(doubleValue > 9)
from accumulate(event(attributeA == $attributeA) from entry-point
"some_entry_point",
sum($quantity.size))
then
System.out.println("Event: " + $event.id );
end
-----------------------------------------------------------------
Everytime when I fire an event that triggers the rule, the accumulate method
throws an "ArrayOutOfBounds" exception. I don't know why, the logic looks
good to me.
Can I get some help, please?
Thx. in advance
Regards
--
View this message in context: http://drools.46999.n3.nabble.com/Rule-triggering-problem-with-Drools-tp4...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 11 months
Drools Fusion: Finding an event that occuring after an event but not before it
by burmanator
I am trying to track when an event object Foo with a distinguishing
identifier of Status.
I want to try and identify a list of events when a Foo event with Status 2
happens after an event with Status 1 but at the same time a Status 1 has not
happened before.
fight now I've come up with:
$foo1 : Foo($status : Status)
not(Foo(Status == $status. this before $foo1))
$foos : ArrayList (size>0) from collect ( Foo(Status != $status, this after
$foo1))
Part of the problem I am having, is that a Foo event with the same Status
can happen at the same timestamp. How do I get it to work so the rule only
triggers once for multiple events on the same timestamp?
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Fusion-Finding-an-event-that-occ...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 11 months