use of org.jbpm.workflow.core.impl.DroolsConsequenceAction in project jbpm by kiegroup.
the class ActionNodeBuilder method build.
public void build(Process process, ProcessDescr processDescr, ProcessBuildContext context, Node node) {
super.build(process, processDescr, context, node);
ActionNode actionNode = (ActionNode) node;
DroolsConsequenceAction action = (DroolsConsequenceAction) actionNode.getAction();
ActionDescr actionDescr = new ActionDescr();
actionDescr.setText(action.getConsequence());
actionDescr.setResource(processDescr.getResource());
ProcessDialect dialect = ProcessDialectRegistry.getDialect(action.getDialect());
dialect.getActionBuilder().build(context, action, actionDescr, (NodeImpl) node);
Transformation transformation = (Transformation) node.getMetaData().get("Transformation");
if (transformation != null) {
WorkflowProcess wfProcess = (WorkflowProcess) process;
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("imports", wfProcess.getImports());
parameters.put("classloader", context.getConfiguration().getClassLoader());
DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
transformation.setCompiledExpression(transformer.compile(transformation.getExpression(), parameters));
}
}
use of org.jbpm.workflow.core.impl.DroolsConsequenceAction in project jbpm by kiegroup.
the class EndEventHandler method handleSignalNode.
public void handleSignalNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
EndNode endNode = (EndNode) node;
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("dataInput".equals(nodeName)) {
String id = ((Element) xmlNode).getAttribute("id");
String inputName = ((Element) xmlNode).getAttribute("name");
dataInputs.put(id, inputName);
} else if ("dataInputAssociation".equals(nodeName)) {
readEndDataInputAssociation(xmlNode, endNode);
} else if ("signalEventDefinition".equals(nodeName)) {
String signalName = ((Element) xmlNode).getAttribute("signalRef");
String variable = (String) endNode.getMetaData("MappingVariable");
signalName = checkSignalAndConvertToRealSignalNam(parser, signalName);
endNode.setMetaData("EventType", "signal");
endNode.setMetaData("Ref", signalName);
endNode.setMetaData("Variable", variable);
// check if signal should be send async
if (dataInputs.containsValue("async")) {
signalName = "ASYNC-" + signalName;
}
String signalExpression = getSignalExpression(endNode, signalName, variable);
List<DroolsAction> actions = new ArrayList<DroolsAction>();
actions.add(new DroolsConsequenceAction("mvel", signalExpression));
endNode.setActions(EndNode.EVENT_NODE_ENTER, actions);
}
xmlNode = xmlNode.getNextSibling();
}
}
use of org.jbpm.workflow.core.impl.DroolsConsequenceAction in project jbpm by kiegroup.
the class EndNodeHandler method writeNode.
public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
EndNode endNode = (EndNode) node;
String eventType = (String) endNode.getMetaData("EventType");
String ref = (String) endNode.getMetaData("Ref");
String variableRef = (String) endNode.getMetaData("Variable");
writeNode("endEvent", endNode, xmlDump, metaDataType);
if (endNode.isTerminate()) {
xmlDump.append(">" + EOL);
writeExtensionElements(endNode, xmlDump);
xmlDump.append(" <terminateEventDefinition " + (endNode.getScope() == EndNode.PROCESS_SCOPE ? "tns:scope=\"process\"" : "") + "/>" + EOL);
endNode("endEvent", xmlDump);
} else {
String scope = (String) endNode.getMetaData("customScope");
List<DroolsAction> actions = endNode.getActions(EndNode.EVENT_NODE_ENTER);
if (actions != null && !actions.isEmpty()) {
if (actions.size() == 1) {
DroolsConsequenceAction action = (DroolsConsequenceAction) actions.get(0);
String s = action.getConsequence();
if (s.startsWith("org.drools.core.process.instance.impl.WorkItemImpl workItem = new org.drools.core.process.instance.impl.WorkItemImpl();")) {
xmlDump.append(">" + EOL);
writeExtensionElements(endNode, xmlDump);
String variable = (String) endNode.getMetaData("MappingVariable");
if (variable != null) {
xmlDump.append(" <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input\" />" + EOL + " <dataInputAssociation>" + EOL + " <sourceRef>" + XmlDumper.replaceIllegalChars(variable) + "</sourceRef>" + EOL + " <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</targetRef>" + EOL + " </dataInputAssociation>" + EOL + " <inputSet>" + EOL + " <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</dataInputRefs>" + EOL + " </inputSet>" + EOL);
}
xmlDump.append(" <messageEventDefinition messageRef=\"" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Message\"/>" + EOL);
endNode("endEvent", xmlDump);
} else if ("signal".equals(eventType)) {
xmlDump.append(">" + EOL);
writeExtensionElements(endNode, xmlDump);
if (!s.startsWith("null")) {
xmlDump.append(" <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input\" />" + EOL + " <dataInputAssociation>" + EOL + " <sourceRef>" + XmlDumper.replaceIllegalChars(variableRef) + "</sourceRef>" + EOL + " <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</targetRef>" + EOL + " </dataInputAssociation>" + EOL + " <inputSet>" + EOL + " <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</dataInputRefs>" + EOL + " </inputSet>" + EOL);
}
xmlDump.append(" <signalEventDefinition signalRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(ref) + "\"/>" + EOL);
endNode("endEvent", xmlDump);
} else if (s.startsWith(RUNTIME_SIGNAL_EVENT)) {
xmlDump.append(">" + EOL);
writeExtensionElements(endNode, xmlDump);
s = s.substring(44);
String type = s.substring(0, s.indexOf("\""));
s = s.substring(s.indexOf(",") + 2);
String variable = null;
if (!s.startsWith("null")) {
variable = s.substring(0, s.indexOf(")"));
xmlDump.append(" <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input\" />" + EOL + " <dataInputAssociation>" + EOL + " <sourceRef>" + XmlDumper.replaceIllegalChars(variable) + "</sourceRef>" + EOL + " <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</targetRef>" + EOL + " </dataInputAssociation>" + EOL + " <inputSet>" + EOL + " <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</dataInputRefs>" + EOL + " </inputSet>" + EOL);
}
xmlDump.append(" <signalEventDefinition signalRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\"/>" + EOL);
endNode("endEvent", xmlDump);
} else if (s.startsWith(PROCESS_INSTANCE_SIGNAL_EVENT) && "processInstance".equals(scope)) {
xmlDump.append(">" + EOL);
writeExtensionElements(endNode, xmlDump);
s = s.substring(43);
String type = s.substring(0, s.indexOf("\""));
s = s.substring(s.indexOf(",") + 2);
String variable = null;
if (!s.startsWith("null")) {
variable = s.substring(0, s.indexOf(")"));
xmlDump.append(" <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input\" />" + EOL + " <dataInputAssociation>" + EOL + " <sourceRef>" + XmlDumper.replaceIllegalChars(variable) + "</sourceRef>" + EOL + " <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</targetRef>" + EOL + " </dataInputAssociation>" + EOL + " <inputSet>" + EOL + " <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</dataInputRefs>" + EOL + " </inputSet>" + EOL);
}
xmlDump.append(" <signalEventDefinition signalRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\"/>" + EOL);
endNode("endEvent", xmlDump);
} else if (s.startsWith(PROCESS_INSTANCE_SIGNAL_EVENT)) {
xmlDump.append(">" + EOL);
writeExtensionElements(endNode, xmlDump);
int begin = (PROCESS_INSTANCE_SIGNAL_EVENT + "Compensation\", ").length() - 2;
int end = s.length() - 3;
String compensationEvent = s.substring(begin, end);
String activityRef = "";
if (!compensationEvent.startsWith(CompensationScope.IMPLICIT_COMPENSATION_PREFIX)) {
// specific
activityRef = "activityRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(activityRef) + "\" ";
}
// else general: activityRef = "" (above)
xmlDump.append(" <compensateEventDefinition " + activityRef + "/>" + EOL);
endNode("endEvent", xmlDump);
} else {
throw new IllegalArgumentException("Unknown action " + s);
}
}
} else {
endNode(xmlDump);
}
}
}
use of org.jbpm.workflow.core.impl.DroolsConsequenceAction in project jbpm by kiegroup.
the class AbstractNodeHandler method writeScript.
public static void writeScript(final DroolsAction action, String type, final StringBuilder xmlDump) {
if (action instanceof DroolsConsequenceAction) {
DroolsConsequenceAction consequenceAction = (DroolsConsequenceAction) action;
xmlDump.append(" <tns:" + type + "-script");
String name = consequenceAction.getName();
if (name != null) {
xmlDump.append(" name=\"" + name + "\"");
}
String dialect = consequenceAction.getDialect();
if (JavaDialect.ID.equals(dialect)) {
xmlDump.append(" scriptFormat=\"" + XmlBPMNProcessDumper.JAVA_LANGUAGE + "\"");
} else if ("JavaScript".equals(dialect)) {
xmlDump.append(" scriptFormat=\"" + XmlBPMNProcessDumper.JAVASCRIPT_LANGUAGE + "\"");
}
String consequence = consequenceAction.getConsequence();
if (consequence != null) {
xmlDump.append(">" + EOL + " <tns:script>" + XmlDumper.replaceIllegalChars(consequence.trim()) + "</tns:script>" + EOL);
xmlDump.append(" </tns:" + type + "-script>" + EOL);
} else {
xmlDump.append("/>" + EOL);
}
} else {
throw new IllegalArgumentException("Unknown action " + action);
}
}
use of org.jbpm.workflow.core.impl.DroolsConsequenceAction in project jbpm by kiegroup.
the class ExtendedNodeBuilder method buildAction.
protected void buildAction(DroolsAction droolsAction, ProcessBuildContext context, NodeImpl node) {
DroolsConsequenceAction action = (DroolsConsequenceAction) droolsAction;
ActionDescr actionDescr = new ActionDescr();
actionDescr.setText(action.getConsequence());
actionDescr.setResource(context.getProcessDescr().getResource());
ProcessDialect dialect = ProcessDialectRegistry.getDialect(action.getDialect());
dialect.getActionBuilder().build(context, action, actionDescr, node);
}
Aggregations