Search in sources :

Example 6 with ItemDefinition

use of org.jbpm.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 7 with ItemDefinition

use of org.jbpm.bpmn2.core.ItemDefinition in project kie-wb-common by kiegroup.

the class BpmnProcessDataEventListener method addDistinctProcessVariables.

public void addDistinctProcessVariables(List<Variable> variables, Resource resource) {
    if (variables != null) {
        uniqueVariables = new HashSet<>();
        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();
            }
            // add only if unique
            if (uniqueVariables.add(data.getName())) {
                resource.addPart(data.getName(), PartType.VARIABLE);
            }
            if (type.contains(".")) {
                getReferencedClasses().add(type);
            } else {
                getUnqualifiedClasses().add(type);
            }
        }
    }
}
Also used : Variable(org.jbpm.process.core.context.variable.Variable) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition)

Example 8 with ItemDefinition

use of org.jbpm.bpmn2.core.ItemDefinition in project jbpm by kiegroup.

the class BoundaryEventHandler method handleErrorNode.

@SuppressWarnings("unchecked")
protected void handleErrorNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser, final String attachedTo, final boolean cancelActivity) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    BoundaryEventNode eventNode = (BoundaryEventNode) node;
    eventNode.setMetaData("AttachedTo", attachedTo);
    eventNode.setAttachedToNodeId(attachedTo);
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataOutput".equals(nodeName)) {
            String id = ((Element) xmlNode).getAttribute("id");
            String outputName = ((Element) xmlNode).getAttribute("name");
            dataOutputs.put(id, outputName);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, eventNode);
        } else if ("errorEventDefinition".equals(nodeName)) {
            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);
                }
                String type = error.getErrorCode();
                boolean hasErrorCode = true;
                if (type == null) {
                    type = error.getId();
                    hasErrorCode = false;
                }
                String structureRef = error.getStructureRef();
                if (structureRef != null) {
                    Map<String, ItemDefinition> itemDefs = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
                    if (itemDefs.containsKey(structureRef)) {
                        structureRef = itemDefs.get(structureRef).getStructureRef();
                    }
                }
                List<EventFilter> eventFilters = new ArrayList<EventFilter>();
                EventTypeFilter eventFilter = new EventTypeFilter();
                eventFilter.setType("Error-" + attachedTo + "-" + type);
                eventFilters.add(eventFilter);
                eventNode.setEventFilters(eventFilters);
                eventNode.setMetaData("ErrorEvent", type);
                eventNode.setMetaData("HasErrorEvent", hasErrorCode);
                eventNode.setMetaData("ErrorStructureRef", structureRef);
            }
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : Element(org.w3c.dom.Element) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) ArrayList(java.util.ArrayList) Error(org.jbpm.bpmn2.core.Error) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventFilter(org.jbpm.process.core.event.EventFilter) NonAcceptingEventTypeFilter(org.jbpm.process.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) Map(java.util.Map)

Example 9 with ItemDefinition

use of org.jbpm.bpmn2.core.ItemDefinition in project jbpm 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");
    if (UndefinedDataType.getInstance().equals(variable.getType()) && itemDefinitions != null && itemSubjectRef != null) {
        DataType dataType = new ObjectDataType();
        ItemDefinition itemDefinition = itemDefinitions.get(itemSubjectRef);
        if (itemDefinition != null) {
            String structureRef = itemDefinition.getStructureRef();
            if ("java.lang.Boolean".equals(structureRef) || "Boolean".equals(structureRef)) {
                dataType = new BooleanDataType();
            } else if ("java.lang.Integer".equals(structureRef) || "Integer".equals(structureRef)) {
                dataType = new IntegerDataType();
            } else if ("java.lang.Float".equals(structureRef) || "Float".equals(structureRef)) {
                dataType = new FloatDataType();
            } else if ("java.lang.String".equals(structureRef) || "String".equals(structureRef)) {
                dataType = new StringDataType();
            } else if ("java.lang.Object".equals(structureRef) || "Object".equals(structureRef)) {
                // use FQCN of Object
                dataType = new ObjectDataType("java.lang.Object");
            } else {
                dataType = new ObjectDataType(structureRef, cl);
            }
        }
        variable.setType(dataType);
    }
}
Also used : StringDataType(org.jbpm.process.core.datatype.impl.type.StringDataType) FloatDataType(org.jbpm.process.core.datatype.impl.type.FloatDataType) IntegerDataType(org.jbpm.process.core.datatype.impl.type.IntegerDataType) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) IntegerDataType(org.jbpm.process.core.datatype.impl.type.IntegerDataType) UndefinedDataType(org.jbpm.process.core.datatype.impl.type.UndefinedDataType) FloatDataType(org.jbpm.process.core.datatype.impl.type.FloatDataType) DataType(org.jbpm.process.core.datatype.DataType) StringDataType(org.jbpm.process.core.datatype.impl.type.StringDataType) BooleanDataType(org.jbpm.process.core.datatype.impl.type.BooleanDataType) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) BooleanDataType(org.jbpm.process.core.datatype.impl.type.BooleanDataType)

