jbmp4常用的方法

	/**
	 * 通过xml部署新流程定义
	 * @param resourceName
	 * @return 返回流程定义标识
	 */
	public String deployProcessEngine(String resourceName) {
		return processEngine.getRepositoryService().createDeployment()
        .addResourceFromClasspath(resourceName).deploy();
	}
	/**
	 * 通过zip文件部署流程
	 * @param zipname
	 * @return 返回流程部署标识
	 */
	public String deployProcessEngineWithZip(String zipName) {
		// 将文件输入流作为参数构造一个ZipInputStream对象
		ZipInputStream zis = null;
		try {
			zis = new ZipInputStream(new FileInputStream(new File(
					zipName)));
		} catch (FileNotFoundException e) {
			throw new BusinessException("部署新流程失败,流程定义文件找不到");
		}
		return repositoryService.createDeployment()
				.addResourcesFromZipInputStream(zis).deploy();

	}
	
	 
	/**
	 * 启动一个流程实例
	 * @param key
	 */
    public ProcessInstance startPIByKey(String key){
    	return  executionService.startProcessInstanceByKey(key);
    }
    /**
	 * 启动一个流程实例
	 * @param id
	 * @param map
	 * @return
	 */
	public ProcessInstance startProcessInstance(String id, Map<String, ?> map) {
		return executionService.startProcessInstanceById(id, map);
	}
	
	
	
	/**
	 * 删除一个流程实例
	 * @param processInstanceId 流程实例id
	 * @return
	 */
	public void deleteProcessInstance(String processInstanceId) {
		executionService.deleteProcessInstance(processInstanceId);
	}
	
	
	/**
	 *通过流程实例比标识 获取流程实例
	 * @param processInstanceId 流程实例标识
	 * @return 流程实例
	 */
	public ProcessInstance getProcessInstance(String processInstanceId) {
		return executionService.findProcessInstanceById(processInstanceId);
	}	
	
	/**
	 * 通过任务标识     获取流程实例
	 * @param taskId 任务id
	 * @return
	 */
	public ProcessInstance getProcessInstanceByTankId(String taskId) {
		Task task = taskService.getTask(taskId); 
		Execution execution = executionService.findExecutionById(task.getExecutionId()); 
		Execution processInstance = execution.getProcessInstance();		
		return (ProcessInstance) processInstance;
	}
	
	
	/**
	 * 完成任务
	 * @param taskId
	 * @param map
	 */

	public void completeTask(String taskId, Map map) {
		taskService.completeTask(taskId, map);
	}

	/**
	 * 完成任务
	 * @param taskId
	 */
	public void completeTask(String taskId) {
		taskService.completeTask(taskId);
	}

	/**
	 * 将任务流转到指定名字的流程中的下一个节点
	 * @param taskId
	 * @param outcome
	 */
	public void completeTask(String taskId, String outcome) {
		taskService.completeTask(taskId, outcome);
	}
	
	/**
	 * 根据任务标识  获得  可以留出的所有节点
	 * @param taskId
	 * @return 集合
	 */
	public Set<String> getOutcomes(String taskId) {
		return taskService.getOutcomes(taskId);
	}
	
	/**
	 * 获得所有发布了的流程定义
	 * @return list
	 */
	public List<ProcessDefinition> getAllPdList() {
		return repositoryService.createProcessDefinitionQuery().list();
	}
	
	/**
	 * 根据流程定义ID获取流程定义实例 
	 * @param id 流程定义ID
	 * @return 流程定义实例 
	 */
	public ProcessDefinition getSinglePD(String id) {
		return repositoryService.createProcessDefinitionQuery()
				.processDefinitionId(id).uniqueResult();
	}
	
	/**
	 * 根据流程部署ID获取流程定义实例 
	 * @param id 流程部署ID
	 * @return 流程定义实例
	 */
	public ProcessDefinition getSingleDPD(String deploymentId) {
		return repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).uniqueResult();
	}
	

	/**
	 * 获得所有流程实例
	 * @return
	 */
	public List<ProcessInstance> getAllPiList() {
		return executionService.createProcessInstanceQuery().list();
	}
	
	/**
	 * 根据流程部署ID 获取流程部署实例 
	 * @param deploymentId 流程部署ID
	 * @return 流程部署实例
	 */	
	public Deployment getSingleD(String deploymentId){
		return repositoryService.createDeploymentQuery().deploymentId(deploymentId).uniqueResult();
	}

	
	
	
	/**
	 * 根据部署id,获取图片名称和xml名称
	 * @param deploymentId 部署id
	 * @return
	 */
	public Set<String> getResourceNames(String deploymentId){
		return repositoryService.getResourceNames(deploymentId);
	}
	
	/**
	 * 根据流程实例Id,即executionId获取指定的变量值
	 * 
	 * @param executionId
	 * @param variableName
	 * @return
	 */
	public Object getVariableByexecutionId(String executionId,
			String variableName) {
		return executionService.getVariable(executionId, variableName);
	}

	/**
	 * 根据任务id,即taskId获取指定变量值
	 * 
	 * @param taskId
	 * @param variableName
	 * @return
	 */
	public Object getVariableByTaskId(String taskId, String variableName) {
		return taskService.getVariable(taskId, variableName);
	}

	/**
	 * 获取指定用户名字的任务
	 * 
	 * @param userName
	 * @return
	 */
	public List<Task> findPersonalTasks(String userName) {
		return taskService.findPersonalTasks(userName);
	}

	
	/**
	 * 获取流程实例
	 * @param taskId 任务id
	 * @return
	 */
	public ProcessInstance getTaskProcessInstance(String taskId) {
		Task task = taskService.getTask(taskId); 
		Execution execution = executionService.findExecutionById(task.getExecutionId()); 
		Execution processInstance = execution.getProcessInstance();		
		return (ProcessInstance) processInstance;
	}
	
	
	/**
	 * 根据任务id获取任务
	 * 
	 * @param taskId
	 * @return
	 */
	public Task getTask(String taskId) {
		return taskService.getTask(taskId);
	}
	
	/**
	 * 根据节点名取一流程实例下的任务 
	 * @param processInstanceId 流程实例id
	 * @param activityName	节点名称
	 * @return
	 * 
	 * 例如:<task assignee="ls" g="118,126,94,55" name="ls审批">
	 * 		name: activityName
	 * 		assignee:assignee
	 */
	public Task getTaskByActivityName(String processInstanceId,String activityName){
		return taskService.createTaskQuery().processInstanceId(processInstanceId).activityName(activityName).uniqueResult();    
	}
	
	
	/**
	 * 根据任务分配者assignee取一流程实例下的任务 
	 * @param processInstanceId 流程实例id
	 * @param assignee	参与者
	 * @return
	 */
	public Task getTaskByAssignee(String processInstanceId,String assignee){
		return taskService.createTaskQuery().processInstanceId(processInstanceId).assignee(assignee).uniqueResult();
	}

	/**
	 * 级联删除流程定义,直接删除该流程定义下的所有实例
	 * 
	 * @param deploymentId 流程部署id
	 */
	public void deleteDeploymentCascade(String deploymentId) {
		repositoryService.deleteDeploymentCascade(deploymentId);
	}
	
	/**
	 * 根据流程的名称  级联删除此流程定义的所有版本及其下所有实例
	 * (注意:这里写key似乎有问题,没太论证,第一次写key出错,第二次写processKey通过)
	 * @param name 
	 */
	public void deleteDeploymentVersions(String processKey) {
		List<ProcessDefinition> pds = repositoryService.createProcessDefinitionQuery().processDefinitionKey(processKey).list();
		for(ProcessDefinition pd : pds){
			repositoryService.deleteDeploymentCascade(pd.getDeploymentId());
		}
	}

	
	
	/**
	 * 根据留出实例标识得到      当前活跃节点集合
	 * @param processInstanceId 流程实例id
	 * @return
	 */
	public Set<String> findActiveActivityNames(String processInstanceId){
		ProcessInstance pi = executionService.findProcessInstanceById(processInstanceId);
		// 获取所有活跃的节点:   
		Set<String> activitySet = pi.findActiveActivityNames();  
		return activitySet;
	}
	

你可能感兴趣的:(xml)