org.activiti.engine.TaskService Java Examples

The following examples show how to use org.activiti.engine.TaskService. 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: InitProcessEngineBySpringAnnotation.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx =
            new AnnotationConfigApplicationContext();
    ctx.register(SpringAnnotationConfiguration.class);
    ctx.refresh();

    assertNotNull(ctx.getBean(ProcessEngine.class));
    assertNotNull(ctx.getBean(RuntimeService.class));
    TaskService bean = ctx.getBean(TaskService.class);
    assertNotNull(bean);
    assertNotNull(ctx.getBean(HistoryService.class));
    assertNotNull(ctx.getBean(RepositoryService.class));
    assertNotNull(ctx.getBean(ManagementService.class));
    assertNotNull(ctx.getBean(FormService.class));
    Task task = bean.newTask();
    task.setName("哈哈");
    bean.saveTask(task);
}
 
Example #2
Source File: TestBPMN001.java    From bamboobsc with Apache License 2.0 6 votes vote down vote up
@Test
public void completeTask() throws Exception {
	
	String assignee = "張三";
	//String assignee = "王經理";
			
	TaskService taskService = (TaskService) AppContext.getBean("taskService");
	List<Task> tasks = taskService.createTaskQuery().list();
	if (tasks == null || tasks.size()<1 ) {
		System.out.println("no task.");
		return;
	}
	for (Task task : tasks) {
		taskService.setAssignee(task.getId(), assignee);
		taskService.complete(task.getId());
		this.printTask(task);
	}
	
}
 
Example #3
Source File: MyTaskController.java    From my_curd with Apache License 2.0 6 votes vote down vote up
@RequirePermission("myTask:changeAssignee")
@TxConfig(ActivitiConfig.DATASOURCE_NAME)
@Before(Tx.class)
public void changeAssigneeAction() {
    String taskId = getPara("taskId"); // taskId;
    String username = getPara("username");
    if (StringUtils.isEmpty(taskId) || StringUtils.isEmpty(username)) {
        renderFail("参数缺失");
        return;
    }
    TaskService taskService = ActivitiKit.getTaskService();
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
    if (task == null) {
        renderFail("任务不存在");
        return;
    }
    if (username.equals(task.getAssignee())) {
        renderFail("原任务处理人 和 转办人 不可相同");
        return;
    }

    // 设置上个任务处理人
    ActivitiKit.getTaskService().setVariableLocal(taskId, "lastAssignee", task.getAssignee());
    ActivitiKit.getTaskService().setAssignee(taskId, username);
    renderSuccess("转办 操作成功 ");
}
 
Example #4
Source File: TaskHistoryResourceRepositoryTest.java    From crnk-framework with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
    super.setup();

    task = addTask("testTask", 12);

    TaskService taskService = processEngine.getTaskService();
    taskService.complete(task.getId());

    isolatedTask = addTask("isolatedTask", 12);
    isolatedTask.setDescription("doesNotMatchRepositoryFilter");
    taskService.saveTask(isolatedTask);

    ActivitiModule activitiModule = boot.getModuleRegistry().getModule(ActivitiModule.class).get();
    historicTaskRepository = activitiModule.getHistoricTaskRepository(HistoricApproveTask.class);
    processInstanceRepository = activitiModule.getProcessInstanceRepository(ScheduleApprovalProcessInstance.class);
}
 
Example #5
Source File: ComplaintUserInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 6 votes vote down vote up
public boolean completeTask(@RequestBody ComplaintDto complaintDto) {
    TaskService taskService = processEngine.getTaskService();
    Task task = taskService.createTaskQuery().taskId(complaintDto.getTaskId()).singleResult();
    String processInstanceId = task.getProcessInstanceId();
    Authentication.setAuthenticatedUserId(complaintDto.getCurrentUserId());
    taskService.addComment(complaintDto.getTaskId(), processInstanceId, complaintDto.getAuditMessage());
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("auditCode", complaintDto.getAuditCode());
    variables.put("currentUserId", complaintDto.getCurrentUserId());
    variables.put("flag", "1200".equals(complaintDto.getAuditCode()) ? "false" : "true");
    variables.put("startUserId", complaintDto.getStartUserId());
    //taskService.setAssignee(complaintDto.getTaskId(),complaintDto.getCurrentUserId());
    //taskService.addCandidateUser(complaintDto.getTaskId(), complaintDto.getCurrentUserId());
    //taskService.claim(complaintDto.getTaskId(), complaintDto.getCurrentUserId());
    taskService.complete(complaintDto.getTaskId(), variables);

    ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    if (pi == null) {
        return true;
    }
    return false;
}
 
