Search in sources :

Example 6 with ItemDefinition

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

the class ServicesProcessDataEventListener method onBuildComplete.

@SuppressWarnings("unchecked")
@Override
public void onBuildComplete(Process process) {
    // process java dialect types
    Set<String> referencedTypes = (Set<String>) process.getMetaData().get("JavaDialectReferencedTypes");
    if (referencedTypes != null && !referencedTypes.isEmpty()) {
        processDescriptor.getReferencedClasses().addAll(referencedTypes);
    }
    Set<String> unqualifiedClasses = (Set<String>) process.getMetaData().get("JavaDialectUnqualifiedTypes");
    if (unqualifiedClasses != null && !unqualifiedClasses.isEmpty()) {
        processDescriptor.getUnqualifiedClasses().addAll(unqualifiedClasses);
    }
    // process java return value types
    referencedTypes = (Set<String>) process.getMetaData().get("JavaReturnValueReferencedTypes");
    if (referencedTypes != null && !referencedTypes.isEmpty()) {
        processDescriptor.getReferencedClasses().addAll(referencedTypes);
    }
    unqualifiedClasses = (Set<String>) process.getMetaData().get("JavaReturnValueUnqualifiedTypes");
    if (unqualifiedClasses != null && !unqualifiedClasses.isEmpty()) {
        processDescriptor.getUnqualifiedClasses().addAll(unqualifiedClasses);
    }
    // process mvel dialect types
    referencedTypes = (Set<String>) process.getMetaData().get("MVELDialectReferencedTypes");
    if (referencedTypes != null && !referencedTypes.isEmpty()) {
        processDescriptor.getReferencedClasses().addAll(referencedTypes);
    }
    // process mvel return value types
    referencedTypes = (Set<String>) process.getMetaData().get("MVELReturnValueReferencedTypes");
    if (referencedTypes != null && !referencedTypes.isEmpty()) {
        processDescriptor.getReferencedClasses().addAll(referencedTypes);
    }
    // process unqualified classes
    resolveUnqualifiedClasses();
    // process variables
    if (variables != null) {
        for (Variable data : variables) {
            String type = data.getType().getStringType();
            String itemSubjectRef = (String) data.getMetaData("ItemSubjectRef");
            if (itemSubjectRef != null && itemDefinitions != null) {
                ItemDefinition itemDef = itemDefinitions.get(itemSubjectRef);
                type = itemDef.getStructureRef();
            }
            processDescriptor.getInputs().put(data.getName(), type);
            processDescriptor.getInputTags(data.getName()).addAll(data.getTags());
        }
    }
    // process signals
    if (signals != null) {
        processDescriptor.setSignals(signals);
    }
    if (messages != null) {
        processDescriptor.setMessages(messages.stream().map(MessageDescImpl::from).collect(Collectors.toSet()));
    }
    if (signalsInfo != null) {
        processDescriptor.setSignalsDesc(signalsInfo.stream().map(SignalDescImpl::from).collect(Collectors.toSet()));
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Variable(org.jbpm.process.core.context.variable.Variable) SignalDescImpl(org.jbpm.kie.services.impl.model.SignalDescImpl) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) MessageDescImpl(org.jbpm.kie.services.impl.model.MessageDescImpl)

Example 7 with ItemDefinition

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

the class ServicesProcessDataEventListener method onComplete.

@Override
public void onComplete(Process process) {
    // process item definitions
    if (itemDefinitions != null) {
        for (ItemDefinition item : itemDefinitions.values()) {
            String id = item.getId();
            String structureRef = item.getStructureRef();
            // NPE!
            String itemDefinitionId = processDescriptor.getGlobalItemDefinitions().get(id);
            if (itemDefinitionId == null) {
                processDescriptor.getGlobalItemDefinitions().put(id, structureRef);
                if (structureRef.contains(".")) {
                    processDescriptor.getReferencedClasses().add(structureRef);
                } else {
                    processDescriptor.getUnqualifiedClasses().add(structureRef);
                }
            }
        }
    }
    // process globals
    Map<String, String> globals = ((RuleFlowProcess) process).getGlobals();
    if (globals != null) {
        Set<String> globalNames = new HashSet<>();
        for (Entry<String, String> globalEntry : globals.entrySet()) {
            globalNames.add(globalEntry.getKey());
            String type = globalEntry.getValue();
            if (type.contains(".")) {
                processDescriptor.getReferencedClasses().add(type);
            } else {
                processDescriptor.getUnqualifiedClasses().add(type);
            }
        }
        processDescriptor.setGlobals(globalNames);
    }
    // process imports
    Set<String> imports = ((RuleFlowProcess) process).getImports();
    if (imports != null) {
        for (String type : imports) {
            if (type.contains(".")) {
                processDescriptor.getReferencedClasses().add(type);
            } else {
                processDescriptor.getUnqualifiedClasses().add(type);
            }
        }
    }
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) HashSet(java.util.HashSet)

Example 8 with ItemDefinition

use of io.automatiko.engine.workflow.bpmn2.core.ItemDefinition in project kogito-runtimes 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<Node> processNodes = new ArrayList<Node>();
    for (org.kie.api.definition.process.Node procNode : process.getNodes()) {
        processNodes.add((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 : 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) KogitoNode(org.kie.kogito.internal.process.runtime.KogitoNode) Node(org.jbpm.workflow.core.Node) 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) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) ArrayList(java.util.ArrayList) Association(org.jbpm.bpmn2.core.Association) DataStore(org.jbpm.bpmn2.core.DataStore) List(java.util.List) ArrayList(java.util.ArrayList) WorkflowProcess(org.kie.api.definition.process.WorkflowProcess) HashSet(java.util.HashSet) Definitions(org.jbpm.bpmn2.core.Definitions) ProcessImpl(org.jbpm.process.core.impl.ProcessImpl) Map(java.util.Map) HashMap(java.util.HashMap) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Example 9 with ItemDefinition

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

the class DataObjectHandler method start.

@Override
@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 itemSubjectRef = attrs.getValue("itemSubjectRef");
    Object parent = parser.getParent();
    if (parent instanceof ContextContainer) {
        ContextContainer contextContainer = (ContextContainer) parent;
        VariableScope variableScope = (VariableScope) contextContainer.getDefaultContext(VariableScope.VARIABLE_SCOPE);
        List variables = variableScope.getVariables();
        Variable variable = new Variable();
        variable.setMetaData("DataObject", "true");
        variable.setId(id);
        variable.setName(id);
        variable.setMetaData(id, variable.getName());
        // retrieve type from item definition
        DataType dataType = DataTypeResolver.defaultDataType;
        Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
        if (itemDefinitions != null) {
            ItemDefinition itemDefinition = itemDefinitions.get(itemSubjectRef);
            if (itemDefinition != null) {
                dataType = DataTypeResolver.fromType(itemDefinition.getStructureRef(), parser.getClassLoader());
            }
        }
        variable.setType(dataType);
        variables.add(variable);
        return variable;
    }
    return new Variable();
}
Also used : ContextContainer(org.jbpm.process.core.ContextContainer) Variable(org.jbpm.process.core.context.variable.Variable) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) DataType(org.jbpm.process.core.datatype.DataType) List(java.util.List) Map(java.util.Map) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Example 10 with ItemDefinition

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

