Java Code Examples for org.activiti.engine.runtime.ProcessInstance#getProcessDefinitionId()

The following examples show how to use org.activiti.engine.runtime.ProcessInstance#getProcessDefinitionId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScriptTaskTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testDynamicScript() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testDynamicScript", CollectionUtil.map("a", 20, "b", 22));
  assertEquals(42, ((Number) runtimeService.getVariable(processInstance.getId(), "test")).intValue());
  taskService.complete(taskService.createTaskQuery().singleResult().getId());
  assertProcessEnded(processInstance.getId());

  String processDefinitionId = processInstance.getProcessDefinitionId();
  ObjectNode infoNode = dynamicBpmnService.changeScriptTaskScript("script1", "var sum = c + d;\nexecution.setVariable('test2', sum);");
  dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);

  processInstance = runtimeService.startProcessInstanceByKey("testDynamicScript", CollectionUtil.map("c", 10, "d", 12));
  assertEquals(22, ((Number) runtimeService.getVariable(processInstance.getId(), "test2")).intValue());
  taskService.complete(taskService.createTaskQuery().singleResult().getId());
  assertProcessEnded(processInstance.getId());
}
 
Example 2
Source File: DynamicUserTaskTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testChangeFormKey() {
  // first test without changing the form key
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
  String processDefinitionId = processInstance.getProcessDefinitionId();
  
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertEquals("test", task.getFormKey());
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
  
  // now test with changing the form key
  ObjectNode infoNode = dynamicBpmnService.changeUserTaskFormKey("task1", "test2");
  dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
  
  processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertEquals("test2", task.getFormKey());
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
}
 
Example 3
Source File: DynamicUserTaskTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources={"org/activiti5/engine/test/bpmn/usertask/DynamicUserTaskTest.assignment.bpmn20.xml"})
public void testChangeAssignee() {
  // first test without changing the form key
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
  String processDefinitionId = processInstance.getProcessDefinitionId();
  
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertEquals("test", task.getAssignee());
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
  
  // now test with changing the form key
  ObjectNode infoNode = dynamicBpmnService.changeUserTaskAssignee("task1", "test2");
  dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
  
  processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertEquals("test2", task.getAssignee());
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
}
 
Example 4
Source File: SecureScriptingTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testDynamicScript() {
  addWhiteListedClass("org.activiti.engine.impl.persistence.entity.ExecutionEntityImpl");

  deployProcessDefinition("test-dynamic-secure-script.bpmn20.xml");

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testDynamicScript", CollectionUtil.map("a", 20, "b", 22));
  Assert.assertEquals(42.0, runtimeService.getVariable(processInstance.getId(), "test"));
  taskService.complete(taskService.createTaskQuery().singleResult().getId());
  assertProcessEnded(processInstance.getId());

  String processDefinitionId = processInstance.getProcessDefinitionId();
  ObjectNode infoNode = dynamicBpmnService.changeScriptTaskScript("script1", "var sum = c + d;\nexecution.setVariable('test2', sum);");
  dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);

  processInstance = runtimeService.startProcessInstanceByKey("testDynamicScript", CollectionUtil.map("c", 10, "d", 12));
  Assert.assertEquals(22.0, runtimeService.getVariable(processInstance.getId(), "test2"));
  taskService.complete(taskService.createTaskQuery().singleResult().getId());
  assertProcessEnded(processInstance.getId());
  removeWhiteListedClass("org.activiti.engine.impl.persistence.entity.ExecutionEntityImpl");
}
 
Example 5
Source File: DisabledDefinitionInfoCacheTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testChangeFormKey() {
  // first test without changing the form key
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
  String processDefinitionId = processInstance.getProcessDefinitionId();
  
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertEquals("test", task.getFormKey());
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
  
  // now test with changing the form key
  ObjectNode infoNode = dynamicBpmnService.changeUserTaskFormKey("task1", "test2");
  dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
  
  processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertEquals("test", task.getFormKey());
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
}
 
