org.activiti.engine.impl.pvm.process.TransitionImpl Java Examples

The following examples show how to use org.activiti.engine.impl.pvm.process.TransitionImpl. 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: ProcessExtensionServiceImpl.java    From activiti-demo with Apache License 2.0 6 votes vote down vote up
/**
 * 根据当前节点,查询输出流向是否为并行终点,如果为并行终点,则拼装对应的并行起点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 gettewayType = gatewayId.substring(gatewayId.lastIndexOf("_")+1);
            if("END".equals(gettewayType.toUpperCase())){
                return gatewayId.substring(0, gatewayId.lastIndexOf("_"))+"_start";
            }
        }
    }

    return null;
}
 
Example #2
Source File: ProcessExtensionServiceImpl.java    From activiti-demo with Apache License 2.0 6 votes vote down vote up
/**
 * 流程转向操作
 * @param taskId 当前任务ID
 * @param activityId 目标节点任务ID
 * @param variables  流程变量
 * @throws Exception
 */
private void turnTransition(String taskId,String activityId,Map<String,Object> variables)throws Exception{
    //当前节点
    ActivityImpl currActivity = findActivitiImpl(taskId,null);
    //清空当前流向
    List<PvmTransition> oriPvmTransitionList =  clearTransition(currActivity);

    //创建新流向
    TransitionImpl newTransition = currActivity.createOutgoingTransition();

    //目标节点
    ActivityImpl pointActivity = findActivitiImpl(taskId,activityId);

    //设置新流向的目标节点
    newTransition.setDestination(pointActivity);

    //执行转向任务
    taskService.complete(taskId,variables);

    //删除目标节点新流入
    pointActivity.getIncomingTransitions().remove(newTransition);

}
 
Example #3
Source File: ProcessCustomService.java    From maven-framework-project with MIT License 6 votes vote down vote up
/** 
 * 流程转向操作 
 *  
 * @param taskId 
 *            当前任务ID 
 * @param activityId 
 *            目标节点任务ID 
 * @param variables 
 *            流程变量 
 * @throws Exception 
 */  
private static void turnTransition(String taskId, String activityId,  
        Map<String, Object> variables) throws Exception {  
    // 当前节点  
    ActivityImpl currActivity = findActivitiImpl(taskId, null);  
    // 清空当前流向  
    List<PvmTransition> oriPvmTransitionList = clearTransition(currActivity);  
  
    // 创建新流向  
    TransitionImpl newTransition = currActivity.createOutgoingTransition();  
    // 目标节点  
    ActivityImpl pointActivity = findActivitiImpl(taskId, activityId);  
    // 设置新流向的目标节点  
    newTransition.setDestination(pointActivity);  
  
    // 执行转向任务  
    taskService.complete(taskId, variables);  
    // 删除目标节点新流入  
    pointActivity.getIncomingTransitions().remove(newTransition);  
  
    // 还原以前流向  
    restoreTransition(currActivity, oriPvmTransitionList);  
}
 
Example #4
Source File: ProcessCustomService.java    From maven-framework-project with MIT License 6 votes vote down vote up
/** 
 * 根据当前节点,查询输出流向是否为并行终点,如果为并行终点,则拼装对应的并行起点ID 
 *  
 * @param activityImpl 
 *            当前节点 
 * @return 
 */  
private static 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("_") + 1);  
            if ("END".equals(gatewayType.toUpperCase())) {  
                return gatewayId.substring(0, gatewayId.lastIndexOf("_"))  
                        + "_start";  
            }  
        }  
    }  
    return null;  
}
 
Example #5
Source File: ActivitiWorkFlowServiceImpl.java    From maven-framework-project with MIT License 6 votes vote down vote up
public void turnTransition(String taskId, String activityId,  
        Map<String, Object> variables) throws Exception {  
    // 当前节点  
    ActivityImpl currActivity = findActivitiImpl(taskId, null);  
    // 清空当前流向  
    List<PvmTransition> oriPvmTransitionList = clearTransition(currActivity);  
  
    // 创建新流向  
    TransitionImpl newTransition = currActivity.createOutgoingTransition();  
    // 目标节点  
    ActivityImpl pointActivity = findActivitiImpl(taskId, activityId);  
    // 设置新流向的目标节点  
    newTransition.setDestination(pointActivity);  
  
    // 执行转向任务  
    taskService.complete(taskId, variables);  
    // 删除目标节点新流入  
    pointActivity.getIncomingTransitions().remove(newTransition);  
  
    // 还原以前流向  
    restoreTransition(currActivity, oriPvmTransitionList);  
}
 
