Search in sources :

Example 1 with Transaction

use of org.activiti.bpmn.model.Transaction in project Activiti by Activiti.

the class SubProcessParser method parse.

public void parse(XMLStreamReader xtr, List<SubProcess> activeSubProcessList, Process activeProcess) {
    SubProcess subProcess = null;
    if (ELEMENT_TRANSACTION.equalsIgnoreCase(xtr.getLocalName())) {
        subProcess = new Transaction();
    } else if (ELEMENT_ADHOC_SUBPROCESS.equalsIgnoreCase(xtr.getLocalName())) {
        AdhocSubProcess adhocSubProcess = new AdhocSubProcess();
        String orderingAttributeValue = xtr.getAttributeValue(null, ATTRIBUTE_ORDERING);
        if (StringUtils.isNotEmpty(orderingAttributeValue)) {
            adhocSubProcess.setOrdering(orderingAttributeValue);
        }
        if (ATTRIBUTE_VALUE_FALSE.equalsIgnoreCase(xtr.getAttributeValue(null, ATTRIBUTE_CANCEL_REMAINING_INSTANCES))) {
            adhocSubProcess.setCancelRemainingInstances(false);
        }
        subProcess = adhocSubProcess;
    } else if (ATTRIBUTE_VALUE_TRUE.equalsIgnoreCase(xtr.getAttributeValue(null, ATTRIBUTE_TRIGGERED_BY))) {
        subProcess = new EventSubProcess();
    } else {
        subProcess = new SubProcess();
    }
    BpmnXMLUtil.addXMLLocation(subProcess, xtr);
    activeSubProcessList.add(subProcess);
    subProcess.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));
    subProcess.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
    boolean async = false;
    String asyncString = xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_ACTIVITY_ASYNCHRONOUS);
    if (ATTRIBUTE_VALUE_TRUE.equalsIgnoreCase(asyncString)) {
        async = true;
    }
    boolean notExclusive = false;
    String exclusiveString = xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_ACTIVITY_EXCLUSIVE);
    if (ATTRIBUTE_VALUE_FALSE.equalsIgnoreCase(exclusiveString)) {
        notExclusive = true;
    }
    boolean forCompensation = false;
    String compensationString = xtr.getAttributeValue(null, ATTRIBUTE_ACTIVITY_ISFORCOMPENSATION);
    if (ATTRIBUTE_VALUE_TRUE.equalsIgnoreCase(compensationString)) {
        forCompensation = true;
    }
    subProcess.setAsynchronous(async);
    subProcess.setNotExclusive(notExclusive);
    subProcess.setForCompensation(forCompensation);
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_DEFAULT))) {
        subProcess.setDefaultFlow(xtr.getAttributeValue(null, ATTRIBUTE_DEFAULT));
    }
    if (activeSubProcessList.size() > 1) {
        SubProcess parentSubProcess = activeSubProcessList.get(activeSubProcessList.size() - 2);
        parentSubProcess.addFlowElement(subProcess);
    } else {
        activeProcess.addFlowElement(subProcess);
    }
}
Also used : EventSubProcess(org.activiti.bpmn.model.EventSubProcess) SubProcess(org.activiti.bpmn.model.SubProcess) AdhocSubProcess(org.activiti.bpmn.model.AdhocSubProcess) AdhocSubProcess(org.activiti.bpmn.model.AdhocSubProcess) Transaction(org.activiti.bpmn.model.Transaction) EventSubProcess(org.activiti.bpmn.model.EventSubProcess)

Example 2 with Transaction

use of org.activiti.bpmn.model.Transaction in project Activiti by Activiti.

the class EndExecutionOperation method handleSubProcessEnd.

