Importing JAVA bean into Drools Workbench - drools

I start using KIE Drools Workbench and I practice in creating DRL files so I can tutor pepole that are not programmers in creating rules.
I know how to create a JAVA class within the Workbench but I need to know how to import a class I already wrote that will be part of the statement.
For example:
Employer - class I create within the Workbench
Employee - class I developed in eclipse and wish to import into the Workbench
So the drl could look like this:
when
$employer:Employer(isHappy == true)
then
Employee emp = new Employee();
emp.setSalary(100);
insert(emp);
end
Any idea how can I import JAVA bean to use in KIE Drools Workbench?
Thanks!

Create a jar with the beans you want to use (use maven for convenience).
Upload jar into workbench through Artifact Repository.
Include dependency using project editor AND include all packages of the jar to the Package white list.
Add the classes you need at the Data Objects menu of the rules to use them.

What Stathis stated gives you one option to do this. Alternatively you can
maven install your beans project (this will extract a jar in .m2 repository to use as a dependency)
add a dependency with the jar extracted in .m2 in your project's pom
As for the tutoring part you should examine the possibility of using dsl (Domain Specific Language) for your rules. This and this (chapter 5.10) might be handy to you

Related

Strange issue between Eclipse Mars and Maven

Some context
I am creating a Spring Boot base code application that is in fact separated in three projects/modules:
springbase-core
contains:
custom annotations
custom exceptions
custom generic Spring components
model (entities)
metamodels (generated by maven through the maven-processor-plugin)
utils
depends on: nothing
springbase-data
contains:
data related annotations
services
repositories
data related util classes
depends on: springbase-core
springbase-web
controllers
form classes
filters
listeners
interceptors
JSPs
JSP Tags
etc.
depends on: springbase-data, springbase-core
The problem I am having is that if I have springbase-core in my Eclipse workspace, I'm not able to import metamodels in repository classes in springbase-data. If I remove the springbase-core project (where metamodels reisde) from my Eclipse workspace, it works.
I have also tried copying springbase-core-0.0.1-SNAPSHOT.jar from my .m2 repository, directly at the root of my project (and taking care of adding it in .classpath), and I was able to import metamodels.
When opening springbase-core-0.0.1-SNAPSHOT.jar with WinZip, I can see the metamodels. Building springbase-core with Maven also shows the generated metamodels under /target/metamodel as configured in my pom.xml.
Looks like a glitch between Eclipse and Maven.
Any thoughts?
Here is a solution to my problem: Right click on all projects, click on Maven, and then Disable Workspace Resolution.
That way Maven is going to look for the dependency only from .m2, regardless of what's in my workspace.

KIE Workbench- Uploading Java Class For Use in Guided Rule

I'm somewhat new to drools. I'm using KIE workbench running on tomcat 8. I would like to upload a .jar file containing a Java class I wrote in Netbeans to Drools/KIE workbench THEN use it in the guided rule section of the workbench. I've figured out how to upload the .jar containing the class to my project and include it as a dependency, I've added it to project package whitelist. I am able to use this uploaded object in a new DRL file (new item > DRL file) where I write a rule by hand, but I'm unable to see or use this data model/object in parts of the wb like the guided rule creator (new item> guided rule) or tests (new item> test scenario).
Anyone have any idea if this is possible or know how to do it?
Thank you.
You need to go to the 'Data Objects' tab and import your class using 'New Item' and then picking your class in the dropdown.
Import Data Objects

How to configure Eclipselink nosql JPA implementation with mongodb nosql database?

