Search in sources :

Example 16 with Node

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

the class MetaDataHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    Node node = (Node) parser.getParent();
    final String name = attrs.getValue("name");
    emptyAttributeCheck(localName, "name", name, parser);
    return new MetaDataWrapper(node, name);
}
Also used : Node(io.automatiko.engine.workflow.process.core.Node)

Example 17 with Node

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

the class StartEventHandler method handleNode.

@Override
@SuppressWarnings("unchecked")
protected 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);
    StartNode startNode = (StartNode) node;
    // TODO: StartEventHandler.handleNode(): the parser doesn't discriminate between
    // the schema default and the actual set value
    // However, while the schema says the "isInterrupting" attr should default to
    // true
    // The spec says that Escalation start events should default to not
    // interrupting..
    startNode.setInterrupting(Boolean.parseBoolean(element.getAttribute("isInterrupting")));
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataOutput".equals(nodeName)) {
            readDataOutput(xmlNode, parser);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, startNode);
        } else if ("outputSet".equals(nodeName)) {
            // p. 225, BPMN2 spec (2011-01-03)
            // InputSet and OutputSet elements imply that process execution should wait for
            // them to be filled
            // and are therefore not applicable to catch events
            String message = "Ignoring <" + nodeName + "> element: " + "<" + nodeName + "> elements should not be used on start or other catch events.";
            SAXParseException saxpe = new SAXParseException(message, parser.getLocator());
            parser.warning(saxpe);
        // no exception thrown for backwards compatibility (we used to ignore these
        // elements)
        } else if ("conditionalEventDefinition".equals(nodeName)) {
            String constraint = null;
            org.w3c.dom.Node subNode = xmlNode.getFirstChild();
            while (subNode != null) {
                String subnodeName = subNode.getNodeName();
                if ("condition".equals(subnodeName)) {
                    constraint = xmlNode.getTextContent();
                    break;
                }
                subNode = subNode.getNextSibling();
            }
            ConstraintTrigger trigger = new ConstraintTrigger();
            trigger.setConstraint(constraint);
            startNode.addTrigger(trigger);
            startNode.setMetaData(TRIGGER_REF, "Condition-" + node.getId());
            startNode.setMetaData(TRIGGER_TYPE, "Condition");
            break;
        } else if ("signalEventDefinition".equals(nodeName)) {
            String type = ((Element) xmlNode).getAttribute("signalRef");
            Signal signal = findSignalByName(parser, type);
            type = checkSignalAndConvertToRealSignalNam(parser, type);
            if (type != null && type.trim().length() > 0) {
                addTriggerWithInMappings(startNode, type);
            }
            startNode.setMetaData(MESSAGE_TYPE, type);
            startNode.setMetaData(TRIGGER_TYPE, "Signal");
            if (signal != null) {
                String eventType = signal.getStructureRef();
                ProcessBuildData buildData = ((ProcessBuildData) parser.getData());
                Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) buildData.getMetaData("ItemDefinitions");
                if (itemDefinitions != null && itemDefinitions.containsKey(eventType)) {
                    startNode.setMetaData(TRIGGER_REF, itemDefinitions.get(eventType).getStructureRef());
                } else {
                    startNode.setMetaData(TRIGGER_REF, type);
                }
            } else {
                startNode.setMetaData(TRIGGER_REF, type);
            }
        } else if ("messageEventDefinition".equals(nodeName)) {
            String messageRef = ((Element) xmlNode).getAttribute("messageRef");
            Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
            if (messages == null) {
                throw new IllegalArgumentException("No messages found");
            }
            Message message = messages.get(messageRef);
            if (message == null) {
                throw new IllegalArgumentException("Could not find message " + messageRef);
            }
            startNode.setMetaData(MESSAGE_TYPE, message.getType());
            startNode.setMetaData(TRIGGER_TYPE, "ConsumeMessage");
            startNode.setMetaData(TRIGGER_REF, message.getName());
            startNode.setMetaData(TRIGGER_CORRELATION, message.getCorrelation());
            startNode.setMetaData(TRIGGER_CORRELATION_EXPR, message.getCorrelationExpression());
            for (Entry<String, Object> entry : message.getMetaData().entrySet()) {
                startNode.setMetaData(entry.getKey(), entry.getValue());
            }
            addTriggerWithInMappings(startNode, "Message-" + message.getName());
        } else if ("timerEventDefinition".equals(nodeName)) {
            handleTimerNode(startNode, element, uri, localName, parser);
            startNode.setMetaData(TRIGGER_TYPE, "Timer");
        // following event definitions are only for event sub process and will be
        // validated to not be included in top process definitions
        } else if ("errorEventDefinition".equals(nodeName)) {
            if (!startNode.isInterrupting()) {
                // BPMN2 spec (p.245-246, (2011-01-03)) implies that
                // - a <startEvent> in an Event Sub-Process
                // - *without* the 'isInterupting' attribute always interrupts (containing
                // process)
                String errorMsg = "Error Start Events in an Event Sub-Process always interrupt the containing (sub)process(es).";
                throw new IllegalArgumentException(errorMsg);
            }
            String errorRef = ((Element) xmlNode).getAttribute("errorRef");
            if (errorRef != null && errorRef.trim().length() > 0) {
                List<Error> errors = (List<Error>) ((ProcessBuildData) parser.getData()).getMetaData("Errors");
                if (errors == null) {
                    throw new IllegalArgumentException("No errors found");
                }
                Error error = null;
                for (Error listError : errors) {
                    if (errorRef.equals(listError.getId())) {
                        error = listError;
                    }
                }
                if (error == null) {
                    throw new IllegalArgumentException("Could not find error " + errorRef);
                }
                startNode.setMetaData("FaultCode", error.getErrorCode());
                addTriggerWithInMappings(startNode, "Error-" + error.getErrorCode());
                startNode.setMetaData(TRIGGER_TYPE, "Error");
                startNode.setMetaData(TRIGGER_REF, "Error-" + error.getErrorCode());
                if (error.getMetaData().get("retry") != null) {
                    startNode.setMetaData("ErrorRetry", ((Long) DateTimeUtils.parseDuration((String) error.getMetaData().get("retry"))).intValue());
                    if (error.getMetaData().get("retryLimit") != null) {
                        startNode.setMetaData("ErrorRetryLimit", Integer.parseInt((String) error.getMetaData().get("retryLimit")));
                    }
                    if (error.getMetaData().get("retryIncrement") != null) {
                        startNode.setMetaData("ErrorRetryIncrement", ((Long) DateTimeUtils.parseDuration((String) error.getMetaData().get("retryIncrement"))).intValue());
                    }
                    if (error.getMetaData().get("retryMultiplier") != null) {
                        startNode.setMetaData("ErrorRetryIncrementMultiplier", Float.parseFloat((String) error.getMetaData().get("retryMultiplier")));
                    }
                }
            }
        } else if ("escalationEventDefinition".equals(nodeName)) {
            String escalationRef = ((Element) xmlNode).getAttribute("escalationRef");
            if (escalationRef != null && escalationRef.trim().length() > 0) {
                Map<String, Escalation> escalations = (Map<String, Escalation>) ((ProcessBuildData) parser.getData()).getMetaData(ProcessHandler.ESCALATIONS);
                if (escalations == null) {
                    throw new IllegalArgumentException("No escalations found");
                }
                Escalation escalation = escalations.get(escalationRef);
                if (escalation == null) {
                    throw new IllegalArgumentException("Could not find escalation " + escalationRef);
                }
                addTriggerWithInMappings(startNode, "Escalation-" + escalation.getEscalationCode());
                startNode.setMetaData(TRIGGER_TYPE, "Escalation");
            }
        } else if ("compensateEventDefinition".equals(nodeName)) {
            handleCompensationNode(startNode, xmlNode);
        }
        xmlNode = xmlNode.getNextSibling();
    }
    node.setMetaData("DataOutputs", new LinkedHashMap<String, String>(dataOutputTypes));
}
Also used : ConstraintTrigger(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Message(io.automatiko.engine.workflow.bpmn2.core.Message) Node(io.automatiko.engine.workflow.process.core.Node) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Element(org.w3c.dom.Element) Escalation(io.automatiko.engine.workflow.bpmn2.core.Escalation) ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) Error(io.automatiko.engine.workflow.bpmn2.core.Error) Signal(io.automatiko.engine.workflow.bpmn2.core.Signal) Entry(java.util.Map.Entry) ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) SAXParseException(org.xml.sax.SAXParseException) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 18 with Node

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

