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);
}
}
}
}
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());
}
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());
}
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;
}
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);
}
}
Aggregations