Search in sources :

Example 1 with AdhocSubProcess

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

the class BpmnXMLConverter method convertToBpmnModel.

public BpmnModel convertToBpmnModel(XMLStreamReader xtr) {
    BpmnModel model = new BpmnModel();
    model.setStartEventFormTypes(startEventFormTypes);
    model.setUserTaskFormTypes(userTaskFormTypes);
    try {
        Process activeProcess = null;
        List<SubProcess> activeSubProcessList = new ArrayList<SubProcess>();
        while (xtr.hasNext()) {
            try {
                xtr.next();
            } catch (Exception e) {
                LOGGER.debug("Error reading XML document", e);
                throw new XMLException("Error reading XML", e);
            }
            if (xtr.isEndElement() && (ELEMENT_SUBPROCESS.equals(xtr.getLocalName()) || ELEMENT_TRANSACTION.equals(xtr.getLocalName()) || ELEMENT_ADHOC_SUBPROCESS.equals(xtr.getLocalName()))) {
                activeSubProcessList.remove(activeSubProcessList.size() - 1);
            }
            if (!xtr.isStartElement()) {
                continue;
            }
            if (ELEMENT_DEFINITIONS.equals(xtr.getLocalName())) {
                definitionsParser.parse(xtr, model);
            } else if (ELEMENT_RESOURCE.equals(xtr.getLocalName())) {
                resourceParser.parse(xtr, model);
            } else if (ELEMENT_SIGNAL.equals(xtr.getLocalName())) {
                signalParser.parse(xtr, model);
            } else if (ELEMENT_MESSAGE.equals(xtr.getLocalName())) {
                messageParser.parse(xtr, model);
            } else if (ELEMENT_ERROR.equals(xtr.getLocalName())) {
                if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_ID))) {
                    model.addError(xtr.getAttributeValue(null, ATTRIBUTE_ID), xtr.getAttributeValue(null, ATTRIBUTE_NAME), xtr.getAttributeValue(null, ATTRIBUTE_ERROR_CODE));
                }
            } else if (ELEMENT_IMPORT.equals(xtr.getLocalName())) {
                importParser.parse(xtr, model);
            } else if (ELEMENT_ITEM_DEFINITION.equals(xtr.getLocalName())) {
                itemDefinitionParser.parse(xtr, model);
            } else if (ELEMENT_DATA_STORE.equals(xtr.getLocalName())) {
                dataStoreParser.parse(xtr, model);
            } else if (ELEMENT_INTERFACE.equals(xtr.getLocalName())) {
                interfaceParser.parse(xtr, model);
            } else if (ELEMENT_IOSPECIFICATION.equals(xtr.getLocalName())) {
                ioSpecificationParser.parseChildElement(xtr, activeProcess, model);
            } else if (ELEMENT_PARTICIPANT.equals(xtr.getLocalName())) {
                participantParser.parse(xtr, model);
            } else if (ELEMENT_MESSAGE_FLOW.equals(xtr.getLocalName())) {
                messageFlowParser.parse(xtr, model);
            } else if (ELEMENT_PROCESS.equals(xtr.getLocalName())) {
                Process process = processParser.parse(xtr, model);
                if (process != null) {
                    activeProcess = process;
                }
            } else if (ELEMENT_POTENTIAL_STARTER.equals(xtr.getLocalName())) {
                potentialStarterParser.parse(xtr, activeProcess);
            } else if (ELEMENT_LANE.equals(xtr.getLocalName())) {
                laneParser.parse(xtr, activeProcess, model);
            } else if (ELEMENT_DOCUMENTATION.equals(xtr.getLocalName())) {
                BaseElement parentElement = null;
                if (!activeSubProcessList.isEmpty()) {
                    parentElement = activeSubProcessList.get(activeSubProcessList.size() - 1);
                } else if (activeProcess != null) {
                    parentElement = activeProcess;
                }
                documentationParser.parseChildElement(xtr, parentElement, model);
            } else if (activeProcess == null && ELEMENT_TEXT_ANNOTATION.equals(xtr.getLocalName())) {
                String elementId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
                TextAnnotation textAnnotation = (TextAnnotation) new TextAnnotationXMLConverter().convertXMLToElement(xtr, model);
                textAnnotation.setId(elementId);
                model.getGlobalArtifacts().add(textAnnotation);
            } else if (activeProcess == null && ELEMENT_ASSOCIATION.equals(xtr.getLocalName())) {
                String elementId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
                Association association = (Association) new AssociationXMLConverter().convertXMLToElement(xtr, model);
                association.setId(elementId);
                model.getGlobalArtifacts().add(association);
            } else if (ELEMENT_EXTENSIONS.equals(xtr.getLocalName())) {
                extensionElementsParser.parse(xtr, activeSubProcessList, activeProcess, model);
            } else if (ELEMENT_SUBPROCESS.equals(xtr.getLocalName()) || ELEMENT_TRANSACTION.equals(xtr.getLocalName()) || ELEMENT_ADHOC_SUBPROCESS.equals(xtr.getLocalName())) {
                subProcessParser.parse(xtr, activeSubProcessList, activeProcess);
            } else if (ELEMENT_COMPLETION_CONDITION.equals(xtr.getLocalName())) {
                if (!activeSubProcessList.isEmpty()) {
                    SubProcess subProcess = activeSubProcessList.get(activeSubProcessList.size() - 1);
                    if (subProcess instanceof AdhocSubProcess) {
                        AdhocSubProcess adhocSubProcess = (AdhocSubProcess) subProcess;
                        adhocSubProcess.setCompletionCondition(xtr.getElementText());
                    }
                }
            } else if (ELEMENT_DI_SHAPE.equals(xtr.getLocalName())) {
                bpmnShapeParser.parse(xtr, model);
            } else if (ELEMENT_DI_EDGE.equals(xtr.getLocalName())) {
                bpmnEdgeParser.parse(xtr, model);
            } else {
                if (!activeSubProcessList.isEmpty() && ELEMENT_MULTIINSTANCE.equalsIgnoreCase(xtr.getLocalName())) {
                    multiInstanceParser.parseChildElement(xtr, activeSubProcessList.get(activeSubProcessList.size() - 1), model);
                } else if (convertersToBpmnMap.containsKey(xtr.getLocalName())) {
                    if (activeProcess != null) {
                        BaseBpmnXMLConverter converter = convertersToBpmnMap.get(xtr.getLocalName());
                        converter.convertToBpmnModel(xtr, model, activeProcess, activeSubProcessList);
                    }
                }
            }
        }
        for (Process process : model.getProcesses()) {
            for (Pool pool : model.getPools()) {
                if (process.getId().equals(pool.getProcessRef())) {
                    pool.setExecutable(process.isExecutable());
                }
            }
            processFlowElements(process.getFlowElements(), process);
        }
    } catch (XMLException e) {
        throw e;
    } catch (Exception e) {
        LOGGER.error("Error processing BPMN document", e);
        throw new XMLException("Error processing BPMN document", e);
    }
    return model;
}
Also used : AdhocSubProcess(org.activiti.bpmn.model.AdhocSubProcess) EventSubProcess(org.activiti.bpmn.model.EventSubProcess) SubProcess(org.activiti.bpmn.model.SubProcess) ArrayList(java.util.ArrayList) AdhocSubProcess(org.activiti.bpmn.model.AdhocSubProcess) EventSubProcess(org.activiti.bpmn.model.EventSubProcess) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) XMLStreamException(javax.xml.stream.XMLStreamException) XMLException(org.activiti.bpmn.exceptions.XMLException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) BpmnModel(org.activiti.bpmn.model.BpmnModel) BaseElement(org.activiti.bpmn.model.BaseElement) XMLException(org.activiti.bpmn.exceptions.XMLException) AdhocSubProcess(org.activiti.bpmn.model.AdhocSubProcess) Association(org.activiti.bpmn.model.Association) Pool(org.activiti.bpmn.model.Pool) TextAnnotation(org.activiti.bpmn.model.TextAnnotation)

