Search in sources :

Example 11 with Definitions

use of io.automatiko.engine.workflow.bpmn2.core.Definitions in project automatiko-engine by automatiko-io.

the class MessageHandler 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);
    String id = attrs.getValue("id");
    String itemRef = attrs.getValue("itemRef");
    String name = attrs.getValue("name");
    if (name == null) {
        name = id;
    }
    Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
    if (itemDefinitions == null) {
        throw new IllegalArgumentException("No item definitions found");
    }
    ItemDefinition itemDefinition = itemDefinitions.get(itemRef);
    if (itemDefinition == null) {
        throw new IllegalArgumentException("Could not find itemDefinition " + itemRef);
    }
    ProcessBuildData buildData = (ProcessBuildData) parser.getData();
    Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
    if (messages == null) {
        messages = new HashMap<String, Message>();
        buildData.setMetaData("Messages", messages);
    }
    Message message = new Message(id);
    message.setType(itemDefinition.getStructureRef());
    message.setName(name);
    if (message.getType() != null && !message.getType().isEmpty()) {
        messages.put(id, message);
    }
    return message;
}
Also used : ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) Message(io.automatiko.engine.workflow.bpmn2.core.Message) ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with Definitions

use of io.automatiko.engine.workflow.bpmn2.core.Definitions in project jbpm by kiegroup.

the class XmlBPMNProcessDumper method visitProcess.

