Search in sources :

Example 11 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 applyScriptTaskProperties.

protected void applyScriptTaskProperties(ScriptTask scriptTask, Map<String, String> properties) {
    String scriptTypeStr = properties.get("script");
    if (scriptTypeStr != null && !scriptTypeStr.isEmpty()) {
        ScriptTypeValue value = new ScriptTypeTypeSerializer().parse(scriptTypeStr);
        if (value.getScript() != null && !value.getScript().isEmpty()) {
            scriptTask.setScript(wrapInCDATABlock(value.getScript()));
        }
        String languageFormat = Utils.getScriptLanguageFormat(value.getLanguage());
        if (languageFormat == null) {
            // default to java
            languageFormat = "http://www.java.com/java";
        }
        scriptTask.setScriptFormat(languageFormat);
    }
}
Also used : ScriptTypeTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeTypeSerializer) ScriptTypeValue(org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeValue)

Example 12 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 applyAdHocSubProcessProperties.

protected void applyAdHocSubProcessProperties(AdHocSubProcess ahsp, Map<String, String> properties) {
    if (properties.get("adhocordering") != null) {
        if (properties.get("adhocordering").equals("Parallel")) {
            ahsp.setOrdering(AdHocOrdering.PARALLEL);
        } else {
            ahsp.setOrdering(AdHocOrdering.SEQUENTIAL);
        }
    }
    String adHocCompletionCondition = properties.get("adhoccompletioncondition");
    if (adHocCompletionCondition != null) {
        ScriptTypeValue value = new ScriptTypeTypeSerializer().parse(adHocCompletionCondition);
        FormalExpression completionConditionExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
        String completionExpression = value.getScript();
        if (completionExpression == null || completionExpression.isEmpty()) {
            // default to autocomplete
            completionExpression = "autocomplete";
        }
        completionConditionExpression.setBody(wrapInCDATABlock(completionExpression));
        String languageFormat = Utils.getScriptLanguageFormat(value.getLanguage());
        if (languageFormat == null) {
            // default to mvel
            languageFormat = "mvel";
        }
        completionConditionExpression.setLanguage(languageFormat);
        ahsp.setCompletionCondition(completionConditionExpression);
    }
}
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 13 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 applyOnExitActions.

protected void applyOnExitActions(BaseElement element, Map<String, String> properties) {
    if (properties.get("onexitactions") != null && properties.get("onexitactions").length() > 0) {
        ScriptTypeListValue onExitActions = new ScriptTypeListTypeSerializer().parse(properties.get("onexitactions"));
        if (!onExitActions.isEmpty()) {
            ScriptTypeValue onExitAction = onExitActions.getValues().get(0);
            if (onExitAction.getScript() != null && !onExitAction.getScript().isEmpty()) {
                OnExitScriptType onExitScript = DroolsFactory.eINSTANCE.createOnExitScriptType();
                onExitScript.setScript(wrapInCDATABlock(onExitAction.getScript()));
                String scriptLanguage = Utils.getScriptLanguageFormat(onExitAction.getLanguage());
                if (scriptLanguage == null) {
                    // default to java
                    scriptLanguage = "http://www.java.com/java";
                }
                onExitScript.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_EXIT_SCRIPT, onExitScript);
                element.getExtensionValues().get(0).getValue().add(extensionElementEntry);
            }
        }
    }
}
Also used : FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) 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) 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 14 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 applyConditionalEventProperties.

protected void applyConditionalEventProperties(ConditionalEventDefinition event, Map<String, String> properties) {
    FormalExpression conditionExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
    ScriptTypeValue value = new ScriptTypeTypeSerializer().parse(properties.get("conditionexpression"));
    if (value.getLanguage() != null && !value.getLanguage().isEmpty()) {
        String languageFormat = Utils.getScriptLanguageFormat(value.getLanguage());
        if (languageFormat == null) {
            // default to drools
            languageFormat = "http://www.jboss.org/drools/rule";
        }
        conditionExpression.setLanguage(languageFormat);
    }
    if (value.getScript() != null && !value.getScript().isEmpty()) {
        String scriptStr = value.getScript().replaceAll("\\\\n", "\n");
        conditionExpression.setBody(wrapInCDATABlock(scriptStr));
    }
    event.setCondition(conditionExpression);
}
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 15 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 setOnEntryAction.

public static void setOnEntryAction(FlowElement flowElement, OnEntryAction onEntryAction) {
    ScriptTypeListValue value = onEntryAction.getValue();
    for (ScriptTypeValue scriptTypeValue : value.getValues()) {
        if (scriptTypeValue.getScript() == null && scriptTypeValue.getScript().isEmpty()) {
            continue;
        }
        OnEntryScriptType script = droolsFactory.createOnEntryScriptType();
        script.setScript(asCData(scriptTypeValue.getScript()));
        String scriptLanguage = Scripts.scriptLanguageToUri(scriptTypeValue.getLanguage());
        script.setScriptFormat(scriptLanguage);
        addExtensionValue(flowElement, DOCUMENT_ROOT__ON_ENTRY_SCRIPT, script);
    }
}
Also used : OnEntryScriptType(org.jboss.drools.OnEntryScriptType) ScriptTypeListValue(org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeListValue) 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