Example 10 with ItemDefinition

use of org.jbpm.bpmn2.core.ItemDefinition in project jbpm by kiegroup.

the class AbstractNodeHandler method readMultiInstanceLoopCharacteristics.

@SuppressWarnings("unchecked")
protected void readMultiInstanceLoopCharacteristics(org.w3c.dom.Node xmlNode, ForEachNode forEachNode, ExtensibleXmlParser parser) {
    // sourceRef
    org.w3c.dom.Node subNode = xmlNode.getFirstChild();
    while (subNode != null) {
        String nodeName = subNode.getNodeName();
        if ("inputDataItem".equals(nodeName)) {
            String variableName = ((Element) subNode).getAttribute("id");
            String itemSubjectRef = ((Element) subNode).getAttribute("itemSubjectRef");
            DataType dataType = null;
            Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
            dataType = getDataType(itemSubjectRef, itemDefinitions, parser.getClassLoader());
            if (variableName != null && variableName.trim().length() > 0) {
                forEachNode.setVariable(variableName, dataType);
            }
        } else if ("outputDataItem".equals(nodeName)) {
            String variableName = ((Element) subNode).getAttribute("id");
            String itemSubjectRef = ((Element) subNode).getAttribute("itemSubjectRef");
            DataType dataType = null;
            Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
            dataType = getDataType(itemSubjectRef, itemDefinitions, parser.getClassLoader());
            if (variableName != null && variableName.trim().length() > 0) {
                forEachNode.setOutputVariable(variableName, dataType);
            }
        } else if ("loopDataOutputRef".equals(nodeName)) {
            String outputDataRef = ((Element) subNode).getTextContent();
            if (outputDataRef != null && outputDataRef.trim().length() > 0) {
                String collectionName = outputAssociation.get(outputDataRef);
                if (collectionName == null) {
                    collectionName = dataOutputs.get(outputDataRef);
                }
                forEachNode.setOutputCollectionExpression(collectionName);
            }
            forEachNode.setMetaData("MICollectionOutput", outputDataRef);
        } else if ("loopDataInputRef".equals(nodeName)) {
            String inputDataRef = ((Element) subNode).getTextContent();
            if (inputDataRef != null && inputDataRef.trim().length() > 0) {
                String collectionName = inputAssociation.get(inputDataRef);
                if (collectionName == null) {
                    collectionName = dataInputs.get(inputDataRef);
                }
                forEachNode.setCollectionExpression(collectionName);
            }
            forEachNode.setMetaData("MICollectionInput", inputDataRef);
        } else if ("completionCondition".equals(nodeName)) {
            String expression = subNode.getTextContent();
            forEachNode.setCompletionConditionExpression(expression);
        }
        subNode = subNode.getNextSibling();
    }
}
Also used : ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) Element(org.w3c.dom.Element) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) IntegerDataType(org.jbpm.process.core.datatype.impl.type.IntegerDataType) FloatDataType(org.jbpm.process.core.datatype.impl.type.FloatDataType) DataType(org.jbpm.process.core.datatype.DataType) StringDataType(org.jbpm.process.core.datatype.impl.type.StringDataType) BooleanDataType(org.jbpm.process.core.datatype.impl.type.BooleanDataType) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ItemDefinition (org.jbpm.bpmn2.core.ItemDefinition)11 Map (java.util.Map)5 List (java.util.List)4 DataType (org.jbpm.process.core.datatype.DataType)4 BooleanDataType (org.jbpm.process.core.datatype.impl.type.BooleanDataType)4 FloatDataType (org.jbpm.process.core.datatype.impl.type.FloatDataType)4 IntegerDataType (org.jbpm.process.core.datatype.impl.type.IntegerDataType)4 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)4 StringDataType (org.jbpm.process.core.datatype.impl.type.StringDataType)4 HashSet (java.util.HashSet)3 ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)3 Variable (org.jbpm.process.core.context.variable.Variable)3 Element (org.w3c.dom.Element)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Definitions (org.jbpm.bpmn2.core.Definitions)2 VariableScope (org.jbpm.process.core.context.variable.VariableScope)2 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)2 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)2 Set (java.util.Set)1