@Test @Deployment(resources = {"chapter4/bookorder.bpmn20.xml"}) public void queryHistoricVariableUpdates() { startAndComplete(); HistoryService historyService = activitiRule.getHistoryService(); List<HistoricDetail> historicVariableUpdateList = historyService.createHistoricDetailQuery().variableUpdates().list(); assertNotNull(historicVariableUpdateList); assertEquals(3, historicVariableUpdateList.size()); for (HistoricDetail historicDetail : historicVariableUpdateList) { assertTrue(historicDetail instanceof HistoricVariableUpdate); HistoricVariableUpdate historicVariableUpdate = (HistoricVariableUpdate) historicDetail; assertNotNull(historicVariableUpdate.getExecutionId()); System.out.println( "historic variable update, revision " + historicVariableUpdate.getRevision() + ", variable type name " + historicVariableUpdate.getVariableTypeName() + ", variable name " + historicVariableUpdate.getVariableName() + ", Variable value '" + historicVariableUpdate.getValue() + "'"); } }
/** * 获取流程详细及工作流参数 * * @param id */ @SuppressWarnings("unchecked") public Leave get(String id) { Leave leave = leaveDao.get(id); Map<String, Object> variables = null; HistoricProcessInstance historicProcessInstance = historyService .createHistoricProcessInstanceQuery() .processInstanceId(leave.getProcessInstanceId()) .singleResult(); if (historicProcessInstance != null) { variables = Collections3.extractToMap( historyService .createHistoricVariableInstanceQuery() .processInstanceId(historicProcessInstance.getId()) .list(), "variableName", "value"); } else { variables = runtimeService.getVariables( runtimeService .createProcessInstanceQuery() .processInstanceId(leave.getProcessInstanceId()) .active() .singleResult() .getId()); } leave.setVariables(variables); return leave; }
public String listHistoricTasks() { HistoryService historyService = processEngine.getHistoryService(); historicTaskInstances = historyService.createHistoricTaskInstanceQuery().list(); return "listHistoricTasks"; }
/** * 已办任务(历史任务) * * @return */ public String listHistoryTasks() { HistoryService historyService = processEngine.getHistoryService(); String username = SpringSecurityUtils.getCurrentUsername(); historicTasks = historyService.createHistoricTaskInstanceQuery().taskAssignee(username).finished().list(); return "listHistoryTasks"; }
/** * 用户参与的流程(包含已经完成和未完成) * * @return */ public String listInvolvedProcessInstances() { HistoryService historyService = processEngine.getHistoryService(); // TODO: finished(), unfinished() String username = SpringSecurityUtils.getCurrentUsername(); historicProcessInstances = historyService.createHistoricProcessInstanceQuery().involvedUser(username).list(); return "listInvolvedProcessInstances"; }
/** * Get completed process instances which were finished after the given date and time * * @return BPMNProcessInstance array if the historic process instance list is not null */ public BPMNProcessInstance[] getCompletedProcessInstances() { HistoryService historyService = BPMNServerHolder.getInstance().getEngine().getHistoryService(); HistoricProcessInstanceQuery instanceQuery = historyService.createHistoricProcessInstanceQuery(); List<HistoricProcessInstance> historicProcessInstanceList = null; String time = readPublishTimeFromRegistry( AnalyticsPublisherConstants.PROCESS_RESOURCE_PATH, AnalyticsPublisherConstants.LAST_PROCESS_INSTANCE_PUBLISH_TIME); if (time == null) { if (instanceQuery.finished().list().size() != 0) { // if the stored time is null in the registry file then send all completed process // instances. historicProcessInstanceList = instanceQuery.finished().orderByProcessInstanceStartTime().asc().list(); } } else { Date timeInDateFormat = DateConverter.convertStringToDate(time); int listSize = instanceQuery.finished().startedAfter(timeInDateFormat).list().size(); if (listSize != 0) { /*When using the startedAfter() method it returns the finished objects according to the time stored of last completed instance. But if the list length is one then it always return the same object in the list twice from the last updated time which stored in the carbon registry. (avoid to return same object repeatedly if the list has only one object)*/ if (listSize == 1) { return null; } // send the process instances which were finished after the given date/time in registry historicProcessInstanceList = instanceQuery .finished() .startedAfter(timeInDateFormat) .orderByProcessInstanceStartTime() .asc() .listPage(1, listSize); } } if (historicProcessInstanceList != null) { if (log.isDebugEnabled()) { log.debug( "Write the published time of the last BPMN process instance to the carbon registry..." + historicProcessInstanceList.toString()); } /*write the last published time to the registry because lets say as an example when a new process is completed, then the attributes belong to that process instance should be published to the DAS and if we are not stored the last published time, then all the completed processes which were previously published are also re-published to the DAS.*/ writePublishTimeToRegistry(historicProcessInstanceList); // return ProcessInstances set as BPMNProcessInstance array return getBPMNProcessInstances(historicProcessInstanceList); } return null; }
@Test @Deployment(resources = {PROCESS_RESOURCE}) public void processRejected() throws InterruptedException { Map<String, Object> procVars = createStartFormVariables(); ProcessInstance pi = activitiRule .getProcessEngine() .getRuntimeService() .startProcessInstanceByKey(PROCESS_KEY, procVars); // assertNotNull(pi); Task task = activitiRule.getTaskService().createTaskQuery().singleResult(); // assertNotNull(task); Map<String, Object> taskVars = new HashMap<String, Object>(); taskVars.put("decide", "reject"); activitiRule.getProcessEngine().getTaskService().complete(task.getId(), taskVars); HistoryService historyService = activitiRule.getHistoryService(); HistoricProcessInstance historicProcessInstance = historyService .createHistoricProcessInstanceQuery() .processInstanceId(pi.getProcessInstanceId()) .singleResult(); // assertNotNull(historicProcessInstance); // check that only one process running // assertEquals(pi.getProcessInstanceId(), historicProcessInstance.getId()); List<HistoricActivityInstance> activityList = historyService .createHistoricActivityInstanceQuery() .processInstanceId(pi.getProcessInstanceId()) .list(); JobQuery jquery = activitiRule.getManagementService().createJobQuery(); // check how many tasks must be done // assertEquals("done task count", 6, activityList.size()); // and the job is done // assertEquals("job is done", 0, jquery.count()); // assertEquals(0, activitiRule.getProcessEngine().getRuntimeService() // .createProcessInstanceQuery().count()); }
/** 历史任务. */ public Page findHistoricTaskInstances(String tenantId, Page page) { HistoryService historyService = processEngine.getHistoryService(); long count = historyService.createHistoricTaskInstanceQuery().taskTenantId(tenantId).count(); List<HistoricTaskInstance> historicTaskInstances = historyService .createHistoricTaskInstanceQuery() .taskTenantId(tenantId) .listPage((int) page.getStart(), page.getPageSize()); page.setResult(historicTaskInstances); page.setTotalCount(count); return page; }
/** * 查看历史【包含流程跟踪、任务列表(完成和未完成)、流程变量】 * * @return */ public String viewHistory() { HistoryService historyService = processEngine.getHistoryService(); historicTasks = historyService .createHistoricTaskInstanceQuery() .processInstanceId(processInstanceId) .list(); historicVariableInstances = historyService .createHistoricVariableInstanceQuery() .processInstanceId(processInstanceId) .list(); return "viewHistory"; }
/** * easyui AJAX请求数据 已办任务 * * @param request * @param response * @param dataGrid */ @RequestMapping(params = "finishedTaskDataGrid") public void finishedTask( HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { // String userId = "leaderuser"; String userId = ResourceUtil.getSessionUserName().getId(); List<HistoricTaskInstance> historicTasks = historyService.createHistoricTaskInstanceQuery().taskAssignee(userId).finished().list(); StringBuffer rows = new StringBuffer(); for (HistoricTaskInstance t : historicTasks) { rows.append( "{'name':'" + t.getName() + "','description':'" + t.getDescription() + "','taskId':'" + t.getId() + "','processDefinitionId':'" + t.getProcessDefinitionId() + "','processInstanceId':'" + t.getProcessInstanceId() + "'},"); } String rowStr = StringUtils.substringBeforeLast(rows.toString(), ","); JSONObject jObject = JSONObject.fromObject("{'total':" + historicTasks.size() + ",'rows':[" + rowStr + "]}"); responseDatagrid(response, jObject); }
public static List<HistoricTaskInstance> getHistoricTaskInstanceByProcessInstanceId( String processInstanceId) { return historyService .createHistoricTaskInstanceQuery() .processInstanceId(processInstanceId) .list(); }
@RequestMapping( value = "/history/historic-task-instances/{taskId}", method = RequestMethod.DELETE) public void deleteTaskInstance(@PathVariable String taskId, HttpServletResponse response) { historyService.deleteHistoricTaskInstance(taskId); response.setStatus(HttpStatus.NO_CONTENT.value()); }
/** * @param processInstanceId * @return */ @Override public List<HistoricTaskInstance> createHistoricTaskInstanceQuery(String processInstanceId) { return historyService .createHistoricTaskInstanceQuery() .processInstanceId(processInstanceId) .list(); }
public int size() { return (int) historyService .createHistoricProcessInstanceQuery() .startedBy(ExplorerApp.get().getLoggedInUser().getId()) .unfinished() .count(); }
protected HistoricTaskInstance getHistoricTaskInstanceFromRequest(String taskId) { HistoricTaskInstance taskInstance = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult(); if (taskInstance == null) { throw new ActivitiObjectNotFoundException( "Could not find a task instance with id '" + taskId + "'.", HistoricTaskInstance.class); } return taskInstance; }
/** * Get completed task instances which were finished after the given date and time * * @return BPMNTaskInstance array if the historic task instance list is not null */ public BPMNTaskInstance[] getCompletedTaskInstances() { HistoryService historyService = BPMNServerHolder.getInstance().getEngine().getHistoryService(); HistoricTaskInstanceQuery instanceQuery = historyService.createHistoricTaskInstanceQuery(); List<HistoricTaskInstance> historicTaskInstanceList = null; String time = readPublishTimeFromRegistry( AnalyticsPublisherConstants.TASK_RESOURCE_PATH, AnalyticsPublisherConstants.LAST_TASK_INSTANCE_END_TIME); if (time == null) { if (instanceQuery.finished().list().size() != 0) { historicTaskInstanceList = instanceQuery.finished().orderByHistoricTaskInstanceEndTime().asc().list(); } } else { Date dateFormat = DateConverter.convertStringToDate(time); int listSize = instanceQuery.finished().taskCompletedAfter(dateFormat).list().size(); if (listSize != 0) { /*When using the startedAfter() method it returns the finished objects according to the time stored of last completed instance. But if the list length is one then it always return the same object in the list twice from the last updated time which stored in the carbon registry. (avoid to return same object repeatedly if the list has only one object)*/ if (listSize == 1) { return null; } historicTaskInstanceList = instanceQuery .finished() .taskCompletedAfter(dateFormat) .orderByHistoricTaskInstanceEndTime() .asc() .listPage(1, listSize); } } if (historicTaskInstanceList != null) { if (log.isDebugEnabled()) { log.debug( "Write BPMN task instance to the carbon registry..." + historicTaskInstanceList.toString()); } writeTaskEndTimeToRegistry(historicTaskInstanceList); return getBPMNTaskInstances(historicTaskInstanceList); } return null; }
private Object getProccessVariableValue(String processInstance_ID, String variableName) { HistoricVariableInstance historicVariableInstance = historyService .createHistoricVariableInstanceQuery() .processInstanceId(processInstance_ID) .variableName(variableName) .singleResult(); return (Object) historicVariableInstance.getValue(); }
/** * 根据流程实例ID查询流程定义对象{@link ProcessDefinition} * * @param processInstanceId 流程实例ID * @return 流程定义对象{@link ProcessDefinition} */ public ProcessDefinition findProcessDefinitionByPid(String processInstanceId) { HistoricProcessInstance historicProcessInstance = historyService .createHistoricProcessInstanceQuery() .processInstanceId(processInstanceId) .singleResult(); String processDefinitionId = historicProcessInstance.getProcessDefinitionId(); ProcessDefinition processDefinition = findProcessDefinition(processDefinitionId); return processDefinition; }
@Test @Ignore public void testHappyPath() { // Create test applicant Applicant applicant = new Applicant("John Doe", "*****@*****.**", "12344"); applicantRepository.save(applicant); // Start process instance Map<String, Object> variables = new HashMap<String, Object>(); variables.put("applicant", applicant); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("hireProcessWithJpa", variables); // First, the 'phone interview' should be active Task task = taskService .createTaskQuery() .processInstanceId(processInstance.getId()) .taskCandidateGroup("dev-managers") .singleResult(); Assert.assertEquals("Telephone interview", task.getName()); // Completing the phone interview with success should trigger two new tasks Map<String, Object> taskVariables = new HashMap<String, Object>(); taskVariables.put("telephoneInterviewOutcome", true); taskService.complete(task.getId(), taskVariables); List<Task> tasks = taskService .createTaskQuery() .processInstanceId(processInstance.getId()) .orderByTaskName() .asc() .list(); Assert.assertEquals(2, tasks.size()); Assert.assertEquals("Financial negotiation", tasks.get(0).getName()); Assert.assertEquals("Tech interview", tasks.get(1).getName()); // Completing both should wrap up the subprocess, send out the 'welcome mail' and end the // process instance taskVariables = new HashMap<String, Object>(); taskVariables.put("techOk", true); taskService.complete(tasks.get(0).getId(), taskVariables); taskVariables = new HashMap<String, Object>(); taskVariables.put("financialOk", true); taskService.complete(tasks.get(1).getId(), taskVariables); // Verify email Assert.assertEquals(1, wiser.getMessages().size()); // Verify process completed Assert.assertEquals(1, historyService.createHistoricProcessInstanceQuery().finished().count()); }
public Item loadSingleResult(String id) { HistoricProcessInstance processInstance = historyService .createHistoricProcessInstanceQuery() .startedBy(ExplorerApp.get().getLoggedInUser().getId()) .unfinished() .processInstanceId(id) .singleResult(); if (processInstance != null) { return createItem(processInstance); } return null; }
/** 参与流程. */ public Page findInvolvedProcessInstances(String userId, String tenantId, Page page) { HistoryService historyService = processEngine.getHistoryService(); // TODO: finished(), unfinished() long count = historyService .createHistoricProcessInstanceQuery() .processInstanceTenantId(tenantId) .involvedUser(userId) .count(); List<HistoricProcessInstance> historicProcessInstances = historyService .createHistoricProcessInstanceQuery() .processInstanceTenantId(tenantId) .involvedUser(userId) .listPage((int) page.getStart(), page.getPageSize()); page.setResult(historicProcessInstances); page.setTotalCount(count); return page; }
@Test @Deployment(resources = {"chapter4/bookorder.bpmn20.xml"}) public void queryHistoricInstances() { String processInstanceID = startAndComplete(); HistoryService historyService = activitiRule.getHistoryService(); HistoricProcessInstance historicProcessInstance = historyService .createHistoricProcessInstanceQuery() .processInstanceId(processInstanceID) .singleResult(); assertNotNull(historicProcessInstance); assertEquals(processInstanceID, historicProcessInstance.getId()); System.out.println( "history process with definition id " + historicProcessInstance.getProcessDefinitionId() + ", started at " + historicProcessInstance.getStartTime() + ", ended at " + historicProcessInstance.getEndTime() + ", duration was " + historicProcessInstance.getDurationInMillis()); }
public List<Item> loadItems(int start, int count) { List<HistoricProcessInstance> processInstances = historyService .createHistoricProcessInstanceQuery() .startedBy(ExplorerApp.get().getLoggedInUser().getId()) .unfinished() .list(); List<Item> items = new ArrayList<Item>(); for (HistoricProcessInstance processInstance : processInstances) { items.add(createItem(processInstance)); } return items; }
@Test public void exportJavaDelegate() throws Exception { // wait for deployment to be done Thread.sleep(5000); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("osgiProcess"); assertTrue(processInstance.isEnded()); HistoricVariableInstance variable = historyService .createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()) .variableName("visited") .singleResult(); assertTrue((Boolean) variable.getValue()); }
@Test @Deployment(resources = {"chapter4/bookorder.bpmn20.xml"}) public void queryHistoricActivities() { startAndComplete(); HistoryService historyService = activitiRule.getHistoryService(); List<HistoricActivityInstance> activityList = historyService.createHistoricActivityInstanceQuery().list(); assertEquals(4, activityList.size()); for (HistoricActivityInstance historicActivityInstance : activityList) { assertNotNull(historicActivityInstance.getActivityId()); System.out.println( "history activity " + historicActivityInstance.getActivityName() + ", type " + historicActivityInstance.getActivityType() + ", starttime " + historicActivityInstance.getStartTime() + ", endtime " + historicActivityInstance.getEndTime() + ", duration was " + historicActivityInstance.getDurationInMillis()); } }
/** 未结流程. */ public Page findRunningProcessInstances(String userId, String tenantId, Page page) { HistoryService historyService = processEngine.getHistoryService(); // TODO: 改成通过runtime表搜索,提高效率 long count = historyService .createHistoricProcessInstanceQuery() .processInstanceTenantId(tenantId) .startedBy(userId) .unfinished() .count(); List<HistoricProcessInstance> historicProcessInstances = historyService .createHistoricProcessInstanceQuery() .processInstanceTenantId(tenantId) .startedBy(userId) .unfinished() .listPage((int) page.getStart(), page.getPageSize()); page.setResult(historicProcessInstances); page.setTotalCount(count); return page; }
public List<KickstartWorkflowInfo> convertToWorkflowInfoList( List<ProcessDefinition> processDefinitions) { List<KickstartWorkflowInfo> infoList = new ArrayList<KickstartWorkflowInfo>(); for (ProcessDefinition processDefinition : processDefinitions) { KickstartWorkflowInfo workflowInfo = new KickstartWorkflowInfo(); workflowInfo.setId(processDefinition.getId()); workflowInfo.setKey(processDefinition.getKey()); workflowInfo.setName(processDefinition.getName()); workflowInfo.setVersion(processDefinition.getVersion()); workflowInfo.setDeploymentId(processDefinition.getDeploymentId()); Date deploymentTime = repositoryService .createDeploymentQuery() .deploymentId(processDefinition.getDeploymentId()) .singleResult() .getDeploymentTime(); workflowInfo.setCreateTime(deploymentTime); workflowInfo.setNrOfRuntimeInstances( historyService .createHistoricProcessInstanceQuery() .processDefinitionId(processDefinition.getId()) .unfinished() .count()); workflowInfo.setNrOfHistoricInstances( historyService .createHistoricProcessInstanceQuery() .processDefinitionId(processDefinition.getId()) .finished() .count()); infoList.add(workflowInfo); } return infoList; }
public Page<Leave> find(Page<Leave> page, Leave leave) { leave.getSqlMap().put("dsf", dataScopeFilter(leave.getCurrentUser(), "o", "u")); leave.setPage(page); page.setList(leaveDao.findList(leave)); for (Leave item : page.getList()) { String processInstanceId = item.getProcessInstanceId(); Task task = taskService .createTaskQuery() .processInstanceId(processInstanceId) .active() .singleResult(); item.setTask(task); HistoricProcessInstance historicProcessInstance = historyService .createHistoricProcessInstanceQuery() .processInstanceId(processInstanceId) .singleResult(); if (historicProcessInstance != null) { item.setHistoricProcessInstance(historicProcessInstance); item.setProcessDefinition( repositoryService .createProcessDefinitionQuery() .processDefinitionId(historicProcessInstance.getProcessDefinitionId()) .singleResult()); } else { ProcessInstance processInstance = runtimeService .createProcessInstanceQuery() .processInstanceId(processInstanceId) .active() .singleResult(); if (processInstance != null) { item.setProcessInstance(processInstance); item.setProcessDefinition( repositoryService .createProcessDefinitionQuery() .processDefinitionId(processInstance.getProcessDefinitionId()) .singleResult()); } } } return page; }
/** * Generic method which will figure out to which task page must be jumped, based on the task data. * * <p>Note that, if possible, it is always more performant to use the more specific showXXXPage() * methods. */ public void showTaskPage(String taskId) { Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); String loggedInUserId = ExplorerApp.get().getLoggedInUser().getId(); if (task == null) { // If no runtime task exists, our only hope is the archive page boolean isOwner = historyService .createHistoricTaskInstanceQuery() .taskId(taskId) .taskOwner(loggedInUserId) .count() == 1; if (isOwner) { showArchivedPage(taskId); } else { showNavigationError(taskId); } } else if (loggedInUserId.equals(task.getOwner())) { showTasksPage(taskId); } else if (loggedInUserId.equals(task.getAssignee())) { showInboxPage(taskId); } else if (taskService.createTaskQuery().taskInvolvedUser(loggedInUserId).count() == 1) { showInvolvedPage(taskId); } else { // queued List<String> groupIds = getGroupIds(loggedInUserId); List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(task.getId()); Iterator<IdentityLink> identityLinkIterator = identityLinks.iterator(); boolean pageFound = false; while (!pageFound && identityLinkIterator.hasNext()) { IdentityLink identityLink = identityLinkIterator.next(); if (identityLink.getGroupId() != null && groupIds.contains(identityLink.getGroupId())) { showQueuedPage(identityLink.getGroupId(), task.getId()); pageFound = true; } } // We've tried hard enough, the user now gets a notification. He deserves it. if (!pageFound) { showNavigationError(taskId); } } }
@RequestMapping(value = "/list") @ResponseBody public Map<String, Object> list( @RequestParam("page") int curPage, @RequestParam("rows") int pageSize, HttpServletRequest req) { HistoricTaskInstanceQuery historicTaskInstanceQuery = historyService.createHistoricTaskInstanceQuery(); // .taskAssignee("5") long total = historicTaskInstanceQuery.count(); List<HistoricTaskInstance> list = historicTaskInstanceQuery .orderByTaskCreateTime() .desc() .listPage((curPage - 1) * pageSize, pageSize); Map<String, Object> obj = new HashMap<String, Object>(); obj.put("total", total); obj.put("list", list); return obj; }