protected ExecutionEntity handleSubProcessEnd(ExecutionEntityManager executionEntityManager, ExecutionEntity parentExecution, SubProcess subProcess) {
    ExecutionEntity executionToContinue = null;
    // create a new execution to take the outgoing sequence flows
    executionToContinue = executionEntityManager.createChildExecution(parentExecution.getParent());
    executionToContinue.setCurrentFlowElement(subProcess);
    boolean hasCompensation = false;
    if (subProcess instanceof Transaction) {
        hasCompensation = true;
    } else {
        for (FlowElement subElement : subProcess.getFlowElements()) {
            if (subElement instanceof Activity) {
                Activity subActivity = (Activity) subElement;
                if (CollectionUtil.isNotEmpty(subActivity.getBoundaryEvents())) {
                    for (BoundaryEvent boundaryEvent : subActivity.getBoundaryEvents()) {
                        if (CollectionUtil.isNotEmpty(boundaryEvent.getEventDefinitions()) && boundaryEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition) {
                            hasCompensation = true;
                            break;
                        }
                    }
                }
            }
        }
    }
    // The following method does exactly that, and moves the executions beneath the process instance.
    if (hasCompensation) {
        ScopeUtil.createCopyOfSubProcessExecutionForCompensation(parentExecution);
    }
    executionEntityManager.deleteChildExecutions(parentExecution, null);
    executionEntityManager.deleteExecutionAndRelatedData(parentExecution, null);
    Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_COMPLETED, subProcess.getId(), subProcess.getName(), parentExecution.getId(), parentExecution.getProcessInstanceId(), parentExecution.getProcessDefinitionId(), subProcess));
    return executionToContinue;
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) Transaction(org.activiti.bpmn.model.Transaction) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) FlowElement(org.activiti.bpmn.model.FlowElement) Activity(org.activiti.bpmn.model.Activity) CompensateEventDefinition(org.activiti.bpmn.model.CompensateEventDefinition)

Example 3 with Transaction

use of org.activiti.bpmn.model.Transaction in project Activiti by Activiti.

the class ParallelMultiInstanceBehavior method leave.

/**
 * Called when the wrapped {@link ActivityBehavior} calls the {@link AbstractBpmnActivityBehavior#leave(ActivityExecution)} method. Handles the completion of one of the parallel instances
 */
