Search in sources :

Example 6 with PvmTransition

use of org.activiti.engine.impl.pvm.PvmTransition in project Activiti by Activiti.

the class BoundaryEventActivityBehavior method execute.

@SuppressWarnings("unchecked")
public void execute(ActivityExecution execution) throws Exception {
    ExecutionEntity executionEntity = (ExecutionEntity) execution;
    ActivityImpl boundaryActivity = executionEntity.getProcessDefinition().findActivity(activityId);
    ActivityImpl interruptedActivity = executionEntity.getActivity();
    List<PvmTransition> outgoingTransitions = boundaryActivity.getOutgoingTransitions();
    List<ExecutionEntity> interruptedExecutions = null;
    if (interrupting) {
        // Call activity
        if (executionEntity.getSubProcessInstance() != null) {
            executionEntity.getSubProcessInstance().deleteCascade(executionEntity.getDeleteReason());
        } else {
            Context.getCommandContext().getHistoryManager().recordActivityEnd(executionEntity);
        }
        executionEntity.setActivity(boundaryActivity);
        interruptedExecutions = new ArrayList<ExecutionEntity>(executionEntity.getExecutions());
        for (ExecutionEntity interruptedExecution : interruptedExecutions) {
            interruptedExecution.deleteCascade("interrupting boundary event '" + execution.getActivity().getId() + "' fired");
        }
        execution.takeAll(outgoingTransitions, (List) interruptedExecutions);
    } else {
        // non interrupting event, introduced with BPMN 2.0, we need to create a new execution in this case
        // create a new execution and move it out from the timer activity
        ExecutionEntity concurrentRoot = executionEntity.getParent().isConcurrent() ? executionEntity.getParent() : executionEntity;
        ExecutionEntity outgoingExecution = concurrentRoot.createExecution();
        outgoingExecution.setActive(true);
        outgoingExecution.setScope(false);
        outgoingExecution.setConcurrent(true);
        outgoingExecution.takeAll(outgoingTransitions, Collections.EMPTY_LIST);
        outgoingExecution.remove();
        // now we have to move the execution back to the real activity
        // since the execution stays there (non interrupting) and it was
        // set to the boundary event before
        executionEntity.setActivity(interruptedActivity);
    }
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition)

Example 7 with PvmTransition

use of org.activiti.engine.impl.pvm.PvmTransition in project Activiti by Activiti.

the class ProcessDefinitionPersistenceTest method testProcessDefinitionIntrospection.

public void testProcessDefinitionIntrospection() {
    String deploymentId = repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/db/processOne.bpmn20.xml").deploy().getId();
    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    ReadOnlyProcessDefinition processDefinition = ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(procDefId);
    assertEquals(procDefId, processDefinition.getId());
    assertEquals("Process One", processDefinition.getName());
    assertEquals("the first process", processDefinition.getProperty("documentation"));
    PvmActivity start = processDefinition.findActivity("start");
    assertNotNull(start);
    assertEquals("start", start.getId());
    assertEquals("S t a r t", start.getProperty("name"));
    assertEquals("the start event", start.getProperty("documentation"));
    assertEquals(Collections.EMPTY_LIST, start.getActivities());
    List<PvmTransition> outgoingTransitions = start.getOutgoingTransitions();
    assertEquals(1, outgoingTransitions.size());
    assertEquals("${a == b}", outgoingTransitions.get(0).getProperty(BpmnParse.PROPERTYNAME_CONDITION_TEXT));
    PvmActivity end = processDefinition.findActivity("end");
    assertNotNull(end);
    assertEquals("end", end.getId());
    PvmTransition transition = outgoingTransitions.get(0);
    assertEquals("flow1", transition.getId());
    assertEquals("Flow One", transition.getProperty("name"));
    assertEquals("The only transitions in the process", transition.getProperty("documentation"));
    assertSame(start, transition.getSource());
    assertSame(end, transition.getDestination());
    repositoryService.deleteDeployment(deploymentId);
}
Also used : ReadOnlyProcessDefinition(org.activiti.engine.impl.pvm.ReadOnlyProcessDefinition) RepositoryServiceImpl(org.activiti.engine.impl.RepositoryServiceImpl) PvmActivity(org.activiti.engine.impl.pvm.PvmActivity) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition)

Example 8 with PvmTransition

use of org.activiti.engine.impl.pvm.PvmTransition in project Activiti by Activiti.

the class BaseProcessDefinitionDiagramLayoutResource method getHighLightedFlows.

private List<String> getHighLightedFlows(String processInstanceId, ProcessDefinitionEntity processDefinition) {
    List<String> highLightedFlows = new ArrayList<String>();
    List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).orderByHistoricActivityInstanceStartTime().asc().list();
    List<String> historicActivityInstanceList = new ArrayList<String>();
    for (HistoricActivityInstance hai : historicActivityInstances) {
        historicActivityInstanceList.add(hai.getActivityId());
    }
    // add current activities to list
    List<String> highLightedActivities = runtimeService.getActiveActivityIds(processInstanceId);
    historicActivityInstanceList.addAll(highLightedActivities);
    // activities and their sequence-flows
    for (ActivityImpl activity : processDefinition.getActivities()) {
        int index = historicActivityInstanceList.indexOf(activity.getId());
        if (index >= 0 && index + 1 < historicActivityInstanceList.size()) {
            List<PvmTransition> pvmTransitionList = activity.getOutgoingTransitions();
            for (PvmTransition pvmTransition : pvmTransitionList) {
                String destinationFlowId = pvmTransition.getDestination().getId();
                if (destinationFlowId.equals(historicActivityInstanceList.get(index + 1))) {
                    highLightedFlows.add(pvmTransition.getId());
                }
            }
        }
    }
    return highLightedFlows;
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ArrayList(java.util.ArrayList) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance)