the class CompensationTest method testNestedCompensationBoundaryEventGeneral.

@Test
public void testNestedCompensationBoundaryEventGeneral() throws Exception {
    String processId = "org.jbpm.process.compensation.boundary.general.nested";
    String[] workItemNames = { "Jip", "Janneke", "Takkie" };
    List<String> eventList = new ArrayList<String>();
    ExecutableProcess process = createNestedCompensationBoundaryEventProcess(processId, workItemNames, eventList);
    // run process
    ksession = createProcessRuntime(process);
    Node toCompensateNode = findNode(process, "sub2");
    String compensationEvent = CompensationScope.IMPLICIT_COMPENSATION_PREFIX + (String) toCompensateNode.getMetaData().get("UniqueId");
    runCompensationBoundaryEventGeneralTest(ksession, process, processId, workItemNames, eventList, compensationEvent);
}
Also used : CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) Node(io.automatiko.engine.workflow.process.core.Node) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) ArrayList(java.util.ArrayList) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest) Test(org.junit.jupiter.api.Test)

Example 19 with Node

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

the class CompensationTest method createCompensationBoundaryEventProcess.

private ExecutableProcess createCompensationBoundaryEventProcess(String processId, String[] workItemNames, final List<String> eventList) throws Exception {
    ExecutableProcess process = new ExecutableProcess();
    process.setAutoComplete(true);
    process.setId(processId);
    process.setName("CESP Process");
    process.setMetaData("Compensation", true);
    List<Variable> variables = new ArrayList<Variable>();
    Variable variable = new Variable();
    variable.setName("event");
    ObjectDataType personDataType = new ObjectDataType(java.lang.String.class);
    variable.setType(personDataType);
    variables.add(variable);
    process.getVariableScope().setVariables(variables);
    NodeCreator<StartNode> startNodeCreator = new NodeCreator<StartNode>(process, StartNode.class);
    NodeCreator<EndNode> endNodeCreator = new NodeCreator<EndNode>(process, EndNode.class);
    NodeCreator<WorkItemNode> workItemNodeCreator = new NodeCreator<WorkItemNode>(process, WorkItemNode.class);
    NodeCreator<BoundaryEventNode> boundaryNodeCreator = new NodeCreator<BoundaryEventNode>(process, BoundaryEventNode.class);
    NodeCreator<ActionNode> actionNodeCreator = new NodeCreator<ActionNode>(process, ActionNode.class);
    // Create process
    StartNode startNode = startNodeCreator.createNode("start");
    Node lastNode = startNode;
    WorkItemNode[] workItemNodes = new WorkItemNode[3];
    for (int i = 0; i < 3; ++i) {
        workItemNodes[i] = workItemNodeCreator.createNode("work" + (i + 1));
        workItemNodes[i].getWork().setName(workItemNames[i]);
        connect(lastNode, workItemNodes[i]);
        lastNode = workItemNodes[i];
    }
    EndNode endNode = endNodeCreator.createNode("end");
    connect(workItemNodes[2], endNode);
    // Compensation (boundary event) handlers
    for (int i = 0; i < 3; ++i) {
        createBoundaryEventCompensationHandler(process, workItemNodes[i], eventList, "" + i + 1);
    }
    return process;
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) Node(io.automatiko.engine.workflow.process.core.Node) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) ArrayList(java.util.ArrayList) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) NodeCreator(io.automatiko.engine.workflow.process.test.NodeCreator) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)