Example #6
Source File: AccessRequestService.java    From Gatekeeper with Apache License 2.0 6 votes vote down vote up
@Autowired
public AccessRequestService(TaskService taskService,
                            AccessRequestRepository accessRequestRepository,
                            GatekeeperRoleService gatekeeperRoleService,
                            RuntimeService runtimeService,
                            HistoryService historyService,
                            AccountInformationService accountInformationService,
                            SsmService ssmService,
                            GatekeeperApprovalProperties gatekeeperApprovalProperties){

    this.taskService = taskService;
    this.accessRequestRepository = accessRequestRepository;
    this.gatekeeperRoleService = gatekeeperRoleService;
    this.runtimeService = runtimeService;
    this.historyService = historyService;
    this.accountInformationService = accountInformationService;
    this.ssmService = ssmService;
    this.approvalPolicy = gatekeeperApprovalProperties;
}
 
Example #7
Source File: AccessRequestService.java    From Gatekeeper with Apache License 2.0 6 votes vote down vote up
@Autowired
public AccessRequestService(TaskService taskService,
                            AccessRequestRepository accessRequestRepository,
                            GatekeeperRoleService gatekeeperRoleService,
                            RuntimeService runtimeService,
                            HistoryService historyService,
                            GatekeeperApprovalProperties gatekeeperApprovalProperties,
                            AccountInformationService accountInformationService,
                            GatekeeperOverrideProperties overridePolicy,
                            DatabaseConnectionService databaseConnectionService){
    this.taskService = taskService;
    this.accessRequestRepository = accessRequestRepository;
    this.gatekeeperRoleService = gatekeeperRoleService;
    this.runtimeService = runtimeService;
    this.historyService = historyService;
    this.approvalThreshold = gatekeeperApprovalProperties;
    this.accountInformationService = accountInformationService;
    this.overridePolicy = overridePolicy;
    this.databaseConnectionService = databaseConnectionService;
}
 
Example #8
Source File: ActivitiWithMuleTest.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
@Test
public void testSpringMaster() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("mule/spring-master/spring-master.xml");

    MuleContext mc = (MuleContext) ctx.getBean("_muleContext");
    mc.start();

    RepositoryService repositoryService = (RepositoryService) ctx.getBean("repositoryService");
    repositoryService.createDeployment().addClasspathResource("mule/leaveWithMule.bpmn").deploy();

    RuntimeService runtimeService = (RuntimeService) ctx.getBean("runtimeService");

    Map<String, Object> variableMap = new HashMap<String, Object>();
    variableMap.put("days", 5);
    runtimeService.startProcessInstanceByKey("leaveWithMule", variableMap);

    TaskService taskService = (TaskService) ctx.getBean("taskService");
    Task task = taskService.createTaskQuery().singleResult();
    assertNotNull(task);
    assertEquals("部门经理审批", task.getName());

    mc.stop();
}
 
Example #9
Source File: PurchaseApplyUserInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 6 votes vote down vote up
public boolean completeTask(@RequestBody PurchaseApplyDto purchaseApplyDto) {
    TaskService taskService = processEngine.getTaskService();
    Task task = taskService.createTaskQuery().taskId(purchaseApplyDto.getTaskId()).singleResult();
    String processInstanceId = task.getProcessInstanceId();
    Authentication.setAuthenticatedUserId(purchaseApplyDto.getCurrentUserId());
    taskService.addComment(purchaseApplyDto.getTaskId(), processInstanceId, purchaseApplyDto.getAuditMessage());
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("auditCode", purchaseApplyDto.getAuditCode());
    variables.put("currentUserId", purchaseApplyDto.getCurrentUserId());
    variables.put("nextAuditStaffId",purchaseApplyDto.getStaffId());
    //taskService.setAssignee(complaintDto.getTaskId(),complaintDto.getCurrentUserId());
    //taskService.addCandidateUser(complaintDto.getTaskId(), complaintDto.getCurrentUserId());
    //taskService.claim(complaintDto.getTaskId(), complaintDto.getCurrentUserId());
    taskService.complete(purchaseApplyDto.getTaskId(), variables);
    //taskService.setVariable(purchaseApplyDto.getTaskId(), "purchaseApplyDto", purchaseApplyDto);

    ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    if (pi == null) {
        return true;
    }
    return false;
}
 
