Problem with DSL and Business Rules creation in Drools - drools

I am using Eclipse with the Drools plugin to create rules.
I want to create business rules and main aim is to try and provide the user a set of options which he can use to create rules.
For eg:If an Apple can have only 3 colors: I want to provide an option like a drop down so that the user can know before hand which are the options he can use in his rules.
Is it possible?
I am creating a dsl but unable to still provide the above functionality for a business rule.
I am having an error implementing a basic dsl also.
The code to add the dsl is as follows in my RuleRunner class()
InputStream ruleSource = RuleRunner.class.getClassLoader().getResourceAsStream("/Rule1.dslr");
InputStream dslSource = RuleRunner.class.getClassLoader().getResourceAsStream("/sample-dsl.dsl");
//Load the rules , using DSL
addRulesToThisPackage.addPackageFromDrl(
new InputStreamReader(ruleSource),new InputStreamReader(dslSource));
I have both the sample-dsl .dsl and Rule1.dslr in my working directory.
Error encountered at adding the dsl to the package (last line)
Error stack:
Exception in thread "main" java.lang.NullPointerException
at java.io.Reader.<init>(Unknown Source)
at java.io.InputStreamReader.<init>(Unknown Source)
at com.org.RuleRunner.loadRuleFile(RuleRunner.java:96)
at com.org.RuleRunner.loadRules(RuleRunner.java:48)
at com.org.RuleRunner.runStatelessRules(RuleRunner.java:109)
at com.org.RulesTest.main(RulesTest.java:41)
my dsl file has basic mapping as per the online documentations.
The dsl rule I created is:
expander sample-dsl.dsl
rule "A status changes B status"
when
There is an A
- has an address
There is a B
- has name
then
- print updated A and Aaddress
End
I have created DSL in eclipse.
Is the code I added for it to be loaded to my package correct?? Or am I missing something????
It seems like my program is unable to find the dsl?
Please help. Can you point me towards the right direction to create a user friendly business rule ??
Thanks.
J

I am not quite familiar with the method you are trying to use to create a knowledge session, but I will show a example of what's used in my applications.
KnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase(<KnowledgeBaseConfiguration>);
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource( "rules/myRuleFile.drl", getClass() ),
ResourceType.DRL );
kbuilder.add( ResourceFactory.newClassPathResource( "rules/myDslFile.dsl", getClass() ),
ResourceType.DSL );
if ( kbuilder.hasErrors() ) {
System.err.println( builder.getErrors().toString() );
}
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
Now as far as giving your users the ability to author rule files, with built in constraints, have you looked at Drools Guvnor?(http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-guvnor/html_single/index.html) I have not incorporated it into my project yet, but have researched it a bit. I think it may provide the functionality your seeking for allowing your users to create and edit rule files. Good luck!

Related

IBM BPM JS Calling external Service from another Toolkit (from dependency)

im using
integration toolkit for each external system ... externalService
definition, Servers registation datas, ENV refers the J2C creds to use, datamapping, bussines-errors handling etc.
(Bussines-Layer TK ex. TK_SAP)
for the common functionality such as logging, tokenizing,
pseudomizing, common http-error handling i want to use another one
toolkit (Generic implementation for Transport-layer ex. TK_COM).
So its looks like this dependicies chain:
ProcessApp -> TK_SAP -> TK_COM
There is the serviceFlow with inputs externalServiceName, operationName and a serviceFlow ask for oAuth-token and call to target system using externalServiceName, operationName.
The problem is - when i try to invoke the BPMRESTRequest from TK_COM, i get NullPointerException because "externalServiceName" cant be resolved.
var request = new BPMRESTRequest();
request.externalServiceName = "language-translator-v2";
request.operationName="checkout";
...
var response = tw.system.invokeREST(request);
is it possible to store service definition in another TK (upper) and refer it from Toolkit-invoker?
Or is there callbacks for BPMRESTRequest-Construct to say which ServiceDefinition must be used and avoid NPE.
Or another way to call Rest programmaticaly supporting Environments.
Im understand that switching the layers can help (serviceDefinition in lower TK-dependency), but it unlogisch is:
ProcessApp -> TK_COM -> TK_SAP
the answer is: JS-lib implementation.
Implementing common functionality as JS-Server-file in TK_COM makes that a call to it from TK_SAP will instatiate JS-execution context in the TK_SAP namespace so all defined in TK_SAP externalServices and variables will be accesible by executing of JS-code (actualy provided by lower-dependency Toolkit)

How to Register Interests using 'ALL_KEYS' in Spring Data GemFire with ClientRegionFactoryBean

