Search in sources :

Example 11 with ExecutableProcess

use of io.automatiko.engine.workflow.process.executable.core.ExecutableProcess in project automatiko-engine by automatiko-io.

the class ProcessHandler method end.

@SuppressWarnings("unchecked")
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    parser.endElementBuilder();
    ExecutableProcess process = (ExecutableProcess) parser.getCurrent();
    List<IntermediateLink> throwLinks = (List<IntermediateLink>) process.getMetaData(LINKS);
    linkIntermediateLinks(process, throwLinks);
    List<SequenceFlow> connections = (List<SequenceFlow>) process.getMetaData(CONNECTIONS);
    linkConnections(process, connections);
    linkBoundaryEvents(process);
    // This must be done *after* linkConnections(process, connections)
    // because it adds hidden connections for compensations
    List<Association> associations = (List<Association>) process.getMetaData(ASSOCIATIONS);
    linkAssociations((Definitions) process.getMetaData("Definitions"), process, associations);
    List<Lane> lanes = (List<Lane>) process.getMetaData(LaneHandler.LANES);
    assignLanes(process, lanes);
    postProcessNodes(process, process);
    // process tags if any defined
    processTags(process);
    return process;
}
Also used : DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) Association(io.automatiko.engine.workflow.bpmn2.core.Association) SequenceFlow(io.automatiko.engine.workflow.bpmn2.core.SequenceFlow) Lane(io.automatiko.engine.workflow.bpmn2.core.Lane) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) List(java.util.List) ArrayList(java.util.ArrayList) IntermediateLink(io.automatiko.engine.workflow.bpmn2.core.IntermediateLink)

Example 12 with ExecutableProcess

use of io.automatiko.engine.workflow.process.executable.core.ExecutableProcess 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);
            }
        }
    }
}
Also used : Handler(io.automatiko.engine.workflow.compiler.xml.Handler) CompensationHandler(io.automatiko.engine.workflow.base.core.context.exception.CompensationHandler) StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) Constraint(io.automatiko.engine.workflow.process.core.Constraint) ExecutableProcessValidator(io.automatiko.engine.workflow.process.executable.core.validation.ExecutableProcessValidator) LoggerFactory(org.slf4j.LoggerFactory) Definitions(io.automatiko.engine.workflow.bpmn2.core.Definitions) ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) FunctionTagDefinition(io.automatiko.engine.workflow.base.core.FunctionTagDefinition) Error(io.automatiko.engine.workflow.bpmn2.core.Error) Action(io.automatiko.engine.workflow.base.instance.impl.Action) NodeImpl(io.automatiko.engine.workflow.process.core.impl.NodeImpl) Matcher(java.util.regex.Matcher) ConstraintImpl(io.automatiko.engine.workflow.process.core.impl.ConstraintImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) DataStore(io.automatiko.engine.workflow.bpmn2.core.DataStore) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) Map(java.util.Map) TagDefinition(io.automatiko.engine.workflow.base.core.TagDefinition) Swimlane(io.automatiko.engine.workflow.base.core.context.swimlane.Swimlane) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope) ExceptionScope(io.automatiko.engine.workflow.base.core.context.exception.ExceptionScope) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer) List(java.util.List) StateNode(io.automatiko.engine.workflow.process.core.node.StateNode) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) ProcessInstanceCompensationAction(io.automatiko.engine.workflow.base.instance.impl.actions.ProcessInstanceCompensationAction) PatternConstants(io.automatiko.engine.workflow.util.PatternConstants) ExtensibleXmlParser(io.automatiko.engine.workflow.compiler.xml.ExtensibleXmlParser) SAXException(org.xml.sax.SAXException) SignalProcessInstanceAction(io.automatiko.engine.workflow.base.instance.impl.actions.SignalProcessInstanceAction) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) BaseAbstractHandler(io.automatiko.engine.workflow.compiler.xml.BaseAbstractHandler) StaticTagDefinition(io.automatiko.engine.workflow.base.core.StaticTagDefinition) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) Interface(io.automatiko.engine.workflow.bpmn2.core.Interface) Lane(io.automatiko.engine.workflow.bpmn2.core.Lane) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) Trigger(io.automatiko.engine.workflow.process.core.node.Trigger) Timer(io.automatiko.engine.workflow.base.core.timer.Timer) IntermediateLink(io.automatiko.engine.workflow.bpmn2.core.IntermediateLink) Resource(io.automatiko.engine.workflow.bpmn2.core.Resource) RuleSetNode(io.automatiko.engine.workflow.process.core.node.RuleSetNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Split(io.automatiko.engine.workflow.process.core.node.Split) HashMap(java.util.HashMap) ConstraintTrigger(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) Node(io.automatiko.engine.api.definition.process.Node) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) HumanTaskNode(io.automatiko.engine.workflow.process.core.node.HumanTaskNode) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) CancelNodeInstanceAction(io.automatiko.engine.workflow.base.instance.impl.actions.CancelNodeInstanceAction) ActionExceptionHandler(io.automatiko.engine.workflow.base.core.context.exception.ActionExceptionHandler) Escalation(io.automatiko.engine.workflow.bpmn2.core.Escalation) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) Attributes(org.xml.sax.Attributes) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) Association(io.automatiko.engine.workflow.bpmn2.core.Association) Logger(org.slf4j.Logger) Signal(io.automatiko.engine.workflow.bpmn2.core.Signal) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl) Connection(io.automatiko.engine.workflow.process.core.Connection) ExtendedNodeImpl(io.automatiko.engine.workflow.process.core.impl.ExtendedNodeImpl) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) SequenceFlow(io.automatiko.engine.workflow.bpmn2.core.SequenceFlow) ConnectionRef(io.automatiko.engine.workflow.process.core.impl.ConnectionRef) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Process(io.automatiko.engine.workflow.base.core.Process) CompensationScope(io.automatiko.engine.workflow.base.core.context.exception.CompensationScope) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) MVEL(org.mvel2.MVEL) Message(io.automatiko.engine.workflow.bpmn2.core.Message) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StateNode(io.automatiko.engine.workflow.process.core.node.StateNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) RuleSetNode(io.automatiko.engine.workflow.process.core.node.RuleSetNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Node(io.automatiko.engine.api.definition.process.Node) HumanTaskNode(io.automatiko.engine.workflow.process.core.node.HumanTaskNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) 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) ArrayList(java.util.ArrayList) StateNode(io.automatiko.engine.workflow.process.core.node.StateNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer) ExceptionScope(io.automatiko.engine.workflow.base.core.context.exception.ExceptionScope) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) Trigger(io.automatiko.engine.workflow.process.core.node.Trigger) ConstraintTrigger(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) ConstraintTrigger(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) SignalProcessInstanceAction(io.automatiko.engine.workflow.base.instance.impl.actions.SignalProcessInstanceAction) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) ActionExceptionHandler(io.automatiko.engine.workflow.base.core.context.exception.ActionExceptionHandler) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope)

