How to create object model (parse into object) from mvel string in drl file?
by neal
Below is the template to generate the rule statement (It is basic one).
What I want to do is to read the string and convert into object.
package @{package};
@foreach{importEntry : imports}
import @{importEntry};
@end{}
@foreach{importEntry : staticImports}
import static @{importEntry};
@end{}
rule "@{ruleName}"
dialect "@{dialectName}"
salience @{salienceValue}
enabled @{enableValue}
when
@foreach{modelObject : modelObjects} @{modelObject.referenceName} :
@{modelObject.referenceType} ( @foreach{ attribute : modelObject.attributes}
@{attribute.name} @{attribute.operator} "@{attribute.value}" @end{} ) @end{}
then
// tempate data to set attribute
end
/ code to run the tempate
TemplateRegistry RULE_REGISTRY = new SimpleTemplateRegistry();
RULE_REGISTRY.addNamedTemplate( "rules",
getCompiledTemplate(prepareSimpleTemplate()));
System.out.println(TemplateRuntime.execute(
RULE_REGISTRY.getNamedTemplate( "rules" ),
getMap(),RULE_REGISTRY ));
}
// method to get tempate in string
public static String prepareSimpleTemplate() {
return StringUtils.readFileAsString(new InputStreamReader(
MvelDemo.class.getResourceAsStream("RuleTemplate.mvel")));
}
The rule statement generated is:
package some;
import rout.Vo;
rule "Row_001"
dialect "mvel"
salience 10
enabled true
when
vo : Vo ( type_code == "S" )
then
vo.a_name = "X"
end
How to generate object model from String generated from MVEL template? Is
there any parser available to convert String into Object model in MVEL?
--
View this message in context: http://drools.46999.n3.nabble.com/How-to-create-object-model-parse-into-o...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 6 months
named consequences for an or...
by pmander
I was using or in a rule for example
rule "or example"
when
$t : (Transaction(org == "us") or Transaction(acc == "111"))
then
insert(new Record($t, 1));
end
This would work but would create 2 Record objects which we sorted out later
on but now for performance reasons I don't want the second match to be
evaluated if the first one matches. I saw a post about named consequences
and came up with something like:
when
$t : Transaction(org == "us")
if ($t != null) break[t1]
$t1 : Transaction(acc == "111")
then
insert(new Record($t1, 1));
then[t1]
insert(new Record($t, 1));
end
This compiles but the "or" doesn't work. This is probably due to my "break".
Is there a way I can do what I need?
Note that the performance implication of performing the or is not apparent
in this example but it is there - I have simplified this example to make it
easier to talk about (and to protect the innocent)
--
View this message in context: http://drools.46999.n3.nabble.com/named-consequences-for-an-or-tp4027775....
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 6 months
Unable to figure out few feature for tomcat7 deployment
by Mohit Srivastava
Hi,
I deployed drools workbench on tomcat. Guide only explains every thing on
Wildfly or JBOSS EPA cluster
But I am unable to figure out following things:
- How to add new user?
- How to change system properties?
Thanks
--
Mohit
10 years, 6 months
Issue with Kie-cli-config
by Soumya.plavaga
Hi,
I tried to use kie-cli-config tools but it is not getting worked. I have
downloaded the zip distribution of that as mentioned in doc but when I am
running the kie-clie-config.sh file it's not resolving the main method under
CmdMain class. I have also tried to add the maven dependency for
'kie-cli-config' in my java project and tried to execute the main method
it's giving some exception at the point where initializing the clicontext.
It's giving exception in the following line -
bootstrap.validateBeans(); (within -
org.jboss.weld.environment.se.Weld.initialize()).
Exception coming -
Unsatisfied dependencies for type [ServletContext] with qualifiers [@Named]
at injection point [[field] @Inject @Named private
org.uberfire.backend.server.plugin.RuntimePluginsServiceServerImpl.servletContext]
Hence I can not go forward after this. Looks like ServletContext is not
getting resolved within 'RuntimePluginsServiceServerImpl' class. Can you
please confirm if this is an issue ? In that case what will be the work
around we will use?
Any help will be really appreciated.
Many Thanks,
Soumya
--
View this message in context: http://drools.46999.n3.nabble.com/Issue-with-Kie-cli-config-tp4027737.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 6 months
How to generate rule statements using MVEL 2.0 template?
by neal
I came to know through drool user forum that a drl file can be created using
recursive MVEL 2.0 template.
I am trying like below.
public static String prepareRule(String RuleName){
String template = "\n rule \""+RuleName+"\" "+
"\n dialect \"mvel\" "+
"\n salience \"10\" " +
"\n when" +
"\n demo : Demo( one == \"N\" , two == \"C\" , three == 1005 )" +
"\n then" +
"\n demo.setFirst( 4003 );" +
"\n demo.setLast( 4003 );" +
"\n demo.setRuleID( \"SEQ_1\" );";
return template;
}
public static String getRuleAsString(String template){
Map vars = new HashMap();
return (String) TemplateRuntime.eval(template,vars);
}
public static void main(String[] args) {
System.out.println(getRuleAsString(prepareRule("Rule 1")));
}
When i am printing it out, It is generating rule skeleton. I am planning to
create whole rule stuff passing arguments like rule name in the example. Am
i doing correct?
How to do it correctly?
--
View this message in context: http://drools.46999.n3.nabble.com/How-to-generate-rule-statements-using-M...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 6 months
No inferred expiration when correlating events in Drools Fusion
by Alexandre Gattiker
Hello,
I am trying to use Drools Fusion (5.6.0 or 6.0.1) to correlate events, but
can't get the internal mechanism for expiring events to work in my rule.
I made up a simple example that detects duplicate messages over a short
time window. The rule below seems to work fine, but facts accumulate
indefinitely in the working memory. Changing window:length(1) to
window:time(10s) does not solve the issue.
declare DataEvent
@role(event)
end
rule "Detect duplicates"
when
DataEvent ( $text: text ) over window:length(1)
ArrayList( size >= 2 ) from collect( DataEvent( text == $text ) over
window:time( 10s ) )
then
System.err.println("Duplicate detected");
end
Now, if I change my condition to the following, I see that facts
automatically expire and are retracted after 10 seconds.
...when
ArrayList( size >= 10 ) from collect( DataEvent( ) over window:time(
10s ) )
then...
Many thanks in advance.
10 years, 6 months
Unable to deploy drool-workbench on tomcat 7
by Mohit Srivastava
Hi Everyone,
I tried to deploy drool-workbench on tomcat 7 . But I have encountered with
errors.
I am unable to figure out the reason, I like to get some help from you guys
.
2014-01-18 19:44:12,202 [http-bio-8081-exec-2] INFO KieModule was
added:ZipKieModule[
ReleaseId=org.drools:drools-wb-rest-defaultapprover:6.0.1.Finalfile=/usr/tomcat/apache-tomcat-7.0.50/webapps/drools-wb-6.0.1.Final-tomcat7.0/WEB-INF/lib/drools-wb-rest-defaultapprover-6.0.1.Final.jar]
2014-01-18 19:44:17,512 [http-bio-8081-exec-2] ERROR Failed to setup
Repository 'uf-playground'
java.lang.RuntimeException:
org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out:
NativeFSLock(a)/.index/write.lock
at
org.uberfire.metadata.backend.lucene.setups.DirectoryLuceneSetup.<init>(DirectoryLuceneSetup.java:78)
~[uberfire-metadata-backend-lucene-0.3.1.Final.jar:0.3.1.Final]
at
org.uberfire.metadata.backend.lucene.setups.NIOLuceneSetup.<init>(NIOLuceneSetup.java:31)
~[uberfire-metadata-backend-lucene-0.3.1.Final.jar:0.3.1.Final]
2014-01-18 19:44:17,926 [http-bio-8081-exec-2] ERROR Can't initialize
FileSystemProviders
java.util.ServiceConfigurationError:
org.uberfire.java.nio.file.spi.FileSystemProvider: Provider
org.uberfire.java.nio.fs.jgit.JGitFileSystemProvider could not be
instantiated: org.uberfire.java.nio.IOException: java.net.BindException:
Address already in use
Thanks
--
Mohit
10 years, 6 months
Guvnor enumerations
by Stephen Masters
Hi folks,
I don't suppose anything notable changed between 5.3 and 5.5 in the way Guvnor loads data enumerations?
I have a number of enumerations similar to the following:
'MyFact.currencies' : (new com.myapp.guvnor.enums.CurrencyEnum()).isoCodes()
But I see the exception in Guvnor:
Unable to load enumeration data.
[Error: unable to invoke method: isoCodes] [Near :{... 'MyFact.': ….}] ^ [Line: 1, Column: 1]
Error type: org.mvel2.PropertyAccessException
The jar is in the lib directory, there is a method called "isoCodes()", and when I run the main class inside it then the various enumerations are returned. And yes, it did (does) work absolutely fine in 5.3 with this same configuration.
Steve
10 years, 6 months
Drools 6.0.0 Camel-server query results
by akjones33
Hi all - I'm just getting started with Drools and trying to get my first
query running through Camel-Server using XML. I had expected that a query
would return the objects found, with their attributes as XML elements but I
only get an identifier.
The query is
query "depositAccept"
dA: DepositAccept();
end
DepositAccept is defined in java as
public class DepositAccept {
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
In my XML batch execution command I have
<batch-execution lookup="ksession2">
<insert out-identifier="person1">
<samples.banking.Deposit>
<accountNumber>1</accountNumber>
<amount>1001</amount>
</samples.banking.Deposit>
</insert>
<fire-all-rules max="-1"/>
<query name="depositAccept" out-identifier="person2"/>
</batch-execution>
which gives me the response
<execution-results>
<result identifier="person1">
<samples.banking.Deposit>
<accountNumber>1</accountNumber>
<amount>1001</amount>
</samples.banking.Deposit>
</result>
<result identifier="person2">
<query-results>
<identifiers>
<identifier>dA</identifier>
</identifiers>
</query-results>
</result>
<fact-handle identifier="person1"
external-form="0:1:1485038299:1485038299:1:DEFAULT:NON_TRAIT"/>
</execution-results>
I take that to mean that "dA" exists (i.e. the query returns one object) but
I would have expected then to have the "message" attribute shown from the
DepoistAccount object that dA refers to. Is that possible ?
thanks
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-6-0-0-Camel-server-query-results...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 6 months
Planner with a list of planning variables
by Justin Case
Hello all,
can I use as planning variable a list of values?
Here's a test use case: planning a food recipe, where the recipe can have say maximally 5 ingredients (taken from the solution property, I guess). So far I could find in the examples and documentation, it's all about ONE planning variable in the solution, but here I'd need a LIST of such... is it actually doable this way?
I cannot do it the other way around, as an ingredient may be found in more recipes...
Many thanks,
JC
10 years, 6 months