Example #10
Source File: PurchaseApplyUserInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 6 votes vote down vote up
public List<AuditMessageDto> getAuditMessage(@RequestBody PurchaseApplyDto purchaseApplyDto) {

        TaskService taskService = processEngine.getTaskService();
        Task task = taskService.createTaskQuery().taskId(purchaseApplyDto.getTaskId()).singleResult();
        String processInstanceId = task.getProcessInstanceId();
        List<Comment> comments = taskService.getProcessInstanceComments(processInstanceId);
        List<AuditMessageDto> auditMessageDtos = new ArrayList<>();
        if (comments == null || comments.size() < 1) {
            return auditMessageDtos;
        }
        AuditMessageDto messageDto = null;
        for (Comment comment : comments) {
            messageDto = new AuditMessageDto();
            messageDto.setCreateTime(comment.getTime());
            messageDto.setUserId(comment.getUserId());
            messageDto.setMessage(comment.getFullMessage());
        }

        return auditMessageDtos;
    }
 
Example #11
Source File: ComplaintUserInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 5 votes vote down vote up
/**
 * 获取任务当前处理人
 *
 * @param complaintDto
 * @return
 */
public ComplaintDto getTaskCurrentUser(@RequestBody ComplaintDto complaintDto) {

    TaskService taskService = processEngine.getTaskService();
    List<Task> tasks = taskService.createTaskQuery().processInstanceBusinessKey(complaintDto.getComplaintId()).list();

    if (tasks == null || tasks.size() == 0) {
        complaintDto.setCurrentUserId("");
        complaintDto.setCurrentUserName("");
        complaintDto.setCurrentUserTel("");
        return complaintDto;
    }
    String userIds = "";
    String userNames = "";
    String userTels = "";
    for (Task task : tasks) {
        String userId = task.getAssignee();
        List<UserDto> users = userInnerServiceSMOImpl.getUserInfo(new String[]{userId});
        if (users == null || users.size() == 0) {
            continue;
        }
        userIds += (userId + "/");
        userNames += (users.get(0).getName() + "/");
        userTels += (users.get(0).getTel() + "/");
    }
    userIds = userIds.endsWith("/") ? userIds.substring(0, userIds.length() - 2) : userIds;
    userNames = userNames.endsWith("/") ? userNames.substring(0, userNames.length() - 2) : userNames;
    userTels = userTels.endsWith("/") ? userTels.substring(0, userTels.length() - 2) : userTels;
    complaintDto.setCurrentUserId(userIds);
    complaintDto.setCurrentUserName(userNames);
    complaintDto.setCurrentUserTel(userTels);
    return complaintDto;

}
 
Example #12
Source File: ActivitiInternalProcessConnector.java    From lemon with Apache License 2.0 5 votes vote down vote up
/**
 * 完成任务.
 */
public void completeTask(String taskId, String userId,
        Map<String, Object> variables) {
    TaskService taskService = processEngine.getTaskService();
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();

    if (task == null) {
        throw new IllegalStateException("任务不存在");
    }

    // 先设置登录用户
    IdentityService identityService = processEngine.getIdentityService();
    identityService.setAuthenticatedUserId(userId);

    // 处理子任务
    if ("subtask".equals(task.getCategory())) {
        processEngine.getManagementService().executeCommand(
                new DeleteTaskWithCommentCmd(taskId, "完成"));

        int count = jdbcTemplate.queryForObject(
                "select count(*) from ACT_RU_TASK where PARENT_TASK_ID_=?",
                Integer.class, task.getParentTaskId());

        if (count > 1) {
            return;
        }

        taskId = task.getParentTaskId();
    }

    processEngine.getManagementService().executeCommand(
            new CompleteTaskWithCommentCmd(taskId, variables, "完成"));
}
 