Example 6
Source File: ActProcessService.java    From Shop-for-JavaWeb with MIT License 6 votes vote down vote up
/**
 * 读取资源,通过部署ID
 * @param processDefinitionId  流程定义ID
 * @param processInstanceId 流程实例ID
 * @param resourceType 资源类型(xml|image)
 */
public InputStream resourceRead(String procDefId, String proInsId, String resType) throws Exception {
	
	if (StringUtils.isBlank(procDefId)){
		ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(proInsId).singleResult();
		procDefId = processInstance.getProcessDefinitionId();
	}
	ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(procDefId).singleResult();
	
	String resourceName = "";
	if (resType.equals("image")) {
		resourceName = processDefinition.getDiagramResourceName();
	} else if (resType.equals("xml")) {
		resourceName = processDefinition.getResourceName();
	}
	
	InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
	return resourceAsStream;
}
 
Example 7
Source File: DynamicUserTaskTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources={"org/activiti/engine/test/bpmn/usertask/DynamicUserTaskTest.assignment.bpmn20.xml"})
public void testChangeAssignee() {
  // first test without changing the form key
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
  String processDefinitionId = processInstance.getProcessDefinitionId();
  
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertEquals("test", task.getAssignee());
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
  
  // now test with changing the form key
  ObjectNode infoNode = dynamicBpmnService.changeUserTaskAssignee("task1", "test2");
  dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
  
  processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertEquals("test2", task.getAssignee());
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
}
 
Example 8
Source File: ActivitiKit.java    From my_curd with Apache License 2.0 5 votes vote down vote up
/**
 * 根据 业务表单记录id 查询流程信息
 *
 * @param businessKey 业务表主键
 * @return
 */
public static Map<String, Object> getInstanceInfoByBusinessKey(String businessKey) {
    Map<String, Object> ret = new HashMap<>();

    // 查询正在运行流程
    ProcessInstance instance = ActivitiKit.getRuntimeService().createProcessInstanceQuery()
            .processInstanceBusinessKey(businessKey)
            .singleResult();
    if (instance != null) {
        // 正运行流程 存在
        ret.put("processInstanceId", instance.getId()); // 流程实例id
        String definitionId = instance.getProcessDefinitionId();
        String activityId = instance.getActivityId();
        ret.put("processDefinitionId", definitionId); // 流程定义id
        ret.put("currentActivityId", activityId); // 当前任务节点 id
        ActivityImpl activity = ActivitiKit.getActivity(definitionId, activityId);
        if (activity != null) {
            ret.put("currentActivityName", activity.getProperty("name")); //当前任务节点名
        }
    } else {
        // 正运行流程 不存在  查询历史流程
        HistoricProcessInstance historicProcessInstance = ActivitiKit.getHistoryService().createHistoricProcessInstanceQuery()
                .processInstanceBusinessKey(businessKey)
                .singleResult();
        if (historicProcessInstance != null) {
            ret.put("hisProcessInstanceId", historicProcessInstance.getId());// 流程实例id
            ret.put("processDefinitionId", historicProcessInstance.getProcessDefinitionId());// 流程定义id
            ret.put("startTime", historicProcessInstance.getStartTime()); // 开始时间
            ret.put("endTime", historicProcessInstance.getEndTime()); // 结束时间
            ret.put("durationInMillis", historicProcessInstance.getDurationInMillis());// 持续时间
        }
    }
    // hisProcessInstanceId  和 processInstanceId 是 一致的
    return ret;
}
 
Example 9
Source File: LeaveWorkflowService.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 查询待办任务
 */