Example 13 with ExecutableProcess

use of io.automatiko.engine.workflow.process.executable.core.ExecutableProcess in project automatiko-engine by automatiko-io.

the class SequenceFlowHandler method start.

@SuppressWarnings("unchecked")
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    final String id = attrs.getValue("id");
    final String sourceRef = attrs.getValue("sourceRef");
    final String targetRef = attrs.getValue("targetRef");
    final String bendpoints = attrs.getValue("g:bendpoints");
    final String name = attrs.getValue("name");
    final String priority = attrs.getValue("https://automatiko.io", "priority");
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    List<SequenceFlow> connections = null;
    if (nodeContainer instanceof ExecutableProcess) {
        ExecutableProcess process = (ExecutableProcess) nodeContainer;
        connections = (List<SequenceFlow>) process.getMetaData(ProcessHandler.CONNECTIONS);
        if (connections == null) {
            connections = new ArrayList<>();
            process.setMetaData(ProcessHandler.CONNECTIONS, connections);
        }
    } else if (nodeContainer instanceof CompositeNode) {
        CompositeNode compositeNode = (CompositeNode) nodeContainer;
        connections = (List<SequenceFlow>) compositeNode.getMetaData(ProcessHandler.CONNECTIONS);
        if (connections == null) {
            connections = new ArrayList<>();
            compositeNode.setMetaData(ProcessHandler.CONNECTIONS, connections);
        }
    }
    SequenceFlow connection = new SequenceFlow(id, sourceRef, targetRef);
    connection.setBendpoints(bendpoints);
    connection.setName(name);
    if (priority != null) {
        connection.setPriority(Integer.parseInt(priority));
    }
    if (connections != null) {
        connections.add(connection);
    }
    return connection;
}
Also used : CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) SequenceFlow(io.automatiko.engine.workflow.bpmn2.core.SequenceFlow) ArrayList(java.util.ArrayList) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with ExecutableProcess

use of io.automatiko.engine.workflow.process.executable.core.ExecutableProcess in project automatiko-engine by automatiko-io.

the class SubProcessTest method testNonExistentSubProcess.