Example #13
Source File: FormResourceRepository.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
public FormResourceRepository(FormService formService, TaskService taskService, ActivitiResourceMapper resourceMapper,
                              Class<F> formClass) {
    super(formClass);
    this.formService = formService;
    this.resourceMapper = resourceMapper;
    this.taskService = taskService;
}
 
Example #14
Source File: WorkspaceController.java    From lemon with Apache License 2.0 5 votes vote down vote up
/**
 * 任务代理
 * 
 * @return
 */
@RequestMapping("workspace-delegateTask")
public String delegateTask(@RequestParam("taskId") String taskId,
        @RequestParam("userId") String userId) {
    TaskService taskService = processEngine.getTaskService();
    taskService.delegateTask(taskId, userId);

    return "redirect:/bpm/workspace-listPersonalTasks.do";
}
 
Example #15
Source File: ActivitiTestBase.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
@After
public void teardown() {
    RuntimeService runtimeService = processEngine.getRuntimeService();
    List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().list();
    for (ProcessInstance processInstance : processInstances) {
        runtimeService.deleteProcessInstance(processInstance.getId(), "");
    }

    TaskService taskService = processEngine.getTaskService();
    List<Task> tasks = taskService.createTaskQuery().list();
    for (Task task : tasks) {
        taskService.deleteTask(task.getId());
    }
}
 
Example #16
Source File: ActivitiTestBase.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
protected Task addTask(String name, int priority) {
    TaskService taskService = processEngine.getTaskService();
    Task task = taskService.newTask();
    task.setName(name);
    task.setPriority(priority);
    task.setAssignee("john");
    task.setCategory("testCategory");
    task.setDueDate(new Date());
    task.setOwner("jane");
    task.setDescription("testDescription");
    task.setTenantId("testTenant");
    taskService.saveTask(task);
    return task;

}
 
Example #17
Source File: ProcessConnectorImpl.java    From lemon with Apache License 2.0 5 votes vote down vote up
/**
 * 待办任务(个人任务).
 */
public Page findPersonalTasks(String userId, String tenantId, Page page) {
    TaskService taskService = processEngine.getTaskService();

    long count = taskService.createTaskQuery().taskTenantId(tenantId)
            .taskAssignee(userId).active().count();
    List<Task> tasks = taskService.createTaskQuery().taskTenantId(tenantId)
            .taskAssignee(userId).active()
            .listPage((int) page.getStart(), page.getPageSize());
    page.setResult(tasks);
    page.setTotalCount(count);

    return page;
}
 
Example #18
Source File: ProcessInstanceHistoryRepositoryTest.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
private ProcessInstance addCompletedProcessInstance() {
    ScheduleApprovalValues newValues = new ScheduleApprovalValues();
    newValues.setName("newName");

    ScheduleApprovalProcessInstance resource = new ScheduleApprovalProcessInstance();
    resource.setResourceId("12");
    resource.setResourceType("schedules");
    resource.setNewValues(newValues);

    Map<String, Object> processVariables = resourceMapper.mapToVariables(resource);
    runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("scheduleChange",
            "testBusinessKey", processVariables);
    runtimeService.setProcessInstanceName(processInstance.getId(), "testName");


    processInstance = runtimeService.createProcessInstanceQuery()
            .processInstanceId(processInstance.getId())
            .includeProcessVariables()
            .singleResult();

    // complete process
    TaskService taskService = processEngine.getTaskService();
    Task task = taskService.createTaskQuery().list().get(0);
    Assert.assertEquals(task.getProcessInstanceId(), processInstance.getId());
    Map<String, Object> variables = new HashMap<>();
    variables.put("approved", false);
    taskService.complete(task.getId(), variables);
    return processInstance;
}
 
