首先我们明确jBPM 6 示例之 rewards-basic与前一篇jBPM 6 示例之 rewards的异同,相同点它们都使用同样的流程,即如下:
不同之处有两个:
最简单运行rewards-basic方法如下面两步:
1. 从http://sourceforge.net/projects/jbpm6examples/files/deployments/下载jbpm-demo-rewards-basic.war
2. 启动 JBoss 7(如软件安装及资料下载所示),部署jbpm-demo-rewards-basic.war(如使用4种方式部署应用到JBoss7/WildFly所示),部署完成既可以通过Web页面运行rewards-basic流程
另为我们也可以从源代码的方式编译生成jbpm-demo-rewards-basic.war,rewards-basic代码位于:https://github.com/kylinsoong/jbpm-6-examples/tree/master/rewards-basic,同样如软件安装及资料下载中描述的方法从github上克隆rewards-basic,使用Maven编译生成jbpm-demo-rewards-basic.war,
运行示例如下面几步:
1. 开始一个流程,在(http://localhost:8080/rewards-basic/)页面点击 Start如下:
2. 点击John's Task,完成approve操作,如下:
3. 点击Mary's Task,完成approve操作,如下:
4. 点击Audit,查看流程节点执行情况,如下:
org.jbpm.demo.rewards.ejb.ProcessBean中我们注入RuntimeManager,如下所示:
@Inject @Singleton private RuntimeManager singletonManager;
@Inject TaskService taskService;
org.jbpm.demo.rewards.ejb.ProcessBean中我们注入UserTransaction如下所示:
@Resource private UserTransaction ut;
ut.begin(); try { // start a new process instance Map<String, Object> params = new HashMap<String, Object>(); params.put("recipient", recipient); ProcessInstance processInstance = ksession.startProcess("org.jbpm.demo.rewards-basic", params); processInstanceId = processInstance.getId() ; System.out.println("Process started ... : processInstanceId = " + processInstanceId); ut.commit(); } catch (Exception e) {
jbpm-demo-rewards-basic.war的classes/META-INF/persistence.xml定义的内容如下:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <persistence version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd" xmlns:orm="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/persistence"> <persistence-unit name="org.jbpm.demo.rewards" transaction-type="JTA"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:jboss/datasources/jBPMRewardsDemotDS</jta-data-source> <mapping-file>META-INF/JBPMorm.xml</mapping-file> <mapping-file>META-INF/Taskorm.xml</mapping-file> <class>org.drools.persistence.info.SessionInfo</class> <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class> <class>org.drools.persistence.info.WorkItemInfo</class> <class>org.jbpm.persistence.correlation.CorrelationKeyInfo</class> <class>org.jbpm.persistence.correlation.CorrelationPropertyInfo</class> <class>org.jbpm.process.audit.ProcessInstanceLog</class> <class>org.jbpm.process.audit.NodeInstanceLog</class> <class>org.jbpm.process.audit.VariableInstanceLog</class> <!-- manager --> <class>org.jbpm.runtime.manager.impl.jpa.ContextMappingInfo</class> <class>org.jbpm.services.task.impl.model.AttachmentImpl</class> <class>org.jbpm.services.task.impl.model.ContentImpl</class> <class>org.jbpm.services.task.impl.model.BooleanExpressionImpl</class> <class>org.jbpm.services.task.impl.model.CommentImpl</class> <class>org.jbpm.services.task.impl.model.DeadlineImpl</class> <class>org.jbpm.services.task.impl.model.DelegationImpl</class> <class>org.jbpm.services.task.impl.model.EscalationImpl</class> <class>org.jbpm.services.task.impl.model.GroupImpl</class> <class>org.jbpm.services.task.impl.model.I18NTextImpl</class> <class>org.jbpm.services.task.impl.model.NotificationImpl</class> <class>org.jbpm.services.task.impl.model.EmailNotificationImpl</class> <class>org.jbpm.services.task.impl.model.EmailNotificationHeaderImpl</class> <class>org.jbpm.services.task.impl.model.PeopleAssignmentsImpl</class> <class>org.jbpm.services.task.impl.model.ReassignmentImpl</class> <class>org.jbpm.services.task.impl.model.TaskImpl</class> <class>org.jbpm.services.task.impl.model.TaskDataImpl</class> <class>org.jbpm.services.task.impl.model.UserImpl</class> <!--BAM for task service --> <class>org.jbpm.services.task.impl.model.BAMTaskSummaryImpl</class> <!-- Event Classes --> <class>org.jbpm.services.task.audit.TaskEventImpl</class> <exclude-unlisted-classes>true</exclude-unlisted-classes> <properties> <property name="hibernate.max_fetch_depth" value="3"/> <property name="hibernate.hbm2ddl.auto" value="update" /> <property name="hibernate.show_sql" value="false" /> <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" /> <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/> <property name="hibernate.id.new_generator_mappings" value="false"/> </properties> </persistence-unit> </persistence>
我们在设计流程时在Script部分除了系统输出外,还添加使用Infinispan来存储节点运行数据,如下为开始节点Script内容:
long id = kcontext.getProcessInstance().getId(); String name = (String)kcontext.getVariable("recipient"); String log = "process " + id + " started by " + name; System.out.println(log); AuditDAO.Factory.get().addAudit(new Long(id), log);