@Transactional(readOnly = true)
public List<Leave> findTodoTasks(String userId) {
    List<Leave> results = new ArrayList<Leave>();
    List<Task> tasks = new ArrayList<Task>();

    // 根据当前人的ID查询
    List<Task> todoList = taskService.createTaskQuery().processDefinitionKey("leave").taskAssignee(userId).list();

    // 根据当前人未签收的任务
    List<Task> unsignedTasks = taskService.createTaskQuery().processDefinitionKey("leave").taskCandidateUser(userId).list();

    // 合并
    tasks.addAll(todoList);
    tasks.addAll(unsignedTasks);

    // 根据流程的业务ID查询实体并关联
    for (Task task : tasks) {
        String processInstanceId = task.getProcessInstanceId();
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
        String businessKey = processInstance.getBusinessKey();
        Leave leave = leaveManager.get(new Long(businessKey));
        leave.setTask(task);
        leave.setProcessInstance(processInstance);
        String processDefinitionId = processInstance.getProcessDefinitionId();
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
        leave.setProcessDefinition(processDefinition);
        results.add(leave);
    }
    return results;
}
 
Example 10
Source File: DynamicUserTaskTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources={"org/activiti/engine/test/bpmn/usertask/DynamicUserTaskTest.basictask.bpmn20.xml"})
public void testChangeNameAndDescription() {
  // first test without changing the form key
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
  String processDefinitionId = processInstance.getProcessDefinitionId();
  
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertNull(task.getName());
  assertNull(task.getDescription());
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
  
  // now test with changing the form key
  ObjectNode infoNode = dynamicBpmnService.changeUserTaskName("task1", "Task name test");
  dynamicBpmnService.changeUserTaskDescription("task1", "Task description test", infoNode);
  dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
  
  processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertEquals("Task name test", task.getName());
  assertEquals("Task description test", task.getDescription());
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
}
 
Example 11
Source File: DisabledDefinitionInfoCacheTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testChangeClassName() {
  // first test without changing the class name
  Map<String, Object> varMap = new HashMap<String, Object>();
  varMap.put("count", 0);
  varMap.put("count2", 0);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicServiceTask", varMap);
  
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.complete(task.getId());
  
  assertEquals(1, runtimeService.getVariable(processInstance.getId(), "count"));
  assertEquals(0, runtimeService.getVariable(processInstance.getId(), "count2"));
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
  
  // now test with changing the class name
  varMap = new HashMap<String, Object>();
  varMap.put("count", 0);
  varMap.put("count2", 0);
  processInstance = runtimeService.startProcessInstanceByKey("dynamicServiceTask", varMap);
  
  String processDefinitionId = processInstance.getProcessDefinitionId();
  ObjectNode infoNode = dynamicBpmnService.changeServiceTaskClassName("service", "org.activiti.engine.test.bpmn.servicetask.DummyServiceTask2");
  dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.complete(task.getId());
  
  assertEquals(1, runtimeService.getVariable(processInstance.getId(), "count"));
  assertEquals(0, runtimeService.getVariable(processInstance.getId(), "count2"));
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
}
 
Example 12
Source File: DynamicServiceTaskTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testChangeClassName() {
  // first test without changing the class name
  Map<String, Object> varMap = new HashMap<String, Object>();
  varMap.put("count", 0);
  varMap.put("count2", 0);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicServiceTask", varMap);
  
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.complete(task.getId());
  
  assertEquals(1, runtimeService.getVariable(processInstance.getId(), "count"));
  assertEquals(0, runtimeService.getVariable(processInstance.getId(), "count2"));
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
  
  // now test with changing the class name
  varMap = new HashMap<String, Object>();
  varMap.put("count", 0);
  varMap.put("count2", 0);
  processInstance = runtimeService.startProcessInstanceByKey("dynamicServiceTask", varMap);
  
  String processDefinitionId = processInstance.getProcessDefinitionId();
  ObjectNode infoNode = dynamicBpmnService.changeServiceTaskClassName("service", "org.activiti.engine.test.bpmn.servicetask.DummyServiceTask2");
  dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.complete(task.getId());
  
  assertEquals(0, runtimeService.getVariable(processInstance.getId(), "count"));
  assertEquals(1, runtimeService.getVariable(processInstance.getId(), "count2"));
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
}
 
