Java Code Examples for org.activiti.engine.impl.persistence.entity.ExecutionEntity#getProcessDefinitionId()
The following examples show how to use
org.activiti.engine.impl.persistence.entity.ExecutionEntity#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: ProcessInstanceDiagramCmd.java From activiti-basic with Apache License 2.0 | 6 votes |
public InputStream execute(CommandContext commandContext) { ExecutionEntityManager executionEntityManager = commandContext .getExecutionEntityManager(); ExecutionEntity executionEntity = executionEntityManager .findExecutionById(processInstanceId); List<String> activiityIds = executionEntity.findActiveActivityIds(); String processDefinitionId = executionEntity.getProcessDefinitionId(); GetBpmnModelCmd getBpmnModelCmd = new GetBpmnModelCmd( processDefinitionId); BpmnModel bpmnModel = getBpmnModelCmd.execute(commandContext); InputStream is = ProcessDiagramGenerator.generateDiagram(bpmnModel, "png", activiityIds); return is; }
Example 2
Source File: ExecutionQueryImpl.java From flowable-engine with Apache License 2.0 | 6 votes |
protected void localize(Execution execution, String activityId) { ExecutionEntity executionEntity = (ExecutionEntity) execution; executionEntity.setLocalizedName(null); executionEntity.setLocalizedDescription(null); String processDefinitionId = executionEntity.getProcessDefinitionId(); if (locale != null && processDefinitionId != null) { ObjectNode languageNode = Context.getLocalizationElementProperties(locale, activityId, processDefinitionId, withLocalizationFallback); if (languageNode != null) { JsonNode languageNameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME); if (languageNameNode != null && !languageNameNode.isNull()) { executionEntity.setLocalizedName(languageNameNode.asText()); } JsonNode languageDescriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION); if (languageDescriptionNode != null && !languageDescriptionNode.isNull()) { executionEntity.setLocalizedDescription(languageDescriptionNode.asText()); } } } }
Example 3
Source File: ProcessInstanceQueryImpl.java From flowable-engine with Apache License 2.0 | 6 votes |
protected void localize(ProcessInstance processInstance) { ExecutionEntity processInstanceExecution = (ExecutionEntity) processInstance; processInstanceExecution.setLocalizedName(null); processInstanceExecution.setLocalizedDescription(null); if (locale != null) { String processDefinitionId = processInstanceExecution.getProcessDefinitionId(); if (processDefinitionId != null) { ObjectNode languageNode = Context.getLocalizationElementProperties(locale, processInstanceExecution.getProcessDefinitionKey(), processDefinitionId, withLocalizationFallback); if (languageNode != null) { JsonNode languageNameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME); if (languageNameNode != null && !languageNameNode.isNull()) { processInstanceExecution.setLocalizedName(languageNameNode.asText()); } JsonNode languageDescriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION); if (languageDescriptionNode != null && !languageDescriptionNode.isNull()) { processInstanceExecution.setLocalizedDescription(languageDescriptionNode.asText()); } } } } }
Example 4
Source File: ExecutionQueryImpl.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
protected void localize(Execution execution, String activityId) { ExecutionEntity executionEntity = (ExecutionEntity) execution; executionEntity.setLocalizedName(null); executionEntity.setLocalizedDescription(null); String processDefinitionId = executionEntity.getProcessDefinitionId(); if (locale != null && processDefinitionId != null) { ObjectNode languageNode = Context.getLocalizationElementProperties(locale, activityId, processDefinitionId, withLocalizationFallback); if (languageNode != null) { JsonNode languageNameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME); if (languageNameNode != null && languageNameNode.isNull() == false) { executionEntity.setLocalizedName(languageNameNode.asText()); } JsonNode languageDescriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION); if (languageDescriptionNode != null && languageDescriptionNode.isNull() == false) { executionEntity.setLocalizedDescription(languageDescriptionNode.asText()); } } } }
Example 5
Source File: ProcessInstanceQueryImpl.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
protected void localize(ProcessInstance processInstance) { ExecutionEntity processInstanceExecution = (ExecutionEntity) processInstance; processInstanceExecution.setLocalizedName(null); processInstanceExecution.setLocalizedDescription(null); if (locale != null) { String processDefinitionId = processInstanceExecution.getProcessDefinitionId(); if (processDefinitionId != null) { ObjectNode languageNode = Context.getLocalizationElementProperties(locale, processInstanceExecution.getProcessDefinitionKey(), processDefinitionId, withLocalizationFallback); if (languageNode != null) { JsonNode languageNameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME); if (languageNameNode != null && languageNameNode.isNull() == false) { processInstanceExecution.setLocalizedName(languageNameNode.asText()); } JsonNode languageDescriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION); if (languageDescriptionNode != null && languageDescriptionNode.isNull() == false) { processInstanceExecution.setLocalizedDescription(languageDescriptionNode.asText()); } } } } }
Example 6
Source File: SaveAttachmentCmd.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public Object execute(CommandContext commandContext) { AttachmentEntity updateAttachment = commandContext.getAttachmentEntityManager().findById(attachment.getId()); String processInstanceId = updateAttachment.getProcessInstanceId(); String processDefinitionId = null; if (updateAttachment.getProcessInstanceId() != null) { ExecutionEntity process = commandContext.getExecutionEntityManager().findById(processInstanceId); if (process != null) { processDefinitionId = process.getProcessDefinitionId(); if (Activiti5Util.isActiviti5ProcessDefinitionId(commandContext, process.getProcessDefinitionId())) { Activiti5CompatibilityHandler activiti5CompatibilityHandler = Activiti5Util.getActiviti5CompatibilityHandler(); activiti5CompatibilityHandler.saveAttachment(attachment); return null; } } } updateAttachment.setName(attachment.getName()); updateAttachment.setDescription(attachment.getDescription()); if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) { commandContext.getProcessEngineConfiguration().getEventDispatcher() .dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, attachment, processInstanceId, processInstanceId, processDefinitionId)); } return null; }
Example 7
Source File: ExecutionQueryImpl.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "unchecked" }) public List<Execution> executeList(CommandContext commandContext, Page page) { checkQueryOk(); ensureVariablesInitialized(); List<?> executions = commandContext.getExecutionEntityManager().findExecutionsByQueryCriteria(this, page); if (Context.getProcessEngineConfiguration().getPerformanceSettings().isEnableLocalization()) { for (ExecutionEntity execution : (List<ExecutionEntity>) executions) { String activityId = null; if (execution.getId().equals(execution.getProcessInstanceId())) { if (execution.getProcessDefinitionId() != null) { ProcessDefinition processDefinition = commandContext.getProcessEngineConfiguration() .getDeploymentManager() .findDeployedProcessDefinitionById(execution.getProcessDefinitionId()); activityId = processDefinition.getKey(); } } else { activityId = execution.getActivityId(); } if (activityId != null) { localize(execution, activityId); } } } return (List<Execution>) executions; }
Example 8
Source File: DefaultHistoryManager.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected HistoricActivityInstanceEntity createHistoricActivityInstanceEntity(ExecutionEntity execution) { IdGenerator idGenerator = getProcessEngineConfiguration().getIdGenerator(); String processDefinitionId = execution.getProcessDefinitionId(); String processInstanceId = execution.getProcessInstanceId(); HistoricActivityInstanceEntity historicActivityInstance = getHistoricActivityInstanceEntityManager().create(); historicActivityInstance.setId(idGenerator.getNextId()); historicActivityInstance.setProcessDefinitionId(processDefinitionId); historicActivityInstance.setProcessInstanceId(processInstanceId); historicActivityInstance.setExecutionId(execution.getId()); historicActivityInstance.setActivityId(execution.getActivityId()); if (execution.getCurrentFlowElement() != null) { historicActivityInstance.setActivityName(execution.getCurrentFlowElement().getName()); historicActivityInstance.setActivityType(parseActivityType(execution.getCurrentFlowElement())); } Date now = getClock().getCurrentTime(); historicActivityInstance.setStartTime(now); // Inherit tenant id (if applicable) if (execution.getTenantId() != null) { historicActivityInstance.setTenantId(execution.getTenantId()); } getHistoricActivityInstanceEntityManager().insert(historicActivityInstance); return historicActivityInstance; }
Example 9
Source File: AbstractOperation.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
/** * Helper method to match the activityId of an execution with a FlowElement of the process definition referenced by the execution. */ protected FlowElement getCurrentFlowElement(final ExecutionEntity execution) { if (execution.getCurrentFlowElement() != null) { return execution.getCurrentFlowElement(); } else if (execution.getCurrentActivityId() != null) { String processDefinitionId = execution.getProcessDefinitionId(); org.activiti.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(processDefinitionId); String activityId = execution.getCurrentActivityId(); FlowElement currentFlowElement = process.getFlowElement(activityId, true); return currentFlowElement; } return null; }
Example 10
Source File: DeleteAttachmentCmd.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override public Object execute(CommandContext commandContext) { AttachmentEntity attachment = commandContext .getDbSqlSession() .selectById(AttachmentEntity.class, attachmentId); commandContext .getDbSqlSession() .delete(attachment); if (attachment.getContentId() != null) { commandContext .getByteArrayEntityManager() .deleteByteArrayById(attachment.getContentId()); } if (attachment.getTaskId() != null) { commandContext.getHistoryManager() .createAttachmentComment(attachment.getTaskId(), attachment.getProcessInstanceId(), attachment.getName(), false); } if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) { // Forced to fetch the process-instance to associate the right process definition String processDefinitionId = null; String processInstanceId = attachment.getProcessInstanceId(); if (attachment.getProcessInstanceId() != null) { ExecutionEntity process = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId); if (process != null) { processDefinitionId = process.getProcessDefinitionId(); } } commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent( ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_DELETED, attachment, processInstanceId, processInstanceId, processDefinitionId)); } return null; }
Example 11
Source File: LogMDC.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public static void putMDCExecution(ExecutionEntity e) { if (e.getId() != null) MDC.put(LOG_MDC_EXECUTION_ID, e.getId()); if (e.getProcessDefinitionId() != null) MDC.put(LOG_MDC_PROCESSDEFINITION_ID, e.getProcessDefinitionId()); if (e.getProcessInstanceId() != null) MDC.put(LOG_MDC_PROCESSINSTANCE_ID, e.getProcessInstanceId()); if (e.getProcessInstanceBusinessKey() != null) MDC.put(LOG_MDC_BUSINESS_KEY, e.getProcessInstanceBusinessKey()); }
Example 12
Source File: CompensationEventHandler.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
public void handleEvent(EventSubscriptionEntity eventSubscription, Object payload, CommandContext commandContext) { String configuration = eventSubscription.getConfiguration(); if (configuration == null) { throw new ActivitiException("Compensating execution not set for compensate event subscription with id " + eventSubscription.getId()); } ExecutionEntity compensatingExecution = commandContext.getExecutionEntityManager().findById(configuration); String processDefinitionId = compensatingExecution.getProcessDefinitionId(); Process process = ProcessDefinitionUtil.getProcess(processDefinitionId); if (process == null) { throw new ActivitiException("Cannot start process instance. Process model (id = " + processDefinitionId + ") could not be found"); } FlowElement flowElement = process.getFlowElement(eventSubscription.getActivityId(), true); if (flowElement instanceof SubProcess && ((SubProcess) flowElement).isForCompensation() == false) { // descend into scope: compensatingExecution.setScope(true); List<CompensateEventSubscriptionEntity> eventsForThisScope = commandContext.getEventSubscriptionEntityManager().findCompensateEventSubscriptionsByExecutionId(compensatingExecution.getId()); ScopeUtil.throwCompensationEvent(eventsForThisScope, compensatingExecution, false); } else { try { if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) { commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent( ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_COMPENSATE, flowElement.getId(), flowElement.getName(), compensatingExecution.getId(), compensatingExecution.getProcessInstanceId(), compensatingExecution.getProcessDefinitionId(), flowElement)); } compensatingExecution.setCurrentFlowElement(flowElement); Context.getAgenda().planContinueProcessInCompensation(compensatingExecution); } catch (Exception e) { throw new ActivitiException("Error while handling compensation event " + eventSubscription, e); } } }
Example 13
Source File: ExecutionController.java From activiti-in-action-codes with Apache License 2.0 | 4 votes |
/** * 用户参与过的流程 * * @return */ @RequestMapping("execution/list") public ModelAndView list(HttpServletRequest request) { ModelAndView mav = new ModelAndView("chapter13/execution-list"); /* 标准查询 List<ProcessInstance> processInstanceList = runtimeService.createProcessInstanceQuery().list(); List<Execution> list = runtimeService.createExecutionQuery().list(); mav.addObject("list", list); */ User user = UserUtil.getUserFromSession(request.getSession()); Page<Execution> page = new Page<Execution>(PageUtil.PAGE_SIZE); int[] pageParams = PageUtil.init(page, request); NativeExecutionQuery nativeExecutionQuery = runtimeService.createNativeExecutionQuery(); // native query String sql = "select distinct * from (select RES.* from ACT_RU_EXECUTION RES left join ACT_HI_TASKINST ART on ART.PROC_INST_ID_ = RES.PROC_INST_ID_ " + " left join ACT_HI_PROCINST AHP on AHP.PROC_INST_ID_ = RES.PROC_INST_ID_ " + " where SUSPENSION_STATE_ = '1' and (ART.ASSIGNEE_ = #{userId} or AHP.START_USER_ID_ = #{userId}) " + " and ACT_ID_ is not null and IS_ACTIVE_ = 'TRUE' order by ART.START_TIME_ desc)"; nativeExecutionQuery.parameter("userId", user.getId()); List<Execution> executionList = nativeExecutionQuery.sql(sql).listPage(pageParams[0], pageParams[1]); // 查询流程定义对象 Map<String, ProcessDefinition> definitionMap = new HashMap<String, ProcessDefinition>(); // 任务的英文-中文对照 Map<String, Task> taskMap = new HashMap<String, Task>(); // 每个Execution的当前活动ID,可能为多个 Map<String, List<String>> currentActivityMap = new HashMap<String, List<String>>(); // 设置每个Execution对象的当前活动节点 for (Execution execution : executionList) { ExecutionEntity executionEntity = (ExecutionEntity) execution; String processInstanceId = executionEntity.getProcessInstanceId(); String processDefinitionId = executionEntity.getProcessDefinitionId(); // 缓存ProcessDefinition对象到Map集合 definitionCache(definitionMap, processDefinitionId); // 查询当前流程的所有处于活动状态的活动ID,如果并行的活动则会有多个 List<String> activeActivityIds = runtimeService.getActiveActivityIds(execution.getId()); currentActivityMap.put(execution.getId(), activeActivityIds); for (String activityId : activeActivityIds) { // 查询处于活动状态的任务 Task task = taskService.createTaskQuery().taskDefinitionKey(activityId).executionId(execution.getId()).singleResult(); // 调用活动 if (task == null) { ProcessInstance processInstance = runtimeService.createProcessInstanceQuery() .superProcessInstanceId(processInstanceId).singleResult(); if (processInstance != null) { task = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult(); definitionCache(definitionMap, processInstance.getProcessDefinitionId()); } } taskMap.put(activityId, task); } } mav.addObject("taskMap", taskMap); mav.addObject("definitions", definitionMap); mav.addObject("currentActivityMap", currentActivityMap); page.setResult(executionList); page.setTotalCount(nativeExecutionQuery.sql("select count(*) from (" + sql + ")").count()); mav.addObject("page", page); return mav; }
Example 14
Source File: ExecutionController.java From activiti-in-action-codes with Apache License 2.0 | 4 votes |
/** * 用户参与过的流程 * * @return */ @RequestMapping("execution/list") public ModelAndView list(HttpServletRequest request) { ModelAndView mav = new ModelAndView("chapter13/execution-list"); /* 标准查询 List<ProcessInstance> processInstanceList = runtimeService.createProcessInstanceQuery().list(); List<Execution> list = runtimeService.createExecutionQuery().list(); mav.addObject("list", list); */ User user = UserUtil.getUserFromSession(request.getSession()); Page<Execution> page = new Page<Execution>(PageUtil.PAGE_SIZE); int[] pageParams = PageUtil.init(page, request); NativeExecutionQuery nativeExecutionQuery = runtimeService.createNativeExecutionQuery(); // native query String sql = "select distinct * from (select RES.* from ACT_RU_EXECUTION RES left join ACT_HI_TASKINST ART on ART.PROC_INST_ID_ = RES.PROC_INST_ID_ " + " left join ACT_HI_PROCINST AHP on AHP.PROC_INST_ID_ = RES.PROC_INST_ID_ " + " where SUSPENSION_STATE_ = '1' and (ART.ASSIGNEE_ = #{userId} or AHP.START_USER_ID_ = #{userId}) " + " and ACT_ID_ is not null and IS_ACTIVE_ = 'TRUE' order by ART.START_TIME_ desc)"; nativeExecutionQuery.parameter("userId", user.getId()); List<Execution> executionList = nativeExecutionQuery.sql(sql).listPage(pageParams[0], pageParams[1]); // 查询流程定义对象 Map<String, ProcessDefinition> definitionMap = new HashMap<String, ProcessDefinition>(); // 任务的英文-中文对照 Map<String, Task> taskMap = new HashMap<String, Task>(); // 每个Execution的当前活动ID,可能为多个 Map<String, List<String>> currentActivityMap = new HashMap<String, List<String>>(); // 设置每个Execution对象的当前活动节点 for (Execution execution : executionList) { ExecutionEntity executionEntity = (ExecutionEntity) execution; String processInstanceId = executionEntity.getProcessInstanceId(); String processDefinitionId = executionEntity.getProcessDefinitionId(); // 缓存ProcessDefinition对象到Map集合 definitionCache(definitionMap, processDefinitionId); // 查询当前流程的所有处于活动状态的活动ID,如果并行的活动则会有多个 List<String> activeActivityIds = runtimeService.getActiveActivityIds(execution.getId()); currentActivityMap.put(execution.getId(), activeActivityIds); for (String activityId : activeActivityIds) { // 查询处于活动状态的任务 Task task = taskService.createTaskQuery().taskDefinitionKey(activityId).executionId(execution.getId()).singleResult(); // 调用活动 if (task == null) { ProcessInstance processInstance = runtimeService.createProcessInstanceQuery() .superProcessInstanceId(processInstanceId).singleResult(); if (processInstance != null) { task = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult(); definitionCache(definitionMap, processInstance.getProcessDefinitionId()); } } taskMap.put(activityId, task); } } mav.addObject("taskMap", taskMap); mav.addObject("definitions", definitionMap); mav.addObject("currentActivityMap", currentActivityMap); page.setResult(executionList); page.setTotalCount(nativeExecutionQuery.sql("select count(*) from (" + sql + ")").count()); mav.addObject("page", page); return mav; }
Example 15
Source File: ProcessInstancesByProcessDefinitionMatcher.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
@Override public boolean isRetained(ExecutionEntity entity, Object parameter) { return entity.getParentId() == null && entity.getProcessDefinitionId() != null && entity.getProcessDefinitionId().equals(parameter); }
Example 16
Source File: ExecutionController.java From activiti-in-action-codes with Apache License 2.0 | 4 votes |
/** * 用户参与过的流程 * * @return */ @RequestMapping("execution/list") public ModelAndView list(HttpServletRequest request) { ModelAndView mav = new ModelAndView("chapter13/execution-list"); /* 标准查询 List<ProcessInstance> processInstanceList = runtimeService.createProcessInstanceQuery().list(); List<Execution> list = runtimeService.createExecutionQuery().list(); mav.addObject("list", list); */ User user = UserUtil.getUserFromSession(request.getSession()); Page<Execution> page = new Page<Execution>(PageUtil.PAGE_SIZE); int[] pageParams = PageUtil.init(page, request); NativeExecutionQuery nativeExecutionQuery = runtimeService.createNativeExecutionQuery(); // native query String sql = "select distinct * from (select RES.* from ACT_RU_EXECUTION RES left join ACT_HI_TASKINST ART on ART.PROC_INST_ID_ = RES.PROC_INST_ID_ " + " left join ACT_HI_PROCINST AHP on AHP.PROC_INST_ID_ = RES.PROC_INST_ID_ " + " where SUSPENSION_STATE_ = '1' and (ART.ASSIGNEE_ = #{userId} or AHP.START_USER_ID_ = #{userId}) " + " and ACT_ID_ is not null and IS_ACTIVE_ = 'TRUE' order by ART.START_TIME_ desc)"; nativeExecutionQuery.parameter("userId", user.getId()); List<Execution> executionList = nativeExecutionQuery.sql(sql).listPage(pageParams[0], pageParams[1]); // 查询流程定义对象 Map<String, ProcessDefinition> definitionMap = new HashMap<String, ProcessDefinition>(); // 任务的英文-中文对照 Map<String, Task> taskMap = new HashMap<String, Task>(); // 每个Execution的当前活动ID,可能为多个 Map<String, List<String>> currentActivityMap = new HashMap<String, List<String>>(); // 设置每个Execution对象的当前活动节点 for (Execution execution : executionList) { ExecutionEntity executionEntity = (ExecutionEntity) execution; String processInstanceId = executionEntity.getProcessInstanceId(); String processDefinitionId = executionEntity.getProcessDefinitionId(); // 缓存ProcessDefinition对象到Map集合 definitionCache(definitionMap, processDefinitionId); // 查询当前流程的所有处于活动状态的活动ID,如果并行的活动则会有多个 List<String> activeActivityIds = runtimeService.getActiveActivityIds(execution.getId()); currentActivityMap.put(execution.getId(), activeActivityIds); for (String activityId : activeActivityIds) { // 查询处于活动状态的任务 Task task = taskService.createTaskQuery().taskDefinitionKey(activityId).executionId(execution.getId()).singleResult(); // 调用活动 if (task == null) { ProcessInstance processInstance = runtimeService.createProcessInstanceQuery() .superProcessInstanceId(processInstanceId).singleResult(); if (processInstance != null) { task = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult(); definitionCache(definitionMap, processInstance.getProcessDefinitionId()); } } taskMap.put(activityId, task); } } mav.addObject("taskMap", taskMap); mav.addObject("definitions", definitionMap); mav.addObject("currentActivityMap", currentActivityMap); page.setResult(executionList); page.setTotalCount(nativeExecutionQuery.sql("select count(*) from (" + sql + ")").count()); mav.addObject("page", page); return mav; }
Example 17
Source File: CreateAttachmentCmd.java From flowable-engine with Apache License 2.0 | 4 votes |
@Override public Attachment execute(CommandContext commandContext) { verifyParameters(commandContext); AttachmentEntity attachment = new AttachmentEntity(); attachment.setName(attachmentName); attachment.setDescription(attachmentDescription); attachment.setType(attachmentType); attachment.setTaskId(taskId); attachment.setProcessInstanceId(processInstanceId); attachment.setUrl(url); attachment.setUserId(Authentication.getAuthenticatedUserId()); attachment.setTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime()); DbSqlSession dbSqlSession = commandContext.getDbSqlSession(); dbSqlSession.insert(attachment); if (content != null) { byte[] bytes = IoUtil.readInputStream(content, attachmentName); ByteArrayEntity byteArray = ByteArrayEntity.createAndInsert(bytes); attachment.setContentId(byteArray.getId()); attachment.setContent(byteArray); } commandContext.getHistoryManager() .createAttachmentComment(taskId, processInstanceId, attachmentName, true); if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) { // Forced to fetch the process-instance to associate the right process definition String processDefinitionId = null; if (attachment.getProcessInstanceId() != null) { ExecutionEntity process = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId); if (process != null) { processDefinitionId = process.getProcessDefinitionId(); } } commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent( ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_CREATED, attachment, processInstanceId, processInstanceId, processDefinitionId)); commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent( ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_INITIALIZED, attachment, processInstanceId, processInstanceId, processDefinitionId)); } return attachment; }
Example 18
Source File: ExecutionController.java From activiti-in-action-codes with Apache License 2.0 | 4 votes |
/** * 用户参与过的流程 * * @return */ @RequestMapping("execution/list") public ModelAndView list(HttpServletRequest request) { ModelAndView mav = new ModelAndView("chapter13/execution-list"); /* 标准查询 List<ProcessInstance> processInstanceList = runtimeService.createProcessInstanceQuery().list(); List<Execution> list = runtimeService.createExecutionQuery().list(); mav.addObject("list", list); */ User user = UserUtil.getUserFromSession(request.getSession()); Page<Execution> page = new Page<Execution>(PageUtil.PAGE_SIZE); int[] pageParams = PageUtil.init(page, request); NativeExecutionQuery nativeExecutionQuery = runtimeService.createNativeExecutionQuery(); // native query String sql = "select RES.* from ACT_RU_EXECUTION RES left join ACT_HI_TASKINST ART on ART.PROC_INST_ID_ = RES.PROC_INST_ID_ " + " where ART.ASSIGNEE_ = #{userId} and ACT_ID_ is not null and IS_ACTIVE_ = 'TRUE' order by START_TIME_ desc"; nativeExecutionQuery.parameter("userId", user.getId()); List<Execution> executionList = nativeExecutionQuery.sql(sql).listPage(pageParams[0], pageParams[1]); // 查询流程定义对象 Map<String, ProcessDefinition> definitionMap = new HashMap<String, ProcessDefinition>(); // 任务的英文-中文对照 Map<String, Task> taskMap = new HashMap<String, Task>(); // 每个Execution的当前活动ID,可能为多个 Map<String, List<String>> currentActivityMap = new HashMap<String, List<String>>(); // 设置每个Execution对象的当前活动节点 for (Execution execution : executionList) { ExecutionEntity executionEntity = (ExecutionEntity) execution; String processInstanceId = executionEntity.getProcessInstanceId(); String processDefinitionId = executionEntity.getProcessDefinitionId(); // 缓存ProcessDefinition对象到Map集合 definitionCache(definitionMap, processDefinitionId); // 查询当前流程的所有处于活动状态的活动ID,如果并行的活动则会有多个 List<String> activeActivityIds = runtimeService.getActiveActivityIds(execution.getId()); currentActivityMap.put(execution.getId(), activeActivityIds); for (String activityId : activeActivityIds) { // 查询处于活动状态的任务 Task task = taskService.createTaskQuery().taskDefinitionKey(activityId).executionId(execution.getId()).singleResult(); // 调用活动 if (task == null) { ProcessInstance processInstance = runtimeService.createProcessInstanceQuery() .superProcessInstanceId(processInstanceId).singleResult(); task = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult(); definitionCache(definitionMap, processInstance.getProcessDefinitionId()); } taskMap.put(activityId, task); } } mav.addObject("taskMap", taskMap); mav.addObject("definitions", definitionMap); mav.addObject("currentActivityMap", currentActivityMap); page.setResult(executionList); page.setTotalCount(nativeExecutionQuery.sql("select count(*) from (" + sql + ")").count()); mav.addObject("page", page); return mav; }
Example 19
Source File: UpdateProcessInstanceNameEventListener.java From lemon with Apache License 2.0 | 4 votes |
protected void onInitialized(ActivitiEvent event) { if (!(event instanceof ActivitiEntityEventImpl)) { return; } ActivitiEntityEventImpl activitiEntityEventImpl = (ActivitiEntityEventImpl) event; Object entity = activitiEntityEventImpl.getEntity(); if (!(entity instanceof ExecutionEntity)) { return; } ActivitiEventType activitiEventType = activitiEntityEventImpl.getType(); if (activitiEventType != ActivitiEventType.ENTITY_INITIALIZED) { return; } ExecutionEntity executionEntity = (ExecutionEntity) entity; if (!executionEntity.isProcessInstanceType()) { return; } String processInstanceId = executionEntity.getId(); String processDefinitionId = executionEntity.getProcessDefinitionId(); CommandContext commandContext = Context.getCommandContext(); ProcessDefinitionEntity processDefinition = new GetDeploymentProcessDefinitionCmd( processDefinitionId).execute(commandContext); // {流程标题:title}-{发起人:startUser}-{发起时间:startTime} String processDefinitionName = processDefinition.getName(); if (processDefinitionName == null) { processDefinitionName = processDefinition.getKey(); } String userId = Authentication.getAuthenticatedUserId(); String displayName = userConnector.findById(userId).getDisplayName(); String processInstanceName = processDefinitionName + "-" + displayName + "-" + new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()); // runtime executionEntity.setName(processInstanceName); // history HistoricProcessInstanceEntity historicProcessInstanceEntity = commandContext .getHistoricProcessInstanceEntityManager() .findHistoricProcessInstance(processInstanceId); historicProcessInstanceEntity.setName(processInstanceName); }
Example 20
Source File: DefaultHistoryManager.java From flowable-engine with Apache License 2.0 | 4 votes |
@Override public void recordProcessInstanceStart(ExecutionEntity processInstance) { if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) { HistoricProcessInstanceEntity historicProcessInstance = new HistoricProcessInstanceEntity(processInstance); // Insert historic process-instance getDbSqlSession().insert(historicProcessInstance); // Fire event ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration(); if (config != null && config.getEventDispatcher().isEnabled()) { config.getEventDispatcher().dispatchEvent( ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.HISTORIC_PROCESS_INSTANCE_CREATED, historicProcessInstance)); } // Also record the start-event manually, as there is no "start" activity history listener for this IdGenerator idGenerator = Context.getProcessEngineConfiguration().getIdGenerator(); String processDefinitionId = processInstance.getProcessDefinitionId(); String processInstanceId = processInstance.getProcessInstanceId(); String executionId = processInstance.getId(); HistoricActivityInstanceEntity historicActivityInstance = new HistoricActivityInstanceEntity(); historicActivityInstance.setId(idGenerator.getNextId()); historicActivityInstance.setProcessDefinitionId(processDefinitionId); historicActivityInstance.setProcessInstanceId(processInstanceId); historicActivityInstance.setExecutionId(executionId); historicActivityInstance.setActivityId(processInstance.getActivityId()); historicActivityInstance.setActivityName((String) processInstance.getActivity().getProperty("name")); historicActivityInstance.setActivityType((String) processInstance.getActivity().getProperty("type")); Date now = Context.getProcessEngineConfiguration().getClock().getCurrentTime(); historicActivityInstance.setStartTime(now); // Inherit tenant id (if applicable) if (processInstance.getTenantId() != null) { historicActivityInstance.setTenantId(processInstance.getTenantId()); } getDbSqlSession().insert(historicActivityInstance); // Fire event if (config != null && config.getEventDispatcher().isEnabled()) { config.getEventDispatcher().dispatchEvent( ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.HISTORIC_ACTIVITY_INSTANCE_CREATED, historicActivityInstance)); } } }