protected ProcessInstanceItem createItem(HistoricProcessInstance processInstance) { ProcessInstanceItem item = new ProcessInstanceItem(); item.addItemProperty("id", new ObjectProperty<String>(processInstance.getId(), String.class)); ProcessDefinition processDefinition = getProcessDefinition(processInstance.getProcessDefinitionId()); String itemName = getProcessDisplayName(processDefinition) + " (" + processInstance.getId() + ")"; item.addItemProperty("name", new ObjectProperty<String>(itemName, String.class)); return item; }
@SuppressWarnings("serial") /** * Creates a popup that allows to see the process history and the final report of * historicProcessInstance * * @param historicProcessInstance = historicProcessInstance to be seen * @return the popup of historicProcessInstance */ private PopupView createHistoricProcessInstancePopup( final HistoricProcessInstance historicProcessInstance) { final VerticalLayout layout = new VerticalLayout(); final PopupView popup = new PopupView(historicProcessInstance.getId(), layout); layout.setSizeUndefined(); layout.setMargin(true); layout.setSpacing(true); Label header = new Label( String.format( "What would you like to do with process: <b>%s</b>?", historicProcessInstance.getId())); header.setContentMode(Label.CONTENT_XHTML); layout.addComponent(header); Button porcessHistory = new Button("See process history"); porcessHistory.addStyleName(Reindeer.BUTTON_SMALL); porcessHistory.addListener( new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { getPresenter().setHistBrowser(historicProcessInstance); popup.setPopupVisible(false); } }); layout.addComponent(porcessHistory); Button finalReport = new Button("see final report"); finalReport.addStyleName(Reindeer.BUTTON_SMALL); finalReport.addListener( new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { getPresenter().setReportBrowser(historicProcessInstance); popup.setPopupVisible(false); } }); layout.addComponent(finalReport); return popup; }
/** * 获取流程详细及工作流参数 * * @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; }
@SuppressWarnings("unchecked") public void deleteHistoricProcessInstanceById(String historicProcessInstanceId) { if (getHistoryManager().isHistoryEnabled()) { CommandContext commandContext = Context.getCommandContext(); HistoricProcessInstanceEntity historicProcessInstance = findHistoricProcessInstance(historicProcessInstanceId); commandContext .getHistoricDetailEntityManager() .deleteHistoricDetailsByProcessInstanceId(historicProcessInstanceId); commandContext .getHistoricVariableInstanceEntityManager() .deleteHistoricVariableInstanceByProcessInstanceId(historicProcessInstanceId); commandContext .getHistoricActivityInstanceEntityManager() .deleteHistoricActivityInstancesByProcessInstanceId(historicProcessInstanceId); commandContext .getHistoricTaskInstanceEntityManager() .deleteHistoricTaskInstancesByProcessInstanceId(historicProcessInstanceId); commandContext .getHistoricIdentityLinkEntityManager() .deleteHistoricIdentityLinksByProcInstance(historicProcessInstanceId); commandContext .getCommentEntityManager() .deleteCommentsByProcessInstanceId(historicProcessInstanceId); getDbSqlSession().delete(historicProcessInstance); // Also delete any sub-processes that may be active (ACT-821) HistoricProcessInstanceQueryImpl subProcessesQueryImpl = new HistoricProcessInstanceQueryImpl(); subProcessesQueryImpl.superProcessInstanceId(historicProcessInstanceId); List<HistoricProcessInstance> selectList = getDbSqlSession() .selectList("selectHistoricProcessInstancesByQueryCriteria", subProcessesQueryImpl); for (HistoricProcessInstance child : selectList) { deleteHistoricProcessInstanceById(child.getId()); } } }
/** * Convert historic process instances to BPMN process instances * * @param historicProcessInstanceList List of historic process instances * @return BPMNProcessInstance array */ private BPMNProcessInstance[] getBPMNProcessInstances( List<HistoricProcessInstance> historicProcessInstanceList) { BPMNProcessInstance bpmnProcessInstance; List<BPMNProcessInstance> bpmnProcessInstances = new ArrayList<>(); for (HistoricProcessInstance instance : historicProcessInstanceList) { bpmnProcessInstance = new BPMNProcessInstance(); bpmnProcessInstance.setProcessDefinitionId(instance.getProcessDefinitionId()); bpmnProcessInstance.setTenantId(instance.getTenantId()); bpmnProcessInstance.setName(instance.getName()); bpmnProcessInstance.setInstanceId(instance.getId()); bpmnProcessInstance.setBusinessKey(instance.getBusinessKey()); bpmnProcessInstance.setStartTime(instance.getStartTime()); bpmnProcessInstance.setEndTime(instance.getEndTime()); bpmnProcessInstance.setDuration(instance.getDurationInMillis()); bpmnProcessInstance.setStartUserId(instance.getStartUserId()); bpmnProcessInstance.setStartActivityId(instance.getStartActivityId()); bpmnProcessInstance.setVariables(formatVariables(instance.getProcessVariables())); bpmnProcessInstances.add(bpmnProcessInstance); } return bpmnProcessInstances.toArray(new BPMNProcessInstance[bpmnProcessInstances.size()]); }
@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()); }
/** * @Title: myWorkTaskData @Description: TODO * * @param request * @param response * @param dataGrid void * @throws * @exception * @author fly * @date 2015年6月23日 上午10:20:42 */ @RequestMapping(params = "myWorkTaskData") public void myWorkTaskData( HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { String userId = ResourceUtil.getSessionUserName().getId(); // involvedUser 当前用户相关的 HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery().involvedUser(userId); List<HistoricProcessInstance> historicTasks = query .orderByProcessInstanceStartTime() .desc() .listPage(dataGrid.getStart(), dataGrid.getEnd()); long total = query.count(); System.out.println(dataGrid.getStart() + " end: " + dataGrid.getEnd()); StringBuffer rows = new StringBuffer(); for (HistoricProcessInstance t : historicTasks) { ProcessDefinition processDefinition = repositoryService.getProcessDefinition(t.getProcessDefinitionId()); rows.append( "{'id':'" + t.getId() + "','key':'" + processDefinition.getName() + "-" + DateUtils.date_sdf.format(t.getStartTime()) + "','taskId':'" + t.getId() + "'"); // 流程详细查看 WorkFlowSetEntity workFlowSet = systemService.findUniqueByProperty( WorkFlowSetEntity.class, "deploymentId", processDefinition.getDeploymentId()); if (workFlowSet != null) { rows.append(",'action':'" + workFlowSet.getDetailUrl() + "'"); } // 流程用户处理 if (t.getStartUserId() != null) { TSUser user = systemService.get(TSUser.class, t.getStartUserId()); rows.append(",'username':'******'"); } // 流程开始结束时间处理 if (t.getStartTime() == null) { rows.append(",'beginDate':'无'"); } else { rows.append(",'beginDate':'" + DateUtils.datetimeFormat.format(t.getStartTime()) + "'"); } if (t.getEndTime() == null) { rows.append(",'endDate':'无','stateType':'办理中'"); } else { rows.append( ",'endDate':'" + DateUtils.datetimeFormat.format(t.getEndTime()) + "','stateType':'已完成'"); } rows.append("},"); } String rowStr = StringUtils.substringBeforeLast(rows.toString(), ","); JSONObject jObject = JSONObject.fromObject("{'total':" + total + ",'rows':[" + rowStr + "]}"); responseDatagrid(response, jObject); }