`
knight_black_bob
  • 浏览: 858516 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

工作流 jbpm

    博客分类:
  • jbpm
阅读更多

 

package com.jbpm.controller;


import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONArray;

import org.dom4j.Document;
import org.jbpm.api.ExecutionService;
import org.jbpm.api.HistoryService;
import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.RepositoryService;
import org.jbpm.api.TaskService;
import org.jbpm.api.cmd.Environment;
import org.jbpm.pvm.internal.env.EnvironmentFactory;
import org.jbpm.pvm.internal.env.EnvironmentImpl;
import org.jbpm.pvm.internal.session.RepositorySession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jbpm.service.MyDayService;
import com.jbpm.workflow.service.BpmConfigParser;
/**
 * controller��
 * @author Administrator
 *
 */
@Controller
@RequestMapping("flow")
public class FlowController {

	@Resource(name="repositoryService")
	private RepositoryService repositoryService;//-流程管理,部署发布
	
	@Resource(name="taskService")
	private TaskService taskService;//任务管理
	
	@Resource(name="executionService")
	private ExecutionService executionService;//-流程实例管理
	
	@Resource(name="myDayService")
	private MyDayService myDayService;//业务逻辑
	
	@Resource(name="historyService")
	private HistoryService historyService;//业务逻辑
	
	@Resource(name="jbpmParser")
	private BpmConfigParser jbpmParser; //jbpm解析器
	
	@Resource(name="processEngine")
	private ProcessEngine processEngine;
	@RequestMapping("toFlow")
	public String toFlow(HttpServletRequest request){
		return "projectFlowAdd";
	}


	@RequestMapping("deploy")
	public @ResponseBody String deploy(HttpServletRequest request,String flowJson){
		try{
			System.out.println(flowJson);
			Document doc = jbpmParser.parseEditorFile(flowJson);
			String key = jbpmParser.getProcessKey(flowJson);
			String resourceName = key + ".jpdl.xml";
			System.out.println(doc.asXML()+","+key);
			String deployId = repositoryService.createDeployment().addResourceFromString(resourceName, doc.asXML()).deploy();
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return "success";
	}
	@RequestMapping("showFlowEdit")
	public String showFlowEdit(HttpServletRequest request,String flowKey){
		if(flowKey == null || "".endsWith(flowKey)){
			request.setAttribute("flowJsonResult", "null");
		}else{
			InputStream ins = this.getProcessDefCfg(flowKey);
			String flowName = this.getProcessDefinition(flowKey).getName();
			String flowJsonResult = jbpmParser.parseBpmConfig(ins);
			
			request.setAttribute("flowJsonResult", flowJsonResult);
			request.setAttribute("flowKey", flowKey);
			request.setAttribute("flowName", flowName);
		}
		return "projectFlowEditor";
	}

	public InputStream getProcessDefCfg(String flowKey) {
		EnvironmentFactory environmentFactory = (EnvironmentFactory) processEngine;
		Environment environment = environmentFactory.openEnvironment();
				
			try{
					RepositorySession repositorySession = environment.get(RepositorySession.class);   
					ProcessDefinition pd = repositorySession.findProcessDefinitionByKey(flowKey);
					Set<String> names = repositoryService.getResourceNames(pd.getDeploymentId());
//					Set<String> names = new GetDeploymentResourceNamesCmd(pd.getDeploymentId()).execute(environment);
					for (String n :names) {
						if (n.indexOf(".jpdl.xml") != -1) {
							InputStream in = repositoryService.getResourceAsStream(pd.getDeploymentId(), n);
							return in;
						}
					}
				}catch(Exception e){
					e.printStackTrace();
				}finally{
					closeEnvironment(environment);
				}
		return null;
	}
	
	private void closeEnvironment(Environment environment){
		if(environment!=null){
			((EnvironmentImpl)environment).close();
		}
	}
	
	public ProcessDefinition getProcessDefinition(String flowKey) {
		EnvironmentFactory environmentFactory = (EnvironmentFactory) processEngine;
		Environment environment = environmentFactory.openEnvironment();
		ProcessDefinition pd = null;		
			try{
					RepositorySession repositorySession = environment.get(RepositorySession.class);   
					 pd = repositorySession.findProcessDefinitionByKey(flowKey);
			}catch(Exception e){
				e.printStackTrace();
			}
		return pd;
	}
	
}

 

 

 

jbpm.spring.default.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>

<jbpm-configuration>

	<process-engine-context>

		<repository-service />
		<repository-cache />
		<execution-service />
		<history-service />
		<management-service />
		<identity-service />
		<task-service />
		<!--

			<hibernate-configuration> <cfg resource="jbpm.hibernate.cfg.xml" />
			</hibernate-configuration> <hibernate-session-factory />
		-->
		<script-manager default-expression-language="juel"
			default-script-language="juel" read-contexts="execution, environment, process-engine"
			write-context="">
			<script-language name="juel"
				factory="org.jbpm.pvm.internal.script.JuelScriptEngineFactory" />
		</script-manager>

		<authentication />

		<id-generator />
		<types resource="jbpm.variable.types.xml" />

		<address-resolver />

		<business-calendar>
			<monday hours="9:00-12:00 and 12:30-17:00" />
			<tuesday hours="9:00-12:00 and 12:30-17:00" />
			<wednesday hours="9:00-12:00 and 12:30-17:00" />
			<thursday hours="9:00-12:00 and 12:30-17:00" />
			<friday hours="9:00-12:00 and 12:30-17:00" />
			<holiday period="01/07/2008 - 31/08/2008" />
		</business-calendar>

		<mail-template name='task-notification'>
			<to users="${task.assignee}" />
			<subject>${task.name}</subject>
			<text><![CDATA[Hi ${task.assignee},Task "${task.name}" has been assigned to you. ${task.description}Sent by JBoss jBPM   
]]></text>
		</mail-template>

		<mail-template name='task-reminder'>
			<to users="${task.assignee}" />
			<subject>${task.name}</subject>
			<text><![CDATA[Hey ${task.assignee},Do not forget about task "${task.name}".${task.description}Sent by JBoss jBPM   
]]></text>
		</mail-template>

	</process-engine-context>

	<transaction-context>
		<repository-session />
		<db-session />

		<message-session />
		<timer-session />
		<history-session />
		<mail-session>
			<mail-server>
				<session-properties resource="jbpm.mail.properties" />
			</mail-server>
		</mail-session>
	</transaction-context>

</jbpm-configuration>    

 

 

jbpm.hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>

	<session-factory>
		<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
		<property name="connection.url">jdbc:mysql://localhost:3306/testjbpm</property>
		<property name="connection.useUnicode">true</property>
  		<property name="connection.characterEncoding">utf-8</property>
		  <property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>  
		<!--<property name="dialect">org.hibernate.dialect.MySQLDialect</property>-->
		<property name="connection.username">root</property>
		<property name="connection.password">123456</property>
		<property name="show_sql">true</property>
		<property name="hbm2ddl.auto">update</property>
		<property name="formate_sql">true</property>
		<property name="hibernate.jdbc.batch_size">20</property>


		<mapping resource="jbpm.repository.hbm.xml" />
		<mapping resource="jbpm.execution.hbm.xml" />
		<mapping resource="jbpm.history.hbm.xml" />
		<mapping resource="jbpm.task.hbm.xml" />
		<mapping resource="jbpm.identity.hbm.xml" />

	</session-factory>
</hibernate-configuration>

 

 

 

jbpm.cfg.xml

 

<?xml version="1.0" encoding="UTF-8"?> 
<jbpm-configuration>
	<process-engine-context>
    	<string name="spring.cfg" value="applicationContext-core.xml" />
  	</process-engine-context>
	<import resource="jbpm.default.cfg.xml" />
	<import resource="jbpm.tx.spring.cfg.xml" />
	<import resource="jbpm.jpdl.cfg.xml" />
	<import resource="jbpm.bpmn.cfg.xml" />
	<import resource="jbpm.identity.cfg.xml" />
	<import resource="jbpm.businesscalendar.cfg.xml" />
	<import resource="jbpm.console.cfg.xml" />
	<import resource="jbpm.spring.default.cfg.xml"/>
	 
</jbpm-configuration>

 

 

 

applicationContext-flow.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:p="http://www.springframework.org/schema/p"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:aop="http://www.springframework.org/schema/aop" 
 xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:mvc="http://www.springframework.org/schema/mvc" 
 xmlns:task="http://www.springframework.org/schema/task"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-3.0.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
      http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
      http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/task
        http://www.springframework.org/schema/task/spring-task-3.0.xsd">

	<bean id="jbpmSpringHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper"
		lazy-init="true" autowire="default" dependency-check="default">
		<property name="jbpmCfg">
			<value>jbpm.cfg.xml</value>
		</property>

	</bean>

	<bean id="processEngine" factory-bean="jbpmSpringHelper"
		factory-method="createProcessEngine" />

	<bean id="repositoryService" factory-bean="processEngine"
		factory-method="getRepositoryService" /><!--流程管理,部署发布  -->

	<bean id="executionService" factory-bean="processEngine"
		factory-method="getExecutionService" /><!--流程实例管理  -->

	<bean id="taskService" factory-bean="processEngine"
		factory-method="getTaskService" /><!--任务管理  -->

	<bean id="historyService" factory-bean="processEngine"
		factory-method="getHistoryService" /><!--历史服务  -->

	<bean id="identityService" factory-bean="processEngine"
		factory-method="getIdentityService" /><!--身份管理  -->

	



</beans>

 

 

 

applicationContext-core.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:p="http://www.springframework.org/schema/p"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:aop="http://www.springframework.org/schema/aop" 
 xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:mvc="http://www.springframework.org/schema/mvc" 
 xmlns:task="http://www.springframework.org/schema/task"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-3.0.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
      http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
      http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/task
        http://www.springframework.org/schema/task/spring-task-3.0.xsd">

	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="configLocations">
			<list>
				<value>
					classpath:jbpm.hibernate.cfg.xml
				</value>
			
			</list>
		</property>
	</bean>

	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>

	<bean id="transactionBese" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" lazy-init="true">
		<property name="transactionManager" ref="transactionManager" />
		<property name="transactionAttributes">
			<props>
				<prop key="add*">PROPAGATION_REQUIRED,-Exception</prop>
				<prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
				<prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
				<prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop>
				<prop key="modify*">PROPAGATION_REQUIRED,-Exception</prop>
				<prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
				<prop key="create*">PROPAGATION_REQUIRED,-Exception</prop>
				<prop key="deploy*">PROPAGATION_REQUIRED,-Exception</prop>
				<prop key="do*">PROPAGATION_REQUIRED,-Exception</prop>
				<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="get*">PROPAGATION_NEVER</prop>
			</props>
		</property>
	</bean>
 <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
	 <property name="driverClassName">
		<value>com.mysql.jdbc.Driver</value>
	</property>
	<property name="url">
		<value>jdbc:mysql://localhost:3306/testjbpm</value>
	</property>
	<property name="username">
		<value>root</value>
	</property>
	<property name="password">
		<value>123456</value>
	</property>
</bean>
<bean id="simpleJdbcTemplate" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
 	<constructor-arg ref="dataSource" />
</bean>

<bean id="namedParameterJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
 	<constructor-arg ref="dataSource" />
</bean>

</beans>

 

 

 

 

applicationContext-bean.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:p="http://www.springframework.org/schema/p"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:aop="http://www.springframework.org/schema/aop" 
 xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:mvc="http://www.springframework.org/schema/mvc" 
 xmlns:task="http://www.springframework.org/schema/task"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-3.0.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
      http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
      http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/task
        http://www.springframework.org/schema/task/spring-task-3.0.xsd">
        
<context:component-scan base-package="com.jbpm"/>
<mvc:annotation-driven/>
 
</beans>

 

 

分享到:
评论

相关推荐

    工作流JBPM开发计划书

    ### 工作流JBPM开发计划书 #### 一、项目背景与目标 在当前数字化转型的大背景下,企业越来越依赖于高效的工作流程管理来提升业务效率和服务质量。JBPM(JBoss流程管理)作为一款开源的工作流引擎,因其灵活性、可...

    工作流jbpm应用的实例

    工作流jbpm应用实例解析 工作流jbpm(Java Business Process Management)是一种开源的工作流管理系统,主要用于设计、执行和管理业务流程。jbpm是基于Java技术的,它提供了丰富的API和图形化工具,使得开发者可以...

    有关工作流jbpm概述(5)

    工作流jbpm是一个开源的工作流引擎,主要用于设计、执行和管理业务流程。本文将深入探讨工作流的概念,jbpm的特点,以及它在实际业务场景中的应用。 首先,工作流起源于生产组织和办公自动化领域,旨在通过将工作...

    工作流JBPM中文开发指南

    总的来说,"工作流JBPM中文开发指南"是学习和掌握JBPM的重要资源,无论你是刚接触工作流管理的新手,还是寻求深化JBPM应用的资深开发者,都能从中受益匪浅。通过深入阅读和实践,你可以熟练地运用JBPM来设计、实施和...

    请假工作流JBPM整合SSH2完整实例

    【标题】"请假工作流JBPM整合SSH2完整实例"涉及了多个IT领域的关键技术,主要集中在企业级应用开发上。JBPM(Java Business Process Management)是用于业务流程管理的开源框架,而SSH2则指的是Spring、Struts和...

    工作流 JBPM SSH 示例

    工作流JBPM SSH示例是将企业级工作流管理系统JBPM与流行的Java开发框架SSH(Struts、Spring、Hibernate)整合的一个典型应用。这个示例旨在帮助开发者理解如何在Java Web环境中集成工作流管理,以实现更高效的企业...

    工作流jbpm---学习文档+简单实例项目

    工作流jbpm是一种广泛应用于企业级应用中的流程自动化框架,它允许开发者定义、执行和管理业务流程。jbpm结合了模型驱动的架构(MDA)和业务流程执行语言(BPEL),为开发者提供了一个强大的工具来处理复杂的业务...

    完整的工作流jbpm实例

    这个“完整的工作流jbpm实例”是一个包含了所有必要组件的示例项目,你可以直接在其中进行学习和实践。它提供的核心功能包括: 1. **流程建模**:jbpm使用BPMN(Business Process Model and Notation)2.0标准,这...

    工作流JBPM

    【工作流JBPM】是一种强大的业务流程管理系统,尤其适合初学者快速掌握。JBPM是JBoss组织提供的一个开源工作流引擎,集成了业务流程管理、工作流和服务协作等多个领域,提供了一个灵活且可扩展的可执行流程语言框架...

    完整工作流JBPM项目实战全过程教程2---项目详细讲解

    【标题】"完整工作流JBPM项目实战全过程教程2---项目详细讲解"涉及的主要知识点是JBPM(Java Business Process Management)的工作流程管理以及如何在实际项目中应用。JBPM是一个开源的工作流管理系统,用于设计、...

    论文研究-工作流jBPM在企业中的应用 .pdf

    工作流jBPM是一种流程自动化工具,能够帮助企业实现工作流的自动化管理。随着企业信息化水平的提升,越来越多的企业期望能够通过使用新的信息管理系统来提高信息交流的效率,并对工作进行有效的监控,以提升企业的...

    工作流 jbpm4.0用户指南

    是我花了好久才找到的资源,开源工作流产品JBPM的开发指南,是本人在学习JPBM过程中所使用的资料,希望能给各位开发者在使用JBPM过程中带来帮助. 想要了解jbpm的不可多得的资料,也是我很多同事都看过的。从配置开发...

    工作流 jbpm培训资料

    【jbpm工作流详解】 jbpm(Java Business Process Management)是一种开源的工作流管理系统,它提供了对业务流程的建模、部署、执行和监控的能力。jbpm不仅是一个强大的工作流引擎,还是一个完整的业务流程管理解决...

    工作流jBPM.jar包

    BPM,全称是Java Business Process Management(业务流程管理),它是覆盖了业务流程管理、工作流、服务协作等领域的一个开源的、灵活的、易扩展的可执行流程语言框架。jBPM是公开源代码项目,使用它要遵循 ASL(Apache...

    jbpm工作流

    **jbpm工作流详解** jbpm(Java Business Process Management)是一个开源的工作流程管理系统,它提供了完整的工作流程自动化和业务流程管理解决方案。jbpm的核心功能包括流程建模、执行、监控和优化,使得开发者和...

    工作流JBPM课程-毕业设计

    利用JBPM设计工作流,比如请假申请,转专业申请,学生会申请,入党申请等等,非常实用。

    工作流引擎jbpm学习笔记

    工作流引擎jbpm学习笔记 jbpm是一个专业的工作流引擎,用于定义、管理和执行业务流程。它可以帮助我们简化工作流程的开发和维护,提高工作效率和可扩展性。 一、什么是公文流转? 公文流转是指公文在定义流转中的...

Global site tag (gtag.js) - Google Analytics