Example 20 with Node

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

the class CompensationTest method testCompensationBoundaryEventSpecific.

/*
	 * TESTS
	 */
@Test
public void testCompensationBoundaryEventSpecific() throws Exception {
    String processId = "org.jbpm.process.compensation.boundary";
    String[] workItemNames = { "Don-Quixote", "Sancho", "Ricote" };
    List<String> eventList = new ArrayList<String>();
    ExecutableProcess process = createCompensationBoundaryEventProcess(processId, workItemNames, eventList);
    // run process
    ksession = createProcessRuntime(process);
    Node compensatedNode = findNode(process, "work1");
    String compensationEvent = (String) compensatedNode.getMetaData().get("UniqueId");
    runCompensationBoundaryEventSpecificTest(ksession, process, processId, workItemNames, eventList, compensationEvent);
}
Also used : CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) Node(io.automatiko.engine.workflow.process.core.Node) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) ArrayList(java.util.ArrayList) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest) Test(org.junit.jupiter.api.Test)

Aggregations

Node (io.automatiko.engine.workflow.process.core.Node)36 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)19 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)19 CompositeContextNode (io.automatiko.engine.workflow.process.core.node.CompositeContextNode)16 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)16 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)16 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)15 ArrayList (java.util.ArrayList)14 NodeContainer (io.automatiko.engine.workflow.process.core.NodeContainer)13 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)13 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)13 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)12 ProcessBuildData (io.automatiko.engine.workflow.compiler.xml.ProcessBuildData)11 Element (org.w3c.dom.Element)11 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)10 ForEachNode (io.automatiko.engine.workflow.process.core.node.ForEachNode)10 AbstractBaseTest (io.automatiko.engine.workflow.test.util.AbstractBaseTest)8 Test (org.junit.jupiter.api.Test)8 SubProcessNode (io.automatiko.engine.workflow.process.core.node.SubProcessNode)6 TimerNode (io.automatiko.engine.workflow.process.core.node.TimerNode)6