protected void visitProcess(WorkflowProcess process, StringBuilder xmlDump, int metaDataType) {
    String targetNamespace = (String) process.getMetaData().get("TargetNamespace");
    if (targetNamespace == null) {
        targetNamespace = "http://www.jboss.org/drools";
    }
    xmlDump.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?> " + EOL + "<definitions id=\"Definition\"" + EOL + "             targetNamespace=\"" + targetNamespace + "\"" + EOL + "             typeLanguage=\"http://www.java.com/javaTypes\"" + EOL + "             expressionLanguage=\"http://www.mvel.org/2.0\"" + EOL + "             xmlns=\"http://www.omg.org/spec/BPMN/20100524/MODEL\"" + EOL + "             xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + EOL + "             xsi:schemaLocation=\"http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd\"" + EOL + "             xmlns:g=\"http://www.jboss.org/drools/flow/gpd\"" + EOL + (metaDataType == META_DATA_USING_DI ? "             xmlns:bpmndi=\"http://www.omg.org/spec/BPMN/20100524/DI\"" + EOL + "             xmlns:dc=\"http://www.omg.org/spec/DD/20100524/DC\"" + EOL + "             xmlns:di=\"http://www.omg.org/spec/DD/20100524/DI\"" + EOL : "") + "             xmlns:tns=\"http://www.jboss.org/drools\">" + EOL + EOL);
    // item definitions
    this.visitedVariables = new HashSet<String>();
    VariableScope variableScope = (VariableScope) ((org.jbpm.process.core.Process) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
    Set<String> dumpedItemDefs = new HashSet<String>();
    Map<String, ItemDefinition> itemDefs = (Map<String, ItemDefinition>) process.getMetaData().get("ItemDefinitions");
    if (itemDefs != null) {
        for (ItemDefinition def : itemDefs.values()) {
            xmlDump.append("  <itemDefinition id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(def.getId()) + "\" ");
            if (def.getStructureRef() != null && !"java.lang.Object".equals(def.getStructureRef())) {
                xmlDump.append("structureRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(def.getStructureRef()) + "\" ");
            }
            xmlDump.append("/>" + EOL);
            dumpedItemDefs.add(def.getId().intern());
        }
    }
    visitVariableScope(variableScope, "_", xmlDump, dumpedItemDefs);
    visitSubVariableScopes(process.getNodes(), xmlDump, dumpedItemDefs);
    visitInterfaces(process.getNodes(), xmlDump);
    visitEscalations(process.getNodes(), xmlDump, new ArrayList<String>());
    Definitions def = (Definitions) process.getMetaData().get("Definitions");
    visitErrors(def, xmlDump);
    // data stores
    if (def != null && def.getDataStores() != null) {
        for (DataStore dataStore : def.getDataStores()) {
            visitDataStore(dataStore, xmlDump);
        }
    }
    // the process itself
    xmlDump.append("  <process processType=\"Private\" isExecutable=\"true\" ");
    if (process.getId() == null || process.getId().trim().length() == 0) {
        ((ProcessImpl) process).setId("com.sample.bpmn2");
    }
    xmlDump.append("id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(process.getId()) + "\" ");
    if (process.getName() != null) {
        xmlDump.append("name=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(process.getName()) + "\" ");
    }
    String packageName = process.getPackageName();
    if (packageName != null && !"org.drools.bpmn2".equals(packageName)) {
        xmlDump.append("tns:packageName=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(packageName) + "\" ");
    }
    if (((org.jbpm.workflow.core.WorkflowProcess) process).isDynamic()) {
        xmlDump.append("tns:adHoc=\"true\" ");
    }
    String version = process.getVersion();
    if (version != null && !"".equals(version)) {
        xmlDump.append("tns:version=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(version) + "\" ");
    }
    // TODO: package, version
    xmlDump.append(">" + EOL + EOL);
    visitHeader(process, xmlDump, metaDataType);
    List<org.jbpm.workflow.core.Node> processNodes = new ArrayList<org.jbpm.workflow.core.Node>();
    for (Node procNode : process.getNodes()) {
        processNodes.add((org.jbpm.workflow.core.Node) procNode);
    }
    visitNodes(processNodes, xmlDump, metaDataType);
    visitConnections(process.getNodes(), xmlDump, metaDataType);
    // add associations
    List<Association> associations = (List<Association>) process.getMetaData().get(ProcessHandler.ASSOCIATIONS);
    if (associations != null) {
        for (Association association : associations) {
            visitAssociation(association, xmlDump);
        }
    }
    xmlDump.append("  </process>" + EOL + EOL);
    if (metaDataType == META_DATA_USING_DI) {
        xmlDump.append("  <bpmndi:BPMNDiagram>" + EOL + "    <bpmndi:BPMNPlane bpmnElement=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(process.getId()) + "\" >" + EOL);
        visitNodesDi(process.getNodes(), xmlDump);
        visitConnectionsDi(process.getNodes(), xmlDump);
        xmlDump.append("    </bpmndi:BPMNPlane>" + EOL + "  </bpmndi:BPMNDiagram>" + EOL + EOL);
    }
    xmlDump.append("</definitions>");
}
Also used : Definitions(org.jbpm.bpmn2.core.Definitions) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) StartNode(org.jbpm.workflow.core.node.StartNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) FaultNode(org.jbpm.workflow.core.node.FaultNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) EventNode(org.jbpm.workflow.core.node.EventNode) Node(org.kie.api.definition.process.Node) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) ArrayList(java.util.ArrayList) Association(org.jbpm.bpmn2.core.Association) DataStore(org.jbpm.bpmn2.core.DataStore) ProcessImpl(org.jbpm.process.core.impl.ProcessImpl) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) WorkflowProcess(org.kie.api.definition.process.WorkflowProcess) VariableScope(org.jbpm.process.core.context.variable.VariableScope) HashSet(java.util.HashSet)

Example 13 with Definitions

use of io.automatiko.engine.workflow.bpmn2.core.Definitions in project kogito-runtimes by kiegroup.

the class AbstractNodeHandler method getErrorIdForErrorCode.

protected String getErrorIdForErrorCode(String errorCode, Node node) {
    org.kie.api.definition.process.NodeContainer parent = node.getParentContainer();
    while (!(parent instanceof RuleFlowProcess) && parent instanceof Node) {
        parent = ((Node) parent).getParentContainer();
    }
    if (!(parent instanceof RuleFlowProcess)) {
        throw new RuntimeException("This should never happen: !(parent instanceof RuleFlowProcess): parent is " + parent.getClass().getSimpleName());
    }
    List<Error> errors = ((Definitions) ((RuleFlowProcess) parent).getMetaData("Definitions")).getErrors();
    Error error = null;
    for (Error listError : errors) {
        if (errorCode.equals(listError.getErrorCode())) {
            error = listError;
            break;
        } else if (errorCode.equals(listError.getId())) {
            error = listError;
            break;
        }
    }
    if (error == null) {
        throw new ProcessParsingValidationException("Could not find error with errorCode " + errorCode);
    }
    return error.getId();
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) StateNode(org.jbpm.workflow.core.node.StateNode) CatchLinkNode(org.jbpm.workflow.core.node.CatchLinkNode) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) Node(org.jbpm.workflow.core.Node) TimerNode(org.jbpm.workflow.core.node.TimerNode) FaultNode(org.jbpm.workflow.core.node.FaultNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) EventNode(org.jbpm.workflow.core.node.EventNode) Definitions(org.jbpm.bpmn2.core.Definitions) Error(org.jbpm.bpmn2.core.Error)

