use of io.automatiko.engine.workflow.process.core.node.StateNode in project automatiko-engine by automatiko-io.
the class IntermediateCatchEventHandler method end.
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
final Element element = parser.endElementBuilder();
Node node = (Node) parser.getCurrent();
// determine type of event definition, so the correct type of node
// can be generated
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("signalEventDefinition".equals(nodeName)) {
// reuse already created EventNode
handleSignalNode(node, element, uri, localName, parser);
node.setMetaData(EVENT_TYPE, "signal");
node.setMetaData("functionFlowContinue", "true");
break;
} else if ("messageEventDefinition".equals(nodeName)) {
// reuse already created EventNode
handleMessageNode(node, element, uri, localName, parser);
node.setMetaData(EVENT_TYPE, "message");
node.setMetaData("functionFlowContinue", "true");
break;
} else if ("timerEventDefinition".equals(nodeName)) {
// create new timerNode
TimerNode timerNode = new TimerNode();
timerNode.setId(node.getId());
timerNode.setName(node.getName());
timerNode.setMetaData("UniqueId", node.getMetaData().get("UniqueId"));
node = timerNode;
node.setMetaData(EVENT_TYPE, "timer");
handleTimerNode(node, element, uri, localName, parser);
node.setMetaData("functionFlowContinue", "true");
break;
} else if ("conditionalEventDefinition".equals(nodeName)) {
// create new stateNode
StateNode stateNode = new StateNode();
stateNode.setId(node.getId());
stateNode.setName(node.getName());
stateNode.setMetaData("UniqueId", node.getMetaData().get("UniqueId"));
node = stateNode;
node.setMetaData(EVENT_TYPE, "conditional");
handleStateNode(node, element, uri, localName, parser);
node.setMetaData("functionFlowContinue", "true");
break;
} else if ("linkEventDefinition".equals(nodeName)) {
CatchLinkNode linkNode = new CatchLinkNode();
linkNode.setId(node.getId());
node = linkNode;
node.setMetaData(EVENT_TYPE, "link");
handleLinkNode(element, node, xmlNode, parser);
break;
}
xmlNode = xmlNode.getNextSibling();
}
node.setMetaData("DataOutputs", new LinkedHashMap<String, String>(dataOutputTypes));
NodeContainer nodeContainer = (NodeContainer) parser.getParent();
nodeContainer.addNode(node);
((ProcessBuildData) parser.getData()).addNode(node);
return node;
}
use of io.automatiko.engine.workflow.process.core.node.StateNode in project automatiko-engine by automatiko-io.
the class StateNodeHandler method writeNode.
public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
StateNode stateNode = (StateNode) node;
writeNode("state", stateNode, xmlDump, includeMeta);
xmlDump.append(">\n");
if (includeMeta) {
writeMetaData(stateNode, xmlDump);
}
for (String eventType : stateNode.getActionTypes()) {
writeActions(eventType, stateNode.getActions(eventType), xmlDump);
}
writeTimers(stateNode.getTimers(), xmlDump);
if (!stateNode.getConstraints().isEmpty()) {
xmlDump.append(" <constraints>" + EOL);
for (Map.Entry<ConnectionRef, Constraint> entry : stateNode.getConstraints().entrySet()) {
ConnectionRef connection = entry.getKey();
Constraint constraint = entry.getValue();
xmlDump.append(" <constraint " + "toNodeId=\"" + connection.getNodeId() + "\" ");
String name = constraint.getName();
if (name != null && !"".equals(name)) {
xmlDump.append("name=\"" + XmlDumper.replaceIllegalChars(constraint.getName()) + "\" ");
}
int priority = constraint.getPriority();
if (priority != 0) {
xmlDump.append("priority=\"" + constraint.getPriority() + "\" ");
}
String constraintString = constraint.getConstraint();
if (constraintString != null) {
xmlDump.append(">" + XmlDumper.replaceIllegalChars(constraintString) + "</constraint>" + EOL);
} else {
xmlDump.append("/>" + EOL);
}
}
xmlDump.append(" </constraints>" + EOL);
}
endNode("state", xmlDump);
}
use of io.automatiko.engine.workflow.process.core.node.StateNode in project automatiko-engine by automatiko-io.
the class StateNodeHandler method handleNode.
public void handleNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
super.handleNode(node, element, uri, localName, parser);
StateNode stateNode = (StateNode) node;
for (String eventType : stateNode.getActionTypes()) {
handleAction(stateNode, element, eventType);
}
}
use of io.automatiko.engine.workflow.process.core.node.StateNode in project automatiko-engine by automatiko-io.
the class SvgBpmnProcessImageGenerator method buildNodeContainer.
/*
* Build methods
*/
protected void buildNodeContainer(int x, int y, NodeContainer nodeContainer, SVGGraphics2D g2) {
try {
for (Node node : nodeContainer.getNodes()) {
if (node instanceof StartNode) {
buildStartEvent(x, y, (StartNode) node, g2);
} else if (node instanceof EndNode) {
buildEndEvent(x, y, (EndNode) node, g2);
} else if (node instanceof FaultNode) {
buildErrorEndEvent(x, y, (FaultNode) node, g2);
} else if (node instanceof BoundaryEventNode) {
buildBoundaryEvent(x, y, node, g2);
} else if (node instanceof EventNode || node instanceof StateNode) {
buildIntermediateEvent(x, y, node, g2);
} else if (node instanceof HumanTaskNode) {
buildHumanTaskNode(x, y, (HumanTaskNode) node, g2);
} else if (node instanceof ActionNode) {
buildScriptTaskNode(x, y, (ActionNode) node, g2);
} else if (node instanceof WorkItemNode) {
buildServiceTaskNode(x, y, (WorkItemNode) node, g2);
} else if (node instanceof Split || node instanceof Join) {
buildGateway(x, y, node, g2);
} else if (node instanceof ForEachNode) {
buildNodeContainer(x(node), y(node), ((ForEachNode) node).getCompositeNode(), g2);
} else if (node instanceof CompositeNode) {
buildSubprocessNode(x, y, (CompositeNode) node, g2);
int sx = x(node);
int sy = y(node);
buildNodeContainer(sx, sy, (CompositeNode) node, g2);
} else if (node instanceof RuleSetNode) {
buildBusinessRuleTaskNode(x, y, (RuleSetNode) node, g2);
} else if (node instanceof TimerNode) {
buildTimerEvent(x, y, (TimerNode) node, g2);
} else if (node instanceof SubProcessNode) {
buildCallActivity(x, y, (SubProcessNode) node, g2);
}
buildSequenceFlow(x, y, node, g2);
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of io.automatiko.engine.workflow.process.core.node.StateNode in project automatiko-engine by automatiko-io.
the class ProcessHandler method postProcessNodes.
private void postProcessNodes(ExecutableProcess process, NodeContainer container) {
List<String> eventSubProcessHandlers = new ArrayList<String>();
for (Node node : container.getNodes()) {
if (node instanceof StartNode) {
List<DataAssociation> associations = ((StartNode) node).getOutAssociations();
if (associations != null) {
for (DataAssociation da : associations) {
VariableScope scope = (VariableScope) process.getDefaultContext(VariableScope.VARIABLE_SCOPE);
Variable variable = scope.findVariable(da.getTarget());
if (variable != null) {
da.setTarget(variable.getName());
}
}
}
} else if (node instanceof StateNode) {
StateNode stateNode = (StateNode) node;
String condition = (String) stateNode.getMetaData("Condition");
stateNode.setCondition(context -> {
return (boolean) MVEL.executeExpression(condition, context.getProcessInstance().getVariables());
});
} else if (node instanceof NodeContainer) {
// prepare event sub process
if (node instanceof EventSubProcessNode) {
EventSubProcessNode eventSubProcessNode = (EventSubProcessNode) node;
Node[] nodes = eventSubProcessNode.getNodes();
for (Node subNode : nodes) {
// avoids cyclomatic complexity
if (subNode == null || !(subNode instanceof StartNode)) {
continue;
}
List<Trigger> triggers = ((StartNode) subNode).getTriggers();
if (triggers == null) {
continue;
}
for (Trigger trigger : triggers) {
if (trigger instanceof EventTrigger) {
final List<EventFilter> filters = ((EventTrigger) trigger).getEventFilters();
for (EventFilter filter : filters) {
if (filter instanceof EventTypeFilter) {
eventSubProcessNode.addEvent((EventTypeFilter) filter);
String type = ((EventTypeFilter) filter).getType();
if (type.startsWith("Error-") || type.startsWith("Escalation")) {
String faultCode = (String) subNode.getMetaData().get("FaultCode");
String replaceRegExp = "Error-|Escalation-";
final String signalType = type;
ExceptionScope exceptionScope = (ExceptionScope) ((ContextContainer) eventSubProcessNode.getParentContainer()).getDefaultContext(ExceptionScope.EXCEPTION_SCOPE);
if (exceptionScope == null) {
exceptionScope = new ExceptionScope();
((ContextContainer) eventSubProcessNode.getParentContainer()).addContext(exceptionScope);
((ContextContainer) eventSubProcessNode.getParentContainer()).setDefaultContext(exceptionScope);
}
String faultVariable = null;
if (trigger.getInAssociations() != null && !trigger.getInAssociations().isEmpty()) {
faultVariable = findVariable(trigger.getInAssociations().get(0).getSources().get(0), process.getVariableScope());
}
ActionExceptionHandler exceptionHandler = new ActionExceptionHandler();
ConsequenceAction action = new ConsequenceAction("java", "");
action.setMetaData("Action", new SignalProcessInstanceAction(signalType, faultVariable, SignalProcessInstanceAction.PROCESS_INSTANCE_SCOPE));
exceptionHandler.setAction(action);
exceptionHandler.setFaultVariable(faultVariable);
exceptionHandler.setRetryAfter((Integer) subNode.getMetaData().get("ErrorRetry"));
exceptionHandler.setRetryIncrement((Integer) subNode.getMetaData().get("ErrorRetryIncrement"));
if (subNode.getMetaData().get("ErrorRetryIncrementMultiplier") != null) {
exceptionHandler.setRetryIncrementMultiplier(((Number) subNode.getMetaData().get("ErrorRetryIncrementMultiplier")).floatValue());
}
exceptionHandler.setRetryLimit((Integer) subNode.getMetaData().get("ErrorRetryLimit"));
if (faultCode != null) {
String trimmedType = type.replaceFirst(replaceRegExp, "");
for (String error : trimmedType.split(",")) {
exceptionScope.setExceptionHandler(error, exceptionHandler);
eventSubProcessHandlers.add(error);
}
} else {
exceptionScope.setExceptionHandler(faultCode, exceptionHandler);
}
} else if (type.equals("Compensation")) {
// 1. Find the parent sub-process to this event sub-process
NodeContainer parentSubProcess;
NodeContainer subProcess = eventSubProcessNode.getParentContainer();
Object isForCompensationObj = eventSubProcessNode.getMetaData("isForCompensation");
if (isForCompensationObj == null) {
eventSubProcessNode.setMetaData("isForCompensation", true);
logger.warn("Overriding empty or false value of \"isForCompensation\" attribute on Event Sub-Process [" + eventSubProcessNode.getMetaData("UniqueId") + "] and setting it to true.");
}
if (subProcess instanceof ExecutableProcess) {
// (instance)?!?
throw new IllegalArgumentException("Compensation Event Sub-Processes at the process level are not supported.");
}
parentSubProcess = ((Node) subProcess).getParentContainer();
// 2. The event filter (never fires, purely for dumping purposes) has
// already been added
// 3. Add compensation scope
String compensationHandlerId = (String) ((CompositeNode) subProcess).getMetaData("UniqueId");
addCompensationScope(process, eventSubProcessNode, parentSubProcess, compensationHandlerId);
}
}
}
} else if (trigger instanceof ConstraintTrigger) {
ConstraintTrigger constraintTrigger = (ConstraintTrigger) trigger;
if (constraintTrigger.getConstraint() != null) {
String processId = ((ExecutableProcess) container).getId();
String type = "RuleFlowStateEventSubProcess-Event-" + processId + "-" + eventSubProcessNode.getUniqueId();
EventTypeFilter eventTypeFilter = new EventTypeFilter();
eventTypeFilter.setType(type);
eventSubProcessNode.addEvent(eventTypeFilter);
eventSubProcessNode.addEvent("variableChanged");
((StartNode) subNode).setCondition(context -> {
return (boolean) MVEL.executeExpression(constraintTrigger.getConstraint(), context.getProcessInstance().getVariables());
});
}
}
}
}
// for( Node subNode : nodes)
}
postProcessNodes(process, (NodeContainer) node);
} else if (node instanceof EndNode) {
handleIntermediateOrEndThrowCompensationEvent((EndNode) node);
} else if (node instanceof ActionNode) {
handleIntermediateOrEndThrowCompensationEvent((ActionNode) node);
} else if (node instanceof EventNode) {
final EventNode eventNode = (EventNode) node;
if (!(eventNode instanceof BoundaryEventNode) && eventNode.getDefaultIncomingConnections().size() == 0) {
throw new IllegalArgumentException("Event node '" + node.getName() + "' [" + node.getId() + "] has no incoming connection");
}
}
}
// handler
for (Node node : container.getNodes()) {
if (node instanceof FaultNode) {
FaultNode faultNode = (FaultNode) node;
if (eventSubProcessHandlers.contains(faultNode.getFaultName())) {
faultNode.setTerminateParent(false);
}
}
}
}
Aggregations