Search in sources :

Example 1 with TransitionImpl

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

the class CdiEventSupportBpmnParseHandler method parse.

public void parse(BpmnParse bpmnParse, BaseElement element) {
    if (element instanceof SequenceFlow) {
        TransitionImpl transition = bpmnParse.getSequenceFlows().get(element.getId());
        transition.addExecutionListener(new CdiExecutionListener(transition.getId()));
    } else {
        ActivityImpl activity = bpmnParse.getCurrentScope().findActivity(element.getId());
        if (element instanceof UserTask) {
            addCreateListener(activity);
            addAssignListener(activity);
            addCompleteListener(activity);
            addDeleteListener(activity);
        }
        if (activity != null) {
            addStartEventListener(activity);
            addEndEventListener(activity);
        }
    }
}
Also used : TransitionImpl(org.activiti.engine.impl.pvm.process.TransitionImpl) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) UserTask(org.activiti.bpmn.model.UserTask)

Example 2 with TransitionImpl

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

the class BpmnParse method createBPMNEdge.

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<Integer>();
        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 " + key + " not found");
    }
}
Also used : TransitionImpl(org.activiti.engine.impl.pvm.process.TransitionImpl) FlowElement(org.activiti.bpmn.model.FlowElement) ArrayList(java.util.ArrayList) GraphicInfo(org.activiti.bpmn.model.GraphicInfo)

Example 3 with TransitionImpl

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

the class SequenceFlowParseHandler method executeParse.

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);
}
Also used : UelExpressionCondition(org.activiti.engine.impl.el.UelExpressionCondition) Condition(org.activiti.engine.impl.Condition) ExpressionManager(org.activiti.engine.impl.el.ExpressionManager) TransitionImpl(org.activiti.engine.impl.pvm.process.TransitionImpl) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) Expression(org.activiti.engine.delegate.Expression) ScopeImpl(org.activiti.engine.impl.pvm.process.ScopeImpl) UelExpressionCondition(org.activiti.engine.impl.el.UelExpressionCondition)

Example 4 with TransitionImpl

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

the class BaseProcessDefinitionDiagramLayoutResource method getActivity.

