Archive for the ‘java’ Category

Drools Flow configuration using Spring


2010
05.28

There are a lot of Drools Flow users that ask us about how to use Drools Flow persistence without JTA transactions, so in order to give those users a proper answer we developed a solution based on the Spring integration. We added support to configure a JpaSessionServiceFactory to the Drools’ configuration namespace. Let’s see how to use it on a real example (you can donwload it from: http://www.plugtree.com/downloads/DroolsFlowSpring.tgz).
Firstly, you need to configure EntityManageFactory and SpringTransactionManager as follows:


<bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="ds" />
<property name="persistenceUnitName" value="org.drools.persistence.jpa.local" />
</bean>

<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="myEmf" />
</bean>

I’m not showing the datasource configuration because it heavily depends on your deployment but you can grab it from the example ;-) .

Secondly, you have to define a kbase that then would be used by the JpaSessionService:


<drools:kbase id="kbase1">
<drools:resource type="DRF" source="classpath:VariablePersistenceStrategyProcess.rf" />
</drools:kbase>

And finally, you need to define the JpaSessionService:


<drools:jpaSessionServiceFactory id="jpaSingleSessionCommandService" kbase="kbase1"
entityManagerFactory="myEmf" transactionManager="txManager">
<drools:variablePersisters>
<drools:persister forClass="javax.persistence.Entity" implementation="org.drools.persistence.processinstance.persisters.JPAVariablePersister"/>
<drools:persister forClass="java.lang.String" implementation="org.plugtree.labs.variablepersistence.StringVariablePersister"/>
<drools:persister forClass="java.io.Serializable" implementation="org.drools.persistence.processinstance.persisters.SerializableVariablePersister"/>
</drools:variablePersisters>
</drools:jpaSessionServiceFactory>

Bear in mind if that you don’t need to define customs variable persisters the configuration it’s only one line!.

Then you can inject it to your own beans or create a Spring Context manually, as shown in the this snippet:


ctx = new ClassPathXmlApplicationContext("beans.xml");
JPASingleSessionCommandService jpaService = (JPASingleSessionCommandService) ctx
.getBean("jpaSingleSessionCommandService");
SingleSessionCommandService service = jpaService.newStatefulKnowledgeSession();
int sessionId = service.getSessionId();
....
//do something
service.dispose();

Then in a future time retrieve the session:
SingleSessionCommandService service = jpaService.loadStatefulKnowledgeSession(sessionId);
//do something
....
service.dispose();

Warning note: when you use the flow persistence with JTA, it automatically reloads the state out the session after a rollback. We couldn’t do that behavior here since simple database connections doesn’t provide a listener mechanism as JTA transactions does.

Drools-Guvnor improvements adding fact constraints


2010
03.26

As you can see here I’m working with Esteban under the orders of Commander Salaboy on improving the user experience of writing rules.

Following those ideas we implemented some tools for configuring a WorkingSet, a mean for filter which Facts you are able to use inside Guvnor’s Guided Editor. But that’s not all what we’ve been doing, you can also define for each field a set of constraints that will restrict what users will be allowing to write inside a rule.

Since a video worth like a thousand posts, I’ve created one showing the new features using the Guvnor demo model. in the video you’ll see how to create a new working set. Once the Working Set is created, it shows how to add facts and define constraints for those facts, as you’ll I defined a Range constraint for a credit Applicant’s age field. And next to demonstrate how to use a WorkingSet to verify a rule, I’ve created a new rule adding a restriction that would make the Range Constraint to fire.

Guvnor FactConstraints Example from Pablo Nussembaum on Vimeo.

Trabajando con Drools


2009
12.02

Una vuelta al mundo del blogging! Acá pueden ver en que estuve laburando en el último tiempo

Curso en el IEEE


2009
09.08

El Martes 29 de Septiembre voy a dar una charla en IEEE. La idea es contar qué herramientas existen para dar soporte al proceso de desarrollo ágil. Nos enfocaremos en cómo utilizar, dentro de un proyecto java, herramientas de control de versiones, de generación de versiones, frameworks de testing unitario y para al final lograr el objetivo de tener un servicio de Integración Continua automatizado. Para más información vean la página del IEEE y se pueden inscribir acá.  Y por supuesto todo esto no hubiese sido posible sin la ayuda de Juan.

Nuevos caminos


2008
12.23

Gracias a la crisis mundial financiera me he quedado sin trabajo y me he propuesto utilizar esta oportunidad para devolverle algo a la comunidad y si es posible aprender algo nuevo en el camino. La idea es contribuir en el desarrollo del plugin de GIT para Eclipse y bloguear durante el proceso.

Ya se que a nadie le va interesar mucho pero igualmente me gustaría contarles como llegué a esta decisión. Lo que tenía claro desde el primer momento era que al ser yo un geek/nerd importante este blog no iba a estar libre de temas de tecnología, programación y demás nerdiadas. Después me di cuenta que no quería caer en el facilísmo de hacer un blog criticando a algunos de los tantos proyectos/frameworks que andan dando vuelta por ahí, porque la gente que ha participado en ellos dando de su tiempo y esfuerzo, no tienen que además soportar que venga cualquiera se monte un blog y los critique. Pero después pensándolo un poco mejor me dije “algunos de estos proyectos son un desastre y merecen ser defenestrados con una buena critica, pero… ¿ cómo ganarme el derecho ? “, entonces me contesté “primero hay que dejar de ser cualquiera y participar en un proyecto y ganarse el crédito para poder hablar del trabajo de los demás”.

Con esa última respuesta se empezaba a divisar el camino a seguir, el siguiente paso era elegir un proyecto. Los que primeros que surgieron fueron: Hibernate, donde ya me han aceptado algunos bug fixes, y o algo relacionado con GIT. Y terminé deciciendome por GIT porque es un aporte a dos comunidades a las cuales a admiro mucho. Sigan sintonizados!