/** * 还原指定活动节点流向 * * @param activityImpl 活动节点 * @param oriPvmTransitionList 原有节点流向集合 */ private void restoreTransition( ActivityImpl activityImpl, List<PvmTransition> oriPvmTransitionList) { // 清空现有流向 List<PvmTransition> pvmTransitionList = activityImpl.getOutgoingTransitions(); pvmTransitionList.clear(); // 还原以前流向 for (PvmTransition pvmTransition : oriPvmTransitionList) { pvmTransitionList.add(pvmTransition); } }
/** * 清空指定活动节点流向 * * @param activityImpl 活动节点 * @return 节点流向集合 */ private List<PvmTransition> clearTransition(ActivityImpl activityImpl) { // 存储当前节点所有流向临时变量 List<PvmTransition> oriPvmTransitionList = new ArrayList<PvmTransition>(); // 获取当前节点所有流向,存储到临时变量,然后清空 List<PvmTransition> pvmTransitionList = activityImpl.getOutgoingTransitions(); for (PvmTransition pvmTransition : pvmTransitionList) { oriPvmTransitionList.add(pvmTransition); } pvmTransitionList.clear(); return oriPvmTransitionList; }
/** * 判断是否为第一个初始节点 * * @return */ public boolean isFirstTask() { ActivityImpl rootActivity = execution.getProcessDefinition().getInitial(); List<PvmTransition> transitions = rootActivity.getOutgoingTransitions(); for (PvmTransition transition : transitions) { TransitionImpl transitionImpl = (TransitionImpl) transition; ActivityImpl destinationActivity = transitionImpl.getDestination(); String firstTaskActivityname = destinationActivity.getId(); String currentActivityName = execution.getActivity().getId(); return currentActivityName.equals(firstTaskActivityname); } return false; }
/** * 根据当前节点,查询输出流向是否为并行终点,如果为并行终点,则拼装对应的并行起点ID * * @param activityImpl 当前节点 * @return */ private String findParallelGatewayId(ActivityImpl activityImpl) { List<PvmTransition> incomingTransitions = activityImpl.getOutgoingTransitions(); for (PvmTransition pvmTransition : incomingTransitions) { TransitionImpl transitionImpl = (TransitionImpl) pvmTransition; activityImpl = transitionImpl.getDestination(); String type = (String) activityImpl.getProperty("type"); if ("parallelGateway".equals(type)) { // 并行路线 String gatewayId = activityImpl.getId(); String gatewayType = gatewayId.substring(gatewayId.lastIndexOf("_") + 0); if ("END".equals(gatewayType.toUpperCase())) { return gatewayId.substring(0, gatewayId.lastIndexOf("_")) + "_start"; } } } return null; }
/** * 根据任务ID和节点ID获取活动节点 <br> * * @param taskId 任务ID * @param activityId 活动节点ID <br> * 如果为null或"",则默认查询当前活动节点 <br> * 如果为"end",则查询结束节点 <br> * @return * @throws Exception */ private ActivityImpl findActivitiImpl(String taskId, String activityId) throws Exception { // 取得流程定义 ProcessDefinitionEntity procDef = this.findProcDefEntityByTaskId(taskId); // 获取当前活动节点ID if (StringUtil.isStrEmpty(activityId)) { activityId = this.findTaskById(taskId).getTaskDefinitionKey(); } // 根据流程定义,获取该流程实例的结束节点 if (activityId.toUpperCase().equals("END")) { for (ActivityImpl activityImpl : procDef.getActivities()) { List<PvmTransition> pvmTransitionList = activityImpl.getOutgoingTransitions(); if (pvmTransitionList.isEmpty()) { return activityImpl; } } } // 根据节点ID,获取对应的活动节点 ActivityImpl activityImpl = ((ProcessDefinitionImpl) procDef).findActivity(activityId); return activityImpl; }
public void validateExclusiveGateway(ActivityImpl activity, ExclusiveGateway exclusiveGateway) { if (activity.getOutgoingTransitions().size() == 0) { // TODO: double check if this is valid (I think in Activiti yes, since we need start events we // will need an end event as well) bpmnModel.addProblem( "Exclusive Gateway '" + activity.getId() + "' has no outgoing sequence flows.", exclusiveGateway); } else if (activity.getOutgoingTransitions().size() == 1) { PvmTransition flow = activity.getOutgoingTransitions().get(0); Condition condition = (Condition) flow.getProperty(BpmnParse.PROPERTYNAME_CONDITION); if (condition != null) { bpmnModel.addProblem( "Exclusive Gateway '" + activity.getId() + "' has only one outgoing sequence flow ('" + flow.getId() + "'). This is not allowed to have a condition.", exclusiveGateway); } } else { String defaultSequenceFlow = (String) activity.getProperty("default"); boolean hasDefaultFlow = StringUtils.isNotEmpty(defaultSequenceFlow); ArrayList<PvmTransition> flowsWithoutCondition = new ArrayList<PvmTransition>(); for (PvmTransition flow : activity.getOutgoingTransitions()) { Condition condition = (Condition) flow.getProperty(BpmnParse.PROPERTYNAME_CONDITION); boolean isDefaultFlow = flow.getId() != null && flow.getId().equals(defaultSequenceFlow); boolean hasConditon = condition != null; if (!hasConditon && !isDefaultFlow) { flowsWithoutCondition.add(flow); } if (hasConditon && isDefaultFlow) { bpmnModel.addProblem( "Exclusive Gateway '" + activity.getId() + "' has outgoing sequence flow '" + flow.getId() + "' which is the default flow but has a condition too.", exclusiveGateway); } } if (hasDefaultFlow || flowsWithoutCondition.size() > 1) { // if we either have a default flow (then no flows without conditions are valid at all) or // if we have more than one flow without condition this is an error for (PvmTransition flow : flowsWithoutCondition) { bpmnModel.addProblem( "Exclusive Gateway '" + activity.getId() + "' has outgoing sequence flow '" + flow.getId() + "' without condition which is not the default flow.", exclusiveGateway); } } else if (flowsWithoutCondition.size() == 1) { // Havinf no default and exactly one flow without condition this is considered the default // one now (to not break backward compatibility) PvmTransition flow = flowsWithoutCondition.get(0); bpmnModel.addWarning( "Exclusive Gateway '" + activity.getId() + "' has outgoing sequence flow '" + flow.getId() + "' without condition which is not the default flow. We assume it to be the default flow, but it is bad modeling practice, better set the default flow in your gateway.", exclusiveGateway); } } }
/** * 打开任务 传入的request必须有以下参数 taskId:task的Id taskPage:处理task的页面路径 model:业务表类名 formId:业务表id * formProperties:控制表单的名称 * * @return * @throws Exception */ public String open_task() throws Exception { log.debug("open_task()"); List<String> nextTaskList = new ArrayList<String>(); String taskId = getpara("taskId"); String taskPage = getpara("taskPage"); String modelStr = getpara("model"); // add by hb for only query user task String readonly = getpara("readonly"); // end String formId = (String) infActiviti.getVariableByTaskId(taskId, "formId"); if (formId == null || formId.equals("") || modelStr == null || "".equals(modelStr)) { rhs.put("model", null); } else { BaseModel model = (BaseModel) baseDao.loadById(modelStr, Long.parseLong(formId)); rhs.put("model", model); } /* add by chenzhijian 20130419 -s */ // 获取 formProperties 配置文件 String formProperties = getpara("formProperties"); HashMap<String, String> formPro = new HashMap<String, String>(); Properties p = new Properties(); try { // String filepath = System.getProperty("webroot", "./src/main/webapp/"); String filepath = getWebroot(); // eg: app/manager/wo/wo.properties filepath += "/app/manager/" + modelStr.toLowerCase() + "/" + modelStr.toLowerCase() + ".properties"; FileInputStream in = new FileInputStream(filepath); p.load(in); in.close(); Set<String> set = p.stringPropertyNames(); for (String s : set) { if (s.startsWith("default")) { formPro.put(s.replace("default.", ""), p.getProperty(s)); } } for (String s : set) { if (s.startsWith(formProperties)) { formPro.put(s.replace(formProperties + ".", ""), p.getProperty(s)); } } } catch (Exception e) { e.printStackTrace(); } rhs.put("formPro", formPro); /* add by chenzhijian 20130419 -e */ Task task = infActiviti.getTaskById(taskId); /*add by hb for get next task 20140128 start*/ String nextTask = ""; String initiator = (String) infActiviti.getVariableByTaskId(task.getId(), "initiator"); // 当前任务获取当前流程的流程定义,然后根据流程定义获得所有的节点 ProcessDefinitionEntity def = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService) .getDeployedProcessDefinition(task.getProcessDefinitionId()); List<ActivityImpl> activitiList = def.getActivities(); // 根据任务获取当前流程执行ID,执行实例以及当前流程节点的ID String excId = task.getExecutionId(); ExecutionEntity execution = (ExecutionEntity) runtimeService.createExecutionQuery().executionId(excId).singleResult(); String activitiId = execution.getActivityId(); // 循环activitiList 并判断出当前流程所处节点,然后得到当前节点实例, // 根据节点实例获取所有从当前节点出发的路径,然后根据路径获得下一个节点实例 for (ActivityImpl activityImpl : activitiList) { String id = activityImpl.getId(); if (activitiId.equals(id)) { log.debug("当前任务:" + activityImpl.getProperty("name")); List<PvmTransition> outTransitions = activityImpl.getOutgoingTransitions(); // 获取从某个节点出来的所有线路 for (PvmTransition tr : outTransitions) { PvmActivity ac = tr.getDestination(); // 获取线路的终点节点,在这里应该还要加个判断,如果是并行或者相容关口,则需要继续往下找下一个任务。 if (ac.getProperty("type").equals("parallelGateway") || ac.getProperty("type") .equals( "inclusiveGateway")) { // 不能包括互斥关口 // ac.getProperty("type").equals("exclusiveGateway") List<PvmTransition> outTransitions2 = ac.getOutgoingTransitions(); // 因为是关口,所以继续往下找任务 for (PvmTransition pvmTransition : outTransitions2) { PvmActivity ac2 = pvmTransition.getDestination(); nextTask = (String) ac2.getId(); log.debug("下一个任务----->:" + nextTask); nextTaskList.add(nextTask); } } else { nextTask = (String) ac.getId(); log.debug("下一个任务++++>:" + nextTask); nextTaskList.add(nextTask); } } break; } } /*end*/ rhs.put("task", task); rhs.put("initiator", initiator); rhs.put("nextTaskList", nextTaskList); rhs.put("taskPage", taskPage); rhs.put("readonly", readonly); getAllUserAndGroupInfo(); return "success"; }
@SuppressWarnings("unchecked") @Override protected void eventNotificationsCompleted(InterpretableExecution execution) { ActivityImpl activity = (ActivityImpl) execution.getActivity(); ActivityImpl parentActivity = activity.getParentActivity(); // if the execution is a single path of execution inside the process definition scope if ((parentActivity != null) && (!parentActivity.isScope())) { execution.setActivity(parentActivity); execution.performOperation(ACTIVITY_END); } else if (execution.isProcessInstance()) { execution.performOperation(PROCESS_END); } else if (execution.isScope()) { ActivityBehavior parentActivityBehavior = (parentActivity != null ? parentActivity.getActivityBehavior() : null); if (parentActivityBehavior instanceof CompositeActivityBehavior) { CompositeActivityBehavior compositeActivityBehavior = (CompositeActivityBehavior) parentActivity.getActivityBehavior(); if (activity.isScope() && activity.getOutgoingTransitions().isEmpty()) { // there is no transition destroying the scope InterpretableExecution parentScopeExecution = (InterpretableExecution) execution.getParent(); execution.destroy(); execution.remove(); parentScopeExecution.setActivity(parentActivity); compositeActivityBehavior.lastExecutionEnded(parentScopeExecution); } else { execution.setActivity(parentActivity); compositeActivityBehavior.lastExecutionEnded(execution); } } else { // default destroy scope behavior InterpretableExecution parentScopeExecution = (InterpretableExecution) execution.getParent(); execution.destroy(); execution.remove(); // if we are a scope under the process instance // and have no outgoing transitions: end the process instance here if (activity.getParent() == activity.getProcessDefinition() && activity.getOutgoingTransitions().isEmpty()) { parentScopeExecution.setActivity(activity); // we call end() because it sets isEnded on the execution parentScopeExecution.end(); } else { parentScopeExecution.setActivity(parentActivity); parentScopeExecution.performOperation(ACTIVITY_END); } } } else { // execution.isConcurrent() && !execution.isScope() execution.remove(); // prune if necessary InterpretableExecution concurrentRoot = (InterpretableExecution) execution.getParent(); if (concurrentRoot.getExecutions().size() == 1) { InterpretableExecution lastConcurrent = (InterpretableExecution) concurrentRoot.getExecutions().get(0); if (!lastConcurrent.isScope()) { concurrentRoot.setActivity((ActivityImpl) lastConcurrent.getActivity()); lastConcurrent.setReplacedBy(concurrentRoot); // Move children of lastConcurrent one level up if (lastConcurrent.getExecutions().size() > 0) { concurrentRoot.getExecutions().clear(); for (ActivityExecution childExecution : lastConcurrent.getExecutions()) { InterpretableExecution childInterpretableExecution = (InterpretableExecution) childExecution; ((List) concurrentRoot.getExecutions()) .add(childExecution); // casting ... damn generics childInterpretableExecution.setParent(concurrentRoot); } lastConcurrent.getExecutions().clear(); } // Copy execution-local variables of lastConcurrent concurrentRoot.setVariablesLocal(lastConcurrent.getVariablesLocal()); lastConcurrent.remove(); } else { lastConcurrent.setConcurrent(false); } } } }
public FirstTaskForm execute(CommandContext commandContext) { ProcessDefinitionEntity processDefinitionEntity = Context.getProcessEngineConfiguration() .getDeploymentManager() .findDeployedProcessDefinitionById(processDefinitionId); if (processDefinitionEntity == null) { throw new IllegalArgumentException("cannot find processDefinition : " + processDefinitionId); } if (processDefinitionEntity.hasStartFormKey()) { return this.findStartEventForm(processDefinitionEntity); } ActivityImpl startActivity = processDefinitionEntity.getInitial(); if (startActivity.getOutgoingTransitions().size() != 1) { throw new IllegalStateException( "start activity outgoing transitions cannot more than 1, now is : " + startActivity.getOutgoingTransitions().size()); } PvmTransition pvmTransition = startActivity.getOutgoingTransitions().get(0); PvmActivity targetActivity = pvmTransition.getDestination(); if (!"userTask".equals(targetActivity.getProperty("type"))) { logger.info("first activity is not userTask, just skip"); return new FirstTaskForm(); } FirstTaskForm firstTaskForm = new FirstTaskForm(); firstTaskForm.setProcessDefinitionId(processDefinitionId); firstTaskForm.setExists(true); firstTaskForm.setTaskForm(true); String taskDefinitionKey = targetActivity.getId(); logger.debug("activityId : {}", targetActivity.getId()); firstTaskForm.setActivityId(taskDefinitionKey); TaskDefinition taskDefinition = processDefinitionEntity.getTaskDefinitions().get(taskDefinitionKey); Expression expression = taskDefinition.getAssigneeExpression(); if (expression != null) { String expressionText = expression.getExpressionText(); logger.debug("{}", expressionText); logger.debug("{}", startActivity.getProperties()); logger.debug("{}", processDefinitionEntity.getProperties()); firstTaskForm.setAssignee(expressionText); } else { logger.info("cannot find expression : {}, {}", processDefinitionId, taskDefinitionKey); } String initiatorVariableName = (String) processDefinitionEntity.getProperty(BpmnParse.PROPERTYNAME_INITIATOR_VARIABLE_NAME); firstTaskForm.setInitiatorName(initiatorVariableName); DefaultFormHandler formHandler = (DefaultFormHandler) taskDefinition.getTaskFormHandler(); if (formHandler.getFormKey() != null) { String formKey = formHandler.getFormKey().getExpressionText(); firstTaskForm.setFormKey(formKey); } else { logger.info("cannot formKey : {}, {}", processDefinitionId, taskDefinitionKey); } return firstTaskForm; }