Search in sources :

Example 16 with Element

use of org.camunda.bpm.engine.impl.util.xml.Element in project camunda-bpm-platform by camunda.

the class ProcessesXmlParse method parseProcessArchive.

/**
 * parse a <code>&lt;process-archive .../&gt;</code> element and add it to the list of parsed elements
 */
protected void parseProcessArchive(Element element, List<ProcessArchiveXml> parsedProcessArchives) {
    ProcessArchiveXmlImpl processArchive = new ProcessArchiveXmlImpl();
    processArchive.setName(element.attribute(NAME));
    processArchive.setTenantId(element.attribute(TENANT_ID));
    List<String> processResourceNames = new ArrayList<String>();
    Map<String, String> properties = new HashMap<String, String>();
    for (Element childElement : element.elements()) {
        if (PROCESS_ENGINE.equals(childElement.getTagName())) {
            processArchive.setProcessEngineName(childElement.getText());
        } else if (PROCESS.equals(childElement.getTagName()) || RESOURCE.equals(childElement.getTagName())) {
            processResourceNames.add(childElement.getText());
        } else if (PROPERTIES.equals(childElement.getTagName())) {
            parseProperties(childElement, properties);
        }
    }
    // set properties
    processArchive.setProperties(properties);
    // add collected resource names.
    processArchive.setProcessResourceNames(processResourceNames);
    // add process archive to list of parsed archives.
    parsedProcessArchives.add(processArchive);
}
Also used : HashMap(java.util.HashMap) Element(org.camunda.bpm.engine.impl.util.xml.Element) ArrayList(java.util.ArrayList)

Example 17 with Element

use of org.camunda.bpm.engine.impl.util.xml.Element in project camunda-bpm-platform by camunda.

the class BpmnParse method parseTaskListeners.

protected void parseTaskListeners(Element userTaskElement, TaskDefinition taskDefinition) {
    Element extentionsElement = userTaskElement.element("extensionElements");
    if (extentionsElement != null) {
        List<Element> taskListenerElements = extentionsElement.elementsNS(CAMUNDA_BPMN_EXTENSIONS_NS, "taskListener");
        for (Element taskListenerElement : taskListenerElements) {
            String eventName = taskListenerElement.attribute("event");
            if (eventName != null) {
                if (TaskListener.EVENTNAME_CREATE.equals(eventName) || TaskListener.EVENTNAME_ASSIGNMENT.equals(eventName) || TaskListener.EVENTNAME_COMPLETE.equals(eventName) || TaskListener.EVENTNAME_DELETE.equals(eventName)) {
                    TaskListener taskListener = parseTaskListener(taskListenerElement);
                    taskDefinition.addTaskListener(eventName, taskListener);
                } else {
                    addError("Attribute 'event' must be one of {create|assignment|complete|delete}", userTaskElement);
                }
            } else {
                addError("Attribute 'event' is mandatory on taskListener", userTaskElement);
            }
        }
    }
}
Also used : Element(org.camunda.bpm.engine.impl.util.xml.Element) ScriptTaskListener(org.camunda.bpm.engine.impl.task.listener.ScriptTaskListener) ExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.ExpressionTaskListener) ClassDelegateTaskListener(org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener) TaskListener(org.camunda.bpm.engine.delegate.TaskListener) DelegateExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener)

Example 18 with Element

use of org.camunda.bpm.engine.impl.util.xml.Element in project camunda-bpm-platform by camunda.

the class BpmnParse method parseLaneSets.

protected void parseLaneSets(Element parentElement, ProcessDefinitionEntity processDefinition) {
    List<Element> laneSets = parentElement.elements("laneSet");
    if (laneSets != null && laneSets.size() > 0) {
        for (Element laneSetElement : laneSets) {
            LaneSet newLaneSet = new LaneSet();
            newLaneSet.setId(laneSetElement.attribute("id"));
            newLaneSet.setName(laneSetElement.attribute("name"));
            parseLanes(laneSetElement, newLaneSet);
            // Finally, add the set
            processDefinition.addLaneSet(newLaneSet);
        }
    }
}
Also used : Element(org.camunda.bpm.engine.impl.util.xml.Element)

