Dynamic Fact(field) Generation in Declarative Model
by srinivasasanda
Hi All,
Please help on this issue
I created a declarative model Person in personDetails package in Drools
Gunvor with 2 fields(age,amount).Now,I need to insert one field with name
gender and datatype String into that declarative model through POJO
class..Here is my code
RuleAgent agent = RuleAgent.newRuleAgent("/Guvnor.properties");
RuleBase rb = agent.getRuleBase();
WorkingMemory workingMemory = rb.newStatefulSession();
PackageBuilder pkgBuilder=new PackageBuilder(rb);
FactType personType = rb.getFactType( "persondetails.Person" );
ClassDefinition cDefinition=(ClassDefinition)
rb.getFactType("persondetails.Person");
FieldDefinition gen = new FieldDefinition( "gender",
"java.lang.String" );
product.setKey(true);
cDefinition.addField(product);
workingMemory.insert(cDefinition);
FactHandle fc=workingMemory.getFactHandle(cDefinition);
workingMemory.update(fc, cDefinition);
rb.newStatelessSession().execute(new Object[] {cDefinition});
}
String s1=cDefinition.getField(0).getTypeName();
String name1=cDefinition.getField(0).getName();
System.out.println(s1);
System.out.println(name1);
String s2=cDefinition.getField(1).getTypeName();
String name2=cDefinition.getField(1).getName();
System.out.println(s2);
System.out.println(name2);
String s3=cDefinition.getField(2).getTypeName();
String name3=cDefinition.getField(2).getName();
System.out.println(s3);
System.out.println(name3);
Output as Age---Java.lang.Integer
Amount-java.lang.Integer
Gender--Java.lang.String..
And when i am printing
It is executing successfuly first time without errors.but i could not find
gender in declarative model.It is failed to inserting.Can anyone help me in
this..plZzzzzz...I was struggling with this....
When Iam executing second time it is displaying as Exception:couldnot find
gender in declarative model..It means iam unable to commit Data into
Server..(Drools guvnor Model)
Please help on this....
--
View this message in context: http://drools.46999.n3.nabble.com/Dynamic-Fact-field-Generation-in-Declar...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 1 month
Planner 5.3.Final - "presumedScore is corrupted" when using "update" on the rules working memory
by guyramirez
I am looking into Planner for a schedule assignment business case.
I created a move factory, got the local search phase set up and quicly ran
into a "presumedScore is corrupted because it is not the realScore" error.
As a work around, I changed my Move::doMove(..) implementation to "retract"
then "insert" rather than "update" the new updated planning entity and the
issue went away.
Then I worked on setting a construction heuristic and I again ran into the
same error. By applying a local code patch to the
PlanningValueWalker::changeWorkingValue(..) method to also "retract" and
"insert" rather than "update" also fixed the issue.
I also tried to correctly implement the hashCode() and equals(..) methods on
my planning entity (as mentioned in Drools Expert documentation) as well as
use the default implementation of those methods (as in the nurse rostering
example) with the same unsuccessful results.
I must mention than I am able to run the nurse rostering example without any
issues.
Could someone maybe point me to the right direction on why "update" does not
work for me? I can provide detailed information if needed.
Thanks,
Guy
--
View this message in context: http://drools.46999.n3.nabble.com/Planner-5-3-Final-presumedScore-is-corr...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 1 month
'else' in rule
by snehils
Hi All,
I want to take action when the condition in WHEN fails. Something like as
follows:
WHEN
<Condition>
THEN
<Action>
/ELSE
<Action when Condition fails>/
Is it possible to have else part in rule? Or I have to make another rule for
failed condition?
I am using Drools 5.1.0 version.
--
View this message in context: http://drools.46999.n3.nabble.com/else-in-rule-tp3264337p3264337.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 1 month
Drools Ruleflow persistence on MySQL - invalid SQL query generated
by victorC
Hi,
After few days of struggling on Drools Ruleflow persistence setup on MySQL I
finally came to the point when I feel it almost works but I am getting an
MySQL error.
I see the following SQL query in the log /it does not look correct/ which
is followed by the MySQL error message.
select processins0_.InstanceId as col_0_0_ from ProcessInstanceInfo
processins0_, EventTypes eventtypes1_ where
processins0_.InstanceId=eventtypes1_.InstanceId and (? in (.))
WARN [JDBCExceptionReporter] SQL Error: 1064, SQLState: 42000
ERROR [JDBCExceptionReporter] You have an error in your SQL syntax; check
the manual that corresponds to your MySQL server version for the right
syntax to use near '))' at line 1
I googled for similar symptoms but with no success.
Will be very grateful for any support, hint, etc!
My setup is:
JBoss 4.2.3.GA
Hibernate 3.2.4.sp1
JBoss Seam 2.2.0.GA
Drools 5.1.1
MySQL 5.1.41 / mysql-connector 5.0.7
persistence.xml
...
<persistence-unit name="org.drools.persistence.jpa" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/edento-MySQL-ds-XA</jta-data-source>
<mapping-file>META-INF/orm.xml</mapping-file>
<class>org.drools.persistence.session.SessionInfo</class>
<class>org.drools.persistence.processinstance.ProcessInstanceInfo</class>
<class>org.drools.persistence.processinstance.WorkItemInfo</class>
<class>org.drools.persistence.processinstance.variabletypes.VariableInstanceInfo</class>
<class>org.drools.persistence.processinstance.variabletypes.JPAPersistedVariable</class>
<class>org.drools.persistence.processinstance.variabletypes.SerializablePersistedVariable</class>
<properties>
<property name="hibernate.dialect"
value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
</properties>
</persistence-unit>
...
datasources-ds.xml
…
<xa-datasource>
<jndi-name>MySQL-ds-XA</jndi-name>
<xa-datasource-property
name="URL">jdbc:mysql://localhost:3306/db</xa-datasource-property>
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
<user-name>root</user-name>
<password></password>
<track-connection-by-tx>true</track-connection-by-tx>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
<min-pool-size>1</min-pool-size>
<max-pool-size>10</max-pool-size>
<idle-timeout-minutes>10</idle-timeout-minutes>
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</xa-datasource>
...
orm.xml
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
version="1.0">
<named-query name="ProcessInstancesWaitingForEvent">
<query>
select
processInstanceInfo.processInstanceId
from
ProcessInstanceInfo processInstanceInfo
where
:type in (processInstanceInfo.eventTypes)
</query>
</named-query>
</entity-mappings>
The bean java code – just starts the process and then immediately attempts
to load it from the database.
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("org.drools.persistence.jpa");
Environment env = KnowledgeBaseFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
env.set(EnvironmentName.GLOBALS, new MapGlobalResolver());
StatefulKnowledgeSession ksession =
JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
WorkflowProcessInstance processInstance =
(WorkflowProcessInstance)ksession.startProcess("TestProcess");
//retrieving...
ksession =
JPAKnowledgeService.loadStatefulKnowledgeSession(ksession.getId(), kbase,
null, env);
processInstance =
(WorkflowProcessInstance)ksession.getProcessInstance(processInstance.getId());
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Ruleflow-persistence-on-MySQL-in...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 1 month
duration attribute & other rule language features issue
by Prashant Badhe
Hi,
we were using drools engine 5.0.1 version with rules having 'duration',
'agenda-group' attributes and now we want to upgrade drools engine to 5.1.1
or latest 5.3.0 but we find 'duration' feature not working. What are the
equivalents of those features in 5.1.1 and in 5.3.0?
>From drools-expert document, 'duration' seems as deprecated with 'timer'.
But even 'timer' is not working. Putting 'timer' attribute as:
rule "test timer attribute"
agenda-group "enrichment"
auto-focus true
no-loop
salience 140
timer ( int: 5s )
//duration ( 5000 )
when
......
then
......
end
gives "Error: java.lang.ArrayStoreException" Drools compilation error.
"timer ( 5s )" compiles, but the rule never fires.
We are also planning to use @expires in declare. But facts are not seems to
be expiring.
What am I missing here? What are the equivalent for 'duration' in
5.1.1/5.3.0 and how to use @expires in declare?
Please point us to some sample rules that uses these semantics and are
working.
Thanks in advance,
Prashant B.
14 years, 1 month
MVEL expression
by Femke De Backere
Hi,
The following expression keeps returning the error [112,32]: [ERR 103]
Line 112:32 no viable alternative at input '+' in rule "RuleFlow-Split-
masterproef.ruleflows.shortsedation-18-22" in pattern Patient:
Patient(sedation.ultiva+0.02 > 0.1)
with sedation.ultiva returning a double
What am I doing wrong?
Thx,
Femke
14 years, 1 month
facts custom sort
by Syargey
Hello all,
I experienced a problem I can't solve.
After rules firing I got a number of facts of certain type.
I would like to get a collection of facts sorted by custom field with a
query.
Drools guide proposes to sort facts by a rule like:
rule "Rule 03"
when
$number : Number( )
not Number( intValue < $number.intValue )
then
System.out.println("Number found with value: "+$number.intValue() );
retract( $number );
end
But it doesn't suit me:
1) I can't retract facts from session
2) I need to get sorted collection with a query which doesn't have 'then'
part.
Is there any method to get custom sorted collection with a query?
--
View this message in context: http://drools.46999.n3.nabble.com/facts-custom-sort-tp3538410p3538410.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 1 month
removing reference to Global Data Model from Drools Package in Guvnor
by Welsh, Armand
Hello community,
I have noticed in interesting paradox in Guvnor.
If I promote my data model to the Global package, I can then import the model from global into my individual packages, so that I can update the model once, and all packages that use the model automatically have the new model.
However, I have a need to remove the imported model from one of my packages.
If I select the Model view, I have three buttons, Refresh List, Open Selected, and Open Selected to Single Tab.
If I open the model, and select the Attributes tab, it show the model comes from Global. If I archive the model, the global model is archived, and removed from all packages. If I restore the model, it is restored to all the packages that referenced it prior to archiving the model.
So my question: how to I remove a model, that was imported into a package from the Global Area, from my package, without remove the global model from the global area?
Regards,
Armand Welsh
14 years, 1 month