I am going to register interests in ALL_KEYS for my Pivotal GemFire client via Spring Data GemFire, but I find that ClientRegionFactoryBean has one method.
org.springframework.data.gemfire.client.ClientRegionFactoryBean.setInterests(Interest<MyRegionPojo>[] interests)
In this case, I only can set the exact keys, but I want to register interests for all keys. My key is not a simple class like String, or Long, but a complex object MyRegionPojo.
Please help if any method to implement so like GemFire API region.registerInterest("ALL_KEYS");
You problem statement is a bit vague but I assume/suspect you are configuring your Spring (Data GemFire) (SDG) application using Spring JavaConfig?
However, I will quickly add that this is not unlike how you would register interests in all keys using SDG's XML namespace, as shown here.
The JavaConfig approach is similar, but clearly based on "strongly-typed arguments", namely 1 or more sub-type instances of the o.s.d.g.client.Interest class to the o.s.d.g.client.ClientRegionFactoryBean.setInterests(:Interest<K>[]) method.
By way of example, you might do the following...
#Bean("Example")
public ClientRegionFactoryBean<?, ?> exampleRegion(GemFireCache gemfireCache) {
ClientRegionFactoryBean<MyRegionKey, MyRegionValue> exampleRegion =
new ClientRegionFactoryBean<>();
RegexInterest regexInterest = new RegexInterest();
regexInterest.setKey(".*");
exampleRegion.setCache(gemfireCache);
exampleRegion.setShortcut(ClientRegionShortcut.PROXY);
exampleRegion.setInterests(new Interest[] { regexInterest });
exampleRegion.setKeyConstraint(MyRegionKey.class);
exampleRegion.setValueConstraint(MyRegionValue.class);
return exampleRegion;
}
NOTE: updated the example above to reflect the proper way to register (Regex) interests based on SDG 1.9 or earlier. Keep in mind that the `o.s.d.g.client.RegexInterest.getRegex() delegates to getKey() therefore you can set the Regular Expression using setKey(:String) as I have shown above.
Notice the o.s.d.g.client.RegexInterest sub-type registration, which is effectively the same as register interests in "ALL_KEYS", as described here as well.
Hope this helps!
-John

How to populate CheckedTreeSelectionDialog

I'm writing a test to learn how to use CheckedTreeSelectionDialog. This is the code.
CheckedTreeSelectionDialog dialog =
new CheckedTreeSelectionDialog(shell, new LabelProvider(), new TreeContentProvider() );
dialog.setTitle("Tree Selection");
dialog.setMessage("Select the elements from the tree:");
ElementTree et = new ElementTree();
et.createElement(new Path("element_1"), "element_1");
dialog.setInput(dt);
dialog.open();
But I get the exception:
org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.NoClassDefFoundError: org/eclipse/pde/internal/ui/elements/TreeContentProvider)
I really appreciate any hint!
Thanks!
You can't use the class org.eclipse.pde.internal.ui.elements.TreeContentProvider because it's only available for Eclipse PDE (the classes that are in a package 'internal' are not intended to be used by client).
Instead you should create your own TreeContentProvider, implementing the interface org.eclipse.jface.viewers.ITreeContentProvider, as you would do for a TreeViewer. A tutorial is here.

Enterprise Library Logging tracelistener extension issue with resolving ILogFormatter

I have been sitting with a problem for quite a while now and I just can't seem to find what I'm missing.
I have written a custom trace listener component for Enterprise Library 5.0 for the Logging application block which works but the configured ILogFormatter just won't resolve and so I always end up with the basic string text when it gets handled by my component.
I saw in the enterprise library source code that they use the "Container.ResolvedIfNotNull()" method. It doesn't seem to work for me. I need it to write out a custom formatted string for my component to use. You know, not just the message but the timestamp, machinename, threadId, etc.
Does anyone have any ideas on how to fix this?
Thanks in advance.
Like I've mentioned on this site: http://entlib.codeplex.com/discussions/261749
When you create your CreationExpression in the TraceListener data class make sure you have a flat constructor definition. To put it in other words, don't return:
() => new MyTraceListener(new TraceListenerConfig(..., Container.ResolvedIfNotNull<ILogFormatter>(), ...));
just have it in the constructor of the MyTraceListener:
() => new MyTraceListener(..., Container.ResolvedIfNotNull<ILogFormatter>(), ...);

Drools related problem

Hi I want to bring a little change in my site. So i have written a set of rules but I dont know how to fire them in the place that i want them to work i.e. the original code of my site.Can anyone plz help me on it?
A little information is missing (like which Drools version, the environment you're running in, etc.), so I'll try to answer in a general way, and if you need something more specific let me know:
In general in Drools you 'assert' objects into the working memory (using methods like, well, assertObject..), this allows the rule engine to be aware of them, and later, when you execute 'fireAllRules' on that working memory, all the rules are executed (so, you explicitly call the fireAllRules method on your working memory when you want to - I think this is what you were asking).
For more detailed information, in case you haven't looked already, you can check this: http://legacy.drools.codehaus.org/Working+Memory .
thanks
Gadi
when you have your abc object, this will be the fact that you insert into the Working Memory. For example:
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newFileSystemResource( fileName ), ResourceType.DRL );
if (kbuilder.hasErrors() ) {
System.out.println( kbuilder.getErrors() );
} else {
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();
ksession.execute( abc );
}
Then you will have your modified abc object when the execute finishes. Take a look at here
You probably dont't want the rules being build everytime (this is really time consumer), so you can use or KnowledgeAgent or have an static KnowledgeBase and recreate it whenever your rules files change.