Example 13
Source File: DynamicServiceTaskTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testChangeClassName() {
  // first test without changing the class name
  Map<String, Object> varMap = new HashMap<String, Object>();
  varMap.put("count", 0);
  varMap.put("count2", 0);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicServiceTask", varMap);
  
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.complete(task.getId());
  
  assertEquals(1, runtimeService.getVariable(processInstance.getId(), "count"));
  assertEquals(0, runtimeService.getVariable(processInstance.getId(), "count2"));
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
  
  // now test with changing the class name
  varMap = new HashMap<String, Object>();
  varMap.put("count", 0);
  varMap.put("count2", 0);
  processInstance = runtimeService.startProcessInstanceByKey("dynamicServiceTask", varMap);
  
  String processDefinitionId = processInstance.getProcessDefinitionId();
  ObjectNode infoNode = dynamicBpmnService.changeServiceTaskClassName("service", "org.activiti5.engine.test.bpmn.servicetask.DummyServiceTask2");
  dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.complete(task.getId());
  
  assertEquals(0, runtimeService.getVariable(processInstance.getId(), "count"));
  assertEquals(1, runtimeService.getVariable(processInstance.getId(), "count2"));
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
}
 
Example 14
Source File: LeaveWorkflowService.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 查询待办任务
 */
@Transactional(readOnly = true)
public List<Leave> findTodoTasks(String userId) {
    List<Leave> results = new ArrayList<Leave>();
    List<Task> tasks = new ArrayList<Task>();

    // 根据当前人的ID查询
    List<Task> todoList = taskService.createTaskQuery().processDefinitionKey("leave").taskAssignee(userId).list();

    // 根据当前人未签收的任务
    List<Task> unsignedTasks = taskService.createTaskQuery().processDefinitionKey("leave").taskCandidateUser(userId).list();

    // 合并
    tasks.addAll(todoList);
    tasks.addAll(unsignedTasks);

    // 根据流程的业务ID查询实体并关联
    for (Task task : tasks) {
        String processInstanceId = task.getProcessInstanceId();
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
        String businessKey = processInstance.getBusinessKey();
        Leave leave = leaveManager.get(new Long(businessKey));
        leave.setTask(task);
        leave.setProcessInstance(processInstance);
        String processDefinitionId = processInstance.getProcessDefinitionId();
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
        leave.setProcessDefinition(processDefinition);
        results.add(leave);
    }
    return results;
}
 
Example 15
Source File: LeaveWorkflowService.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 查询待办任务
 */
@Transactional(readOnly = true)
public List<Leave> findTodoTasks(String userId) {
    List<Leave> results = new ArrayList<Leave>();
    List<Task> tasks = new ArrayList<Task>();

    // 根据当前人的ID查询
    List<Task> todoList = taskService.createTaskQuery().processDefinitionKey("leave").taskAssignee(userId).active().list();

    // 根据当前人未签收的任务
    List<Task> unsignedTasks = taskService.createTaskQuery().processDefinitionKey("leave").taskCandidateUser(userId).active().list();

    // 合并
    tasks.addAll(todoList);
    tasks.addAll(unsignedTasks);

    // 根据流程的业务ID查询实体并关联
    for (Task task : tasks) {
        String processInstanceId = task.getProcessInstanceId();
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
        String businessKey = processInstance.getBusinessKey();
        Leave leave = leaveManager.get(new Long(businessKey));
        leave.setTask(task);
        leave.setProcessInstance(processInstance);
        String processDefinitionId = processInstance.getProcessDefinitionId();
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
        leave.setProcessDefinition(processDefinition);
        results.add(leave);
    }
    return results;
}
 
Example 16
Source File: LeaveWorkflowService.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 查询待办任务
 */
