jbpm4.4 启动,查询任务,做任务,参数

@Test
	public void getResourceNameByDeployment() {
		Set<String> resourceNames = processEngine.getRepositoryService().getResourceNames("100001");// 获取资源名称
		for (String s : resourceNames) {
			System.out.println(s);
		}

	}

	@Test
	public void getResourceByDeployment() {// 获取资源并下载到本地
		InputStream is = processEngine.getRepositoryService().getResourceAsStream("70001", "test.jpdl.xml");
		InputStreamReader isr = null;
		OutputStreamWriter osw = null;
		try {
			isr = new InputStreamReader(is);
			osw = new OutputStreamWriter(new FileOutputStream("c:/test.jpdl.xml"), "utf-8");
			char[] b = new char[1024];
			while (isr.read(b) != -1) {
				osw.write(b);
				osw.flush();
			}
		} catch (Exception e) {

			e.printStackTrace();
		} finally {
			try {
				osw.close();
				isr.close();
			} catch (IOException e) {

				e.printStackTrace();
			}
		}

	}

	@Test
	public void start() {
		org.jbpm.api.ProcessInstance pi = processEngine.getExecutionService()//
				.startProcessInstanceByKey("cccs");// 通过key启动流程
		System.out.println("   state=" + pi.getState() + "   active=" + pi.findActiveActivityNames());
	}

	@Test
	public void startByParam() {// 带参数启动
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("name", "张三");
		org.jbpm.api.ProcessInstance pi = processEngine.getExecutionService()//
				.startProcessInstanceByKey("cccs", params);// 通过key启动流程
		System.out.println("   state=" + pi.getState() + "   active=" + pi.findActiveActivityNames());
	}

	@Test
	public void takeTask() {// 拾取任务列表
		processEngine.getTaskService()//
				.takeTask("580003", "a"); // taskId userId

	}

	@Test
	public void myTask() {// zs的任务列表
		List<Task> tasks = processEngine.getTaskService()//
				.findPersonalTasks("zs");
		for (Task task : tasks) {
			System.out.println("  active=" + task.getActivityName() + "  id=" + task.getId() + "  executionId=" + task.getExecutionId());
		}
	}

	@Test
	public void myGroupTask() {// 组任务列表
		List<Task> tasks = processEngine.getTaskService()//
				.findGroupTasks("b");

		for (Task task : tasks) {
			System.out.println("  active=" + task.getActivityName() + "  id=" + task.getId() + "  executionId=" + task.getExecutionId());
		}
	}

	@Test
	public void doTask01() {// 完成任务
		processEngine.getTaskService()//
				.completeTask("550003");// taskId
	}

	@Test
	public void doTask02() {// 走多个任务中选择一个路线
		processEngine.getTaskService()//
				.completeTask("480003", "to 经理审批");// taskId outcome

	}

	@Test
	public void doTaskByParam() {// 完成任务,带参数
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("day", "2");
		processEngine.getTaskService()//
				.completeTask("480003", params);// taskId
	}

	@Test
	public void setParams() {// 设置参数
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("a", "aaa");
		params.put("b", "bbb");
		params.put("c", "ccc");
		String executionId = "leave.130001";
		processEngine.getExecutionService().setVariables(executionId, params);// 设置多个参数
		// processEngine.getExecutionService().setVariable(executionId, "111", "aaa");// 设置一个参数

		String taskId = "140001";
		processEngine.getTaskService().setVariables(taskId, params);

		User user = new User();
		user.setId(1l);
		user.setName("张三");

		params.put("user", user);
		processEngine.getTaskService().setVariables(taskId, params);

	}

	@Test
	public void getParams() {// 设置参数
		String executionId = "leave.130001";
		Object variable = processEngine.getExecutionService().getVariable(executionId, "c");
		System.out.println(variable);
		String taskId = "140001";
		Object variable2 = processEngine.getTaskService().getVariable(taskId, "user");// 会有懒加载异常
		System.out.println(variable2);

		Set<String> variableNames = processEngine.getTaskService().getVariableNames(taskId);
		System.out.println(variableNames);
	}

详细相关项目实例,可到我的资料列表去下载

http://download.csdn.net/detail/albert_lz/6744245

你可能感兴趣的:(jbpm)