Example 2 with AdhocSubProcess

use of org.activiti.bpmn.model.AdhocSubProcess 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 3 with AdhocSubProcess

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

the class ExecuteActivityForAdhocSubProcessCmd method execute.

public Execution execute(CommandContext commandContext) {
    ExecutionEntity execution = commandContext.getExecutionEntityManager().findById(executionId);
    if (execution == null) {
        throw new ActivitiObjectNotFoundException("No execution found for id '" + executionId + "'", ExecutionEntity.class);
    }
    if (!(execution.getCurrentFlowElement() instanceof AdhocSubProcess)) {
        throw new ActivitiException("The current flow element of the requested execution is not an ad-hoc sub process");
    }
    FlowNode foundNode = null;
    AdhocSubProcess adhocSubProcess = (AdhocSubProcess) execution.getCurrentFlowElement();
    // if sequential ordering, only one child execution can be active
    if (adhocSubProcess.hasSequentialOrdering()) {
        if (execution.getExecutions().size() > 0) {
            throw new ActivitiException("Sequential ad-hoc sub process already has an active execution");
        }
    }
    for (FlowElement flowElement : adhocSubProcess.getFlowElements()) {
        if (activityId.equals(flowElement.getId()) && flowElement instanceof FlowNode) {
            FlowNode flowNode = (FlowNode) flowElement;
            if (flowNode.getIncomingFlows().size() == 0) {
                foundNode = flowNode;
            }
        }
    }
    if (foundNode == null) {
        throw new ActivitiException("The requested activity with id " + activityId + " can not be enabled");
    }
    ExecutionEntity activityExecution = Context.getCommandContext().getExecutionEntityManager().createChildExecution(execution);
    activityExecution.setCurrentFlowElement(foundNode);
    Context.getAgenda().planContinueProcessOperation(activityExecution);
    return activityExecution;
}
Also used : AdhocSubProcess(org.activiti.bpmn.model.AdhocSubProcess) ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) FlowElement(org.activiti.bpmn.model.FlowElement) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) FlowNode(org.activiti.bpmn.model.FlowNode)