Example #19
Source File: ApprovalManagerTest.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
	runtimeService = Mockito.mock(RuntimeService.class);
	TaskService taskService = Mockito.mock(TaskService.class);
	repositoryFacade = Mockito.mock(ResourceRepository.class);
	ApprovalMapper approvalMapper = new ApprovalMapper();
	ActivitiResourceMapper resourceMapper = new ActivitiResourceMapper(new TypeParser(), new DefaultDateTimeMapper());

	ResourceInformation information = Mockito.mock(ResourceInformation.class);
	registryEntry = Mockito.mock(RegistryEntry.class);
	ResourceRegistry resourceRegistry = Mockito.mock(ResourceRegistry.class);
	Mockito.when(registryEntry.getResourceInformation()).thenReturn(information);
	Mockito.when(registryEntry.getResourceRepositoryFacade()).thenReturn(repositoryFacade);
	Mockito.when(information.getResourceType()).thenReturn("schedule");
	Mockito.when(information.getId(Mockito.any())).thenReturn(mockId);
	Mockito.when(resourceRegistry.getEntry(Mockito.any(Class.class))).thenReturn(registryEntry);
	Mockito.when(resourceRegistry.getEntry(Mockito.any(String.class))).thenReturn(registryEntry);
	ModuleRegistry moduleRegistry = Mockito.mock(ModuleRegistry.class);
	Mockito.when(moduleRegistry.getResourceRegistry()).thenReturn(resourceRegistry);


	originalResource = new Schedule();
	originalResource.setId(mockId);
	originalResource.setName("Jane");
	Mockito.when(repositoryFacade.findOne(Mockito.any(Long.class), Mockito.any(QuerySpec.class)))
			.thenReturn(originalResource);

	manager = new ApprovalManager();
	manager.init(runtimeService, taskService, resourceMapper, approvalMapper, moduleRegistry);
}
 
Example #20
Source File: ResourceEntryStoreInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 5 votes vote down vote up
/**
 * 审核 当前任务
 *
 * @param resourceOrderDto 资源订单
 * @return
 */
public boolean complete(@RequestBody ResourceOrderDto resourceOrderDto) {
    TaskService taskService = processEngine.getTaskService();

    taskService.complete(resourceOrderDto.getTaskId());
    return true;
}
 
Example #21
Source File: ResourceEntryStoreInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 5 votes vote down vote up
public boolean refuteCompleteTask(@RequestBody ResourceOrderDto resourceOrderDto) {
    TaskService taskService = processEngine.getTaskService();
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("auditCode", resourceOrderDto.getAuditCode());
    taskService.complete(resourceOrderDto.getTaskId(), variables);
    return true;
}
 
Example #22
Source File: ResourceEntryStoreInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 5 votes vote down vote up
public boolean agreeCompleteTask(@RequestBody ResourceOrderDto resourceOrderDto) {
    TaskService taskService = processEngine.getTaskService();
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("auditCode", resourceOrderDto.getAuditCode());
    taskService.complete(resourceOrderDto.getTaskId(), variables);
    return true;
}
 
Example #23
Source File: ProcessExecutionIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenProcessInstance_whenCompleteTask_thenProcessExecutionContinues() {
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    RepositoryService repositoryService = processEngine.getRepositoryService();
    repositoryService.createDeployment()
      .addClasspathResource("org/activiti/test/vacationRequest.bpmn20.xml")
      .deploy();

    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("employeeName", "Kermit");
    variables.put("numberOfDays", new Integer(4));
    variables.put("vacationMotivation", "I'm really tired!");

    RuntimeService runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance = runtimeService
      .startProcessInstanceByKey("vacationRequest", variables);

    TaskService taskService = processEngine.getTaskService();
    List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("management").list();

    Task task = tasks.get(0);

    Map<String, Object> taskVariables = new HashMap<String, Object>();
    taskVariables.put("vacationApproved", "false");
    taskVariables.put("comments", "We have a tight deadline!");
    taskService.complete(task.getId(), taskVariables);

    Task currentTask = taskService.createTaskQuery().taskName("Modify vacation request").singleResult();
    assertNotNull(currentTask);
}
 
Example #24
Source File: AbstractProcessEngineTest.java    From openwebflow with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 测试前加签
 */