Example 19 with Element

use of org.camunda.bpm.engine.impl.util.xml.Element in project camunda-bpm-platform by camunda.

the class BpmnParse method parseScopeStartEvent.

protected void parseScopeStartEvent(ActivityImpl startEventActivity, Element startEventElement, Element parentElement, ActivityImpl scopeActivity) {
    Properties scopeProperties = scopeActivity.getProperties();
    // set this as the scope's initial
    if (!scopeProperties.contains(BpmnProperties.INITIAL_ACTIVITY)) {
        scopeProperties.set(BpmnProperties.INITIAL_ACTIVITY, startEventActivity);
    } else {
        addError("multiple start events not supported for subprocess", startEventElement);
    }
    Element errorEventDefinition = startEventElement.element(ERROR_EVENT_DEFINITION);
    Element messageEventDefinition = startEventElement.element(MESSAGE_EVENT_DEFINITION);
    Element signalEventDefinition = startEventElement.element(SIGNAL_EVENT_DEFINITION);
    Element timerEventDefinition = startEventElement.element(TIMER_EVENT_DEFINITION);
    Element compensateEventDefinition = startEventElement.element(COMPENSATE_EVENT_DEFINITION);
    Element escalationEventDefinitionElement = startEventElement.element(ESCALATION_EVENT_DEFINITION);
    Element conditionalEventDefinitionElement = startEventElement.element(CONDITIONAL_EVENT_DEFINITION);
    if (scopeActivity.isTriggeredByEvent()) {
        // event subprocess
        EventSubProcessStartEventActivityBehavior behavior = new EventSubProcessStartEventActivityBehavior();
        // parse isInterrupting
        String isInterruptingAttr = startEventElement.attribute(INTERRUPTING);
        boolean isInterrupting = isInterruptingAttr.equalsIgnoreCase(TRUE);
        if (isInterrupting) {
            scopeActivity.setActivityStartBehavior(ActivityStartBehavior.INTERRUPT_EVENT_SCOPE);
        } else {
            scopeActivity.setActivityStartBehavior(ActivityStartBehavior.CONCURRENT_IN_FLOW_SCOPE);
        }
        // the event scope of the start event is the flow scope of the event subprocess
        startEventActivity.setEventScope(scopeActivity.getFlowScope());
        if (errorEventDefinition != null) {
            if (!isInterrupting) {
                addError("error start event of event subprocess must be interrupting", startEventElement);
            }
            parseErrorStartEventDefinition(errorEventDefinition, startEventActivity);
        } else if (messageEventDefinition != null) {
            startEventActivity.getProperties().set(BpmnProperties.TYPE, ActivityTypes.START_EVENT_MESSAGE);
            EventSubscriptionDeclaration messageStartEventSubscriptionDeclaration = parseMessageEventDefinition(messageEventDefinition);
            parseEventDefinitionForSubprocess(messageStartEventSubscriptionDeclaration, startEventActivity, messageEventDefinition);
        } else if (signalEventDefinition != null) {
            startEventActivity.getProperties().set(BpmnProperties.TYPE, ActivityTypes.START_EVENT_SIGNAL);
            EventSubscriptionDeclaration eventSubscriptionDeclaration = parseSignalEventDefinition(signalEventDefinition, false);
            parseEventDefinitionForSubprocess(eventSubscriptionDeclaration, startEventActivity, signalEventDefinition);
        } else if (timerEventDefinition != null) {
            parseTimerStartEventDefinitionForEventSubprocess(timerEventDefinition, startEventActivity, isInterrupting);
        } else if (compensateEventDefinition != null) {
            parseCompensationEventSubprocess(startEventActivity, startEventElement, scopeActivity, compensateEventDefinition);
        } else if (escalationEventDefinitionElement != null) {
            startEventActivity.getProperties().set(BpmnProperties.TYPE, ActivityTypes.START_EVENT_ESCALATION);
            EscalationEventDefinition escalationEventDefinition = createEscalationEventDefinitionForEscalationHandler(escalationEventDefinitionElement, scopeActivity, isInterrupting);
            addEscalationEventDefinition(startEventActivity.getEventScope(), escalationEventDefinition, escalationEventDefinitionElement);
        } else if (conditionalEventDefinitionElement != null) {
            final ConditionalEventDefinition conditionalEventDef = parseConditionalStartEventForEventSubprocess(conditionalEventDefinitionElement, startEventActivity, isInterrupting);
            behavior = new EventSubProcessStartConditionalEventActivityBehavior(conditionalEventDef);
        } else {
            addError("start event of event subprocess must be of type 'error', 'message', 'timer', 'signal', 'compensation' or 'escalation'", startEventElement);
        }
        startEventActivity.setActivityBehavior(behavior);
    } else {
        // "regular" subprocess
        Element conditionalEventDefinition = startEventElement.element(CONDITIONAL_EVENT_DEFINITION);
        if (conditionalEventDefinition != null) {
            addError("conditionalEventDefinition is not allowed on start event within a subprocess", conditionalEventDefinition);
        }
        if (timerEventDefinition != null) {
            addError("timerEventDefinition is not allowed on start event within a subprocess", timerEventDefinition);
        }
        if (escalationEventDefinitionElement != null) {
            addError("escalationEventDefinition is not allowed on start event within a subprocess", escalationEventDefinitionElement);
        }
        if (compensateEventDefinition != null) {
            addError("compensateEventDefinition is not allowed on start event within a subprocess", compensateEventDefinition);
        }
        if (errorEventDefinition != null) {
            addError("errorEventDefinition only allowed on start event if subprocess is an event subprocess", errorEventDefinition);
        }
        if (messageEventDefinition != null) {
            addError("messageEventDefinition only allowed on start event if subprocess is an event subprocess", messageEventDefinition);
        }
        if (signalEventDefinition != null) {
            addError("signalEventDefintion only allowed on start event if subprocess is an event subprocess", messageEventDefinition);
        }
        startEventActivity.setActivityBehavior(new NoneStartEventActivityBehavior());
    }
}
Also used : Element(org.camunda.bpm.engine.impl.util.xml.Element) Properties(org.camunda.bpm.engine.impl.core.model.Properties) BpmnProperties(org.camunda.bpm.engine.impl.bpmn.helper.BpmnProperties)