I want to use JPA to create an entity class that can be used with the persistence context to access my db2 nosql database. The problem is the #NoSql annotation is not being found.
As per http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/NoSQL/Configuring, I:
Created a web project
Enabled JPA via project properties-> Project Facets -> Check mark JPA v2.1
Under Project properties -> JPA -> Set Platform to EclipseLink 2.5x, Set JPA Implementation to Library Provided by Target Runtime
Setup server.xml with the datasource and the persistence.xml
I have java.persistence.org but not java.persistence.org.oracle.nosql. I'm not sure if I am suppose to download it or it should already be setup. And I also do not know how to use maven (and I would prefer not to).
Most tutorials online either only show HOW to use (and not configure) or use mysql connector and somewhere in the project config it just works. I greatly appreciate assistance!
I solved the problem by following this blog post: https://blogs.oracle.com/NoSQL/entry/eclipselink_jpa_and_oracle_nosql.
Excerpt:
Now at first glance it looks like EclipseLink 2.5 includes support for
NoSQL databases right out of the box, but in fact if you look closely
there is another specific NoSQL plugin download necessary. Download,
unzip and save this plugin in a directory e.g. /nosql-plugin . Later
you’ll need to get some libraries from it.
So go here to get the jar files and import the following into your project
org.eclipse.persistence.nosql_2.5.0*.jar
org.eclipse.persistence.oracle.nosql_2.5.0*.jar
javax.resource_1.5.0*.jar
To import go right-click project -> properties -> java build path -> Libraries tab -> Add External Jar -> Navigate to the jar files and import

Configuration required to Run Maven project with Eclipse

I have a Maven project in SVN with trunk\Config\TestProjConfig folder having all the XML configuration files and all Java code is in trunk\JavaSource\TestProj. When I check out to my local Eclipse there are 2 projects created one for TestProjConfig and one for TestProj.
How do I test this project? Do I have to edit the build path to make a connection between the two projects? Do I have to write a main class which accesses the AppContext file to invoke the Spring injections?
Note:I have the m2eclipse plugin in Eclipse.
I don't understand why you separated XML configuration from Java sources. It could be a good practice only if you want to reuse your conf in other project, but in this case, I'm not sure that's suitable.
Solution 1
Move all your xml config into JavaSource\TestProj\src\main\resources
If you really don't have to share your configuration or don't have any legacy / corporate / mysterious reason, you should not separate them.
Solution 2
If you REALLY want to separate them, put them in a zip with an assembly, and add a dependency from TestProj to TestProjConfig.
Here an example : Maven - Depend on assembled zip

Hibernate Setup in eclipse helios

How I can setup Hibernate for a Dynamic Web application by using Eclipse Helios? I am a newbe so please let me know if there is any example.
I tried for Java application and included all JARS and it worked fine. But don't understand how I can do it for Web application and test it.
I will use Struts2 so I will appreciate if I can get appropriate example or guidance.
Drop the jars in WEB-INF/lib. Those jars are automatically added by Eclipse to the project build path, and constitute (with the WEB-INF/classes directory and the container classpath) the classpath of the webapp.
http://hardik4u.wordpress.com/2008/09/02/struts-2-hibernate-3-integrationcomplete-using-eclipse/
https://stackoverflow.com/questions/4364923/struts2-and-hibernate-framework-create-in-eclipse
First, download Struts2, and import example WAR file into Eclipse. You can find it from the source folder: struts-2.3.1-all\struts-2.3.1\apps\struts2-blank.war
Second, you should install Eclipse Hibernate Plugin. Goto Window > Preferences > Install/Update > Available Software Sites and add following link and name it JBossTools or something.
http://download.jboss.org/jbosstools/updates/helios/
Depending on your needs you can install Hibernate Plugins for many project types. In this case, select web application plugin.
And after, you should include Hibernate Core libraries into your classpath. I would recomment Hibernate 3.6 and greater. Because it does not depend on asm (asm-3.3.jar, asm-commons-3.3.jar ...) anymore. If you use earlier versions you might encounter some problems, since Struts2 also depend on asm libraries.
Then create your database, and use following link to configure and generate model bean classes.
http://casteyo.wordpress.com/2007/06/06/conf_hibernate/
Now you don't need to write mapping files by yourselves. And with DAO factory pattern you have your way to finish your project.
Hope this helps, and Goodluck