@Test
public void testInsertTasksBefore() throws Exception
{
	ProcessInstance instance = _processEngine.getRuntimeService().startProcessInstanceByKey("test2");
	TaskService taskService = _processEngine.getTaskService();
	TaskFlowControlService tfcs = _taskFlowControlServiceFactory.create(instance.getId());
	//到了step2
	Assert.assertEquals("step2", taskService.createTaskQuery().singleResult().getTaskDefinitionKey());
	//在前面加两个节点
	ActivityImpl[] as = tfcs.insertTasksBefore("step2", "bluejoe", "alex");
	//应该执行到了第一个节点
	Assert.assertEquals(as[0].getId(), taskService.createTaskQuery().singleResult().getTaskDefinitionKey());
	Assert.assertEquals("bluejoe", taskService.createTaskQuery().singleResult().getAssignee());
	//完成该节点
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//应该到了下一个节点
	Assert.assertEquals(as[1].getId(), taskService.createTaskQuery().singleResult().getTaskDefinitionKey());
	Assert.assertEquals("alex", taskService.createTaskQuery().singleResult().getAssignee());
	//完成该节点
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//应该到了下一个节点
	Assert.assertEquals("step2", taskService.createTaskQuery().singleResult().getTaskDefinitionKey());
	//完成step2
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//应该到了step3
	Assert.assertEquals("step3", taskService.createTaskQuery().singleResult().getTaskDefinitionKey());

	//确认历史轨迹里已保存
	//step1,step2,step2-1,step2-2,step2,step3
	List<HistoricActivityInstance> activities = _processEngine.getHistoryService()
			.createHistoricActivityInstanceQuery().processInstanceId(instance.getId()).list();
	Assert.assertEquals(6, activities.size());

	//删掉流程
	_processEngine.getRuntimeService().deleteProcessInstance(instance.getId(), "test");
}
 
Example #25
Source File: AbstractProcessEngineTest.java    From openwebflow with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 测试后加签
 */
@Test
public void testInsertTasksAfter() throws Exception
{
	ProcessInstance instance = _processEngine.getRuntimeService().startProcessInstanceByKey("test2");
	TaskService taskService = _processEngine.getTaskService();
	TaskFlowControlService tfcs = _taskFlowControlServiceFactory.create(instance.getId());
	//到了step2
	Assert.assertEquals("step2", taskService.createTaskQuery().singleResult().getTaskDefinitionKey());
	//在前面加两个节点
	Authentication.setAuthenticatedUserId("kermit");
	ActivityImpl[] as = tfcs.insertTasksAfter("step2", "bluejoe", "alex");
	//应该执行到了第一个节点
	Assert.assertEquals(as[0].getId(), taskService.createTaskQuery().singleResult().getTaskDefinitionKey());
	Assert.assertEquals("kermit", taskService.createTaskQuery().singleResult().getAssignee());
	//完成该节点
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//应该到了下一个节点
	Assert.assertEquals(as[1].getId(), taskService.createTaskQuery().singleResult().getTaskDefinitionKey());
	Assert.assertEquals("bluejoe", taskService.createTaskQuery().singleResult().getAssignee());
	//完成该节点
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//应该到了下一个节点
	Assert.assertEquals(as[2].getId(), taskService.createTaskQuery().singleResult().getTaskDefinitionKey());
	Assert.assertEquals("alex", taskService.createTaskQuery().singleResult().getAssignee());
	//完成该节点
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//应该到了下一个节点
	Assert.assertEquals("step3", taskService.createTaskQuery().singleResult().getTaskDefinitionKey());

	//确认历史轨迹里已保存
	//step1,step2,step2,step2-1,step2-2,step3
	List<HistoricActivityInstance> activities = _processEngine.getHistoryService()
			.createHistoricActivityInstanceQuery().processInstanceId(instance.getId()).list();
	Assert.assertEquals(6, activities.size());

	//删掉流程
	_processEngine.getRuntimeService().deleteProcessInstance(instance.getId(), "test");
}
 
Example #26
Source File: ResourceEntryStoreInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 5 votes vote down vote up
/**
 * 查询用户任务数
 *
 * @param user
 * @return
 */
public long getUserTaskCount(@RequestBody AuditUser user) {
    TaskService taskService = processEngine.getTaskService();
    TaskQuery query = taskService.createTaskQuery().processDefinitionKey("resourceEntry");
    query.taskAssignee(user.getUserId());
    return query.count();
}
 
