Search in sources :

Example 21 with WorkItemNode

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

the class SendTaskHandler method handleNode.

@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);
    WorkItemNode workItemNode = (WorkItemNode) node;
    String messageRef = element.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);
    }
    workItemNode.getWork().setParameter("MessageType", message.getType());
}
Also used : Message(io.automatiko.engine.workflow.bpmn2.core.Message) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Map(java.util.Map)

Example 22 with WorkItemNode

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

the class TaskHandler method handleNode.

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);
    itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
    dataTypeInputs.clear();
    dataTypeOutputs.clear();
    WorkItemNode workItemNode = (WorkItemNode) node;
    String name = getTaskName(element);
    Work work = new WorkImpl();
    work.setName(name);
    workItemNode.setWork(work);
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("ioSpecification".equals(nodeName)) {
            readIoSpecification(xmlNode, dataInputs, dataOutputs, dataInputTypes);
        } else if ("dataInputAssociation".equals(nodeName)) {
            readDataInputAssociation(xmlNode, workItemNode, dataInputs);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, workItemNode, dataOutputs);
        }
        xmlNode = xmlNode.getNextSibling();
    }
    workItemNode.setMetaData("DataInputs", new LinkedHashMap<String, String>(dataTypeInputs));
    workItemNode.setMetaData("DataOutputs", new LinkedHashMap<String, String>(dataTypeOutputs));
    handleScript(workItemNode, element, "onEntry");
    handleScript(workItemNode, element, "onExit");
    String compensation = element.getAttribute("isForCompensation");
    if (compensation != null) {
        boolean isForCompensation = Boolean.parseBoolean(compensation);
        if (isForCompensation) {
            workItemNode.setMetaData("isForCompensation", isForCompensation);
        }
    }
    for (Entry<String, String> entryInputTypes : dataTypeInputs.entrySet()) {
        ParameterDefinition parameterDefinition = new ParameterDefinitionImpl();
        parameterDefinition.setName(entryInputTypes.getKey());
        parameterDefinition.setType(new ObjectDataType(constructClass(entryInputTypes.getValue()), entryInputTypes.getValue()));
        work.addParameterDefinition(parameterDefinition);
    }
}
Also used : ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) ParameterDefinitionImpl(io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl) ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Work(io.automatiko.engine.workflow.base.core.Work) WorkImpl(io.automatiko.engine.workflow.base.core.impl.WorkImpl) ParameterDefinition(io.automatiko.engine.workflow.base.core.ParameterDefinition)

Example 23 with WorkItemNode

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

the class TaskHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    Node node = (Node) parser.getCurrent();
    // determine type of event definition, so the correct type of node can be
    // generated
    handleNode(node, element, uri, localName, parser);
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    int uniqueIdGen = 1;
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("multiInstanceLoopCharacteristics".equals(nodeName)) {
            // create new timerNode
            ForEachNode forEachNode = new ForEachNode();
            forEachNode.setId(node.getId());
            String uniqueId = (String) node.getMetaData().get("UniqueId");
            forEachNode.setMetaData("UniqueId", uniqueId);
            node.setMetaData("UniqueId", uniqueId + ":" + uniqueIdGen++);
            forEachNode.addNode(node);
            forEachNode.linkIncomingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE, node.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE);
            forEachNode.linkOutgoingConnections(node.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE, NodeImpl.CONNECTION_DEFAULT_TYPE);
            forEachNode.setSequential(Boolean.parseBoolean(((Element) xmlNode).getAttribute("isSequential")));
            Node orignalNode = node;
            node = forEachNode;
            handleForEachNode(node, element, uri, localName, parser);
            // running in variable strict mode
            if (orignalNode instanceof WorkItemNode) {
                adjustNodeConfiguration(orignalNode, forEachNode);
            }
            break;
        }
        xmlNode = xmlNode.getNextSibling();
    }
    // replace node in case it's milestone
    if (node instanceof WorkItemNode && ((WorkItemNode) node).getWork().getName().equals("Milestone")) {
        WorkItemNode workItemNode = (WorkItemNode) node;
        String milestoneCondition = (String) ((WorkItemNode) node).getWork().getParameter(CONDITION);
        MilestoneNode milestoneNode = new MilestoneNode();
        milestoneNode.setId(workItemNode.getId());
        milestoneNode.setMetaData(workItemNode.getMetaData());
        milestoneNode.setConditionExpression(milestoneCondition);
        milestoneNode.setName(workItemNode.getName());
        milestoneNode.setParentContainer(workItemNode.getParentContainer());
        node = milestoneNode;
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    nodeContainer.addNode(node);
    ((ProcessBuildData) parser.getData()).addNode(node);
    return node;
}
Also used : ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) Element(org.w3c.dom.Element) Node(io.automatiko.engine.workflow.process.core.Node) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) MilestoneNode(io.automatiko.engine.workflow.process.core.node.MilestoneNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer) MilestoneNode(io.automatiko.engine.workflow.process.core.node.MilestoneNode)

