Search in sources :

Example 1 with OnEntryScriptType

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

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

the class BPMN2EmfExtTest method testOnEntryScriptElement.

public void testOnEntryScriptElement() 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();
    OnEntryScriptType root = DroolsFactory.eINSTANCE.createOnEntryScriptType();
    root.setScript("script");
    root.setScriptFormat("format");
    documentRoot.setOnEntryScript(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.getOnEntryScript());
    OnEntryScriptType scriptType = outRoot.getOnEntryScript();
    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) OnEntryScriptType(org.jboss.drools.OnEntryScriptType) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Example 3 with OnEntryScriptType

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

the class ActivityPropertyReaderTest method testGetOnEntryScript.

@Test
public void testGetOnEntryScript() {
    OnEntryScriptType onEntryScript = Mockito.mock(OnEntryScriptType.class);
    when(onEntryScript.getScript()).thenReturn(SCRIPT);
    when(onEntryScript.getScriptFormat()).thenReturn(JAVA_FORMAT);
    List<OnEntryScriptType> onEntryScripts = Collections.singletonList(onEntryScript);
    List<ExtensionAttributeValue> extensions = mockExtensions(DroolsPackage.Literals.DOCUMENT_ROOT__ON_ENTRY_SCRIPT, onEntryScripts);
    when(activity.getExtensionValues()).thenReturn(extensions);
    assertScript(JAVA, SCRIPT, reader.getOnEntryAction());
}
Also used : OnEntryScriptType(org.jboss.drools.OnEntryScriptType) ExtensionAttributeValue(org.eclipse.bpmn2.ExtensionAttributeValue) Test(org.junit.Test)

Example 4 with OnEntryScriptType

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

the class Bpmn2JsonMarshaller method getOnEntryActions.

public ScriptTypeListValue getOnEntryActions(final List<ExtensionAttributeValue> extensionValues) {
    final ScriptTypeListValue onEntryActions = new ScriptTypeListValue();
    ScriptTypeValue onEntryAction;
    if (extensionValues != null && !extensionValues.isEmpty()) {
        for (ExtensionAttributeValue extattrval : extensionValues) {
            FeatureMap extensionElements = extattrval.getValue();
            @SuppressWarnings("unchecked") List<OnEntryScriptType> onEntryExtensions = (List<OnEntryScriptType>) extensionElements.get(DroolsPackage.Literals.DOCUMENT_ROOT__ON_ENTRY_SCRIPT, true);
            for (OnEntryScriptType onEntryScript : onEntryExtensions) {
                onEntryAction = getOnEntryAction(onEntryScript);
                if (onEntryAction.getScript() != null && !onEntryAction.getScript().isEmpty()) {
                    onEntryActions.addValue(onEntryAction);
                }
            }
        }
    }
    return onEntryActions;
}
Also used : FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) OnEntryScriptType(org.jboss.drools.OnEntryScriptType) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList) ExtensionAttributeValue(org.eclipse.bpmn2.ExtensionAttributeValue) 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 OnEntryScriptType

use of org.jboss.drools.OnEntryScriptType 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()) {
        String scriptText = scriptTypeValue.getScript();
        if (scriptText == null || scriptText.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

OnEntryScriptType (org.jboss.drools.OnEntryScriptType)5 ExtensionAttributeValue (org.eclipse.bpmn2.ExtensionAttributeValue)3 ScriptTypeListValue (org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeListValue)3 ScriptTypeValue (org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeValue)3 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 Test (org.junit.Test)1 ScriptTypeListTypeSerializer (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeListTypeSerializer)1