Example #27
Source File: AbstractProcessEngineTest.java    From openwebflow with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 测试代理功能
 */
@Test
public void testDelegation() throws Exception
{
	ProcessInstance instance;
	TaskService taskService = _processEngine.getTaskService();

	((TaskDelagationAssignmentHandler) (((ReplaceTaskAssignmentHandler) (((ProcessEngineConfigurationEx) _processEngine
			.getProcessEngineConfiguration()).getStartEngineEventListeners().get(2))).getHandlers().get(1)))
			.setHideDelegated(false);

	//代理关系
	//alex将代理kermit
	_delegations.saveDelegation("kermit", "alex");

	//启动一个流程
	instance = _processEngine.getRuntimeService().startProcessInstanceByKey("test1");
	//kermit是management,所以可以访问
	Assert.assertEquals(1, taskService.createTaskQuery().taskCandidateUser("kermit").count());
	Assert.assertEquals(1, taskService.createTaskQuery().taskCandidateUser("alex").count());
	_processEngine.getRuntimeService().deleteProcessInstance(instance.getId(), "test");

	//设置屏蔽被代理人
	((TaskDelagationAssignmentHandler) (((ReplaceTaskAssignmentHandler) (((ProcessEngineConfigurationEx) _processEngine
			.getProcessEngineConfiguration()).getStartEngineEventListeners().get(2))).getHandlers().get(1)))
			.setHideDelegated(true);

	//再启动一个流程
	instance = _processEngine.getRuntimeService().startProcessInstanceByKey("test1");
	//neo被屏蔽了
	Assert.assertEquals(1, taskService.createTaskQuery().taskCandidateUser("kermit").count());
	Assert.assertEquals(0, taskService.createTaskQuery().taskCandidateUser("neo").count());
	//删掉流程
	_processEngine.getRuntimeService().deleteProcessInstance(instance.getId(), "test");
}
 
Example #28
Source File: IdentityUtils.java    From openwebflow with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static List<String> getInvolvedUsers(TaskService taskService, Task task,
		IdentityMembershipManager membershipManager) throws Exception
{
	Map<String, Object> userIds = new HashMap<String, Object>();
	String assignee = task.getAssignee();
	//如果直接指定了任务执行人,则忽略其他候选人
	if (assignee != null)
	{
		userIds.put(assignee, new Object());
	}
	else
	{
		for (IdentityLink link : taskService.getIdentityLinksForTask(task.getId()))
		{
			String userId = link.getUserId();
			if (userId != null)
			{
				userIds.put(userId, new Object());
			}

			String groupId = link.getGroupId();
			if (groupId != null)
			{
				for (String gUserId : membershipManager.findUserIdsByGroup(groupId))
				{
					userIds.put(gUserId, new Object());
				}
			}
		}
	}

	return new ArrayList<String>(userIds.keySet());
}
 
Example #29
Source File: ProcessConnectorImpl.java    From lemon with Apache License 2.0 5 votes vote down vote up
/**
 * 代理中的任务(代理人还未完成该任务).
 */
public Page findDelegatedTasks(String userId, String tenantId, Page page) {
    TaskService taskService = processEngine.getTaskService();

    long count = taskService.createTaskQuery().taskTenantId(tenantId)
            .taskOwner(userId).taskDelegationState(DelegationState.PENDING)
            .count();
    List<Task> tasks = taskService.createTaskQuery().taskTenantId(tenantId)
            .taskOwner(userId).taskDelegationState(DelegationState.PENDING)
            .listPage((int) page.getStart(), page.getPageSize());
    page.setResult(tasks);
    page.setTotalCount(count);

    return page;
}
 
Example #30
Source File: ComplaintUserInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 5 votes vote down vote up
/**
 * 查询用户任务数
 *
 * @param user
 * @return
 */
public long getUserTaskCount(@RequestBody AuditUser user) {
    TaskService taskService = processEngine.getTaskService();
    TaskQuery query = taskService.createTaskQuery().processDefinitionKey(getWorkflowDto(user.getCommunityId()));
    query.taskAssignee(user.getUserId());
    return query.count();
}