Example 24 with WorkItemNode

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

the class TaskHandler method readDataOutputAssociation.

protected void readDataOutputAssociation(org.w3c.dom.Node xmlNode, WorkItemNode workItemNode, Map<String, String> dataOutputs) {
    // sourceRef
    org.w3c.dom.Node subNode = xmlNode.getFirstChild();
    List<String> sources = new ArrayList<>();
    sources.add(subNode.getTextContent());
    subNode = subNode.getNextSibling();
    while ("sourceRef".equals(subNode.getNodeName())) {
        sources.add(subNode.getTextContent());
        subNode = subNode.getNextSibling();
    }
    // targetRef
    String target = subNode.getTextContent();
    // transformation
    Transformation transformation = null;
    subNode = subNode.getNextSibling();
    if (subNode != null && "transformation".equals(subNode.getNodeName())) {
        String lang = subNode.getAttributes().getNamedItem("language").getNodeValue();
        String expression = subNode.getTextContent();
        DataTransformer transformer = transformerRegistry.find(lang);
        if (transformer == null) {
            throw new IllegalArgumentException("No transformer registered for language " + lang);
        }
        transformation = new Transformation(lang, expression);
        // transformation.setCompiledExpression(transformer.compile(expression));
        subNode = subNode.getNextSibling();
    }
    // assignments
    List<Assignment> assignments = new LinkedList<Assignment>();
    while (subNode != null) {
        String expressionLang = ((Element) subNode).getAttribute("expressionLanguage");
        if (expressionLang == null || expressionLang.trim().isEmpty()) {
            expressionLang = "XPath";
        }
        org.w3c.dom.Node ssubNode = subNode.getFirstChild();
        String from = ssubNode.getTextContent();
        String to = ssubNode.getNextSibling().getTextContent();
        assignments.add(new Assignment(expressionLang, from, to));
        subNode = subNode.getNextSibling();
    }
    workItemNode.addOutAssociation(new DataAssociation(sources.stream().map(source -> dataOutputs.get(source)).collect(Collectors.toList()), target, assignments, transformation));
}
Also used : Text(org.w3c.dom.Text) Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) ArrayList(java.util.ArrayList) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer) LinkedHashMap(java.util.LinkedHashMap) NodeImpl(io.automatiko.engine.workflow.process.core.impl.NodeImpl) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) Map(java.util.Map) Attributes(org.xml.sax.Attributes) LinkedList(java.util.LinkedList) Node(io.automatiko.engine.workflow.process.core.Node) ParameterDefinition(io.automatiko.engine.workflow.base.core.ParameterDefinition) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) NodeList(org.w3c.dom.NodeList) MilestoneNode(io.automatiko.engine.workflow.process.core.node.MilestoneNode) Collectors(java.util.stream.Collectors) ClassUtils.constructClass(io.automatiko.engine.workflow.compiler.util.ClassUtils.constructClass) Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) DataTransformerRegistry(io.automatiko.engine.workflow.base.core.impl.DataTransformerRegistry) List(java.util.List) Element(org.w3c.dom.Element) ExtensibleXmlParser(io.automatiko.engine.workflow.compiler.xml.ExtensibleXmlParser) SAXException(org.xml.sax.SAXException) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Entry(java.util.Map.Entry) CONDITION(io.automatiko.engine.workflow.process.executable.core.Metadata.CONDITION) ParameterDefinitionImpl(io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl) WorkImpl(io.automatiko.engine.workflow.base.core.impl.WorkImpl) Work(io.automatiko.engine.workflow.base.core.Work) Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer)

Example 25 with WorkItemNode

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