Example 14 with Definitions

use of io.automatiko.engine.workflow.bpmn2.core.Definitions in project kogito-runtimes by kiegroup.

the class DefinitionsHandler method end.

@Override
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    Definitions definitions = (Definitions) parser.getCurrent();
    String namespace = element.getAttribute("targetNamespace");
    List<Process> processes = ((ProcessBuildData) parser.getData()).getProcesses();
    Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
    List<Interface> interfaces = (List<Interface>) ((ProcessBuildData) parser.getData()).getMetaData("Interfaces");
    for (Process process : processes) {
        RuleFlowProcess ruleFlowProcess = (RuleFlowProcess) process;
        ruleFlowProcess.setMetaData("TargetNamespace", namespace);
        postProcessItemDefinitions(ruleFlowProcess, itemDefinitions, parser.getClassLoader());
        postProcessInterfaces(ruleFlowProcess, interfaces);
    }
    definitions.setTargetNamespace(namespace);
    return definitions;
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) Element(org.w3c.dom.Element) Definitions(org.jbpm.bpmn2.core.Definitions) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) Process(org.kie.api.definition.process.Process) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) List(java.util.List) Map(java.util.Map) Interface(org.jbpm.bpmn2.core.Interface)

Example 15 with Definitions

use of io.automatiko.engine.workflow.bpmn2.core.Definitions in project automatiko-engine by automatiko-io.

the class DefinitionsHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    Definitions definitions = (Definitions) parser.getCurrent();
    String namespace = element.getAttribute("targetNamespace");
    List<Process> processes = ((ProcessBuildData) parser.getData()).getProcesses();
    Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
    List<Interface> interfaces = (List<Interface>) ((ProcessBuildData) parser.getData()).getMetaData("Interfaces");
    for (Process process : processes) {
        ExecutableProcess ruleFlowProcess = (ExecutableProcess) process;
        ruleFlowProcess.setMetaData("TargetNamespace", namespace);
        postProcessItemDefinitions(ruleFlowProcess, itemDefinitions, parser.getClassLoader());
        postProcessInterfaces(ruleFlowProcess, interfaces);
        postProcessNodes(ruleFlowProcess, Collections.emptyList(), parser);
    }
    definitions.setTargetNamespace(namespace);
    return definitions;
}
Also used : Element(org.w3c.dom.Element) Definitions(io.automatiko.engine.workflow.bpmn2.core.Definitions) ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess) Process(io.automatiko.engine.api.definition.process.Process) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) LinkedList(java.util.LinkedList) List(java.util.List) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) Map(java.util.Map) Interface(io.automatiko.engine.workflow.bpmn2.core.Interface)

Aggregations

List (java.util.List)10 Map (java.util.Map)9 Definitions (org.jbpm.bpmn2.core.Definitions)8 Association (io.automatiko.engine.workflow.bpmn2.core.Association)5 Definitions (io.automatiko.engine.workflow.bpmn2.core.Definitions)5 ItemDefinition (io.automatiko.engine.workflow.bpmn2.core.ItemDefinition)5 ArrayList (java.util.ArrayList)5 Error (io.automatiko.engine.workflow.bpmn2.core.Error)4 ProcessBuildData (io.automatiko.engine.workflow.compiler.xml.ProcessBuildData)4 HashMap (java.util.HashMap)4 ItemDefinition (org.jbpm.bpmn2.core.ItemDefinition)4 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)4 ActionNode (org.jbpm.workflow.core.node.ActionNode)4 EndNode (org.jbpm.workflow.core.node.EndNode)4 EventNode (org.jbpm.workflow.core.node.EventNode)4 ForEachNode (org.jbpm.workflow.core.node.ForEachNode)4 Element (org.w3c.dom.Element)4 DataStore (io.automatiko.engine.workflow.bpmn2.core.DataStore)3 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)3 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)3