工作流 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 names = repositoryService.getResourceNames(pd.getDeploymentId());
//					Set 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





	

		
		
		
		
		
		
		
		
		
			
		

		

		
		

		

		
			
			
			
			
			
			
		

		
			
			${task.name}
			
		

		
			
			${task.name}
			
		

	

	
		
		

		
		
		
		
			
				
			
		
	

    

 

 

jbpm.hibernate.cfg.xml






	
		com.mysql.jdbc.Driver
		jdbc:mysql://localhost:3306/testjbpm
		true
  		utf-8
		  org.hibernate.dialect.MySQLInnoDBDialect  
		
		root
		123456
		true
		update
		true
		20


		
		
		
		
		

	

 

 

 

jbpm.cfg.xml

 

 

	
    	
  	
	
	
	
	
	
	
	
	
	 

 

 

 

applicationContext-flow.xml

 




	
		
			jbpm.cfg.xml
		

	

	

	

	

	

	

	

	




 

 

 

applicationContext-core.xml

 




	
		
			
				
					classpath:jbpm.hibernate.cfg.xml
				
			
			
		
	

	
		
	

	
		
		
			
				PROPAGATION_REQUIRED,-Exception
				PROPAGATION_REQUIRED,-Exception
				PROPAGATION_REQUIRED,-Exception
				PROPAGATION_REQUIRED,-Exception
				PROPAGATION_REQUIRED,-Exception
				PROPAGATION_REQUIRED,-Exception
				PROPAGATION_REQUIRED,-Exception
				PROPAGATION_REQUIRED,-Exception
				PROPAGATION_REQUIRED,-Exception
				PROPAGATION_REQUIRED,readOnly
				PROPAGATION_NEVER
			
		
	
 
	 
		com.mysql.jdbc.Driver
	
	
		jdbc:mysql://localhost:3306/testjbpm
	
	
		root
	
	
		123456
	


 	



 	



 

 

 

 

applicationContext-bean.xml

 



        


 

 

 

你可能感兴趣的:(工作流,jbpm)