use of io.automatiko.engine.workflow.base.core.timer.Timer in project automatiko-engine by automatiko-io.
the class StateBasedNodeInstance method internalTrigger.
@Override
public void internalTrigger(NodeInstance from, String type) {
super.internalTrigger(from, type);
// if node instance was cancelled, abort
if (getNodeInstanceContainer().getNodeInstance(getId()) == null) {
return;
}
addCompletionListeners();
// activate timers
Map<Timer, ProcessAction> timers = getEventBasedNode().getTimers();
if (timers != null) {
addTimerListener();
timerInstances = new ArrayList<>(timers.size());
JobsService jobService = getProcessInstance().getProcessRuntime().getJobsService();
for (Timer timer : timers.keySet()) {
ExpirationTime expirationTime = createTimerInstance(timer);
String jobId = jobService.scheduleProcessInstanceJob(ProcessInstanceJobDescription.of(timer.getId(), expirationTime, getProcessInstanceIdWithParent(), getProcessInstance().getRootProcessInstanceId(), getProcessInstance().getProcessId(), getProcessInstance().getProcess().getVersion(), getProcessInstance().getRootProcessId()));
timerInstances.add(jobId);
}
}
((WorkflowProcessInstanceImpl) getProcessInstance()).addActivatingNodeId((String) getNode().getMetaData().get("UniqueId"));
if (getExtendedNode().hasCondition()) {
ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
context.setProcessInstance(getProcessInstance());
if (getExtendedNode().getMetaData("ConditionEventType") != null && getExtendedNode().isMet(context)) {
getProcessInstance().signalEvent((String) getExtendedNode().getMetaData("ConditionEventType"), null);
} else {
getProcessInstance().addEventListener("variableChanged", this, false);
}
}
}
use of io.automatiko.engine.workflow.base.core.timer.Timer in project automatiko-engine by automatiko-io.
the class WorkflowProcessInstanceImpl method start.
@Override
public void start(String trigger, Object triggerData) {
synchronized (this) {
setStartDate(new Date());
registerExternalEventNodeListeners();
// activate timer event sub processes
Node[] nodes = getNodeContainer().getNodes();
for (Node node : nodes) {
if (node instanceof EventSubProcessNode) {
Map<Timer, ProcessAction> timers = ((EventSubProcessNode) node).getTimers();
if (timers != null && !timers.isEmpty()) {
EventSubProcessNodeInstance eventSubProcess = (EventSubProcessNodeInstance) getNodeInstance(node);
eventSubProcess.trigger(null, io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
}
}
}
super.start(trigger, triggerData);
}
}
use of io.automatiko.engine.workflow.base.core.timer.Timer in project automatiko-engine by automatiko-io.
the class StartNodeVisitor method visitNode.
@Override
public void visitNode(WorkflowProcess process, String factoryField, StartNode node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
body.addStatement(getAssignedFactoryMethod(factoryField, StartNodeFactory.class, getNodeId(node), getNodeKey(), new LongLiteralExpr(node.getId()))).addStatement(getNameMethod(node, "Start")).addStatement(getFactoryMethod(getNodeId(node), METHOD_INTERRUPTING, new BooleanLiteralExpr(node.isInterrupting())));
visitMetaData(node.getMetaData(), body, getNodeId(node));
boolean serverless = ProcessToExecModelGenerator.isServerlessWorkflow(process);
if (serverless) {
for (DataAssociation association : node.getOutAssociations()) {
if (association.getAssignments() != null && !association.getAssignments().isEmpty()) {
TaskOutputJqAssignmentAction action = (TaskOutputJqAssignmentAction) association.getAssignments().get(0).getMetaData("Action");
String outputFilter = action.getOutputFilterExpression();
String scopeFilter = action.getScopeFilter();
body.addStatement(getFactoryMethod(getNodeId(node), METHOD_OUT_JQ_MAPPING, (outputFilter != null ? new StringLiteralExpr().setString(outputFilter) : new NullLiteralExpr()), (scopeFilter != null ? new StringLiteralExpr().setString(scopeFilter) : new NullLiteralExpr()), new BooleanLiteralExpr(action.isIgnoreScopeFilter())));
}
}
} else {
for (DataAssociation entry : node.getOutAssociations()) {
if (entry.getAssignments() != null && !entry.getAssignments().isEmpty()) {
Assignment assignment = entry.getAssignments().get(0);
body.addStatement(getFactoryMethod(getNodeId(node), "outMapping", new StringLiteralExpr(entry.getSources().get(0)), new NullLiteralExpr(), new StringLiteralExpr(assignment.getDialect()), new StringLiteralExpr(assignment.getFrom()), new StringLiteralExpr(assignment.getTo())));
} else {
body.addStatement(getFactoryMethod(getNodeId(node), "outMapping", new StringLiteralExpr(entry.getSources().get(0)), new StringLiteralExpr(entry.getTarget()), new NullLiteralExpr(), new NullLiteralExpr(), new NullLiteralExpr()));
}
}
}
body.addStatement(getDoneMethod(getNodeId(node)));
if (node.getTimer() != null) {
Timer timer = node.getTimer();
body.addStatement(getFactoryMethod(getNodeId(node), METHOD_TIMER, getOrNullExpr(timer.getDelay()), getOrNullExpr(timer.getPeriod()), getOrNullExpr(timer.getDate()), new IntegerLiteralExpr(node.getTimer().getTimeType())));
} else if (node.getTriggers() != null && !node.getTriggers().isEmpty()) {
Map<String, Object> nodeMetaData = node.getMetaData();
TriggerMetaData trigger = new TriggerMetaData((String) nodeMetaData.get(TRIGGER_REF), (String) nodeMetaData.get(TRIGGER_TYPE), (String) nodeMetaData.get(MESSAGE_TYPE), (String) nodeMetaData.get(TRIGGER_MAPPING), String.valueOf(node.getId()), node.getName(), (String) nodeMetaData.get(TRIGGER_CORRELATION), (String) nodeMetaData.get(TRIGGER_CORRELATION_EXPR)).validate();
trigger.addContext(node.getMetaData());
trigger.addContext(Collections.singletonMap("_node_", node));
// mark the trigger as capable of starting new instance only if this is top level start node
if (node.getParentContainer() instanceof WorkflowProcess) {
trigger.setStart(true);
}
metadata.addTrigger(trigger);
handleTrigger(node, nodeMetaData, body, variableScope, metadata);
} else {
// since there is start node without trigger then make sure it is startable
metadata.setStartable(true);
}
}
use of io.automatiko.engine.workflow.base.core.timer.Timer in project automatiko-engine by automatiko-io.
the class TimerHandler method end.
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
Element element = parser.endElementBuilder();
StateBasedNode parent = (StateBasedNode) parser.getParent();
String id = element.getAttribute("id");
emptyAttributeCheck(localName, "id", id, parser);
String delay = element.getAttribute("delay");
String period = element.getAttribute("period");
Timer timer = new Timer();
timer.setId(new Long(id));
if (delay != null && delay.length() != 0) {
timer.setDelay(delay);
}
if (period != null && period.length() != 0) {
timer.setPeriod(period);
}
org.w3c.dom.Node xmlNode = element.getFirstChild();
ProcessAction action = null;
if (xmlNode instanceof Element) {
Element actionXml = (Element) xmlNode;
action = AbstractNodeHandler.extractAction(actionXml);
}
parent.addTimer(timer, action);
return null;
}
use of io.automatiko.engine.workflow.base.core.timer.Timer in project automatiko-engine by automatiko-io.
the class TimerNodeHandler 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);
TimerNode timerNode = (TimerNode) node;
String delay = element.getAttribute("delay");
String period = element.getAttribute("period");
if ((delay != null && delay.length() > 0) || (period != null && period.length() > 0)) {
Timer timer = timerNode.getTimer();
if (timer == null) {
timer = new Timer();
timerNode.setTimer(timer);
}
if (delay != null && delay.length() != 0) {
timer.setDelay(delay);
}
if (period != null && period.length() != 0) {
timer.setPeriod(period);
}
}
}
Aggregations