Example 20 with Element

use of org.camunda.bpm.engine.impl.util.xml.Element in project camunda-bpm-platform by camunda.

the class BpmnParse method parseMultiInstanceLoopCharacteristics.

/**
 * Parses loopCharacteristics (standardLoop/Multi-instance) of an activity, if
 * any is defined.
 */
public ScopeImpl parseMultiInstanceLoopCharacteristics(Element activityElement, ScopeImpl scope) {
    Element miLoopCharacteristics = activityElement.element("multiInstanceLoopCharacteristics");
    if (miLoopCharacteristics == null) {
        return null;
    } else {
        String id = activityElement.attribute("id");
        LOG.parsingElement("mi body for activity", id);
        id = getIdForMiBody(id);
        ActivityImpl miBodyScope = scope.createActivity(id);
        setActivityAsyncDelegates(miBodyScope);
        miBodyScope.setProperty(PROPERTYNAME_TYPE, ActivityTypes.MULTI_INSTANCE_BODY);
        miBodyScope.setScope(true);
        boolean isSequential = parseBooleanAttribute(miLoopCharacteristics.attribute("isSequential"), false);
        MultiInstanceActivityBehavior behavior = null;
        if (isSequential) {
            behavior = new SequentialMultiInstanceActivityBehavior();
        } else {
            behavior = new ParallelMultiInstanceActivityBehavior();
        }
        miBodyScope.setActivityBehavior(behavior);
        // loopCardinality
        Element loopCardinality = miLoopCharacteristics.element("loopCardinality");
        if (loopCardinality != null) {
            String loopCardinalityText = loopCardinality.getText();
            if (loopCardinalityText == null || "".equals(loopCardinalityText)) {
                addError("loopCardinality must be defined for a multiInstanceLoopCharacteristics definition ", miLoopCharacteristics);
            }
            behavior.setLoopCardinalityExpression(expressionManager.createExpression(loopCardinalityText));
        }
        // completionCondition
        Element completionCondition = miLoopCharacteristics.element("completionCondition");
        if (completionCondition != null) {
            String completionConditionText = completionCondition.getText();
            behavior.setCompletionConditionExpression(expressionManager.createExpression(completionConditionText));
        }
        // activiti:collection
        String collection = miLoopCharacteristics.attributeNS(CAMUNDA_BPMN_EXTENSIONS_NS, "collection");
        if (collection != null) {
            if (collection.contains("{")) {
                behavior.setCollectionExpression(expressionManager.createExpression(collection));
            } else {
                behavior.setCollectionVariable(collection);
            }
        }
        // loopDataInputRef
        Element loopDataInputRef = miLoopCharacteristics.element("loopDataInputRef");
        if (loopDataInputRef != null) {
            String loopDataInputRefText = loopDataInputRef.getText();
            if (loopDataInputRefText != null) {
                if (loopDataInputRefText.contains("{")) {
                    behavior.setCollectionExpression(expressionManager.createExpression(loopDataInputRefText));
                } else {
                    behavior.setCollectionVariable(loopDataInputRefText);
                }
            }
        }
        // activiti:elementVariable
        String elementVariable = miLoopCharacteristics.attributeNS(CAMUNDA_BPMN_EXTENSIONS_NS, "elementVariable");
        if (elementVariable != null) {
            behavior.setCollectionElementVariable(elementVariable);
        }
        // dataInputItem
        Element inputDataItem = miLoopCharacteristics.element("inputDataItem");
        if (inputDataItem != null) {
            String inputDataItemName = inputDataItem.attribute("name");
            behavior.setCollectionElementVariable(inputDataItemName);
        }
        // Validation
        if (behavior.getLoopCardinalityExpression() == null && behavior.getCollectionExpression() == null && behavior.getCollectionVariable() == null) {
            addError("Either loopCardinality or loopDataInputRef/activiti:collection must been set", miLoopCharacteristics);
        }
        // Validation
        if (behavior.getCollectionExpression() == null && behavior.getCollectionVariable() == null && behavior.getCollectionElementVariable() != null) {
            addError("LoopDataInputRef/activiti:collection must be set when using inputDataItem or activiti:elementVariable", miLoopCharacteristics);
        }
        for (BpmnParseListener parseListener : parseListeners) {
            parseListener.parseMultiInstanceLoopCharacteristics(activityElement, miLoopCharacteristics, miBodyScope);
        }
        return miBodyScope;
    }
}
Also used : Element(org.camunda.bpm.engine.impl.util.xml.Element)