public void leave(DelegateExecution execution) {
    boolean zeroNrOfInstances = false;
    if (resolveNrOfInstances(execution) == 0) {
        // Empty collection, just leave.
        zeroNrOfInstances = true;
        removeLocalLoopVariable(execution, getCollectionElementIndexVariable());
        // Plan the default leave
        super.leave(execution);
        execution.setMultiInstanceRoot(false);
    }
    int loopCounter = getLoopVariable(execution, getCollectionElementIndexVariable());
    int nrOfInstances = getLoopVariable(execution, NUMBER_OF_INSTANCES);
    int nrOfCompletedInstances = getLoopVariable(execution, NUMBER_OF_COMPLETED_INSTANCES) + 1;
    int nrOfActiveInstances = getLoopVariable(execution, NUMBER_OF_ACTIVE_INSTANCES) - 1;
    Context.getCommandContext().getHistoryManager().recordActivityEnd((ExecutionEntity) execution, null);
    callActivityEndListeners(execution);
    if (zeroNrOfInstances) {
        return;
    }
    DelegateExecution miRootExecution = getMultiInstanceRootExecution(execution);
    if (miRootExecution != null) {
        // will be null in case of empty collection
        setLoopVariable(miRootExecution, NUMBER_OF_COMPLETED_INSTANCES, nrOfCompletedInstances);
        setLoopVariable(miRootExecution, NUMBER_OF_ACTIVE_INSTANCES, nrOfActiveInstances);
    }
    updateResultCollection(execution, miRootExecution);
    // executeCompensationBoundaryEvents(execution.getCurrentFlowElement(), execution);
    logLoopDetails(execution, "instance completed", loopCounter, nrOfCompletedInstances, nrOfActiveInstances, nrOfInstances);
    ExecutionEntity executionEntity = (ExecutionEntity) execution;
    if (executionEntity.getParent() != null) {
        executionEntity.inactivate();
        lockFirstParentScope(executionEntity);
        if (nrOfCompletedInstances >= nrOfInstances || completionConditionSatisfied(execution.getParent())) {
            ExecutionEntity executionToUse = null;
            if (nrOfInstances > 0) {
                executionToUse = executionEntity.getParent();
            } else {
                executionToUse = executionEntity;
            }
            propagateLoopDataOutputRefToProcessInstance(executionToUse);
            boolean hasCompensation = false;
            Activity activity = (Activity) execution.getCurrentFlowElement();
            if (activity instanceof Transaction) {
                hasCompensation = true;
            } else if (activity instanceof SubProcess) {
                SubProcess subProcess = (SubProcess) activity;
                for (FlowElement subElement : subProcess.getFlowElements()) {
                    if (subElement instanceof Activity) {
                        Activity subActivity = (Activity) subElement;
                        if (CollectionUtil.isNotEmpty(subActivity.getBoundaryEvents())) {
                            for (BoundaryEvent boundaryEvent : subActivity.getBoundaryEvents()) {
                                if (CollectionUtil.isNotEmpty(boundaryEvent.getEventDefinitions()) && boundaryEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition) {
                                    hasCompensation = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            if (hasCompensation) {
                ScopeUtil.createCopyOfSubProcessExecutionForCompensation(executionToUse);
            }
            if (activity instanceof CallActivity) {
                ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager();
                if (executionToUse != null) {
                    List<String> callActivityExecutionIds = new ArrayList<String>();
                    // Find all execution entities that are at the call activity
                    List<ExecutionEntity> childExecutions = executionEntityManager.collectChildren(executionToUse);
                    if (childExecutions != null) {
                        for (ExecutionEntity childExecution : childExecutions) {
                            if (activity.getId().equals(childExecution.getCurrentActivityId())) {
                                callActivityExecutionIds.add(childExecution.getId());
                            }
                        }
                        // Now all call activity executions have been collected, loop again and check which should be removed
                        for (int i = childExecutions.size() - 1; i >= 0; i--) {
                            ExecutionEntity childExecution = childExecutions.get(i);
                            if (StringUtils.isNotEmpty(childExecution.getSuperExecutionId()) && callActivityExecutionIds.contains(childExecution.getSuperExecutionId())) {
                                executionEntityManager.deleteProcessInstanceExecutionEntity(childExecution.getId(), activity.getId(), "call activity completion condition met", true, true);
                            }
                        }
                    }
                }
            }
            deleteChildExecutions(executionToUse, false, Context.getCommandContext());
            removeLocalLoopVariable(executionToUse, getCollectionElementIndexVariable());
            executionToUse.setScope(false);
            executionToUse.setMultiInstanceRoot(false);
            Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(executionToUse, true);
        }
        dispatchActivityCompletedEvent(executionEntity);
    } else {
        dispatchActivityCompletedEvent(executionEntity);
        removeLocalLoopVariable(execution, getCollectionElementIndexVariable());
        execution.setMultiInstanceRoot(false);
        super.leave(execution);
    }
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) ArrayList(java.util.ArrayList) CallActivity(org.activiti.bpmn.model.CallActivity) Activity(org.activiti.bpmn.model.Activity) CallActivity(org.activiti.bpmn.model.CallActivity) ExecutionEntityManager(org.activiti.engine.impl.persistence.entity.ExecutionEntityManager) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) Transaction(org.activiti.bpmn.model.Transaction) FlowElement(org.activiti.bpmn.model.FlowElement) DelegateExecution(org.activiti.engine.delegate.DelegateExecution) CompensateEventDefinition(org.activiti.bpmn.model.CompensateEventDefinition)

Example 4 with Transaction

use of org.activiti.bpmn.model.Transaction in project Activiti by Activiti.

the class SubProcessJsonConverter method convertElementToJson.

protected void convertElementToJson(ObjectNode propertiesNode, BaseElement baseElement) {
    SubProcess subProcess = (SubProcess) baseElement;
    propertiesNode.put("activitytype", "Sub-Process");
    propertiesNode.put("subprocesstype", "Embedded");
    ArrayNode subProcessShapesArrayNode = objectMapper.createArrayNode();
    GraphicInfo graphicInfo = model.getGraphicInfo(subProcess.getId());
    processor.processFlowElements(subProcess, model, subProcessShapesArrayNode, formKeyMap, decisionTableKeyMap, graphicInfo.getX(), graphicInfo.getY());
    flowElementNode.set("childShapes", subProcessShapesArrayNode);
    if (subProcess instanceof Transaction) {
        propertiesNode.put("istransaction", true);
    }
    BpmnJsonConverterUtil.convertDataPropertiesToJson(subProcess.getDataObjects(), propertiesNode);
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) Transaction(org.activiti.bpmn.model.Transaction) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 5 with Transaction

use of org.activiti.bpmn.model.Transaction in project Activiti by Activiti.

the class BoundaryEventValidator method executeValidation.

@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
    List<BoundaryEvent> boundaryEvents = process.findFlowElementsOfType(BoundaryEvent.class);
    // Only one boundary event of type 'cancel' can be attached to the same
    // element, so we store the count temporarily here
    HashMap<String, Integer> cancelBoundaryEventsCounts = new HashMap<String, Integer>();
    // Only one boundary event of type 'compensate' can be attached to the
    // same element, so we store the count temporarily here
    HashMap<String, Integer> compensateBoundaryEventsCounts = new HashMap<String, Integer>();
    for (int i = 0; i < boundaryEvents.size(); i++) {
        BoundaryEvent boundaryEvent = boundaryEvents.get(i);
        if (boundaryEvent.getEventDefinitions() != null && !boundaryEvent.getEventDefinitions().isEmpty()) {
            EventDefinition eventDefinition = boundaryEvent.getEventDefinitions().get(0);
            if (!(eventDefinition instanceof TimerEventDefinition) && !(eventDefinition instanceof ErrorEventDefinition) && !(eventDefinition instanceof SignalEventDefinition) && !(eventDefinition instanceof CancelEventDefinition) && !(eventDefinition instanceof MessageEventDefinition) && !(eventDefinition instanceof CompensateEventDefinition)) {
                addError(errors, Problems.BOUNDARY_EVENT_INVALID_EVENT_DEFINITION, process, boundaryEvent, "Invalid or unsupported event definition");
            }
            if (eventDefinition instanceof CancelEventDefinition) {
                FlowElement attachedToFlowElement = bpmnModel.getFlowElement(boundaryEvent.getAttachedToRefId());
                if (!(attachedToFlowElement instanceof Transaction)) {
                    addError(errors, Problems.BOUNDARY_EVENT_CANCEL_ONLY_ON_TRANSACTION, process, boundaryEvent, "boundary event with cancelEventDefinition only supported on transaction subprocesses");
                } else {
                    if (!cancelBoundaryEventsCounts.containsKey(attachedToFlowElement.getId())) {
                        cancelBoundaryEventsCounts.put(attachedToFlowElement.getId(), new Integer(0));
                    }
                    cancelBoundaryEventsCounts.put(attachedToFlowElement.getId(), new Integer(cancelBoundaryEventsCounts.get(attachedToFlowElement.getId()) + 1));
                }
            } else if (eventDefinition instanceof CompensateEventDefinition) {
                if (!compensateBoundaryEventsCounts.containsKey(boundaryEvent.getAttachedToRefId())) {
                    compensateBoundaryEventsCounts.put(boundaryEvent.getAttachedToRefId(), new Integer(0));
                }
                compensateBoundaryEventsCounts.put(boundaryEvent.getAttachedToRefId(), compensateBoundaryEventsCounts.get(boundaryEvent.getAttachedToRefId()) + 1);
            } else if (eventDefinition instanceof MessageEventDefinition) {
                // id
                for (int j = 0; j < boundaryEvents.size(); j++) {
                    if (j != i) {
                        BoundaryEvent otherBoundaryEvent = boundaryEvents.get(j);
                        if (otherBoundaryEvent.getAttachedToRefId() != null && otherBoundaryEvent.getAttachedToRefId().equals(boundaryEvent.getAttachedToRefId())) {
                            if (otherBoundaryEvent.getEventDefinitions() != null && !otherBoundaryEvent.getEventDefinitions().isEmpty()) {
                                EventDefinition otherEventDefinition = otherBoundaryEvent.getEventDefinitions().get(0);
                                if (otherEventDefinition instanceof MessageEventDefinition) {
                                    MessageEventDefinition currentMessageEventDefinition = (MessageEventDefinition) eventDefinition;
                                    MessageEventDefinition otherMessageEventDefinition = (MessageEventDefinition) otherEventDefinition;
                                    if (otherMessageEventDefinition.getMessageRef() != null && otherMessageEventDefinition.getMessageRef().equals(currentMessageEventDefinition.getMessageRef())) {
                                        addError(errors, Problems.MESSAGE_EVENT_MULTIPLE_ON_BOUNDARY_SAME_MESSAGE_ID, process, boundaryEvent, "Multiple message events with same message id not supported");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } else {
            addError(errors, Problems.BOUNDARY_EVENT_NO_EVENT_DEFINITION, process, boundaryEvent, "Event definition is missing from boundary event");
        }
    }
    for (String elementId : cancelBoundaryEventsCounts.keySet()) {
        if (cancelBoundaryEventsCounts.get(elementId) > 1) {
            addError(errors, Problems.BOUNDARY_EVENT_MULTIPLE_CANCEL_ON_TRANSACTION, process, bpmnModel.getFlowElement(elementId), "multiple boundary events with cancelEventDefinition not supported on same transaction subprocess.");
        }
    }
    for (String elementId : compensateBoundaryEventsCounts.keySet()) {
        if (compensateBoundaryEventsCounts.get(elementId) > 1) {
            addError(errors, Problems.COMPENSATE_EVENT_MULTIPLE_ON_BOUNDARY, process, bpmnModel.getFlowElement(elementId), "Multiple boundary events of type 'compensate' is invalid");
        }
    }
}
Also used : BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) HashMap(java.util.HashMap) ErrorEventDefinition(org.activiti.bpmn.model.ErrorEventDefinition) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) CancelEventDefinition(org.activiti.bpmn.model.CancelEventDefinition) EventDefinition(org.activiti.bpmn.model.EventDefinition) CompensateEventDefinition(org.activiti.bpmn.model.CompensateEventDefinition) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) Transaction(org.activiti.bpmn.model.Transaction) FlowElement(org.activiti.bpmn.model.FlowElement) ErrorEventDefinition(org.activiti.bpmn.model.ErrorEventDefinition) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) CancelEventDefinition(org.activiti.bpmn.model.CancelEventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition) CompensateEventDefinition(org.activiti.bpmn.model.CompensateEventDefinition)

Aggregations

Transaction (org.activiti.bpmn.model.Transaction)7 SubProcess (org.activiti.bpmn.model.SubProcess)5 FlowElement (org.activiti.bpmn.model.FlowElement)4 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)3 CompensateEventDefinition (org.activiti.bpmn.model.CompensateEventDefinition)3 Activity (org.activiti.bpmn.model.Activity)2 AdhocSubProcess (org.activiti.bpmn.model.AdhocSubProcess)2 EventSubProcess (org.activiti.bpmn.model.EventSubProcess)2 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 XMLException (org.activiti.bpmn.exceptions.XMLException)1 Artifact (org.activiti.bpmn.model.Artifact)1 CallActivity (org.activiti.bpmn.model.CallActivity)1 CancelEventDefinition (org.activiti.bpmn.model.CancelEventDefinition)1 ErrorEventDefinition (org.activiti.bpmn.model.ErrorEventDefinition)1 EventDefinition (org.activiti.bpmn.model.EventDefinition)1 GraphicInfo (org.activiti.bpmn.model.GraphicInfo)1