02-13-2018 07:56 AM
Good Morning,
I'm new to activiti, i have read activiti books articles, forums, books during aprox six months , i think i catch the point about the architecture. But i have not found any clear documentation of how to perform the integration with Drools. Almost all examples finish with the instantation and integration within junit tests. The question is ,how to do it with the real bpm, with activiti tasks and java classes?
I'm developing in Eclipse Oxygen, with Activiti 6.0, maven dependencies:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<activiti-version>6.0.0</activiti-version>
<drools-version>6.5.0.Final</drools-version>
</properties>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>${activiti-version}</version>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>${activiti-version}</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-rest-api</artifactId>
<version>${activiti-version}</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-actuator</artifactId>
<version>${activiti-version}</version>
</dependency>
<!-- Drools -->
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>${drools-version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>knowledge-api</artifactId>
<version>${drools-version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>${drools-version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-decisiontables</artifactId>
<version>${drools-version}</version>
</dependency>
<dependency>
<groupId>org.mvel</groupId>
<artifactId>mvel2</artifactId>
<version>2.4.0.Final</version>
</dependency>
First i write my rules in an Excel file, the junit test works perfect, but i read that activiti doesn't deploy the xls, so i convert the xls to a drl file. Also the junit test of the drl works perfect.
Content of the drl file:
package com.drools.rules;
//generated from Decision Table
import com.model.bpm.FacturaBPM;
// rule values at B13, header at B8
rule "ValidarFactura_13"
when
fa : FacturaBPM(importeFactura >= 10000, continenteFactura == ("Oceania"))
then
fa.setNecesitaValidacion(true);
end
// rule values at B14, header at B8
rule "ValidarFactura_14"
when
fa : FacturaBPM(importeFactura >= 20000, continenteFactura == ("Asia"))
then
fa.setNecesitaValidacion(true);
end
// rule values at B15, header at B8
rule "ValidarFactura_15"
when
fa : FacturaBPM(importeFactura >= 5000, continenteFactura == ("Africa"))
then
fa.setNecesitaValidacion(true);
end
// rule values at B16, header at B8
rule "ValidarFactura_16"
when
fa : FacturaBPM(importeFactura >= 30000, continenteFactura == ("America"))
then
fa.setNecesitaValidacion(true);
end
// rule values at B17, header at B8
rule "ValidarFactura_17"
when
fa : FacturaBPM(importeFactura >= 60000, continenteFactura == ("Europa"))
then
fa.setNecesitaValidacion(true);
end
I also added to activiti-cfx.xml, in the processEngineConfiguration bean:
<property name="customPostDeployers">
<list>
<bean class="org.activiti.engine.impl.rules.RulesDeployer" />
</list>
</property>
The xml code of the bpm:
<serviceTask id="setPrepareDataDrools" name="Preparar datos Drools" activiti:class="com.transcoma.facturacion.business.PrepararDatosDrools"></serviceTask>
<sequenceFlow id="flPrepararDatosDrools2DroolsRequiereValidacion" sourceRef="setPrepareDataDrools" targetRef="drtRequiereValidacion"></sequenceFlow>
<businessRuleTask id="drtRequiereValidacion" name="Drools Requiere Validación" activiti:ruleVariablesInput="$(facturaBPM)"
activiti:rules="ValidarFactura_13,ValidarFactura_14,ValidarFactura_15" activiti:resultVariable="rulesOutput">
<documentation>In rule names field, we need to provide the name of the rule that we want to call from BusinessRuleTasks</documentation>
</businessRuleTask>
Code of PrepararDatosDrools
FacturaBPM facturaBPM = new FacturaBPM();
String continente = "Africa";
BigDecimal importe = new BigDecimal(258999);
facturaBPM.setContinenteFactura(continente);
facturaBPM.setImporteFactura(importe);
execution.setVariable("facturaBPM", facturaBPM);
When i run the whole bpm flow inside Eclipse, with a junit test, always get
org.activiti.engine.ActivitiException: deployment 135001 doesn't contain any rules
So, what are the steps to integrate activiti with drools?
1) Where i put the drl file? In which folder?
2) How it works the integration of activiti? When the flow finds an businessRuleTask, what exactly do?
3) What i'm missing, why it doesn't work?
Best Regards and thank you in advance
02-14-2018 07:45 AM
1) Where i put the drl file? In which folder? --> same place you put the activiti.cfg.xml
3) What i'm missing, why it doesn't work? --> because i don't deploy the *.drl file
Changed
repositoryService.createDeployment()
.addInputStream("processFacturacion.bpmn20.xml",new FileInputStream(filename))
.deploy();
To
repositoryService.createDeployment()
.addInputStream("processFacturacion.bpmn20.xml",new FileInputStream(filename))
.addInputStream("ValidarFactura.drl",new FileInputStream(droolsfilename))
.deploy();
So sorry for the time you have spend reading my "issue"
Anyway, thanks a lot
02-14-2018 07:45 AM
1) Where i put the drl file? In which folder? --> same place you put the activiti.cfg.xml
3) What i'm missing, why it doesn't work? --> because i don't deploy the *.drl file
Changed
repositoryService.createDeployment()
.addInputStream("processFacturacion.bpmn20.xml",new FileInputStream(filename))
.deploy();
To
repositoryService.createDeployment()
.addInputStream("processFacturacion.bpmn20.xml",new FileInputStream(filename))
.addInputStream("ValidarFactura.drl",new FileInputStream(droolsfilename))
.deploy();
So sorry for the time you have spend reading my "issue"
Anyway, thanks a lot
Explore our Alfresco products with the links below. Use labels to filter content by product module.