@Transactional(readOnly = true)
public List<Leave> findTodoTasks(String userId) {
    List<Leave> results = new ArrayList<Leave>();
    List<Task> tasks = new ArrayList<Task>();

    // 根据当前人的ID查询
    List<Task> todoList = taskService.createTaskQuery().processDefinitionKey("leave").taskAssignee(userId).active().list();

    // 根据当前人未签收的任务
    List<Task> unsignedTasks = taskService.createTaskQuery().processDefinitionKey("leave").taskCandidateUser(userId).active().list();

    // 合并
    tasks.addAll(todoList);
    tasks.addAll(unsignedTasks);

    // 根据流程的业务ID查询实体并关联
    for (Task task : tasks) {
        String processInstanceId = task.getProcessInstanceId();
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
        String businessKey = processInstance.getBusinessKey();
        Leave leave = leaveManager.get(new Long(businessKey));
        leave.setTask(task);
        leave.setProcessInstance(processInstance);
        String processDefinitionId = processInstance.getProcessDefinitionId();
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
        leave.setProcessDefinition(processDefinition);
        results.add(leave);
    }
    return results;
}
 
Example 17
Source File: LeaveWorkflowService.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 查询待办任务
 */
@Transactional(readOnly = true)
public List<Leave> findTodoTasks(String userId) {
    List<Leave> results = new ArrayList<Leave>();
    List<Task> tasks = new ArrayList<Task>();

    // 根据当前人的ID查询
    List<Task> todoList = taskService.createTaskQuery().processDefinitionKey("leave").taskAssignee(userId).list();

    // 根据当前人未签收的任务
    List<Task> unsignedTasks = taskService.createTaskQuery().processDefinitionKey("leave").taskCandidateUser(userId).list();

    // 合并
    tasks.addAll(todoList);
    tasks.addAll(unsignedTasks);

    // 根据流程的业务ID查询实体并关联
    for (Task task : tasks) {
        String processInstanceId = task.getProcessInstanceId();
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
        String businessKey = processInstance.getBusinessKey();
        Leave leave = leaveManager.get(new Long(businessKey));
        leave.setTask(task);
        leave.setProcessInstance(processInstance);
        String processDefinitionId = processInstance.getProcessDefinitionId();
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
        leave.setProcessDefinition(processDefinition);
        results.add(leave);
    }
    return results;
}
 
Example 18
Source File: DynamicUserTaskTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources={"org/activiti5/engine/test/bpmn/usertask/DynamicUserTaskTest.basictask.bpmn20.xml"})
public void testChangeNameAndDescription() {
  // first test without changing the form key
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
  String processDefinitionId = processInstance.getProcessDefinitionId();
  
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertNull(task.getName());
  assertNull(task.getDescription());
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
  
  // now test with changing the form key
  ObjectNode infoNode = dynamicBpmnService.changeUserTaskName("task1", "Task name test");
  dynamicBpmnService.changeUserTaskDescription("task1", "Task description test", infoNode);
  dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
  
  processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertEquals("Task name test", task.getName());
  assertEquals("Task description test", task.getDescription());
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
}
 
Example 19
Source File: DynamicUserTaskTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources={"org/activiti5/engine/test/bpmn/usertask/DynamicUserTaskTest.assignment.bpmn20.xml"})
public void testChangePriorityAndCategory() {
  // first test without changing the form key
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
  String processDefinitionId = processInstance.getProcessDefinitionId();
  
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertEquals(50, task.getPriority());
  assertNull(task.getCategory());
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
  
  // now test with changing the form key
  ObjectNode infoNode = dynamicBpmnService.changeUserTaskPriority("task1", "99");
  dynamicBpmnService.changeUserTaskCategory("task1", "categoryTest", infoNode);
  dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
  
  processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertEquals(99, task.getPriority());
  assertEquals("categoryTest", task.getCategory());
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
}
 
Example 20
Source File: ProcessInstanceRepresentation.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ProcessInstanceRepresentation(ProcessInstance processInstance, boolean graphicalNotation, User startedBy) {
    this.id = processInstance.getId();
    this.name = processInstance.getName();
    this.businessKey = processInstance.getBusinessKey();
    this.processDefinitionId = processInstance.getProcessDefinitionId();
    this.tenantId = processInstance.getTenantId();
    this.graphicalNotationDefined = graphicalNotation;
    this.startedBy = new UserRepresentation(startedBy);
}