the class DefinitionsHandler method setVariableDataType.

private void setVariableDataType(Variable variable, Map<String, ItemDefinition> itemDefinitions, ClassLoader cl) {
    // retrieve type from item definition
    String itemSubjectRef = (String) variable.getMetaData("ItemSubjectRef");
    Object defaultValue = variable.getMetaData("defaultValue");
    if (UndefinedDataType.getInstance().equals(variable.getType()) && itemDefinitions != null && itemSubjectRef != null) {
        DataType dataType = DataTypeResolver.defaultDataType;
        ItemDefinition itemDefinition = itemDefinitions.get(itemSubjectRef);
        if (itemDefinition != null) {
            dataType = DataTypeResolver.fromType(itemDefinition.getStructureRef(), cl);
        }
        variable.setType(dataType);
        variable.setValue(dataType.verifyDataType(defaultValue) ? defaultValue : dataType.readValue((String) defaultValue));
    }
}
Also used : ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) UndefinedDataType(org.jbpm.process.core.datatype.impl.type.UndefinedDataType) DataType(org.jbpm.process.core.datatype.DataType)

Aggregations

Map (java.util.Map)19 ItemDefinition (org.jbpm.bpmn2.core.ItemDefinition)19 List (java.util.List)13 ItemDefinition (io.automatiko.engine.workflow.bpmn2.core.ItemDefinition)12 Element (org.w3c.dom.Element)10 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 ObjectDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType)6 ProcessBuildData (io.automatiko.engine.workflow.compiler.xml.ProcessBuildData)6 DataType (org.jbpm.process.core.datatype.DataType)6 DataType (io.automatiko.engine.api.workflow.datatype.DataType)5 HashSet (java.util.HashSet)5 ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)5 BooleanDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.BooleanDataType)4 FloatDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.FloatDataType)4 IntegerDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType)4 StringDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.StringDataType)4 Definitions (org.jbpm.bpmn2.core.Definitions)4 Variable (org.jbpm.process.core.context.variable.Variable)4 BooleanDataType (org.jbpm.process.core.datatype.impl.type.BooleanDataType)4