Example #6
Source File: ActivitiWorkFlowServiceImpl.java    From maven-framework-project with MIT License 6 votes vote down vote up
public 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("_") + 1);  
            if ("END".equals(gatewayType.toUpperCase())) {  
                return gatewayId.substring(0, gatewayId.lastIndexOf("_"))  
                        + "_start";  
            }  
        }  
    }  
    return null;  
}
 
Example #7
Source File: ExecutionEntity.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * @param fireActivityCompletionEvent This method can be called from other places (like {@link #takeAll(List, List)}), where the event is already fired. In that case, false is passed an no second event is fired.
 */
@Override
public void take(PvmTransition transition, boolean fireActivityCompletionEvent) {

    if (fireActivityCompletionEvent) {
        fireActivityCompletedEvent();
    }

    if (this.transition != null) {
        throw new PvmException("already taking a transition");
    }
    if (transition == null) {
        throw new PvmException("transition is null");
    }
    setActivity((ActivityImpl) transition.getSource());
    setTransition((TransitionImpl) transition);
    performOperation(AtomicOperation.TRANSITION_NOTIFY_LISTENER_END);
}
 
Example #8
Source File: BpmnParse.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void createBPMNEdge(String key, List<GraphicInfo> graphicList) {
    FlowElement flowElement = bpmnModel.getFlowElement(key);
    if (flowElement != null && sequenceFlows.containsKey(key)) {
        TransitionImpl sequenceFlow = sequenceFlows.get(key);
        List<Integer> waypoints = new ArrayList<>();
        for (GraphicInfo waypointInfo : graphicList) {
            waypoints.add((int) waypointInfo.getX());
            waypoints.add((int) waypointInfo.getY());
        }
        sequenceFlow.setWaypoints(waypoints);
    } else if (bpmnModel.getArtifact(key) != null) {
        // it's an association, so nothing to do
    } else {
        LOGGER.warn("Invalid reference in 'bpmnElement' attribute, sequenceFlow {} not found", key);
    }
}
 
Example #9
Source File: ProcessDefinitionBuilder.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public PvmProcessDefinition buildProcessDefinition() {
    for (Object[] unresolvedTransition : unresolvedTransitions) {
        TransitionImpl transition = (TransitionImpl) unresolvedTransition[0];
        String destinationActivityName = (String) unresolvedTransition[1];
        ActivityImpl destination = processDefinition.findActivity(destinationActivityName);
        if (destination == null) {
            throw new ActivitiException("destination '" + destinationActivityName + "' not found.  (referenced from transition in '" + transition.getSource().getId() + "')");
        }
        transition.setDestination(destination);
    }
    return processDefinition;
}
 
Example #10
Source File: ExecutionImpl.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void take(PvmTransition transition) {
    if (this.transition != null) {
        throw new PvmException("already taking a transition");
    }
    if (transition == null) {
        throw new PvmException("transition is null");
    }
    setTransition((TransitionImpl) transition);
    performOperation(AtomicOperation.TRANSITION_NOTIFY_LISTENER_END);
}
 
Example #11
Source File: ExecutionEntity.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void setTransition(TransitionImpl transition) {
    this.transition = transition;
    if (replacedBy != null) {
        replacedBy.setTransition(transition);
    }
}
 
Example #12
Source File: SequenceFlowParseHandler.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeParse(BpmnParse bpmnParse, SequenceFlow sequenceFlow) {

    ScopeImpl scope = bpmnParse.getCurrentScope();

    ActivityImpl sourceActivity = scope.findActivity(sequenceFlow.getSourceRef());
    ActivityImpl destinationActivity = scope.findActivity(sequenceFlow.getTargetRef());

    Expression skipExpression;
    if (StringUtils.isNotEmpty(sequenceFlow.getSkipExpression())) {
        ExpressionManager expressionManager = bpmnParse.getExpressionManager();
        skipExpression = expressionManager.createExpression(sequenceFlow.getSkipExpression());
    } else {
        skipExpression = null;
    }

    TransitionImpl transition = sourceActivity.createOutgoingTransition(sequenceFlow.getId(), skipExpression);
    bpmnParse.getSequenceFlows().put(sequenceFlow.getId(), transition);
    transition.setProperty("name", sequenceFlow.getName());
    transition.setProperty("documentation", sequenceFlow.getDocumentation());
    transition.setDestination(destinationActivity);

    if (StringUtils.isNotEmpty(sequenceFlow.getConditionExpression())) {
        Condition expressionCondition = new UelExpressionCondition(sequenceFlow.getConditionExpression());
        transition.setProperty(PROPERTYNAME_CONDITION_TEXT, sequenceFlow.getConditionExpression());
        transition.setProperty(PROPERTYNAME_CONDITION, expressionCondition);
    }

    createExecutionListenersOnTransition(bpmnParse, sequenceFlow.getExecutionListeners(), transition);

}
 
Example #13
Source File: ExecutionEntity.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public TransitionImpl getTransitionBeingTaken() {
    return transitionBeingTaken;
}
 
Example #14
Source File: BpmnParse.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public Map<String, TransitionImpl> getSequenceFlows() {
    return sequenceFlows;
}
 
Example #15
Source File: AbstractBpmnParseHandler.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
protected void createExecutionListenersOnTransition(BpmnParse bpmnParse, List<FlowableListener> activitiListenerList, TransitionImpl transition) {
    for (FlowableListener activitiListener : activitiListenerList) {
        transition.addExecutionListener(createExecutionListener(bpmnParse, activitiListener));
    }
}
 
Example #16
Source File: ExecutionEntity.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void setTransitionBeingTaken(TransitionImpl transitionBeingTaken) {
    this.transitionBeingTaken = transitionBeingTaken;
    if (replacedBy != null) {
        replacedBy.setTransitionBeingTaken(transitionBeingTaken);
    }
}
 
Example #17
Source File: BpmnParseTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Deployment
public void testParseDiagramInterchangeElements() {

    ProcessDefinition processDefinition = processEngineConfiguration.getFlowable5CompatibilityHandler().getProcessDefinitionByKey("myProcess");
    ProcessDefinitionEntity rawEntity = (ProcessDefinitionEntity) processDefinition;

    assertNotNull(rawEntity);
    assertEquals(7, rawEntity.getActivities().size());

    // Check if diagram has been created based on Diagram Interchange when it's not a headless instance
    List<String> resourceNames = repositoryService.getDeploymentResourceNames(rawEntity.getDeploymentId());
    assertEquals(2, resourceNames.size());

    for (ActivityImpl activity : rawEntity.getActivities()) {

        if (activity.getId().equals("theStart")) {
            assertActivityBounds(activity, 70, 255, 30, 30);
        } else if (activity.getId().equals("task1")) {
            assertActivityBounds(activity, 176, 230, 100, 80);
        } else if (activity.getId().equals("gateway1")) {
            assertActivityBounds(activity, 340, 250, 40, 40);
        } else if (activity.getId().equals("task2")) {
            assertActivityBounds(activity, 445, 138, 100, 80);
        } else if (activity.getId().equals("gateway2")) {
            assertActivityBounds(activity, 620, 250, 40, 40);
        } else if (activity.getId().equals("task3")) {
            assertActivityBounds(activity, 453, 304, 100, 80);
        } else if (activity.getId().equals("theEnd")) {
            assertActivityBounds(activity, 713, 256, 28, 28);
        }

        for (PvmTransition sequenceFlow : activity.getOutgoingTransitions()) {
            assertTrue(((TransitionImpl) sequenceFlow).getWaypoints().size() >= 4);

            TransitionImpl transitionImpl = (TransitionImpl) sequenceFlow;
            if (transitionImpl.getId().equals("flowStartToTask1")) {
                assertSequenceFlowWayPoints(transitionImpl, 100, 270, 176, 270);
            } else if (transitionImpl.getId().equals("flowTask1ToGateway1")) {
                assertSequenceFlowWayPoints(transitionImpl, 276, 270, 340, 270);
            } else if (transitionImpl.getId().equals("flowGateway1ToTask2")) {
                assertSequenceFlowWayPoints(transitionImpl, 360, 250, 360, 178, 445, 178);
            } else if (transitionImpl.getId().equals("flowGateway1ToTask3")) {
                assertSequenceFlowWayPoints(transitionImpl, 360, 290, 360, 344, 453, 344);
            } else if (transitionImpl.getId().equals("flowTask2ToGateway2")) {
                assertSequenceFlowWayPoints(transitionImpl, 545, 178, 640, 178, 640, 250);
            } else if (transitionImpl.getId().equals("flowTask3ToGateway2")) {
                assertSequenceFlowWayPoints(transitionImpl, 553, 344, 640, 344, 640, 290);
            } else if (transitionImpl.getId().equals("flowGateway2ToEnd")) {
                assertSequenceFlowWayPoints(transitionImpl, 660, 270, 713, 270);
            }

        }
    }
}
 
Example #18
Source File: ExecutionEntity.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public TransitionImpl getTransition() {
    return transition;
}
 
Example #19
Source File: AtomicOperationTransitionDestroyScope.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void execute(InterpretableExecution execution) {
    InterpretableExecution propagatingExecution = null;

    ActivityImpl activity = (ActivityImpl) execution.getActivity();
    // if this transition is crossing a scope boundary
    if (activity.isScope()) {

        InterpretableExecution parentScopeInstance = null;
        // if this is a concurrent execution crossing a scope boundary
        if (execution.isConcurrent() && !execution.isScope()) {
            // first remove the execution from the current root
            InterpretableExecution concurrentRoot = (InterpretableExecution) execution.getParent();
            parentScopeInstance = (InterpretableExecution) execution.getParent().getParent();

            LOGGER.debug("moving concurrent {} one scope up under {}", execution, parentScopeInstance);
            List<InterpretableExecution> parentScopeInstanceExecutions = (List<InterpretableExecution>) parentScopeInstance.getExecutions();
            List<InterpretableExecution> concurrentRootExecutions = (List<InterpretableExecution>) concurrentRoot.getExecutions();
            // if the parent scope had only one single scope child
            if (parentScopeInstanceExecutions.size() == 1) {
                // it now becomes a concurrent execution
                parentScopeInstanceExecutions.get(0).setConcurrent(true);
            }

            concurrentRootExecutions.remove(execution);
            parentScopeInstanceExecutions.add(execution);
            execution.setParent(parentScopeInstance);
            execution.setActivity(activity);
            propagatingExecution = execution;

            // if there is only a single concurrent execution left
            // in the concurrent root, auto-prune it. meaning, the
            // last concurrent child execution data should be cloned into
            // the concurrent root.
            if (concurrentRootExecutions.size() == 1) {
                InterpretableExecution lastConcurrent = concurrentRootExecutions.get(0);
                if (lastConcurrent.isScope()) {
                    lastConcurrent.setConcurrent(false);

                } else {
                    LOGGER.debug("merging last concurrent {} into concurrent root {}", lastConcurrent, concurrentRoot);

                    // We can't just merge the data of the lastConcurrent into the concurrentRoot.
                    // This is because the concurrent root might be in a takeAll-loop. So the
                    // concurrent execution is the one that will be receiving the take
                    concurrentRoot.setActivity((ActivityImpl) lastConcurrent.getActivity());
                    concurrentRoot.setActive(lastConcurrent.isActive());
                    lastConcurrent.setReplacedBy(concurrentRoot);
                    lastConcurrent.remove();
                }
            }

        } else if (execution.isConcurrent() && execution.isScope()) {
            LOGGER.debug("scoped concurrent {} becomes concurrent and remains under {}", execution, execution.getParent());

            // TODO!
            execution.destroy();
            propagatingExecution = execution;

        } else {
            propagatingExecution = (InterpretableExecution) execution.getParent();
            propagatingExecution.setActivity((ActivityImpl) execution.getActivity());
            propagatingExecution.setTransition(execution.getTransition());
            propagatingExecution.setActive(true);
            LOGGER.debug("destroy scope: scoped {} continues as parent scope {}", execution, propagatingExecution);
            execution.destroy();
            execution.remove();
        }

    } else {
        propagatingExecution = execution;
    }

    // if there is another scope element that is ended
    ScopeImpl nextOuterScopeElement = activity.getParent();
    TransitionImpl transition = propagatingExecution.getTransition();
    ActivityImpl destination = transition.getDestination();
    if (transitionLeavesNextOuterScope(nextOuterScopeElement, destination)) {
        propagatingExecution.setActivity((ActivityImpl) nextOuterScopeElement);
        propagatingExecution.performOperation(TRANSITION_NOTIFY_LISTENER_END);
    } else {
        propagatingExecution.performOperation(TRANSITION_NOTIFY_LISTENER_TAKE);
    }
}
 
Example #20
Source File: ExecutionImpl.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void setTransition(TransitionImpl transition) {
    this.transition = transition;
}
 
Example #21
Source File: ExecutionImpl.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public TransitionImpl getTransition() {
    return transition;
}
 
Example #22
Source File: BpmnParseTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
protected void assertSequenceFlowWayPoints(TransitionImpl sequenceFlow, Integer... waypoints) {
    assertEquals(waypoints.length, sequenceFlow.getWaypoints().size());
    for (int i = 0; i < waypoints.length; i++) {
        assertEquals(waypoints[i], sequenceFlow.getWaypoints().get(i));
    }
}
 
Example #23
Source File: InterpretableExecution.java    From flowable-engine with Apache License 2.0 votes vote down vote up
void setTransition(TransitionImpl object); 
Example #24
Source File: InterpretableExecution.java    From flowable-engine with Apache License 2.0 votes vote down vote up
TransitionImpl getTransition();