Primeramente si no tenemos descargado JBoss tenemos que descargarlo de:http://www.jboss.org/jbossas/downloads/
Una vez descargado JBoss, descargamos el JBPM Installer(jbpm-installer-3.2.6.GA.jar) de: http://sourceforge.net/projects/jbpm/files/

Ejecutamos el instalador desde un terminal como:java -jar jbpm-installer-3.2.6.GA.jar






Una vez hecho esto, abrimos Eclipse

Y vamos a software update para actualizar la versión actual. Para esto vamos a Help/Software Updates



Luego, tenemos que descargar el plugin del Designer de JBPM para Eclipse, para este caso descargamos un archivo zip llamado jbpm-jpdl-designer-site-3.1.6.zip de http://sourceforge.net/projects/jbpm/files/

Una vez instalado este plugin, reiniciamos Eclipse. También aqui debemos hacer un paso importante, para evitar un problema de referencia a una libreria desde Eclipse. Tenemos que copiar la libreria activation.jar a

Luego desde Eclipse creamos un Process Project bajo la categoría JBoss jBPM





Le damos un nombre y seleccionamos donde se guardará

Entonces se nos abrirá el Designer


El archivo gpd.xml(que tiene información sobre el dibujo) debe quedar:
<? xml version = "1.0" encoding = "UTF-8"?>
<process-diagram name="simple" width="469" height="438">
<node name="start" x="150" y="25" width="140" height="40">
<transition name="to_state"/>
</ node>
<node name="first" x="150" y="125" width="140" height="40">
<transition name="to_end"/>
</ node>
<node name="end" x="150" y="225" width="140" height="40"/>
</ process-diagram>
El archivo processdefinition.xml(Que tiene la definición del flujo y clases handler que se utilizaran en cada estado) debe quedar como:
<?xml version="1.0" encoding="UTF-8"?>
<process-definition xmlns="urn:jbpm.org:jpdl-3.2"
name="Proceso1">
<start-state name="start">
<transition name="to_state" to="first">
<action name="action" class="com.sample.action.MessageActionHandler">
<message>Vamos al primer Estado</message>
</action>
</transition>
</start-state>
<state name="first">
<transition name="to_end" to="end">
<action name="action" class="com.sample.action.MessageActionHandler">
<message>Vamos al estado Final</message>
</action>
</transition>
</state>
<end-state name="end"></end-state>
</process-definition>
La clase MessageActionHandler(Que es la clase handler) tiene el siguiente código
package com.sample.action;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;
public class MessageActionHandler implements ActionHandler {
private static final long serialVersionUID = 1L;
/**
* The message member gets its value from the configuration in the
* processdefinition. The value is injected directly by the engine.
*/
String message;
/**
* A message process variable is assigned the value of the message
* member. The process variable is created if it doesn't exist yet.
*/
public void execute(ExecutionContext context) throws Exception {
context.getContextInstance().setVariable("message", message);
}
}
Finalmente el test case para probar todo lo anterior, llamado SimpleProcessTest tiene el siguiente código:
package com.sample;
import java.io.File;
import java.io.FileInputStream;
import junit.framework.TestCase;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
public class SimpleProcessTest extends TestCase {
public void testSimpleProcess() throws Exception {
FileInputStream fis = new FileInputStream(
"src/main/jpdl/simple/Proceso1/processdefinition.xml");
ProcessDefinition processDefinition = ProcessDefinition
.parseXmlInputStream(fis);
ProcessInstance instance = new ProcessInstance(processDefinition);
assertEquals("start state",
instance.getRootToken().getNode().getName(), "start");
System.out.println(instance.getRootToken().getNode().getName());
System.out.println(instance.getContextInstance().getVariable("message"));
instance.signal();
assertEquals("first state",
instance.getRootToken().getNode().getName(), "first");
System.out.println(instance.getRootToken().getNode().getName());
System.out.println(instance.getContextInstance().getVariable("message"));
instance.signal();
assertEquals("Instance is in end state", instance.getRootToken()
.getNode().getName(), "end");
System.out.println(instance.getRootToken().getNode().getName());
System.out.println(instance.getContextInstance().getVariable("message"));
assertTrue("Instance has ended", instance.hasEnded());
}
}
Lo cual genera la siguiente salida

No hay comentarios:
Publicar un comentario