Search in sources :

Example 1 with ScriptTypeValue

use of org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeValue in project kie-wb-common by kiegroup.

the class SequenceFlowConverter method toFlowElement.

public SequenceFlowPropertyWriter toFlowElement(Edge<?, ?> edge, ElementContainer process) {
    ViewConnector<SequenceFlow> content = (ViewConnector<SequenceFlow>) edge.getContent();
    SequenceFlow definition = content.getDefinition();
    org.eclipse.bpmn2.SequenceFlow seq = bpmn2.createSequenceFlow();
    SequenceFlowPropertyWriter p = propertyWriterFactory.of(seq);
    seq.setId(edge.getUUID());
    BasePropertyWriter pSrc = process.getChildElement(edge.getSourceNode().getUUID());
    BasePropertyWriter pTgt = process.getChildElement(edge.getTargetNode().getUUID());
    p.setSource(pSrc);
    p.setTarget(pTgt);
    seq.setId(edge.getUUID());
    seq.setName(definition.getGeneral().getName().getValue());
    p.setConnection(content);
    SequenceFlowExecutionSet executionSet = definition.getExecutionSet();
    ScriptTypeValue scriptTypeValue = executionSet.getConditionExpression().getValue();
    String language = scriptTypeValue.getLanguage();
    String script = scriptTypeValue.getScript();
    if (script != null) {
        FormalExpression formalExpression = bpmn2.createFormalExpression();
        String uri = Scripts.scriptLanguageToUri(language);
        formalExpression.setLanguage(uri);
        formalExpression.setBody(asCData(script));
        seq.setConditionExpression(formalExpression);
    }
    process.addChildElement(p);
    process.addChildEdge(p.getEdge());
    return p;
}
Also used : BasePropertyWriter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.BasePropertyWriter) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) SequenceFlow(org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow) Factories.bpmn2(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.Factories.bpmn2) SequenceFlowPropertyWriter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.SequenceFlowPropertyWriter) SequenceFlowExecutionSet(org.kie.workbench.common.stunner.bpmn.definition.property.connectors.SequenceFlowExecutionSet) FormalExpression(org.eclipse.bpmn2.FormalExpression) ScriptTypeValue(org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeValue)

Example 2 with ScriptTypeValue

use of org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeValue in project kie-wb-common by kiegroup.

the class Scripts method setOnExitAction.

public static void setOnExitAction(FlowElement flowElement, OnExitAction onExitAction) {
    ScriptTypeListValue value = onExitAction.getValue();
    for (ScriptTypeValue scriptTypeValue : value.getValues()) {
        if (scriptTypeValue.getScript() == null && scriptTypeValue.getScript().isEmpty()) {
            continue;
        }
        OnExitScriptType script = droolsFactory.createOnExitScriptType();
        script.setScript(asCData(scriptTypeValue.getScript()));
        String scriptLanguage = Scripts.scriptLanguageToUri(scriptTypeValue.getLanguage());
        script.setScriptFormat(scriptLanguage);
        addExtensionValue(flowElement, DOCUMENT_ROOT__ON_EXIT_SCRIPT, script);
    }
}
Also used : OnExitScriptType(org.jboss.drools.OnExitScriptType) ScriptTypeListValue(org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeListValue) ScriptTypeValue(org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeValue)

Example 3 with ScriptTypeValue

use of org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeValue in project kie-wb-common by kiegroup.

the class Bpmn2JsonMarshaller method setAdHocSubProcessProperties.

private void setAdHocSubProcessProperties(final AdHocSubProcess subProcess, final Map<String, Object> properties) {
    if (subProcess.getOrdering().equals(AdHocOrdering.PARALLEL)) {
        properties.put(ADHOCORDERING, "Parallel");
    } else if (subProcess.getOrdering().equals(AdHocOrdering.SEQUENTIAL)) {
        properties.put(ADHOCORDERING, "Sequential");
    } else {
        // default to parallel
        properties.put(ADHOCORDERING, "Parallel");
    }
    if (subProcess.getCompletionCondition() != null) {
        final FormalExpression expression = (FormalExpression) subProcess.getCompletionCondition();
        final String language = Utils.getScriptLanguage(expression.getLanguage());
        final String script = expression.getBody().replaceAll("\n", "\\\\n");
        final ScriptTypeValue value = new ScriptTypeValue(language, script);
        properties.put(ADHOCCOMPLETIONCONDITION, new ScriptTypeTypeSerializer().serialize(value));
    }
}
Also used : ScriptTypeTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeTypeSerializer) FormalExpression(org.eclipse.bpmn2.FormalExpression) ScriptTypeValue(org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeValue)

