Search in sources :

Example 1 with OnExitScriptType

use of org.jboss.drools.OnExitScriptType 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 2 with OnExitScriptType

use of org.jboss.drools.OnExitScriptType 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 3 with OnExitScriptType

use of org.jboss.drools.OnExitScriptType in project kie-wb-common by kiegroup.

the class Bpmn2JsonMarshaller method getOnExitActions.

public ScriptTypeListValue getOnExitActions(final List<ExtensionAttributeValue> extensionValues) {
    final ScriptTypeListValue onExitActions = new ScriptTypeListValue();
    ScriptTypeValue onExitAction;
    if (extensionValues != null && !extensionValues.isEmpty()) {
        for (ExtensionAttributeValue extattrval : extensionValues) {
            FeatureMap extensionElements = extattrval.getValue();
            @SuppressWarnings("unchecked") List<OnExitScriptType> onExitExtensions = (List<OnExitScriptType>) extensionElements.get(DroolsPackage.Literals.DOCUMENT_ROOT__ON_EXIT_SCRIPT, true);
            for (OnExitScriptType onExitScript : onExitExtensions) {
                onExitAction = getOnExitAction(onExitScript);
                if (onExitAction.getScript() != null && !onExitAction.getScript().isEmpty()) {
                    onExitActions.addValue(onExitAction);
                }
            }
        }
    }
    return onExitActions;
}
Also used : FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList) ExtensionAttributeValue(org.eclipse.bpmn2.ExtensionAttributeValue) 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 4 with OnExitScriptType

use of org.jboss.drools.OnExitScriptType in project jbpm by kiegroup.

the class BPMN2EmfExtTest method testOnExitScriptElement.

public void testOnExitScriptElement() throws Exception {
    // write
    XMLResource inResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
    inResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
    inResource.setEncoding("UTF-8");
    DocumentRoot documentRoot = DroolsFactory.eINSTANCE.createDocumentRoot();
    OnExitScriptType root = DroolsFactory.eINSTANCE.createOnExitScriptType();
    root.setScript("script");
    root.setScriptFormat("format");
    documentRoot.setOnExitScript(root);
    inResource.getContents().add(documentRoot);
    StringWriter stringWriter = new StringWriter();
    inResource.save(stringWriter, null);
    assertNotNull(stringWriter.getBuffer().toString());
    if (stringWriter.getBuffer().toString().length() < 1) {
        fail("generated xml is empty");
    }
    // read
    XMLResource outResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
    outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
    outResource.setEncoding("UTF-8");
    Map<String, Object> options = new HashMap<String, Object>();
    options.put(XMLResource.OPTION_ENCODING, "UTF-8");
    InputStream is = new ByteArrayInputStream(stringWriter.getBuffer().toString().getBytes("UTF-8"));
    outResource.load(is, options);
    DocumentRoot outRoot = (DocumentRoot) outResource.getContents().get(0);
    assertNotNull(outRoot.getOnExitScript());
    OnExitScriptType scriptType = outRoot.getOnExitScript();
    assertEquals("script", scriptType.getScript());
    assertEquals("format", scriptType.getScriptFormat());
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentRoot(org.jboss.drools.DocumentRoot) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OnExitScriptType(org.jboss.drools.OnExitScriptType) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Aggregations

OnExitScriptType (org.jboss.drools.OnExitScriptType)4 ScriptTypeListValue (org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeListValue)3 ScriptTypeValue (org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeValue)3 ExtensionAttributeValue (org.eclipse.bpmn2.ExtensionAttributeValue)2 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 EList (org.eclipse.emf.common.util.EList)1 SimpleFeatureMapEntry (org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry)1 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)1 DocumentRoot (org.jboss.drools.DocumentRoot)1 ScriptTypeListTypeSerializer (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeListTypeSerializer)1