use of io.automatiko.engine.api.definition.process.Node in project automatiko-engine by automatiko-io.
the class ServerlessWorkflowFactory method connect.
public Connection connect(long fromId, long toId, String uniqueId, NodeContainer nodeContainer, boolean association) {
Node from = nodeContainer.getNode(fromId);
Node to = nodeContainer.getNode(toId);
ConnectionImpl connection = new ConnectionImpl(from, io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE, to, io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
connection.setMetaData(UNIQUE_ID_PARAM, uniqueId);
if (association) {
connection.setMetaData("association", true);
}
return connection;
}
use of io.automatiko.engine.api.definition.process.Node in project automatiko-engine by automatiko-io.
the class ServerlessWorkflowFactory method errorBoundaryEventNode.
public BoundaryEventNode errorBoundaryEventNode(long id, List<ErrorDefinition> defs, RetryDefinition retry, NodeContainer nodeContainer, Node attachedTo, Workflow workflow) {
BoundaryEventNode boundaryEventNode = new BoundaryEventNode();
boundaryEventNode.setId(id);
boundaryEventNode.setName(defs.stream().map(def -> def.getName()).collect(Collectors.joining("|")));
String errorCodes = defs.stream().map(def -> def.getCode()).collect(Collectors.joining(","));
String attachedToId = (String) attachedTo.getMetaData().getOrDefault(UNIQUE_ID_PARAM, Long.toString(attachedTo.getId()));
EventTypeFilter filter = new EventTypeFilter();
filter.setType("Error-" + attachedToId + "-" + errorCodes);
boundaryEventNode.addEventFilter(filter);
boundaryEventNode.setAttachedToNodeId(attachedToId);
boundaryEventNode.setMetaData(UNIQUE_ID_PARAM, Long.toString(id));
boundaryEventNode.setMetaData("EventType", "error");
boundaryEventNode.setMetaData("ErrorEvent", errorCodes);
boundaryEventNode.setMetaData("AttachedTo", attachedToId);
boundaryEventNode.setMetaData("HasErrorEvent", true);
if (retry != null) {
int delayAsInt = ((Long) DateTimeUtils.parseDuration(retry.getDelay())).intValue();
boundaryEventNode.setMetaData("ErrorRetry", retry.getDelay() == null ? DEFAULT_RETRY_AFTER : delayAsInt);
boundaryEventNode.setMetaData("ErrorRetryLimit", retry.getMaxAttempts() == null ? DEFAULT_RETRY_LIMIT : Integer.parseInt(retry.getMaxAttempts()));
if (retry.getMultiplier() != null) {
boundaryEventNode.setMetaData("ErrorRetryIncrementMultiplier", Float.parseFloat(retry.getMultiplier()));
}
}
nodeContainer.addNode(boundaryEventNode);
return boundaryEventNode;
}
use of io.automatiko.engine.api.definition.process.Node in project automatiko-engine by automatiko-io.
the class ServiceTaskDescriptor method collectHandledErrorCodes.
private Set<String> collectHandledErrorCodes() {
Set<String> errorCodes = new HashSet<>();
NodeContainer container = workItemNode.getParentContainer();
String thisNodeId = (String) workItemNode.getMetaData("UniqueId");
for (Node node : container.getNodes()) {
if (node instanceof BoundaryEventNode) {
String errorCode = (String) node.getMetaData().get("ErrorEvent");
if (errorCode != null && ((BoundaryEventNode) node).getAttachedToNodeId().equals(thisNodeId)) {
errorCodes.add(errorCode);
}
}
}
// next collect event subprocess node with error start event from this level and to all parents
String replaceRegExp = "Error-|Escalation-";
for (Node node : container.getNodes()) {
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-")) {
String trimmedType = type.replaceFirst(replaceRegExp, "");
for (String error : trimmedType.split(",")) {
errorCodes.add(error);
}
}
}
}
}
}
}
}
}
return errorCodes;
}
use of io.automatiko.engine.api.definition.process.Node in project automatiko-engine by automatiko-io.
the class CompositeNodeInstance method signalEvent.
@Override
public void signalEvent(String type, Object event) {
List<NodeInstance> currentView = new ArrayList<>(this.nodeInstances);
super.signalEvent(type, event);
for (Node node : getCompositeNode().internalGetNodes()) {
if (node instanceof EventNodeInterface && ((EventNodeInterface) node).acceptsEvent(type, event)) {
if (node instanceof EventNode && ((EventNode) node).getFrom() == null || node instanceof EventSubProcessNode) {
EventNodeInstanceInterface eventNodeInstance = (EventNodeInstanceInterface) getNodeInstance(node);
eventNodeInstance.signalEvent(type, event);
} else {
List<NodeInstance> nodeInstances = getNodeInstances(node.getId(), currentView);
if (nodeInstances != null && !nodeInstances.isEmpty()) {
for (NodeInstance nodeInstance : nodeInstances) {
((EventNodeInstanceInterface) nodeInstance).signalEvent(type, event);
}
}
}
}
if (type.equals(node.getName()) && node.getIncomingConnections().isEmpty()) {
NodeInstance nodeInstance = getNodeInstance(node);
if (nodeInstance != null) {
if (event != null) {
Map<String, Object> dynamicParams = new HashMap<>(getProcessInstance().getVariables());
if (event instanceof Map) {
dynamicParams.putAll((Map<String, Object>) event);
} else if (event instanceof WorkflowProcessInstance) {
// ignore variables of process instance type
} else {
dynamicParams.put("Data", event);
}
nodeInstance.setDynamicParameters(dynamicParams);
}
nodeInstance.trigger(null, null);
}
}
}
}
use of io.automatiko.engine.api.definition.process.Node in project automatiko-engine by automatiko-io.
the class ExecutableProcessValidator method validateCompensationIntermediateOrEndEvent.
protected void validateCompensationIntermediateOrEndEvent(Node node, ExecutableProcess process, List<ProcessValidationError> errors) {
if (node.getMetaData().containsKey("Compensation")) {
// Validate that activityRef in throw/end compensation event refers to "visible"
// compensation
String activityRef = (String) node.getMetaData().get("Compensation");
Node refNode = null;
if (activityRef != null) {
Queue<Node> nodeQueue = new LinkedList<>();
nodeQueue.addAll(Arrays.asList(process.getNodes()));
while (!nodeQueue.isEmpty()) {
Node polledNode = nodeQueue.poll();
if (activityRef.equals(polledNode.getMetaData().get("UniqueId"))) {
refNode = polledNode;
break;
}
if (node instanceof NodeContainer) {
nodeQueue.addAll(Arrays.asList(((NodeContainer) node).getNodes()));
}
}
}
if (refNode == null) {
addErrorMessage(process, node, errors, "Does not reference an activity that exists (" + activityRef + ") in its compensation event definition.");
}
CompensationScope compensationScope = (CompensationScope) ((NodeImpl) node).resolveContext(CompensationScope.COMPENSATION_SCOPE, activityRef);
if (compensationScope == null) {
addErrorMessage(process, node, errors, "References an activity (" + activityRef + ") in its compensation event definition that is not visible to it.");
}
}
}
Aggregations