RestFule example
by Qian, Tony
All,
I have installed Drools Execution Server and try to figure out how to use execution server as stateless web service. I have a few questions:
1) I checked out the all examples in the document. I didn't see any examples using RestFul web service. Is there any example out there?
2) By looking at the Sample request content and response content, I cannot figure out what this example tries to tell us. Detail explanation would be really appreciated, especially for new user.
3) In the example, which part works as 'fact Model' (inOutFacts, inFacts), the data we try to apply rule on? What is inFacts used for?
4) If I only need to apply rule to a single object, how do I use restful web service? For example, I have an object Model
Person {
firstName
LastName
Gender
}
My rule is to check the first name. If first name is "Jenny", set gender to "F" and return the Person Object. How can I use Drools Execution Server to do that? (Of cource I have to deploy knowledgebase generated from Guvnor first).
Thanks,
Tony
<HR>
<font size="1" face="Arial"><B>CONFIDENTIALITY NOTICE: </B>The information in this electronic transmission and
any documents accompanying it may contain confidential and privileged
information intended for use by the individual or entity that is the intended
recipient. If you have received this message in error or due to an unauthorized
transmission or interception, please delete all copies from your system without
disclosing, copying, or transmitting this message and notify us by telephone
877TELLUS9 or by electronic mail <a href = "servicecomments(a)progressive-medical.com">servicecomments(a)progressive-medical.com</a>.</font>
15 years
(no subject)
by Lindy hagan
I have 4 drl files in my app. Loading all the 4 files during application
startup.
If any rule is satisfied in File 1,I don't want File 2 be called.Should
execute File 3 and 4.
If rules in File 1 is not satisfied,want to call File 2 then File 3 and 4.
At present I am doing this way.Please let me know if this is ok or if there
is any better solution.
Set an attribute when a rule is satisfied. (attribute is not dummy,I need it
in my app)
Attribute is checked in each and every if it is null.
Example File1.drl contains 2 rules.If first rule is satisfied, don't want to
execute second rule.So setting rule with a valid number.
File1.drl
rule "1.Age Factor and Junior"
when
d : CustomerDetail( rule == "" && sale == 'Junior' && age in
("16","17"))
then
System.out.println("Junior and Age Satisfied ");
d.setRule("1");
end
rule "2.Junior only Age Factor"
when
m : CustomerDetail( rule == "" && age in ("16","17"))
then
System.out.println("Only junior Age satisfied.");
m.setRule("2");
end
File2.drl
rule "3.Age Factor and Senior"
when
d : CustomerDetail( rule == "" && sale == 'Senior' && age in
("70","75"))
then
System.out.println("Senior and Age Satisfied ");
d.setRule("10");
end
rule "4.Senior only Age Factor "
when
m : CustomerDetail( rule == "" && age in ("70","75"))
then
System.out.println("Only senior Age satisfied.");
m.setRule("11");
end
This one works but is it possible , If the rule 1 is satisfied, rule2 is
still executed.Is there any way we can stop rule2 from beinge executed?
Similary stop File2.drl being executed. Any suggestions?
15 years
(no subject)
by Jason Smith
SUMMARY:
I am getting a NPE when using modify() with a JavaBean that implements PropertyChangeSupport.
I have included the original source and a proposed fix. Stack trace is also included.
This applies to Drools 5.0.1, and has been verified to also be a problem for 5.1.0.M1.
DETAIL:
I have a rule that looks like this:
rule "Constrain to owner or published to public"
when
$fact : ListFact(
path not matches ".*owner.*",
noopResponse == true
)
then
modify($fact)
{
setPath( "[owner/username='' or publishlist/publish='All Users']")
}
end
The $fact is a JavaBean that implements PropertyChangeSupport, and I've verified that everything is working correctly at the bean level. When I run this rule, I get this exception:
Caused by: java.lang.NullPointerException:
at org.drools.common.EqualityKey.removeFactHandle(EqualityKey.java:109)
at org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:1435)
at org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:1350)
at org.drools.common.AbstractWorkingMemory.propertyChange(AbstractWorkingMemory.java:1577)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:339)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:276)
at com.infotrustgroup.rules.RestFact.setPath(RestFact.java:264)
at com.infotrustgroup.facts.ParametersFact.setPath(ParametersFact.java:105)
at com.infotrustgroup.facts.ParametersFact.setPath(ParametersFact.java:74)
at com.infotrustgroup.what.Rule_Constrain_to_owner_or_published_to_public_0.consequence(Rule_Constrain_to_owner_or_published_to_public_0.java:12)
at com.infotrustgroup.what.Rule_Constrain_to_owner_or_published_to_public_0ConsequenceInvoker.evaluate(Rule_Constrain_to_owner_or_published_to_public_0ConsequenceInvoker.java:23)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:934)
... 38 more
The offending line is marked below. It looks like maybe "this.instances" is null in the "else" clause.
public void removeFactHandle(final InternalFactHandle handle) {
if ( this.handle == handle ) {
if ( this.instances == null ) {
this.handle = null;
} else {
this.handle = (InternalFactHandle) this.instances.remove( 0 );
if ( this.instances.isEmpty() ) {
this.instances = null;
}
}
} else {
***this.instances.remove( handle );***
if ( this.instances.isEmpty() ) {
this.instances = null;
}
}
}
It looks like someone else ran into this problem before, but only fixed it for the "if" portion, not the "else" portion. I modified the code as follows, and this seems to fix the NPE. Basically, I followed the pattern from the "if" portion.
public void removeFactHandle(final InternalFactHandle handle) {
if ( this.handle == handle ) {
if ( this.instances == null ) {
this.handle = null;
} else {
this.handle = (InternalFactHandle) this.instances.remove( 0 );
if ( this.instances.isEmpty() ) {
this.instances = null;
}
}
} else {
if(this.instances == null)
{
this.handle = null;
}
else
{
this.instances.remove( handle );
if ( this.instances.isEmpty() ) {
this.instances = null;
}
}
}
}
Please read around the formatting. Can someone verify if this is a correct fix, and if it should be applied to the codebase? It seems to work for me. It does not break any unit tests in drools-core 5.0.1 either.
Jason Smith
Software Engineer
InfoTrust Group, Inc.
500 Discovery Parkway, Suite 200
Superior, CO 80027
Office 303-627-6571
Fax 303-666-6711
Email jsmith(a)infotrustgroup.com<mailto:jsmith@infotrustgroup.com>
WEB www.infotrustgroup.com<http://www.infotrustgroup.com/>
This e-mail and all information included herein do not constitute a legal agreement accorded by INFOTRUST GROUP and its affiliates and subsidiaries. All legal agreements must be formulated in writing by a legal representative of INFOTRUST GROUP. This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail by mistake, please inform us and destroy this e-mail and any documents it might contain. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Finally, the recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. Thank you for your cooperation.
15 years
Drools Flow 5.1.0.M1 - Persistence - WorkItemInfo Entity
by Vijay K Pandey
I have a question related to the (Drools Flow 5.1.0.M1 - Persistence) on the data that gets stored as part of the org.drools.persistence.processinstance.WorkItemInfo.
a) If I am using variable persistence strategy - and I pass a JPA Entity(stored in its own table) to a session.startProcess("", map) and map this entity variable to a parameter in the work item node - then this entity will get stored in the WorkItemInfo table as a part of the serialized form in the column (workItemByteArray). So if that is true we have got the same data stored twice? Is this correct?
b) If "a" is true how can we avoid storing in the WorkItemInfo - is there somehow we can map the JPA entity to the WorkItemInfo - so that it doesn't gets stored twice?
Thanks
Vijay
15 years
Starting Procss instance from outside of the GWT console
by ramram8
Hi all
I have the following question and I was wondering if someone can help me?
can we initiate a new process instance in the GWT console without using the
start button?
can we start this process from a call from outside of the application by
using a specific API and passing to it parameters?
I have the following process : START -> USER TASK -> MAIL -> END
i need to start this process from outside the application so that the used
when logging into the gwt console can see that he have a task to validate?
--
View this message in context: http://old.nabble.com/Starting-Procss-instance-from-outside-of-the-GWT-co...
Sent from the drools - user mailing list archive at Nabble.com.
15 years
Could not find work item handler
by ramram8
Hi
I am performing a process in the GWT console:
The process is as follows:
START -> UAERTASK -> LOG -> END
in the gwt console I can see the process and I start the process after
starting the process and executing the user task I have the following error
although I have uploaded a .jar file and the .rf file through Guvnor:
ERROR is :
13:50:37,093 INFO [STDOUT] Hibernate: insert into NodeInstanceLog (id,
type, nodeInstanceId, nodeId, processInstanceId, processId, DATE) values
(null, ?, ?, ?,
?, ?, ?)
13:50:37,093 ERROR [STDERR] Could not find work item handler for Log
13:50:38,578 INFO [STDOUT] [2009:11:322 13:11:578:debug] Message receieved
on client : QueryTaskSummaryResponse
where I should define the Log work item handler?
--
View this message in context: http://old.nabble.com/Could-not-find-work-item-handler-tp26406563p2640656...
Sent from the drools - user mailing list archive at Nabble.com.
15 years
Changing PackageIsSource from false to true
by ramram8
Hi All
I found on the server trace the following:
16:29:03,968 INFO [STDOUT] PackageName: default
16:29:03,968 INFO [STDOUT] PackageVersion: LATEST
16:29:03,968 INFO [STDOUT] PackageIsLatest: true
16:29:03,968 INFO [STDOUT] PackageIsSource: false
I think that this is causing me problem when trying to execute a process
with work item handler
error: ERROR [STDERR] Could not find work item handler for Log
can someone help on how we can change 16:29:03,968 INFO [STDOUT]
PackageIsSource: false
from false to true
Regards
--
View this message in context: http://old.nabble.com/Changing-PackageIsSource-from-false-to-true-tp26408...
Sent from the drools - user mailing list archive at Nabble.com.
15 years
Re: [rules-users] Drools solver info => provide DSL instead of DRL to Drools Solver
by dmzpippo-drools@yahoo.it
Hi Geoffrey,
I have modified the LocalSearchSolverConfig class to accept the <scoreDsl> tag.
To
use this tag need gonfigure the XML solverConfig file adding the path
of Drl file and Dsl file associated in two line consecutive in the
configuration file. This code is not the best but is a start....
I send you the code if it can be useful.
I
would also ask when it launches the new version of the solver, and if
this will also include other local search algorithms than Tabu Search
with kind regards,
Marco
LocalSearchSolverConfig class Code
/**
* @author Geoffrey De Smet
*/
@XStreamAlias("localSearchSolver")
public class LocalSearchSolverConfig {
private Long randomSeed = null;
@XStreamImplicit(itemFieldName = "scoreDrl")
private List<String> scoreDrlList = null;
@XStreamImplicit(itemFieldName = "scoreDsl")//FIXME adding DslList
private List<String> scoreDslList = null;
@XStreamAlias("scoreDefinition")
private ScoreDefinitionConfig scoreDefinitionConfig = new ScoreDefinitionConfig();
private StartingSolutionInitializer
startingSolutionInitializer = null;
private Class<StartingSolutionInitializer> startingSolutionInitializerClass = null;
@XStreamAlias("termination")
private TerminationConfig terminationConfig = new TerminationConfig(); // TODO this new is pointless due to xstream
@XStreamAlias("deciderScoreComparatorFactory")
private DeciderScoreComparatorFactoryConfig deciderScoreComparatorFactoryConfig
= new DeciderScoreComparatorFactoryConfig();
@XStreamAlias("selector")
private SelectorConfig selectorConfig = new SelectorConfig();
@XStreamAlias("accepter")
private AccepterConfig accepterConfig = new AccepterConfig();
@XStreamAlias("forager")
private ForagerConfig foragerConfig = new ForagerConfig();
public Long getRandomSeed() {
return randomSeed;
}
public void setRandomSeed(Long randomSeed) {
this.randomSeed = randomSeed;
}
public List<String> getScoreDrlList() {
return scoreDrlList;
}
public void setScoreDrlList(List<String> scoreDrlList) {
this.scoreDrlList = scoreDrlList;
}
public List<String> getScoreDslList() {
return scoreDslList;
}
public void setScoreDslList(List<String>
scoreDslList) {
this.scoreDslList = scoreDslList;
}
public ScoreDefinitionConfig getScoreDefinitionConfig() {
return scoreDefinitionConfig;
}
public void setScoreDefinitionConfig(ScoreDefinitionConfig scoreDefinitionConfig) {
this.scoreDefinitionConfig = scoreDefinitionConfig;
}
public StartingSolutionInitializer getStartingSolutionInitializer() {
return startingSolutionInitializer;
}
public void setStartingSolutionInitializer(StartingSolutionInitializer startingSolutionInitializer) {
this.startingSolutionInitializer =
startingSolutionInitializer;
}
public Class<StartingSolutionInitializer> getStartingSolutionInitializerClass() {
return startingSolutionInitializerClass;
}
public void setStartingSolutionInitializerClass(Class<StartingSolutionInitializer> startingSolutionInitializerClass) {
this.startingSolutionInitializerClass = startingSolutionInitializerClass;
}
public TerminationConfig getTerminationConfig() {
return terminationConfig;
}
public void setTerminationConfig(TerminationConfig terminationConfig) {
this.terminationConfig = terminationConfig;
}
public DeciderScoreComparatorFactoryConfig getDeciderScoreComparatorFactoryConfig() {
return deciderScoreComparatorFactoryConfig;
}
public void setDeciderScoreComparatorFactoryConfig(
DeciderScoreComparatorFactoryConfig deciderScoreComparatorFactoryConfig) {
this.deciderScoreComparatorFactoryConfig = deciderScoreComparatorFactoryConfig;
}
public SelectorConfig getSelectorConfig() {
return selectorConfig;
}
public void setSelectorConfig(SelectorConfig selectorConfig) {
this.selectorConfig = selectorConfig;
}
public AccepterConfig getAccepterConfig() {
return accepterConfig;
}
public void setAccepterConfig(AccepterConfig accepterConfig) {
this.accepterConfig = accepterConfig;
}
public ForagerConfig getForagerConfig() {
return foragerConfig;
}
public void setForagerConfig(ForagerConfig foragerConfig) {
this.foragerConfig = foragerConfig;
}
// ************************************************************************
// Builder methods
//
************************************************************************
public LocalSearchSolver buildSolver() {
DefaultLocalSearchSolver localSearchSolver = new DefaultLocalSearchSolver();
if (randomSeed != null) {
localSearchSolver.setRandomSeed(randomSeed);
} else {
localSearchSolver.setRandomSeed(0L);
}
localSearchSolver.setRuleBase(buildRuleBase());
ScoreDefinition scoreDefinition = scoreDefinitionConfig.buildScoreDefinition();
localSearchSolver.setScoreDefinition(scoreDefinition);
// remove when score-in-solution refactor
localSearchSolver.setScoreCalculator(scoreDefinitionConfig.buildScoreCalculator());
localSearchSolver.setStartingSolutionInitializer(buildStartingSolutionInitializer());
localSearchSolver.setBestSolutionRecaller(new BestSolutionRecaller());
localSearchSolver.setTermination(terminationConfig.buildTermination(scoreDefinition));
localSearchSolver.setDecider(buildDecider());
return localSearchSolver;
}
private RuleBase buildRuleBase() {
PackageBuilder
packageBuilder = new PackageBuilder();
if(scoreDrlList!=null)
for (String scoreDrl : scoreDrlList) {
InputStream scoreDrlIn = getClass().getResourceAsStream(scoreDrl);
if (scoreDrlIn == null) {
throw new IllegalArgumentException("scoreDrl (" + scoreDrl + ") does not exist as a classpath resource.");
}
try {
packageBuilder.addPackageFromDrl(new InputStreamReader(scoreDrlIn, "utf-8"));
} catch (DroolsParserException e) {
throw new IllegalArgumentException("scoreDrl (" + scoreDrl + ") could not be loaded.", e);
} catch (IOException e) {
throw new IllegalArgumentException("scoreDrl (" + scoreDrl + ") could not be loaded.", e);
} finally {
IOUtils.closeQuietly(scoreDrlIn);
}
}
//FIXME scoreDslList addPackageFrom(Drl,Dsl)
if(scoreDslList!=null){
String scoreDrl=null;
String scoreDsl=null;
for(int i=0;i< scoreDslList.size();i++){
if(scoreDslList.get(i).endsWith("drl")){
scoreDrl=scoreDslList.get(i);
}
else{
scoreDsl=scoreDslList.get(i);
}
if(scoreDrl!=null&&scoreDsl!=null){
InputStream scoreDrlIn = getClass().getResourceAsStream(scoreDrl);
InputStream scoreDslIn = getClass().getResourceAsStream(scoreDsl);
if (scoreDrlIn == null || scoreDslIn == null)
{
throw new IllegalArgumentException("score does not exist as a classpath resource.");
}
try {
packageBuilder.addPackageFromDrl(new
InputStreamReader(scoreDrlIn, "utf-8"),new
InputStreamReader(scoreDslIn, "utf-8"));
} catch (DroolsParserException e) {
throw new
IllegalArgumentException("scoreDrl could not be loaded.", e);
} catch (IOException e) {
throw new IllegalArgumentException("scoreDrl could not be loaded.", e);
} finally {
IOUtils.closeQuietly(scoreDrlIn);
}
scoreDrl=null;
scoreDsl=null;
}
}
}
RuleBaseConfiguration ruleBaseConfiguration = new RuleBaseConfiguration();
RuleBase ruleBase = RuleBaseFactory.newRuleBase(ruleBaseConfiguration);
if (packageBuilder.hasErrors()) {
throw new IllegalStateException("There are errors in the scoreDrl's:"
+ packageBuilder.getErrors().toString());
}
ruleBase.addPackage(packageBuilder.getPackage());
return ruleBase;
}
public StartingSolutionInitializer buildStartingSolutionInitializer() {
if (startingSolutionInitializer != null) {
return startingSolutionInitializer;
} else if (startingSolutionInitializerClass != null) {
try {
return startingSolutionInitializerClass.newInstance();
} catch (InstantiationException e) {
throw new
IllegalArgumentException("startingSolutionInitializerClass ("
+ startingSolutionInitializerClass.getName()
+ ") does not have a public no-arg constructor", e);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("startingSolutionInitializerClass ("
+
startingSolutionInitializerClass.getName()
+ ") does not have a public no-arg constructor", e);
}
} else {
return null;
}
}
private Decider buildDecider() {
DefaultDecider decider = new DefaultDecider();
decider.setDeciderScoreComparator(deciderScoreComparatorFactoryConfig.buildDeciderScoreComparatorFactory());
decider.setSelector(selectorConfig.buildSelector());
decider.setAccepter(accepterConfig.buildAccepter());
decider.setForager(foragerConfig.buildForager());
return decider;
}
public void inherit(LocalSearchSolverConfig inheritedConfig) {
if (randomSeed == null) {
randomSeed = inheritedConfig.getRandomSeed();
}
if (scoreDrlList == null) {
scoreDrlList = inheritedConfig.getScoreDrlList();
} else
{
List<String> inheritedScoreDrlList = inheritedConfig.getScoreDrlList();
if (inheritedScoreDrlList != null) {
for (String inheritedScoreDrl : inheritedScoreDrlList) {
if (!scoreDrlList.contains(inheritedScoreDrl)) {
scoreDrlList.add(inheritedScoreDrl);
}
}
}
}
//FIXME scoreDSLlist
if(scoreDslList ==null){
scoreDslList=inheritedConfig.getScoreDslList();
}else{
List<String> inheritedScoreDslList=inheritedConfig.getScoreDslList();
if(inheritedScoreDslList != null){
for(String inheritedScoreDsl : inheritedScoreDslList){
if(!scoreDslList.contains(inheritedScoreDsl)){
scoreDslList.add(inheritedScoreDsl);
}
}
}
}
if (scoreDefinitionConfig == null) {
scoreDefinitionConfig = inheritedConfig.getScoreDefinitionConfig();
} else if (inheritedConfig.getScoreDefinitionConfig() != null) {
scoreDefinitionConfig.inherit(inheritedConfig.getScoreDefinitionConfig());
}
if (startingSolutionInitializer == null && startingSolutionInitializerClass == null) {
startingSolutionInitializer = inheritedConfig.getStartingSolutionInitializer();
startingSolutionInitializerClass = inheritedConfig.getStartingSolutionInitializerClass();
}
if (terminationConfig == null) {
terminationConfig = inheritedConfig.getTerminationConfig();
} else if (inheritedConfig.getTerminationConfig() != null)
{
terminationConfig.inherit(inheritedConfig.getTerminationConfig());
}
if (deciderScoreComparatorFactoryConfig == null) {
deciderScoreComparatorFactoryConfig = inheritedConfig.getDeciderScoreComparatorFactoryConfig();
} else if (inheritedConfig.getDeciderScoreComparatorFactoryConfig() != null) {
deciderScoreComparatorFactoryConfig.inherit(inheritedConfig.getDeciderScoreComparatorFactoryConfig());
}
if (selectorConfig == null) {
selectorConfig =
inheritedConfig.getSelectorConfig();
} else if (inheritedConfig.getSelectorConfig() != null) {
selectorConfig.inherit(inheritedConfig.getSelectorConfig());
}
if (accepterConfig == null) {
accepterConfig = inheritedConfig.getAccepterConfig();
} else if (inheritedConfig.getAccepterConfig() != null) {
accepterConfig.inherit(inheritedConfig.getAccepterConfig());
}
if (foragerConfig == null) {
foragerConfig =
inheritedConfig.getForagerConfig();
} else if (inheritedConfig.getForagerConfig() != null) {
foragerConfig.inherit(inheritedConfig.getForagerConfig());
}
}
}
15 years
Adding jars for Guvnor to work
by richarda
Hi,
I have some rules that include a class that I created.. part of that class
requires the Apache common library.
When I run Drools in my application it all works fine as the Apache jar
files are in my classpath.
However, when I try to setup in Guvnor I am getting errors that the
classpath is not found.
Is there anyway to add jar files to the classpath of guvnor?
Cheers
Ric
--
View this message in context: http://old.nabble.com/Adding-jars-for-Guvnor-to-work-tp26443607p26443607....
Sent from the drools - user mailing list archive at Nabble.com.
15 years