private void getActivity(String processInstanceId, ActivityImpl activity, ArrayNode activityArray, ArrayNode sequenceFlowArray, ProcessInstance processInstance, List<String> highLightedFlows, Map<String, ObjectNode> subProcessInstanceMap) {
    ObjectNode activityJSON = new ObjectMapper().createObjectNode();
    // Gather info on the multi instance marker
    String multiInstance = (String) activity.getProperty("multiInstance");
    if (multiInstance != null) {
        if (!"sequential".equals(multiInstance)) {
            multiInstance = "parallel";
        }
    }
    ActivityBehavior activityBehavior = activity.getActivityBehavior();
    // Gather info on the collapsed marker
    Boolean collapsed = (activityBehavior instanceof CallActivityBehavior);
    Boolean expanded = (Boolean) activity.getProperty(BpmnParse.PROPERTYNAME_ISEXPANDED);
    if (expanded != null) {
        collapsed = !expanded;
    }
    Boolean isInterrupting = null;
    if (activityBehavior instanceof BoundaryEventActivityBehavior) {
        isInterrupting = ((BoundaryEventActivityBehavior) activityBehavior).isInterrupting();
    }
    // Outgoing transitions of activity
    for (PvmTransition sequenceFlow : activity.getOutgoingTransitions()) {
        String flowName = (String) sequenceFlow.getProperty("name");
        boolean isHighLighted = (highLightedFlows.contains(sequenceFlow.getId()));
        boolean isConditional = sequenceFlow.getProperty(BpmnParse.PROPERTYNAME_CONDITION) != null && !((String) activity.getProperty("type")).toLowerCase().contains("gateway");
        boolean isDefault = sequenceFlow.getId().equals(activity.getProperty("default")) && ((String) activity.getProperty("type")).toLowerCase().contains("gateway");
        List<Integer> waypoints = ((TransitionImpl) sequenceFlow).getWaypoints();
        ArrayNode xPointArray = new ObjectMapper().createArrayNode();
        ArrayNode yPointArray = new ObjectMapper().createArrayNode();
        for (int i = 0; i < waypoints.size(); i += 2) {
            // waypoints.size()
            // minimally 4: x1, y1,
            // x2, y2
            xPointArray.add(waypoints.get(i));
            yPointArray.add(waypoints.get(i + 1));
        }
        ObjectNode flowJSON = new ObjectMapper().createObjectNode();
        flowJSON.put("id", sequenceFlow.getId());
        flowJSON.put("name", flowName);
        flowJSON.put("flow", "(" + sequenceFlow.getSource().getId() + ")--" + sequenceFlow.getId() + "-->(" + sequenceFlow.getDestination().getId() + ")");
        if (isConditional)
            flowJSON.put("isConditional", isConditional);
        if (isDefault)
            flowJSON.put("isDefault", isDefault);
        if (isHighLighted)
            flowJSON.put("isHighLighted", isHighLighted);
        flowJSON.put("xPointArray", xPointArray);
        flowJSON.put("yPointArray", yPointArray);
        sequenceFlowArray.add(flowJSON);
    }
    // Nested activities (boundary events)
    ArrayNode nestedActivityArray = new ObjectMapper().createArrayNode();
    for (ActivityImpl nestedActivity : activity.getActivities()) {
        nestedActivityArray.add(nestedActivity.getId());
    }
    Map<String, Object> properties = activity.getProperties();
    ObjectNode propertiesJSON = new ObjectMapper().createObjectNode();
    for (String key : properties.keySet()) {
        Object prop = properties.get(key);
        if (prop instanceof String)
            propertiesJSON.put(key, (String) properties.get(key));
        else if (prop instanceof Integer)
            propertiesJSON.put(key, (Integer) properties.get(key));
        else if (prop instanceof Boolean)
            propertiesJSON.put(key, (Boolean) properties.get(key));
        else if ("initial".equals(key)) {
            ActivityImpl act = (ActivityImpl) properties.get(key);
            propertiesJSON.put(key, act.getId());
        } else if ("timerDeclarations".equals(key)) {
            ArrayList<TimerDeclarationImpl> timerDeclarations = (ArrayList<TimerDeclarationImpl>) properties.get(key);
            ArrayNode timerDeclarationArray = new ObjectMapper().createArrayNode();
            if (timerDeclarations != null)
                for (TimerDeclarationImpl timerDeclaration : timerDeclarations) {
                    ObjectNode timerDeclarationJSON = new ObjectMapper().createObjectNode();
                    timerDeclarationJSON.put("isExclusive", timerDeclaration.isExclusive());
                    if (timerDeclaration.getRepeat() != null)
                        timerDeclarationJSON.put("repeat", timerDeclaration.getRepeat());
                    timerDeclarationJSON.put("retries", String.valueOf(timerDeclaration.getRetries()));
                    timerDeclarationJSON.put("type", timerDeclaration.getJobHandlerType());
                    timerDeclarationJSON.put("configuration", timerDeclaration.getJobHandlerConfiguration());
                    //timerDeclarationJSON.put("expression", timerDeclaration.getDescription());
                    timerDeclarationArray.add(timerDeclarationJSON);
                }
            if (timerDeclarationArray.size() > 0)
                propertiesJSON.put(key, timerDeclarationArray);
        // TODO: implement getting description
        } else if ("eventDefinitions".equals(key)) {
            ArrayList<EventSubscriptionDeclaration> eventDefinitions = (ArrayList<EventSubscriptionDeclaration>) properties.get(key);
            ArrayNode eventDefinitionsArray = new ObjectMapper().createArrayNode();
            if (eventDefinitions != null) {
                for (EventSubscriptionDeclaration eventDefinition : eventDefinitions) {
                    ObjectNode eventDefinitionJSON = new ObjectMapper().createObjectNode();
                    if (eventDefinition.getActivityId() != null)
                        eventDefinitionJSON.put("activityId", eventDefinition.getActivityId());
                    eventDefinitionJSON.put("eventName", eventDefinition.getEventName());
                    eventDefinitionJSON.put("eventType", eventDefinition.getEventType());
                    eventDefinitionJSON.put("isAsync", eventDefinition.isAsync());
                    eventDefinitionJSON.put("isStartEvent", eventDefinition.isStartEvent());
                    eventDefinitionsArray.add(eventDefinitionJSON);
                }
            }
            if (eventDefinitionsArray.size() > 0)
                propertiesJSON.put(key, eventDefinitionsArray);
        // TODO: implement it
        } else if ("errorEventDefinitions".equals(key)) {
            ArrayList<ErrorEventDefinition> errorEventDefinitions = (ArrayList<ErrorEventDefinition>) properties.get(key);
            ArrayNode errorEventDefinitionsArray = new ObjectMapper().createArrayNode();
            if (errorEventDefinitions != null) {
                for (ErrorEventDefinition errorEventDefinition : errorEventDefinitions) {
                    ObjectNode errorEventDefinitionJSON = new ObjectMapper().createObjectNode();
                    if (errorEventDefinition.getErrorCode() != null)
                        errorEventDefinitionJSON.put("errorCode", errorEventDefinition.getErrorCode());
                    else
                        errorEventDefinitionJSON.putNull("errorCode");
                    errorEventDefinitionJSON.put("handlerActivityId", errorEventDefinition.getHandlerActivityId());
                    errorEventDefinitionsArray.add(errorEventDefinitionJSON);
                }
            }
            if (errorEventDefinitionsArray.size() > 0)
                propertiesJSON.put(key, errorEventDefinitionsArray);
        }
    }
    if ("callActivity".equals(properties.get("type"))) {
        CallActivityBehavior callActivityBehavior = null;
        if (activityBehavior instanceof CallActivityBehavior) {
            callActivityBehavior = (CallActivityBehavior) activityBehavior;
        }
        if (callActivityBehavior != null) {
            propertiesJSON.put("processDefinitonKey", callActivityBehavior.getProcessDefinitonKey());
            // get processDefinitonId from execution or get last processDefinitonId
            // by key
            ArrayNode processInstanceArray = new ObjectMapper().createArrayNode();
            if (processInstance != null) {
                List<Execution> executionList = runtimeService.createExecutionQuery().processInstanceId(processInstanceId).activityId(activity.getId()).list();
                if (!executionList.isEmpty()) {
                    for (Execution execution : executionList) {
                        ObjectNode processInstanceJSON = subProcessInstanceMap.get(execution.getId());
                        processInstanceArray.add(processInstanceJSON);
                    }
                }
            }
            // last definition
            if (processInstanceArray.size() == 0 && StringUtils.isNotEmpty(callActivityBehavior.getProcessDefinitonKey())) {
                // Get last definition by key
                ProcessDefinition lastProcessDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey(callActivityBehavior.getProcessDefinitonKey()).latestVersion().singleResult();
                // TODO: unuseful fields there are processDefinitionName, processDefinitionKey
                if (lastProcessDefinition != null) {
                    ObjectNode processInstanceJSON = new ObjectMapper().createObjectNode();
                    processInstanceJSON.put("processDefinitionId", lastProcessDefinition.getId());
                    processInstanceJSON.put("processDefinitionKey", lastProcessDefinition.getKey());
                    processInstanceJSON.put("processDefinitionName", lastProcessDefinition.getName());
                    processInstanceArray.add(processInstanceJSON);
                }
            }
            if (processInstanceArray.size() > 0) {
                propertiesJSON.put("processDefinitons", processInstanceArray);
            }
        }
    }
    activityJSON.put("activityId", activity.getId());
    activityJSON.put("properties", propertiesJSON);
    if (multiInstance != null)
        activityJSON.put("multiInstance", multiInstance);
    if (collapsed)
        activityJSON.put("collapsed", collapsed);
    if (nestedActivityArray.size() > 0)
        activityJSON.put("nestedActivities", nestedActivityArray);
    if (isInterrupting != null)
        activityJSON.put("isInterrupting", isInterrupting);
    activityJSON.put("x", activity.getX());
    activityJSON.put("y", activity.getY());
    activityJSON.put("width", activity.getWidth());
    activityJSON.put("height", activity.getHeight());
    activityArray.add(activityJSON);
    // Nested activities (boundary events)
    for (ActivityImpl nestedActivity : activity.getActivities()) {
        getActivity(processInstanceId, nestedActivity, activityArray, sequenceFlowArray, processInstance, highLightedFlows, subProcessInstanceMap);
    }
}
Also used : TimerDeclarationImpl(org.activiti.engine.impl.jobexecutor.TimerDeclarationImpl) ArrayList(java.util.ArrayList) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Execution(org.activiti.engine.runtime.Execution) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TransitionImpl(org.activiti.engine.impl.pvm.process.TransitionImpl) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CallActivityBehavior(org.activiti.engine.impl.bpmn.behavior.CallActivityBehavior) BoundaryEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.BoundaryEventActivityBehavior) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ErrorEventDefinition(org.activiti.engine.impl.bpmn.parser.ErrorEventDefinition) BoundaryEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.BoundaryEventActivityBehavior) ActivityBehavior(org.activiti.engine.impl.pvm.delegate.ActivityBehavior) CallActivityBehavior(org.activiti.engine.impl.bpmn.behavior.CallActivityBehavior) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition) EventSubscriptionDeclaration(org.activiti.engine.impl.bpmn.parser.EventSubscriptionDeclaration)

