use of io.automatiko.engine.workflow.process.core.impl.ConsequenceAction in project automatiko-engine by automatiko-io.
the class DefinitionsHandler method postProcessNodes.
protected void postProcessNodes(NodeContainer nodeContainer, List<Variable> parentVariables, ExtensibleXmlParser parser) throws SAXException {
for (Node node : nodeContainer.getNodes()) {
List<Variable> variables = new LinkedList<>(parentVariables);
VariableScope variableScope = (VariableScope) ((ContextContainer) nodeContainer).getDefaultContext(VariableScope.VARIABLE_SCOPE);
if (variableScope != null) {
variables.addAll(variableScope.getVariables());
}
if (node instanceof NodeContainer) {
postProcessNodes((NodeContainer) node, variables, parser);
} else {
if (node instanceof ActionNode) {
ActionNode actionNode = (ActionNode) node;
ProcessAction action = actionNode.getAction();
if (action instanceof ConsequenceAction) {
ConsequenceAction consequenceAction = (ConsequenceAction) action;
switch(consequenceAction.getDialect()) {
case "java":
if (actionNode.getAction().getMetaData("Action") == null) {
actionNode.getAction().setMetaData("Action", new MvelAction(actionNode));
}
break;
case "mvel":
if (actionNode.getAction().getMetaData("Action") == null) {
actionNode.getAction().setMetaData("Action", new MvelAction(actionNode));
}
break;
default:
}
}
}
}
}
}
use of io.automatiko.engine.workflow.process.core.impl.ConsequenceAction in project automatiko-engine by automatiko-io.
the class IntermediateThrowEventHandler method handleMessageNode.
@SuppressWarnings("unchecked")
public void handleMessageNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
ActionNode actionNode = (ActionNode) 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)) {
readDataInputAssociation(xmlNode, actionNode, parser);
} else if ("messageEventDefinition".equals(nodeName)) {
String messageRef = ((Element) xmlNode).getAttribute("messageRef");
Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
if (messages == null) {
throw new IllegalArgumentException("No messages found");
}
Message message = messages.get(messageRef);
if (message == null) {
throw new IllegalArgumentException("Could not find message " + messageRef);
}
String variable = (String) actionNode.getMetaData(MAPPING_VARIABLE_KEY);
Variable v = (Variable) ((ProcessBuildData) parser.getData()).getMetaData("Variable");
if (v != null) {
variable = (String) v.getMetaData(variable);
}
actionNode.setMetaData("MessageType", message.getType());
actionNode.setMetaData("TriggerType", "ProduceMessage");
actionNode.setMetaData("TriggerRef", message.getName());
for (Entry<String, Object> entry : message.getMetaData().entrySet()) {
actionNode.setMetaData(entry.getKey(), entry.getValue());
}
ConsequenceAction action = createJavaAction(new HandleMessageAction(message.getType(), variable, (Transformation) actionNode.getMetaData().get(TRANSFORMATION_KEY)));
actionNode.setAction(action);
}
xmlNode = xmlNode.getNextSibling();
}
}
use of io.automatiko.engine.workflow.process.core.impl.ConsequenceAction in project automatiko-engine by automatiko-io.
the class IntermediateThrowEventHandler method handleEscalationNode.
@SuppressWarnings("unchecked")
public void handleEscalationNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
ActionNode actionNode = (ActionNode) node;
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("dataInputAssociation".equals(nodeName)) {
readDataInputAssociation(xmlNode, actionNode, parser);
} else if ("escalationEventDefinition".equals(nodeName)) {
String escalationRef = ((Element) xmlNode).getAttribute("escalationRef");
if (escalationRef != null && escalationRef.trim().length() > 0) {
Map<String, Escalation> escalations = (Map<String, Escalation>) ((ProcessBuildData) parser.getData()).getMetaData(ProcessHandler.ESCALATIONS);
if (escalations == null) {
throw new IllegalArgumentException("No escalations found");
}
Escalation escalation = escalations.get(escalationRef);
if (escalation == null) {
throw new IllegalArgumentException("Could not find escalation " + escalationRef);
}
String faultName = escalation.getEscalationCode();
String variable = (String) actionNode.getMetaData(MAPPING_VARIABLE_KEY);
ConsequenceAction action = createJavaAction(new HandleEscalationAction(faultName, variable));
actionNode.setAction(action);
actionNode.setMetaData("TriggerType", "Escalation");
} else {
throw new IllegalArgumentException("General escalation is not yet supported");
}
}
xmlNode = xmlNode.getNextSibling();
}
}
use of io.automatiko.engine.workflow.process.core.impl.ConsequenceAction in project automatiko-engine by automatiko-io.
the class AbstractNodeHandler method extractScript.
public static ProcessAction extractScript(Element xmlNode) {
String dialect = "mvel";
if ("http://www.java.com/java".equals(xmlNode.getAttribute("scriptFormat"))) {
dialect = "java";
} else if ("http://www.javascript.com/javascript".equals(xmlNode.getAttribute("scriptFormat"))) {
dialect = "JavaScript";
}
NodeList subNodeList = xmlNode.getChildNodes();
for (int j = 0; j < subNodeList.getLength(); j++) {
if (subNodeList.item(j) instanceof Element) {
Element subXmlNode = (Element) subNodeList.item(j);
if ("script".equals(subXmlNode.getNodeName())) {
String consequence = subXmlNode.getTextContent();
ConsequenceAction action = new ConsequenceAction(dialect, consequence);
return action;
}
}
}
return new ConsequenceAction("mvel", "");
}
use of io.automatiko.engine.workflow.process.core.impl.ConsequenceAction in project automatiko-engine by automatiko-io.
the class ServerlessWorkflowFactory method stateDataFilterActionNode.
public ActionNode stateDataFilterActionNode(long id, String name, NodeContainer nodeContainer, String outputFilterString) {
ActionNode actionNode = new ActionNode();
actionNode.setId(id);
actionNode.setName(name);
String outputFilter = unwrapExpression(outputFilterString);
ConsequenceAction processAction = new ConsequenceAction(null, "new io.automatiko.engine.workflow.base.instance.impl.jq.OutputJqAssignmentAction(" + escapeExpression(outputFilter) + ").execute(null, context);");
io.automatiko.engine.workflow.base.instance.impl.Action injectAction = context -> {
new OutputJqAssignmentAction(outputFilter).execute(null, context);
};
processAction.setMetaData(ACTION, injectAction);
actionNode.setAction(processAction);
nodeContainer.addNode(actionNode);
return actionNode;
}
Aggregations