小言_互联网的博客

Activiti中的RuntimeService测试

262人阅读  评论(0)
//会给每个节点都添加监听器
		runtimeService.addEventListener(listenerToAdd);

		User shr = identityService.newUser("shr");
		shr.setId("12313123");
		identityService.saveUser(shr);

		Group group = identityService.newGroup("group");
		group.setId("123546");
		identityService.saveGroup(group);
		//添加组和任务的关系
		runtimeService.addGroupIdentityLink(processInstance.getId(), group.getId(), "必须");

		//以IdentityLinkType.CANDIDATE方式指定
//		runtimeService.addParticipantGroup(processInstance.getId(), group.getId());

		//	addUserIdentityLink(String processInstanceId, String userId, String identityLinkType)

		//更新bussinessKey
		runtimeService.updateBusinessKey(processInstance.getProcessInstanceId(), "321654");

//		挂起 suspendProcessInstanceById(String processInstanceId)

	private static final Logger LOGGER = LoggerFactory.getLogger(RepositoryServiceTest.class);

	@Autowired
	private RuntimeService runtimeService;

	@Autowired
	private RepositoryService repositoryService;

	/** 根据流程id启动 */
	@Test
	public void testStartProcessByKey() {

		Map<String, Object> map = Maps.newHashMap();
		map.put("key1", "value1");
		ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process");
		LOGGER.info("processInstance = {}", processInstance);
	}

	/** 根据产生的流程id启动 */
	@Test
	public void testStartProcessById() {

		DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
		Deployment deploy = deploymentBuilder.name("测试部署")
				.addClasspathResource("my-process.bpmn20.xml")
				.deploy();

		ProcessDefinition processDefinition =
				repositoryService.createProcessDefinitionQuery().singleResult();

		Map<String, Object> map = Maps.newHashMap();
		map.put("key1", "value1");
		ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
		LOGGER.info("processInstance = {}", processInstance);
	}

	/** 测试通过流程构造实例启动 */
	@Test
	public void testProcessInstanceBuilder() {

		Map<String, Object> map = Maps.newHashMap();
		map.put("key1", "value1");
		ProcessInstanceBuilder processInstance = runtimeService.createProcessInstanceBuilder();
		processInstance.businessKey("businessKey001")
				.processDefinitionKey("my-process")
				.variables(map);
		processInstance.start();
		LOGGER.info("processInstance = {}", processInstance);
	}

	/** 测试加入参数启动 */
	@Test
	public void testVariables() {

		ProcessDefinition processDefinition =
				repositoryService.createProcessDefinitionQuery().singleResult();
		Map<String, Object> map = Maps.newHashMap();
		map.put("key1", "value1");
		map.put("key2", "value2");
		ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
		LOGGER.info("processInstance = {}", processInstance);

		runtimeService.setVariable(processInstance.getId(), "key3", "values3");
		runtimeService.setVariable(processInstance.getId(), "key2", "key2-1");
		Map<String, Object> variables = runtimeService.getVariables(processInstance.getId());
		LOGGER.info("variables = {}", variables);
	}

	/** 获取流程执行对象 */
	@Test
	public void testExecutionQuery() {

		Map<String, Object> map = Maps.newHashMap();
		ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process");
		LOGGER.info("processInstance = {}", processInstance);

		List<Execution> list = runtimeService.createExecutionQuery()
				.listPage(0, 100);

		list.forEach(l -> {
			LOGGER.info("Execution = {}", l);
		});
	}

转载:https://blog.csdn.net/qq_42046342/article/details/101164257
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场