Example 4 with ScriptTypeValue

use of org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeValue in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method applyOnEntryActions.

protected void applyOnEntryActions(BaseElement element, Map<String, String> properties) {
    if (properties.get("onentryactions") != null && properties.get("onentryactions").length() > 0) {
        ScriptTypeListValue onEntryActions = new ScriptTypeListTypeSerializer().parse(properties.get("onentryactions"));
        if (!onEntryActions.isEmpty()) {
            ScriptTypeValue onEntryAction = onEntryActions.getValues().get(0);
            if (onEntryAction.getScript() != null && !onEntryAction.getScript().isEmpty()) {
                OnEntryScriptType onEntryScript = DroolsFactory.eINSTANCE.createOnEntryScriptType();
                onEntryScript.setScript(wrapInCDATABlock(onEntryAction.getScript()));
                String scriptLanguage = Utils.getScriptLanguageFormat(onEntryAction.getLanguage());
                if (scriptLanguage == null) {
                    // default to java
                    scriptLanguage = "http://www.java.com/java";
                }
                onEntryScript.setScriptFormat(scriptLanguage);
                if (element.getExtensionValues() == null || element.getExtensionValues().size() < 1) {
                    ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
                    element.getExtensionValues().add(extensionElement);
                }
                FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry((Internal) DroolsPackage.Literals.DOCUMENT_ROOT__ON_ENTRY_SCRIPT, onEntryScript);
                element.getExtensionValues().get(0).getValue().add(extensionElementEntry);
            }
        }
    }
}
Also used : FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) OnEntryScriptType(org.jboss.drools.OnEntryScriptType) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) ExtensionAttributeValue(org.eclipse.bpmn2.ExtensionAttributeValue) ScriptTypeListTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeListTypeSerializer) ScriptTypeListValue(org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeListValue) ScriptTypeValue(org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeValue)

Example 5 with ScriptTypeValue

use of org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeValue in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method applySequenceFlowCondition.

protected void applySequenceFlowCondition(SequenceFlow sequenceFlow, Map<String, String> properties) {
    String conditionExpression = properties.get("conditionexpression");
    if (conditionExpression != null && !conditionExpression.isEmpty()) {
        ScriptTypeValue value = new ScriptTypeTypeSerializer().parse(conditionExpression);
        if (value.getScript() != null && !value.getScript().isEmpty()) {
            FormalExpression expr = Bpmn2Factory.eINSTANCE.createFormalExpression();
            expr.setBody(wrapInCDATABlock(value.getScript()));
            if (value.getLanguage() != null && !value.getLanguage().isEmpty()) {
                String languageFormat = Utils.getScriptLanguageFormat(value.getLanguage());
                if (languageFormat == null) {
                    // default to mvel
                    languageFormat = "http://www.mvel.org/2.0";
                }
                expr.setLanguage(languageFormat);
            }
            sequenceFlow.setConditionExpression(expr);
        }
    }
}
Also used : ScriptTypeTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeTypeSerializer) FormalExpression(org.eclipse.bpmn2.FormalExpression) ScriptTypeValue(org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeValue)

Aggregations

ScriptTypeValue (org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeValue)23 ScriptTypeListValue (org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeListValue)9 Test (org.junit.Test)7 FormalExpression (org.eclipse.bpmn2.FormalExpression)6 ScriptTypeTypeSerializer (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeTypeSerializer)6 ExtensionAttributeValue (org.eclipse.bpmn2.ExtensionAttributeValue)4 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)4 OnEntryScriptType (org.jboss.drools.OnEntryScriptType)3 OnExitScriptType (org.jboss.drools.OnExitScriptType)3 FieldEditorPresenterBaseTest (org.kie.workbench.common.stunner.bpmn.client.forms.util.FieldEditorPresenterBaseTest)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 EList (org.eclipse.emf.common.util.EList)2 SimpleFeatureMapEntry (org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry)2 ScriptTypeListTypeSerializer (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeListTypeSerializer)2 Before (org.junit.Before)1 Factories.bpmn2 (org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.Factories.bpmn2)1 BasePropertyWriter (org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.BasePropertyWriter)1 SequenceFlowPropertyWriter (org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.SequenceFlowPropertyWriter)1 SequenceFlow (org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow)1