@Test
public void testNonExistentSubProcess() {
    String nonExistentSubProcessName = "nonexistent.process";
    ExecutableProcess process = new ExecutableProcess();
    process.setId("org.company.core.process.process");
    process.setName("Process");
    StartNode startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    SubProcessNode subProcessNode = new SubProcessNode();
    subProcessNode.setName("SubProcessNode");
    subProcessNode.setId(2);
    subProcessNode.setProcessId(nonExistentSubProcessName);
    EndNode endNode = new EndNode();
    endNode.setName("End");
    endNode.setId(3);
    connect(startNode, subProcessNode);
    connect(subProcessNode, endNode);
    process.addNode(startNode);
    process.addNode(subProcessNode);
    process.addNode(endNode);
    InternalProcessRuntime ksession = createProcessRuntime(process);
    ProcessInstance pi = ksession.startProcess("org.company.core.process.process");
    assertEquals(ProcessInstance.STATE_ERROR, pi.getState());
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) Test(org.junit.jupiter.api.Test) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest)

Example 15 with ExecutableProcess

use of io.automatiko.engine.workflow.process.executable.core.ExecutableProcess in project automatiko-engine by automatiko-io.

the class WorkItemTest method testMockDataWorkItemHandlerCustomFunction.

@Test
public void testMockDataWorkItemHandlerCustomFunction() {
    String processId = "org.company.actions";
    String workName = "Unnexistent Task";
    ExecutableProcess process = getWorkItemProcess(processId, workName);
    InternalProcessRuntime ksession = createProcessRuntime(process);
    ksession.getWorkItemManager().registerWorkItemHandler(workName, new MockDataWorkItemHandler((input) -> {
        Map<String, Object> output = new HashMap<String, Object>();
        if ("John Doe".equals(input.get("Comment"))) {
            output.put("Result", "one");
        } else {
            output.put("Result", "two");
        }
        return output;
    }));
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("UserName", "John Doe");
    parameters.put("Person", new Person("John Doe"));
    ProcessInstance processInstance = ksession.startProcess("org.company.actions", parameters);
    Object numberVariable = ((WorkflowProcessInstance) processInstance).getVariable("MyObject");
    assertNotNull(numberVariable);
    assertEquals("one", numberVariable);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    parameters = new HashMap<String, Object>();
    parameters.put("UserName", "John Doe");
    parameters.put("Person", new Person("John Deen"));
    processInstance = ksession.startProcess("org.company.actions", parameters);
    numberVariable = ((WorkflowProcessInstance) processInstance).getVariable("MyObject");
    assertNotNull(numberVariable);
    assertEquals("two", numberVariable);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) MockDataWorkItemHandler(io.automatiko.engine.workflow.base.instance.impl.demo.MockDataWorkItemHandler) WorkItemHandlerNotFoundException(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IntegerDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) Map(java.util.Map) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Node(io.automatiko.engine.workflow.process.core.Node) ParameterDefinition(io.automatiko.engine.workflow.base.core.ParameterDefinition) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) Set(java.util.Set) DoNothingWorkItemHandler(io.automatiko.engine.workflow.base.instance.impl.demo.DoNothingWorkItemHandler) Test(org.junit.jupiter.api.Test) List(java.util.List) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Person(io.automatiko.engine.workflow.process.test.Person) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) ParameterDefinitionImpl(io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl) WorkImpl(io.automatiko.engine.workflow.base.core.impl.WorkImpl) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance) StringDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.StringDataType) Work(io.automatiko.engine.workflow.base.core.Work) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) HashMap(java.util.HashMap) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance) MockDataWorkItemHandler(io.automatiko.engine.workflow.base.instance.impl.demo.MockDataWorkItemHandler) HashMap(java.util.HashMap) Map(java.util.Map) Person(io.automatiko.engine.workflow.process.test.Person) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest) Test(org.junit.jupiter.api.Test)

Aggregations

ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)58 ArrayList (java.util.ArrayList)29 Test (org.junit.jupiter.api.Test)29 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)28 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)26 AbstractBaseTest (io.automatiko.engine.workflow.test.util.AbstractBaseTest)23 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)20 InternalProcessRuntime (io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)16 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)16 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)15 CompositeContextNode (io.automatiko.engine.workflow.process.core.node.CompositeContextNode)14 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)13 Node (io.automatiko.engine.workflow.process.core.Node)12 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)12 List (java.util.List)12 ProcessAction (io.automatiko.engine.workflow.process.core.ProcessAction)11 ConsequenceAction (io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)11 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)10 ConnectionImpl (io.automatiko.engine.workflow.process.core.impl.ConnectionImpl)10 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)9