Example 5 with TransitionImpl

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

the class AtomicOperationTransitionDestroyScope method execute.

@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();
            log.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;
            // the concurrent root.   
            if (concurrentRootExecutions.size() == 1) {
                InterpretableExecution lastConcurrent = concurrentRootExecutions.get(0);
                if (lastConcurrent.isScope()) {
                    lastConcurrent.setConcurrent(false);
                } else {
                    log.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()) {
            log.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);
            log.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);
    }
}
Also used : TransitionImpl(org.activiti.engine.impl.pvm.process.TransitionImpl) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) List(java.util.List) ScopeImpl(org.activiti.engine.impl.pvm.process.ScopeImpl)

Aggregations

TransitionImpl (org.activiti.engine.impl.pvm.process.TransitionImpl)9 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)8 ArrayList (java.util.ArrayList)2 PvmTransition (org.activiti.engine.impl.pvm.PvmTransition)2 ScopeImpl (org.activiti.engine.impl.pvm.process.ScopeImpl)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 List (java.util.List)1 FlowElement (org.activiti.bpmn.model.FlowElement)1 GraphicInfo (org.activiti.bpmn.model.GraphicInfo)1 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)1 UserTask (org.activiti.bpmn.model.UserTask)1 ActivitiException (org.activiti.engine.ActivitiException)1 ExecutionListener (org.activiti.engine.delegate.ExecutionListener)1 Expression (org.activiti.engine.delegate.Expression)1 Condition (org.activiti.engine.impl.Condition)1 BoundaryEventActivityBehavior (org.activiti.engine.impl.bpmn.behavior.BoundaryEventActivityBehavior)1 CallActivityBehavior (org.activiti.engine.impl.bpmn.behavior.CallActivityBehavior)1 ErrorEventDefinition (org.activiti.engine.impl.bpmn.parser.ErrorEventDefinition)1