the class WorkItemNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
    WorkItemNode workItemNode = (WorkItemNode) node;
    String type = workItemNode.getWork().getName();
    if ("Manual Task".equals(type)) {
        writeNode("manualTask", workItemNode, xmlDump, metaDataType);
        xmlDump.append(">" + EOL);
        writeExtensionElements(workItemNode, xmlDump);
        endNode("manualTask", xmlDump);
        return;
    }
    if ("Service Task".equals(type)) {
        writeNode("serviceTask", workItemNode, xmlDump, metaDataType);
        String impl = "Other";
        if (workItemNode.getWork().getParameter("implementation") != null) {
            impl = (String) workItemNode.getWork().getParameter("implementation");
        }
        xmlDump.append("operationRef=\"" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_ServiceOperation\" implementation=\"" + impl + "\" >" + EOL);
        writeExtensionElements(workItemNode, xmlDump);
        xmlDump.append("      <ioSpecification>" + EOL + "        <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param\" name=\"Parameter\" />" + EOL + "        <dataOutput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result\" name=\"Result\" />" + EOL + "        <inputSet>" + EOL + "          <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param</dataInputRefs>" + EOL + "        </inputSet>" + EOL + "        <outputSet>" + EOL + "          <dataOutputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result</dataOutputRefs>" + EOL + "        </outputSet>" + EOL + "      </ioSpecification>" + EOL);
        String inMapping = workItemNode.getInMapping("Parameter");
        if (inMapping != null) {
            xmlDump.append("      <dataInputAssociation>" + EOL + "        <sourceRef>" + XmlDumper.replaceIllegalChars(inMapping) + "</sourceRef>" + EOL + "        <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param</targetRef>" + EOL + "      </dataInputAssociation>" + EOL);
        }
        String outMapping = workItemNode.getOutMapping("Result");
        if (outMapping != null) {
            xmlDump.append("      <dataOutputAssociation>" + EOL + "        <sourceRef>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result</sourceRef>" + EOL + "        <targetRef>" + XmlDumper.replaceIllegalChars(outMapping) + "</targetRef>" + EOL + "      </dataOutputAssociation>" + EOL);
        }
        endNode("serviceTask", xmlDump);
        return;
    }
    if ("Send Task".equals(type)) {
        writeNode("sendTask", workItemNode, xmlDump, metaDataType);
        xmlDump.append("messageRef=\"" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_Message\" implementation=\"Other\" >" + EOL);
        writeExtensionElements(workItemNode, xmlDump);
        xmlDump.append("      <ioSpecification>" + EOL + "        <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param\" name=\"Message\" />" + EOL + "        <inputSet>" + EOL + "          <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param</dataInputRefs>" + EOL + "        </inputSet>" + EOL + "        <outputSet/>" + EOL + "      </ioSpecification>" + EOL);
        String inMapping = workItemNode.getInMapping("Message");
        if (inMapping != null) {
            xmlDump.append("      <dataInputAssociation>" + EOL + "        <sourceRef>" + XmlDumper.replaceIllegalChars(inMapping) + "</sourceRef>" + EOL + "        <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param</targetRef>" + EOL + "      </dataInputAssociation>" + EOL);
        }
        endNode("sendTask", xmlDump);
        return;
    }
    if ("Receive Task".equals(type)) {
        writeNode("receiveTask", workItemNode, xmlDump, metaDataType);
        String messageId = (String) workItemNode.getWork().getParameter("MessageId");
        xmlDump.append("messageRef=\"" + messageId + "\" implementation=\"Other\" >" + EOL);
        writeExtensionElements(workItemNode, xmlDump);
        xmlDump.append("      <ioSpecification>" + EOL + "        <dataOutput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result\" name=\"Message\" />" + EOL + "        <inputSet/>" + EOL + "        <outputSet>" + EOL + "          <dataOutputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result</dataOutputRefs>" + EOL + "        </outputSet>" + EOL + "      </ioSpecification>" + EOL);
        String outMapping = workItemNode.getOutMapping("Message");
        if (outMapping != null) {
            xmlDump.append("      <dataOutputAssociation>" + EOL + "        <sourceRef>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result</sourceRef>" + EOL + "        <targetRef>" + XmlDumper.replaceIllegalChars(outMapping) + "</targetRef>" + EOL + "      </dataOutputAssociation>" + EOL);
        }
        endNode("receiveTask", xmlDump);
        return;
    }
    writeNode("task", workItemNode, xmlDump, metaDataType);
    Object isForCompensationObject = workItemNode.getMetaData("isForCompensation");
    if (isForCompensationObject != null && ((Boolean) isForCompensationObject)) {
        xmlDump.append("isForCompensation=\"true\" ");
    }
    xmlDump.append("tns:taskName=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\" >" + EOL);
    writeExtensionElements(workItemNode, xmlDump);
    writeIO(workItemNode, xmlDump);
    endNode("task", xmlDump);
}
Also used : WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode)

Aggregations

WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)26 Work (io.automatiko.engine.workflow.base.core.Work)10 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)10 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)10 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)10 ArrayList (java.util.ArrayList)8 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)7 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)7 ObjectDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType)6 WorkImpl (io.automatiko.engine.workflow.base.core.impl.WorkImpl)6 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)6 CompositeContextNode (io.automatiko.engine.workflow.process.core.node.CompositeContextNode)6 ForEachNode (io.automatiko.engine.workflow.process.core.node.ForEachNode)6 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)6 List (java.util.List)6 Map (java.util.Map)6 Node (io.automatiko.engine.api.definition.process.Node)5 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)5 Node (io.automatiko.engine.workflow.process.core.Node)5 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)4