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