Aggregations

Element (org.camunda.bpm.engine.impl.util.xml.Element)60 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 BpmnParseException (org.camunda.bpm.engine.BpmnParseException)4 ExecutableScript (org.camunda.bpm.engine.impl.scripting.ExecutableScript)4 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)3 ProcessEngineXml (org.camunda.bpm.container.impl.metadata.spi.ProcessEngineXml)2 TaskListener (org.camunda.bpm.engine.delegate.TaskListener)2 Condition (org.camunda.bpm.engine.impl.Condition)2 IoMapping (org.camunda.bpm.engine.impl.core.variable.mapping.IoMapping)2 ParameterValueProvider (org.camunda.bpm.engine.impl.core.variable.mapping.value.ParameterValueProvider)2 ActivityBehavior (org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior)2 ScriptCondition (org.camunda.bpm.engine.impl.scripting.ScriptCondition)2 ClassDelegateTaskListener (org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener)2 DelegateExpressionTaskListener (org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener)2 ExpressionTaskListener (org.camunda.bpm.engine.impl.task.listener.ExpressionTaskListener)2 ScriptTaskListener (org.camunda.bpm.engine.impl.task.listener.ScriptTaskListener)2 LinkedHashMap (java.util.LinkedHashMap)1 TreeMap (java.util.TreeMap)1 ProcessArchiveXml (org.camunda.bpm.application.impl.metadata.spi.ProcessArchiveXml)1