Example 4 with AdhocSubProcess

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

the class BpmnXMLConverter method createXML.

protected void createXML(FlowElement flowElement, BpmnModel model, XMLStreamWriter xtw) throws Exception {
    if (flowElement instanceof SubProcess) {
        SubProcess subProcess = (SubProcess) flowElement;
        if (flowElement instanceof Transaction) {
            xtw.writeStartElement(ELEMENT_TRANSACTION);
        } else if (flowElement instanceof AdhocSubProcess) {
            xtw.writeStartElement(ELEMENT_ADHOC_SUBPROCESS);
        } else {
            xtw.writeStartElement(BPMN2_PREFIX, ELEMENT_SUBPROCESS, BPMN2_NAMESPACE);
        }
        xtw.writeAttribute(ATTRIBUTE_ID, subProcess.getId());
        if (StringUtils.isNotEmpty(subProcess.getName())) {
            xtw.writeAttribute(ATTRIBUTE_NAME, subProcess.getName());
        } else {
            xtw.writeAttribute(ATTRIBUTE_NAME, "subProcess");
        }
        if (subProcess instanceof EventSubProcess) {
            xtw.writeAttribute(ATTRIBUTE_TRIGGERED_BY, ATTRIBUTE_VALUE_TRUE);
        } else if (!(subProcess instanceof Transaction)) {
            if (subProcess.isAsynchronous()) {
                BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, ATTRIBUTE_VALUE_TRUE, xtw);
                if (subProcess.isNotExclusive()) {
                    BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_EXCLUSIVE, ATTRIBUTE_VALUE_FALSE, xtw);
                }
            }
        } else if (subProcess instanceof AdhocSubProcess) {
            AdhocSubProcess adhocSubProcess = (AdhocSubProcess) subProcess;
            BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_CANCEL_REMAINING_INSTANCES, String.valueOf(adhocSubProcess.isCancelRemainingInstances()), xtw);
            if (StringUtils.isNotEmpty(adhocSubProcess.getOrdering())) {
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_ORDERING, adhocSubProcess.getOrdering(), xtw);
            }
        }
        if (StringUtils.isNotEmpty(subProcess.getDocumentation())) {
            xtw.writeStartElement(BPMN2_PREFIX, ELEMENT_DOCUMENTATION, BPMN2_NAMESPACE);
            xtw.writeCharacters(subProcess.getDocumentation());
            xtw.writeEndElement();
        }
        boolean didWriteExtensionStartElement = ActivitiListenerExport.writeListeners(subProcess, false, xtw);
        didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(subProcess, didWriteExtensionStartElement, model.getNamespaces(), xtw);
        if (didWriteExtensionStartElement) {
            // closing extensions element
            xtw.writeEndElement();
        }
        MultiInstanceExport.writeMultiInstance(subProcess, xtw);
        if (subProcess instanceof AdhocSubProcess) {
            AdhocSubProcess adhocSubProcess = (AdhocSubProcess) subProcess;
            if (StringUtils.isNotEmpty(adhocSubProcess.getCompletionCondition())) {
                xtw.writeStartElement(ELEMENT_COMPLETION_CONDITION);
                xtw.writeCData(adhocSubProcess.getCompletionCondition());
                xtw.writeEndElement();
            }
        }
        for (FlowElement subElement : subProcess.getFlowElements()) {
            createXML(subElement, model, xtw);
        }
        for (Artifact artifact : subProcess.getArtifacts()) {
            createXML(artifact, model, xtw);
        }
        xtw.writeEndElement();
    } else {
        BaseBpmnXMLConverter converter = convertersToXMLMap.get(flowElement.getClass());
        if (converter == null) {
            throw new XMLException("No converter for " + flowElement.getClass() + " found");
        }
        converter.convertToXML(xtw, flowElement, model);
    }
}
Also used : AdhocSubProcess(org.activiti.bpmn.model.AdhocSubProcess) EventSubProcess(org.activiti.bpmn.model.EventSubProcess) SubProcess(org.activiti.bpmn.model.SubProcess) AdhocSubProcess(org.activiti.bpmn.model.AdhocSubProcess) XMLException(org.activiti.bpmn.exceptions.XMLException) Transaction(org.activiti.bpmn.model.Transaction) FlowElement(org.activiti.bpmn.model.FlowElement) EventSubProcess(org.activiti.bpmn.model.EventSubProcess) Artifact(org.activiti.bpmn.model.Artifact)