Example 9 with PvmTransition

use of org.activiti.engine.impl.pvm.PvmTransition in project Activiti by Activiti.

the class ProcessInstanceHighlightsResource method getHighlightedFlows.

/**
	 * find out single activity's highlighted flowIds
	 * 
	 * @param activity
	 * @param hisActInstList
	 * @param isExclusive if true only return one flowId(Such as exclusiveGateway, BoundaryEvent On Task)
	 * @return
	 */
private List<String> getHighlightedFlows(List<PvmTransition> pvmTransitionList, LinkedList<HistoricActivityInstance> hisActInstList, boolean isParallel) {
    List<String> highLightedFlowIds = new ArrayList<String>();
    PvmTransition earliestTrans = null;
    HistoricActivityInstance earliestHisActInst = null;
    for (PvmTransition pvmTransition : pvmTransitionList) {
        String destActId = pvmTransition.getDestination().getId();
        HistoricActivityInstance destHisActInst = findHisActInst(hisActInstList, destActId);
        if (destHisActInst != null) {
            if (isParallel) {
                highLightedFlowIds.add(pvmTransition.getId());
            } else if (earliestHisActInst == null || (earliestHisActInst.getId().compareTo(destHisActInst.getId()) > 0)) {
                earliestTrans = pvmTransition;
                earliestHisActInst = destHisActInst;
            }
        }
    }
    if ((!isParallel) && earliestTrans != null) {
        highLightedFlowIds.add(earliestTrans.getId());
    }
    return highLightedFlowIds;
}
Also used : ArrayList(java.util.ArrayList) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance)

Example 10 with PvmTransition

use of org.activiti.engine.impl.pvm.PvmTransition in project Activiti by Activiti.

the class ProcessInstanceHighlightsResource method getHighlightedFlows.

/**
	 * getHighlightedFlows
	 * 
	 * code logic: 
	 * 1. Loop all activities by id asc order;
	 * 2. Check each activity's outgoing transitions and eventBoundery outgoing transitions, if outgoing transitions's destination.id is in other executed activityIds, add this transition to highLightedFlows List;
	 * 3. But if activity is not a parallelGateway or inclusiveGateway, only choose the earliest flow.
	 * 
	 * @param activityList
	 * @param hisActInstList
	 * @param highLightedFlows
	 */
private void getHighlightedFlows(List<ActivityImpl> activityList, LinkedList<HistoricActivityInstance> hisActInstList, List<String> highLightedFlows) {
    //check out startEvents in activityList
    List<ActivityImpl> startEventActList = new ArrayList<ActivityImpl>();
    Map<String, ActivityImpl> activityMap = new HashMap<String, ActivityImpl>(activityList.size());
    for (ActivityImpl activity : activityList) {
        activityMap.put(activity.getId(), activity);
        String actType = (String) activity.getProperty("type");
        if (actType != null && actType.toLowerCase().indexOf("startevent") >= 0) {
            startEventActList.add(activity);
        }
    }
    //These codes is used to avoid a bug: 
    //ACT-1728 If the process instance was started by a callActivity, it will be not have the startEvent activity in ACT_HI_ACTINST table 
    //Code logic:
    //Check the first activity if it is a startEvent, if not check out the startEvent's highlight outgoing flow.
    HistoricActivityInstance firstHistActInst = hisActInstList.getFirst();
    String firstActType = (String) firstHistActInst.getActivityType();
    if (firstActType != null && firstActType.toLowerCase().indexOf("startevent") < 0) {
        PvmTransition startTrans = getStartTransaction(startEventActList, firstHistActInst);
        if (startTrans != null) {
            highLightedFlows.add(startTrans.getId());
        }
    }
    while (!hisActInstList.isEmpty()) {
        HistoricActivityInstance histActInst = hisActInstList.removeFirst();
        ActivityImpl activity = activityMap.get(histActInst.getActivityId());
        if (activity != null) {
            boolean isParallel = false;
            String type = histActInst.getActivityType();
            if ("parallelGateway".equals(type) || "inclusiveGateway".equals(type)) {
                isParallel = true;
            } else if ("subProcess".equals(histActInst.getActivityType())) {
                getHighlightedFlows(activity.getActivities(), hisActInstList, highLightedFlows);
            }
            List<PvmTransition> allOutgoingTrans = new ArrayList<PvmTransition>();
            allOutgoingTrans.addAll(activity.getOutgoingTransitions());
            allOutgoingTrans.addAll(getBoundaryEventOutgoingTransitions(activity));
            List<String> activityHighLightedFlowIds = getHighlightedFlows(allOutgoingTrans, hisActInstList, isParallel);
            highLightedFlows.addAll(activityHighLightedFlowIds);
        }
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance)

Aggregations

PvmTransition (org.activiti.engine.impl.pvm.PvmTransition)25 ArrayList (java.util.ArrayList)8 ActivityExecution (org.activiti.engine.impl.pvm.delegate.ActivityExecution)7 PvmActivity (org.activiti.engine.impl.pvm.PvmActivity)6 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)6 ActivitiException (org.activiti.engine.ActivitiException)3 Expression (org.activiti.engine.delegate.Expression)3 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)3 Condition (org.activiti.engine.impl.Condition)3 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)3 List (java.util.List)2 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)2 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)2 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)2 PvmException (org.activiti.engine.impl.pvm.PvmException)2 TransitionImpl (org.activiti.engine.impl.pvm.process.TransitionImpl)2 InterpretableExecution (org.activiti.engine.impl.pvm.runtime.InterpretableExecution)2 Deployment (org.activiti.engine.test.Deployment)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1