protected FlowNode getFlowNodeFromScope(String elementId, BaseElement scope) { FlowNode flowNode = null; if (StringUtils.isNotEmpty(elementId)) { if (scope instanceof Process) { flowNode = (FlowNode) ((Process) scope).getFlowElement(elementId); } else if (scope instanceof SubProcess) { flowNode = (FlowNode) ((SubProcess) scope).getFlowElement(elementId); } } return flowNode; }
FlowElement source = process.getFlowElement(sourceRef, true); FlowElement target = process.getFlowElement(targetRef, true);
protected void handleCompensationEventDefinition(BpmnModel bpmnModel, Process process, Event event, EventDefinition eventDefinition, List<ValidationError> errors) { CompensateEventDefinition compensateEventDefinition = (CompensateEventDefinition) eventDefinition; // Check activityRef if ((StringUtils.isNotEmpty(compensateEventDefinition.getActivityRef()) && process.getFlowElement(compensateEventDefinition.getActivityRef(), true) == null)) { addError(errors, Problems.COMPENSATE_EVENT_INVALID_ACTIVITY_REF, process, event, "Invalid attribute value for 'activityRef': no activity with the given id"); } }
protected void executeParse(BpmnParse bpmnParse, SequenceFlow sequenceFlow) { org.activiti.bpmn.model.Process process = bpmnParse.getCurrentProcess(); sequenceFlow.setSourceFlowElement(process.getFlowElement(sequenceFlow.getSourceRef(), true)); sequenceFlow.setTargetFlowElement(process.getFlowElement(sequenceFlow.getTargetRef(), true)); }
public FlowElement getCurrentFlowElement() { if (currentFlowElement == null) { String processDefinitionId = getProcessDefinitionId(); if (processDefinitionId != null) { org.activiti.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(processDefinitionId); currentFlowElement = process.getFlowElement(getCurrentActivityId(), true); } } return currentFlowElement; }
@Override protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) { List<EventGateway> eventGateways = process.findFlowElementsOfType(EventGateway.class); for (EventGateway eventGateway : eventGateways) { for (SequenceFlow sequenceFlow : eventGateway.getOutgoingFlows()) { FlowElement flowElement = process.getFlowElement(sequenceFlow.getTargetRef(), true); if (flowElement != null && !(flowElement instanceof IntermediateCatchEvent)) { addError(errors, Problems.EVENT_GATEWAY_ONLY_CONNECTED_TO_INTERMEDIATE_EVENTS, process, eventGateway, "Event based gateway can only be connected to elements of type intermediateCatchEvent"); } } } }
/** * Verifies if the element with the given source identifier can reach the element with the target identifier through following sequence flow. */ public static boolean isReachable(String processDefinitionId, String sourceElementId, String targetElementId) { // Fetch source and target elements Process process = ProcessDefinitionUtil.getProcess(processDefinitionId); FlowElement sourceFlowElement = process.getFlowElement(sourceElementId, true); FlowNode sourceElement = null; if (sourceFlowElement instanceof FlowNode) { sourceElement = (FlowNode) sourceFlowElement; } else if (sourceFlowElement instanceof SequenceFlow) { sourceElement = (FlowNode) ((SequenceFlow) sourceFlowElement).getTargetFlowElement(); } FlowElement targetFlowElement = process.getFlowElement(targetElementId, true); FlowNode targetElement = null; if (targetFlowElement instanceof FlowNode) { targetElement = (FlowNode) targetFlowElement; } else if (targetFlowElement instanceof SequenceFlow) { targetElement = (FlowNode) ((SequenceFlow) targetFlowElement).getTargetFlowElement(); } if (sourceElement == null) { throw new ActivitiException("Invalid sourceElementId '" + sourceElementId + "': no element found for this id n process definition '" + processDefinitionId + "'"); } if (targetElement == null) { throw new ActivitiException("Invalid targetElementId '" + targetElementId + "': no element found for this id n process definition '" + processDefinitionId + "'"); } Set<String> visitedElements = new HashSet<String>(); return isReachable(process, sourceElement, targetElement, visitedElements); }
public void executeTaskListeners(TaskEntity taskEntity, String eventType) { if (taskEntity.getProcessDefinitionId() != null) { org.activiti.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(taskEntity.getProcessDefinitionId()); FlowElement flowElement = process.getFlowElement(taskEntity.getTaskDefinitionKey(), true); if (flowElement instanceof UserTask) { UserTask userTask = (UserTask) flowElement; executeTaskListeners(userTask, taskEntity, eventType); } } }
protected int getMaxIterations(org.activiti.bpmn.model.Process process, String activityId) { FlowElement flowElement = process.getFlowElement(activityId, true); if (flowElement != null) { if (flowElement instanceof Event) { Event event = (Event) flowElement; List<EventDefinition> eventDefinitions = event.getEventDefinitions(); if (eventDefinitions != null) { for (EventDefinition eventDefinition : eventDefinitions) { if (eventDefinition instanceof TimerEventDefinition) { TimerEventDefinition timerEventDefinition = (TimerEventDefinition) eventDefinition; if (timerEventDefinition.getTimeCycle() != null) { return calculateMaxIterationsValue(timerEventDefinition.getTimeCycle()); } } } } } } return -1; }
for (SequenceFlow sequenceFlow : sequenceFlows) { String targetRef = sequenceFlow.getTargetRef(); FlowNode sequenceFlowTarget = (FlowNode) process.getFlowElement(targetRef, true); if (sequenceFlowTarget != null && !visitedElements.contains(sequenceFlowTarget.getId())) { boolean reachable = isReachable(process, sequenceFlowTarget, targetElement, visitedElements);
/** * 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; }
/** * To be used in an {@link ActivityBehavior} or {@link JavaDelegate}: leaves * the current activity via one specific sequenceflow. */ public static void leaveDelegate(DelegateExecution delegateExecution, String sequenceFlowId) { String processDefinitionId = delegateExecution.getProcessDefinitionId(); Process process = ProcessDefinitionUtil.getProcess(processDefinitionId); FlowElement flowElement = process.getFlowElement(sequenceFlowId); if (flowElement instanceof SequenceFlow) { delegateExecution.setCurrentFlowElement(flowElement); Context.getAgenda().planTakeOutgoingSequenceFlowsOperation((ExecutionEntity) delegateExecution, false); } else { throw new ActivitiException(sequenceFlowId + " does not match a sequence flow"); } }
&& !inactiveExecution.isDeleted()) { FlowNode flowNode = (FlowNode) process.getFlowElement(inactiveExecution.getActivityId(), true); InactiveActivityBehavior inactiveActivityBehavior = ((InactiveActivityBehavior) flowNode.getBehavior()); logger.debug("Found InactiveActivityBehavior instance of class {} that can be executed on activity '{}'", inactiveActivityBehavior.getClass(), flowNode.getId());
String activityId = TimerEventHandler.getActivityIdFromConfiguration(configuration); if (activityId != null) { FlowElement flowElement = process.getFlowElement(activityId, true); if (flowElement == null) { throw new ActivitiException("Could not find matching FlowElement for activityId " + activityId);
FlowElement flowElement = process.getFlowElement(eventSubscription.getActivityId(), true); if (flowElement == null) { throw new ActivitiException("Could not find matching FlowElement for activityId " + eventSubscription.getActivityId());
protected void validateAndSwitchVersionOfExecution(CommandContext commandContext, ExecutionEntity execution, ProcessDefinition newProcessDefinition) { // check that the new process definition version contains the current activity org.activiti.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(newProcessDefinition.getId()); if (execution.getActivityId() != null && process.getFlowElement(execution.getActivityId(), true) == null) { throw new ActivitiException("The new process definition " + "(key = '" + newProcessDefinition.getKey() + "') " + "does not contain the current activity " + "(id = '" + execution.getActivityId() + "') " + "of the process instance " + "(id = '" + processInstanceId + "')."); } // switch the process instance to the new process definition version execution.setProcessDefinitionId(newProcessDefinition.getId()); execution.setProcessDefinitionName(newProcessDefinition.getName()); execution.setProcessDefinitionKey(newProcessDefinition.getKey()); // and change possible existing tasks (as the process definition id is stored there too) List<TaskEntity> tasks = commandContext.getTaskEntityManager().findTasksByExecutionId(execution.getId()); for (TaskEntity taskEntity : tasks) { taskEntity.setProcessDefinitionId(newProcessDefinition.getId()); commandContext.getHistoryManager().recordTaskProcessDefinitionChange(taskEntity.getId(), newProcessDefinition.getId()); } }
List<Association> associations = process.findAssociationsWithSourceRefRecursive(boundaryEvent.getId()); for (Association association : associations) { FlowElement targetElement = process.getFlowElement(association.getTargetRef(), true); if (targetElement instanceof Activity) { Activity activity = (Activity) targetElement;
FlowElement flowElement = process.getFlowElement(eventSubscription.getActivityId(), true);
public FlowElement getCurrentFlowElement() { if (currentFlowElement == null) { String processDefinitionId = getProcessDefinitionId(); if (processDefinitionId != null) { org.activiti.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(processDefinitionId); currentFlowElement = process.getFlowElement(getCurrentActivityId(), true); } } return currentFlowElement; }
public void executeTaskListeners(TaskEntity taskEntity, String eventType) { if (taskEntity.getProcessDefinitionId() != null) { org.activiti.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(taskEntity.getProcessDefinitionId()); FlowElement flowElement = process.getFlowElement(taskEntity.getTaskDefinitionKey(), true); if (flowElement instanceof UserTask) { UserTask userTask = (UserTask) flowElement; executeTaskListeners(userTask, taskEntity, eventType); } } }