Search in sources :

Example 16 with Timer

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);
        }
    }
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) Timer(io.automatiko.engine.workflow.base.core.timer.Timer) JobsService(io.automatiko.engine.api.jobs.JobsService) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) ExactExpirationTime(io.automatiko.engine.api.jobs.ExactExpirationTime) ExpirationTime(io.automatiko.engine.api.jobs.ExpirationTime) DurationExpirationTime(io.automatiko.engine.api.jobs.DurationExpirationTime) CronExpirationTime(io.automatiko.engine.workflow.base.core.timer.CronExpirationTime) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext)

Example 17 with Timer

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);
    }
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) Timer(io.automatiko.engine.workflow.base.core.timer.Timer) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) MilestoneNode(io.automatiko.engine.workflow.process.core.node.MilestoneNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StateNode(io.automatiko.engine.workflow.process.core.node.StateNode) Node(io.automatiko.engine.api.definition.process.Node) DynamicNode(io.automatiko.engine.workflow.process.core.node.DynamicNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) Date(java.util.Date) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance)

Example 18 with Timer

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);
    }
}
Also used : IntegerLiteralExpr(com.github.javaparser.ast.expr.IntegerLiteralExpr) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) TaskOutputJqAssignmentAction(io.automatiko.engine.workflow.base.instance.impl.jq.TaskOutputJqAssignmentAction) NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) StartNodeFactory(io.automatiko.engine.workflow.process.executable.core.factory.StartNodeFactory) Timer(io.automatiko.engine.workflow.base.core.timer.Timer) BooleanLiteralExpr(com.github.javaparser.ast.expr.BooleanLiteralExpr) LongLiteralExpr(com.github.javaparser.ast.expr.LongLiteralExpr) Map(java.util.Map) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess)

Example 19 with Timer

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;
}
Also used : StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) Timer(io.automatiko.engine.workflow.base.core.timer.Timer) Element(org.w3c.dom.Element)

Example 20 with Timer

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);
        }
    }
}
Also used : Timer(io.automatiko.engine.workflow.base.core.timer.Timer) TimerNode(io.automatiko.engine.workflow.process.core.node.TimerNode)

Aggregations

Timer (io.automatiko.engine.workflow.base.core.timer.Timer)28 ProcessAction (io.automatiko.engine.workflow.process.core.ProcessAction)9 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)6 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)6 EventTrigger (io.automatiko.engine.workflow.process.core.node.EventTrigger)6 StateBasedNode (io.automatiko.engine.workflow.process.core.node.StateBasedNode)6 TimerNode (io.automatiko.engine.workflow.process.core.node.TimerNode)6 List (java.util.List)6 Node (io.automatiko.engine.api.definition.process.Node)5 ConsequenceAction (io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)5 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)5 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)5 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)5 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)5 StateNode (io.automatiko.engine.workflow.process.core.node.StateNode)5 ArrayList (java.util.ArrayList)5 WorkflowProcess (io.automatiko.engine.api.definition.process.WorkflowProcess)4