Example 5 with AdhocSubProcess

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

the class TakeOutgoingSequenceFlowsOperation method handleAdhocSubProcess.

protected void handleAdhocSubProcess(FlowNode flowNode) {
    boolean completeAdhocSubProcess = false;
    AdhocSubProcess adhocSubProcess = (AdhocSubProcess) flowNode.getParentContainer();
    if (adhocSubProcess.getCompletionCondition() != null) {
        Expression expression = Context.getProcessEngineConfiguration().getExpressionManager().createExpression(adhocSubProcess.getCompletionCondition());
        Condition condition = new UelExpressionCondition(expression);
        if (condition.evaluate(adhocSubProcess.getId(), execution)) {
            completeAdhocSubProcess = true;
        }
    }
    if (flowNode.getOutgoingFlows().size() > 0) {
        leaveFlowNode(flowNode);
    } else {
        commandContext.getExecutionEntityManager().deleteExecutionAndRelatedData(execution, null);
    }
    if (completeAdhocSubProcess) {
        boolean endAdhocSubProcess = true;
        if (!adhocSubProcess.isCancelRemainingInstances()) {
            List<ExecutionEntity> childExecutions = commandContext.getExecutionEntityManager().findChildExecutionsByParentExecutionId(execution.getParentId());
            for (ExecutionEntity executionEntity : childExecutions) {
                if (!executionEntity.getId().equals(execution.getId())) {
                    endAdhocSubProcess = false;
                    break;
                }
            }
        }
        if (endAdhocSubProcess) {
            Context.getAgenda().planEndExecutionOperation(execution.getParent());
        }
    }
}
Also used : Condition(org.activiti.engine.impl.Condition) UelExpressionCondition(org.activiti.engine.impl.el.UelExpressionCondition) AdhocSubProcess(org.activiti.bpmn.model.AdhocSubProcess) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) Expression(org.activiti.engine.delegate.Expression) UelExpressionCondition(org.activiti.engine.impl.el.UelExpressionCondition)

Aggregations

AdhocSubProcess (org.activiti.bpmn.model.AdhocSubProcess)7 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)4 EventSubProcess (org.activiti.bpmn.model.EventSubProcess)3 FlowElement (org.activiti.bpmn.model.FlowElement)3 SubProcess (org.activiti.bpmn.model.SubProcess)3 ActivitiException (org.activiti.engine.ActivitiException)3 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)3 ArrayList (java.util.ArrayList)2 XMLException (org.activiti.bpmn.exceptions.XMLException)2 FlowNode (org.activiti.bpmn.model.FlowNode)2 Transaction (org.activiti.bpmn.model.Transaction)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 Artifact (org.activiti.bpmn.model.Artifact)1 Association (org.activiti.bpmn.model.Association)1 BaseElement (org.activiti.bpmn.model.BaseElement)1 BpmnModel (org.activiti.bpmn.model.BpmnModel)1 Pool (org.activiti.bpmn.model.Pool)1 Process (org.activiti.bpmn.model.Process)1