@Override public void costWorkFlowStart(CostApprovalEntity costApproval, HttpServletRequest request) { // 由session取到登录用户id String applyUserId = ResourceUtil.getSessionUserName().getId(); this.save(costApproval); String processKey = request.getParameter("processKey"); if (!StringUtil.isNotEmpty(processKey)) { WorkFlowSetEntity workFlowSet = this.findUniqueByProperty( WorkFlowSetEntity.class, "entityName", costApproval.getClass().getSimpleName()); processKey = workFlowSet.getProcessKey(); } String businessKey = costApproval.getId().toString(); ProcessInstance processInstance = null; // 用来设置启动流程的人员ID,引擎会自动把用户ID保存到activiti:initiator中 identityService.setAuthenticatedUserId(applyUserId); Map<String, Object> variables = new HashMap<String, Object>(); variables.put(ProcessConstantsUtil.getApplyUserId(), applyUserId); processInstance = runtimeService.startProcessInstanceByKey(processKey, businessKey, variables); String processInstanceId = processInstance.getId(); costApproval.setProcessinstanceId(processInstanceId); // 获取并执行当前流程实例的下一步任务 Task task = null; TaskQuery query = taskService.createTaskQuery().processInstanceBusinessKey(businessKey).active(); task = query.singleResult(); variables.put( ProcessConstantsUtil.getDeptLeaderId(), ResourceUtil.getSessionUserName().getCurrentDepart().getDepartManager().getId()); taskService.complete(task.getId(), variables); }
/** http://jira.codehaus.org/browse/ACT-1222 */ @Deployment public void testReceyclingExecutionWithCallActivity() { runtimeService.startProcessInstanceByKey("parent-process"); // After process start we have two tasks, one from the parent and one from the sub process TaskQuery query = taskService.createTaskQuery().orderByTaskName().asc(); List<Task> tasks = query.list(); assertEquals(2, tasks.size()); assertEquals("Another task", tasks.get(0).getName()); assertEquals("Some Task", tasks.get(1).getName()); // we complete the task from the parent process, the root execution is receycled, the task in // the sub process is still there taskService.complete(tasks.get(1).getId()); tasks = query.list(); assertEquals(1, tasks.size()); assertEquals("Another task", tasks.get(0).getName()); // we end the task in the sub process and the sub process instance end is propagated to the // parent process taskService.complete(tasks.get(0).getId()); assertEquals(0, taskService.createTaskQuery().count()); // There is a QA config without history, so we cannot work with this: // assertEquals(1, // historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).finished().count()); }
public void testQueryCreatedOn() throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS"); // Exact matching of createTime, should result in 6 tasks Date createTime = sdf.parse("01/01/2001 01:01:01.000"); TaskQuery query = taskService.createTaskQuery().taskCreatedOn(createTime); assertEquals(6, query.count()); assertEquals(6, query.list().size()); }
public void testQueryNoCriteria() { TaskQuery query = taskService.createTaskQuery(); assertEquals(12, query.count()); assertEquals(12, query.list().size()); try { query.singleResult(); fail("expected exception"); } catch (ActivitiException e) { // OK } }
public void testQueryByDescription() { TaskQuery query = taskService.createTaskQuery().taskDescription("testTask description"); assertEquals(6, query.list().size()); assertEquals(6, query.count()); try { query.singleResult(); fail(); } catch (ActivitiException e) { } }
public void testQueryByInvalidNameLike() { TaskQuery query = taskService.createTaskQuery().taskNameLike("1"); assertNull(query.singleResult()); assertEquals(0, query.list().size()); assertEquals(0, query.count()); try { taskService.createTaskQuery().taskNameLike(null).singleResult(); fail(); } catch (ActivitiIllegalArgumentException e) { } }
public void testQueryByInvalidTaskId() { TaskQuery query = taskService.createTaskQuery().taskId("invalid"); assertNull(query.singleResult()); assertEquals(0, query.list().size()); assertEquals(0, query.count()); try { taskService.createTaskQuery().taskId(null); fail("expected exception"); } catch (ActivitiIllegalArgumentException e) { // OK } }
/** * @param taskQueryForm * @param userId * @return */ @Override public List<TaskVo> queryToDoTaskFiltered(TaskQueryForm taskQueryForm, String userId) { DataTablesInfo dataTablesInfo = taskQueryForm.getDataTablesInfo(); int start = dataTablesInfo.getStart(); int length = dataTablesInfo.getLength(); TaskQuery taskQuery = taskService .createTaskQuery() .taskCandidateOrAssigned(userId) .orderByTaskCreateTime() .desc(); List<Task> tasks = taskQuery.listPage(start, start + length); List<TaskVo> taskRtn = buildTaskVos(tasks); return taskRtn; }
public void testQueryCreatedBefore() throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS"); // Should result in 7 tasks Date before = sdf.parse("03/02/2002 02:02:02.000"); TaskQuery query = taskService.createTaskQuery().taskCreatedBefore(before); assertEquals(7, query.count()); assertEquals(7, query.list().size()); before = sdf.parse("01/01/2001 01:01:01.000"); query = taskService.createTaskQuery().taskCreatedBefore(before); assertEquals(0, query.count()); assertEquals(0, query.list().size()); }
public void testQueryCreatedAfter() throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS"); // Should result in 3 tasks Date after = sdf.parse("03/03/2003 03:03:03.000"); TaskQuery query = taskService.createTaskQuery().taskCreatedAfter(after); assertEquals(3, query.count()); assertEquals(3, query.list().size()); after = sdf.parse("05/05/2005 05:05:05.000"); query = taskService.createTaskQuery().taskCreatedAfter(after); assertEquals(0, query.count()); assertEquals(0, query.list().size()); }
public void testQueryPaging() { TaskQuery query = taskService.createTaskQuery().taskCandidateUser("kermit"); assertEquals(11, query.listPage(0, Integer.MAX_VALUE).size()); // Verifying the un-paged results assertEquals(11, query.count()); assertEquals(11, query.list().size()); // Verifying paged results assertEquals(2, query.listPage(0, 2).size()); assertEquals(2, query.listPage(2, 2).size()); assertEquals(3, query.listPage(4, 3).size()); assertEquals(1, query.listPage(10, 3).size()); assertEquals(1, query.listPage(10, 1).size()); // Verifying odd usages assertEquals(0, query.listPage(-1, -1).size()); assertEquals(0, query.listPage(11, 2).size()); // 10 is the last index with a result assertEquals(11, query.listPage(0, 15).size()); // there are only 11 tasks }
public void testQueryByAssignee() { TaskQuery query = taskService.createTaskQuery().taskAssignee("gonzo"); assertEquals(1, query.count()); assertEquals(1, query.list().size()); assertNotNull(query.singleResult()); query = taskService.createTaskQuery().taskAssignee("kermit"); assertEquals(0, query.count()); assertEquals(0, query.list().size()); assertNull(query.singleResult()); }
public void testQueryByCandidateGroup() { TaskQuery query = taskService.createTaskQuery().taskCandidateGroup("management"); assertEquals(3, query.count()); assertEquals(3, query.list().size()); try { query.singleResult(); fail("expected exception"); } catch (ActivitiException e) { // OK } query = taskService.createTaskQuery().taskCandidateGroup("sales"); assertEquals(0, query.count()); assertEquals(0, query.list().size()); }
public void testQueryByCandidateUser() { TaskQuery query = taskService.createTaskQuery().taskCandidateUser("kermit"); assertEquals(11, query.count()); assertEquals(11, query.list().size()); try { query.singleResult(); fail("expected exception"); } catch (ActivitiException e) { // OK } query = taskService.createTaskQuery().taskCandidateUser("fozzie"); assertEquals(3, query.count()); assertEquals(3, query.list().size()); try { query.singleResult(); fail("expected exception"); } catch (ActivitiException e) { // OK } }
public void testQueryByCandidateGroupIn() { List<String> groups = Arrays.asList("management", "accountancy"); TaskQuery query = taskService.createTaskQuery().taskCandidateGroupIn(groups); assertEquals(5, query.count()); assertEquals(5, query.list().size()); try { query.singleResult(); fail("expected exception"); } catch (ActivitiException e) { // OK } // Unexisting groups or groups that don't have candidate tasks shouldn't influence other results groups = Arrays.asList("management", "accountancy", "sales", "unexising"); query = taskService.createTaskQuery().taskCandidateGroupIn(groups); assertEquals(5, query.count()); assertEquals(5, query.list().size()); }
// ACT-482 @Deployment public void testNestedForkJoin() { runtimeService.startProcessInstanceByKey("nestedForkJoin"); // After process startm, only task 0 should be active TaskQuery query = taskService.createTaskQuery().orderByTaskName().asc(); List<Task> tasks = query.list(); assertEquals(1, tasks.size()); assertEquals("Task 0", tasks.get(0).getName()); // Completing task 0 will create Task A and B taskService.complete(tasks.get(0).getId()); tasks = query.list(); assertEquals(2, tasks.size()); assertEquals("Task A", tasks.get(0).getName()); assertEquals("Task B", tasks.get(1).getName()); // Completing task A should not trigger any new tasks taskService.complete(tasks.get(0).getId()); tasks = query.list(); assertEquals(1, tasks.size()); assertEquals("Task B", tasks.get(0).getName()); // Completing task B creates tasks B1 and B2 taskService.complete(tasks.get(0).getId()); tasks = query.list(); assertEquals(2, tasks.size()); assertEquals("Task B1", tasks.get(0).getName()); assertEquals("Task B2", tasks.get(1).getName()); // Completing B1 and B2 will activate both joins, and process reaches task C taskService.complete(tasks.get(0).getId()); taskService.complete(tasks.get(1).getId()); tasks = query.list(); assertEquals(1, tasks.size()); assertEquals("Task C", tasks.get(0).getName()); }
public void testQueryByDescriptionLike() { TaskQuery query = taskService.createTaskQuery().taskDescriptionLike("%gonzo%"); assertNotNull(query.singleResult()); assertEquals(1, query.list().size()); assertEquals(1, query.count()); }
@Override public long listFilteredPantoneInfosCounts(TaskQueryForm taskQueryForm, String userId) { TaskQuery taskQuery = taskService.createTaskQuery().taskCandidateOrAssigned(userId); List<Task> tasks = taskQuery.list(); return tasks.size(); }
public void testQueryByDelegationState() { TaskQuery query = taskService.createTaskQuery().taskDelegationState(null); assertEquals(12, query.count()); assertEquals(12, query.list().size()); query = taskService.createTaskQuery().taskDelegationState(DelegationState.PENDING); assertEquals(0, query.count()); assertEquals(0, query.list().size()); query = taskService.createTaskQuery().taskDelegationState(DelegationState.RESOLVED); assertEquals(0, query.count()); assertEquals(0, query.list().size()); String taskId = taskService.createTaskQuery().taskAssignee("gonzo").singleResult().getId(); taskService.delegateTask(taskId, "kermit"); query = taskService.createTaskQuery().taskDelegationState(null); assertEquals(11, query.count()); assertEquals(11, query.list().size()); query = taskService.createTaskQuery().taskDelegationState(DelegationState.PENDING); assertEquals(1, query.count()); assertEquals(1, query.list().size()); query = taskService.createTaskQuery().taskDelegationState(DelegationState.RESOLVED); assertEquals(0, query.count()); assertEquals(0, query.list().size()); taskService.resolveTask(taskId); query = taskService.createTaskQuery().taskDelegationState(null); assertEquals(11, query.count()); assertEquals(11, query.list().size()); query = taskService.createTaskQuery().taskDelegationState(DelegationState.PENDING); assertEquals(0, query.count()); assertEquals(0, query.list().size()); query = taskService.createTaskQuery().taskDelegationState(DelegationState.RESOLVED); assertEquals(1, query.count()); assertEquals(1, query.list().size()); }
public void testQueryByUnassigned() { TaskQuery query = taskService.createTaskQuery().taskUnassigned(); assertEquals(11, query.count()); assertEquals(11, query.list().size()); }
/** * 查询用户的待办任务总数 * * @param userId * @return */ @Override public long queryTaskTotal(String userId) { TaskQuery taskQuery = taskService.createTaskQuery().taskCandidateOrAssigned(userId); long totals = taskQuery.count(); return totals; }
public void testQueryByTaskId() { TaskQuery query = taskService.createTaskQuery().taskId(taskIds.get(0)); assertNotNull(query.singleResult()); assertEquals(1, query.list().size()); assertEquals(1, query.count()); }
public void testQueryByPriority() { TaskQuery query = taskService.createTaskQuery().taskPriority(10); assertEquals(2, query.list().size()); assertEquals(2, query.count()); try { query.singleResult(); fail(); } catch (ActivitiException e) { } query = taskService.createTaskQuery().taskPriority(100); assertNull(query.singleResult()); assertEquals(0, query.list().size()); assertEquals(0, query.count()); query = taskService.createTaskQuery().taskMinPriority(50); assertEquals(3, query.list().size()); query = taskService.createTaskQuery().taskMinPriority(10); assertEquals(5, query.list().size()); query = taskService.createTaskQuery().taskMaxPriority(10); assertEquals(9, query.list().size()); query = taskService.createTaskQuery().taskMaxPriority(3); assertEquals(6, query.list().size()); }
/** * Get the number of Task Instances with various states States: Completed , Active, Suspended, * Failed * * @return list with the states and the count of task instances in each state */ @GET @Path("/taskStatusCount/") @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public ResponseHolder getCountOfTaskInstanceStatus() { List taskCountList = new ArrayList<>(); ResponseHolder response = new ResponseHolder(); ProcessTaskCount completedTaskInstances, activeTaskInstances, suspendedTaskInstances, failedTaskInstances; TaskQuery taskQuery = BPMNOSGIService.getTaskService().createTaskQuery(); long countOfCompletedTaskInstances = BPMNOSGIService.getHistoryService() .createHistoricTaskInstanceQuery() .taskTenantId(str) .finished() .count(); long countOfActiveTaskInstances = taskQuery.taskTenantId(str).active().count(); long countOfSuspendedTaskInstances = taskQuery.taskTenantId(str).suspended().count(); // Check on this long countOfFailedTaskInstances = BPMNOSGIService.getManagementService() .createJobQuery() .jobTenantId(str) .withException() .count(); if (countOfCompletedTaskInstances == 0 && countOfActiveTaskInstances == 0 && countOfSuspendedTaskInstances == 0 && countOfFailedTaskInstances == 0) { response.setData(taskCountList); } else { completedTaskInstances = new ProcessTaskCount(); completedTaskInstances.setStatusOfProcessOrTask("Completed"); completedTaskInstances.setCount(countOfCompletedTaskInstances); taskCountList.add(completedTaskInstances); activeTaskInstances = new ProcessTaskCount(); activeTaskInstances.setStatusOfProcessOrTask("Active"); activeTaskInstances.setCount(countOfActiveTaskInstances); taskCountList.add(activeTaskInstances); suspendedTaskInstances = new ProcessTaskCount(); suspendedTaskInstances.setStatusOfProcessOrTask("Suspended"); suspendedTaskInstances.setCount(countOfSuspendedTaskInstances); taskCountList.add(suspendedTaskInstances); failedTaskInstances = new ProcessTaskCount(); failedTaskInstances.setStatusOfProcessOrTask("Failed"); failedTaskInstances.setCount(countOfFailedTaskInstances); taskCountList.add(failedTaskInstances); response.setData(taskCountList); } return response; }
@Get public DataResponse getTasks() { if (authenticate() == false) return null; String personalTaskUserId = getQuery().getValues("assignee"); String ownerTaskUserId = getQuery().getValues("owner"); String involvedTaskUserId = getQuery().getValues("involved"); String candidateTaskUserId = getQuery().getValues("candidate"); String candidateGroupId = getQuery().getValues("candidate-group"); String strPriority = getQuery().getValues("priority"); String strMinPriority = getQuery().getValues("minPriority"); String strMaxPriority = getQuery().getValues("maxPriority"); String strDueDate = getQuery().getValues("dueDate"); String strMinDueDate = getQuery().getValues("minDueDate"); String strMaxDueDate = getQuery().getValues("maxDueDate"); TaskQuery taskQuery = ActivitiUtil.getTaskService().createTaskQuery(); if (personalTaskUserId != null) { taskQuery.taskAssignee(personalTaskUserId); } else if (ownerTaskUserId != null) { taskQuery.taskOwner(ownerTaskUserId); } else if (involvedTaskUserId != null) { taskQuery.taskInvolvedUser(involvedTaskUserId); } else if (candidateTaskUserId != null) { taskQuery.taskCandidateUser(candidateTaskUserId); } else if (candidateGroupId != null) { taskQuery.taskCandidateGroup(candidateGroupId); } else { throw new ActivitiIllegalArgumentException( "Tasks must be filtered with 'assignee', 'owner', 'involved', 'candidate' or 'candidate-group'"); } if (strPriority != null) { taskQuery.taskPriority(RequestUtil.parseToInteger(strPriority)); } else if (strMinPriority != null) { taskQuery.taskMinPriority(RequestUtil.parseToInteger(strMinPriority)); } else if (strMaxPriority != null) { taskQuery.taskMaxPriority(RequestUtil.parseToInteger(strMaxPriority)); } if (strDueDate != null) { taskQuery.dueDate(RequestUtil.parseToDate(strDueDate)); } else if (strMinDueDate != null) { taskQuery.dueAfter(RequestUtil.parseToDate(strMinDueDate)); } else if (strMaxDueDate != null) { taskQuery.dueBefore(RequestUtil.parseToDate(strMaxDueDate)); } DataResponse dataResponse = new TasksPaginateList().paginateList(getQuery(), taskQuery, "id", properties); return dataResponse; }