Search in sources :

Example 21 with DataDefinition

use of org.jbpm.workflow.core.impl.DataDefinition in project kogito-runtimes by kiegroup.

the class AbstractNodeHandler method getVariableDataSpec.

protected DataDefinition getVariableDataSpec(ExtensibleXmlParser parser, String propertyIdRef) {
    RuleFlowProcess process = (RuleFlowProcess) ((ProcessBuildData) parser.getData()).getMetaData(ProcessHandler.CURRENT_PROCESS);
    Optional<Variable> var = process.getVariableScope().getVariables().stream().filter(e -> e.getId().equals(propertyIdRef)).findAny();
    if (var.isEmpty()) {
        return null;
    }
    Variable variable = var.get();
    return new DataDefinition(variable.getId(), variable.getName(), variable.getType().getStringType());
}
Also used : SequenceFlow(org.jbpm.bpmn2.core.SequenceFlow) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) LoggerFactory(org.slf4j.LoggerFactory) PatternConstants(org.jbpm.util.PatternConstants) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) Thread.currentThread(java.lang.Thread.currentThread) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) Assignment(org.jbpm.workflow.core.node.Assignment) ExtensibleXmlParser(org.drools.core.xml.ExtensibleXmlParser) Association(org.jbpm.bpmn2.core.Association) StateNode(org.jbpm.workflow.core.node.StateNode) Matcher(java.util.regex.Matcher) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Signal(org.jbpm.bpmn2.core.Signal) Transformation(org.jbpm.workflow.core.node.Transformation) IOSpecification(org.jbpm.workflow.core.impl.IOSpecification) XmlDumper(org.drools.compiler.compiler.xml.XmlDumper) MultiInstanceSpecification(org.jbpm.workflow.core.impl.MultiInstanceSpecification) CatchLinkNode(org.jbpm.workflow.core.node.CatchLinkNode) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) Collection(java.util.Collection) Set(java.util.Set) UUID(java.util.UUID) VariableScope(org.jbpm.process.core.context.variable.VariableScope) List(java.util.List) Error(org.jbpm.bpmn2.core.Error) ContextContainer(org.jbpm.process.core.ContextContainer) Node(org.jbpm.workflow.core.Node) JavaDialect(org.drools.mvel.java.JavaDialect) SAXException(org.xml.sax.SAXException) Optional(java.util.Optional) MAPPING_VARIABLE_INPUT(org.jbpm.ruleflow.core.Metadata.MAPPING_VARIABLE_INPUT) VARIABLE(org.jbpm.ruleflow.core.Metadata.VARIABLE) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) DataDefinition(org.jbpm.workflow.core.impl.DataDefinition) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Lane(org.jbpm.bpmn2.core.Lane) TimerNode(org.jbpm.workflow.core.node.TimerNode) HashSet(java.util.HashSet) DataTypeResolver.fromType(org.jbpm.process.core.datatype.DataTypeResolver.fromType) NodeContainer(org.jbpm.workflow.core.NodeContainer) DataAssociation(org.jbpm.workflow.core.impl.DataAssociation) Attributes(org.xml.sax.Attributes) BaseAbstractHandler(org.drools.core.xml.BaseAbstractHandler) FaultNode(org.jbpm.workflow.core.node.FaultNode) DroolsAction(org.jbpm.workflow.core.DroolsAction) Variable(org.jbpm.process.core.context.variable.Variable) DataTransformer(org.kie.api.runtime.process.DataTransformer) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) Logger(org.slf4j.Logger) NodeList(org.w3c.dom.NodeList) Iterator(java.util.Iterator) EventNode(org.jbpm.workflow.core.node.EventNode) COMPLETION_CONDITION(org.jbpm.ruleflow.core.Metadata.COMPLETION_CONDITION) Handler(org.drools.core.xml.Handler) DataTypeResolver(org.jbpm.process.core.datatype.DataTypeResolver) SAXParseException(org.xml.sax.SAXParseException) Element(org.w3c.dom.Element) DataTransformerRegistry(org.jbpm.process.core.impl.DataTransformerRegistry) MAPPING_VARIABLE(org.jbpm.ruleflow.core.Metadata.MAPPING_VARIABLE) Definitions(org.jbpm.bpmn2.core.Definitions) ExtendedNodeImpl(org.jbpm.workflow.core.impl.ExtendedNodeImpl) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) Variable(org.jbpm.process.core.context.variable.Variable) DataDefinition(org.jbpm.workflow.core.impl.DataDefinition)

Example 22 with DataDefinition

use of org.jbpm.workflow.core.impl.DataDefinition in project kogito-runtimes by kiegroup.

the class ForEachNodeFactory method outputVariable.

public ForEachNodeFactory<T> outputVariable(String varRef, String variableName, DataType dataType) {
    getForEachNode().setOutputRef(variableName);
    getForEachNode().addContextVariable(varRef, variableName, dataType);
    getForEachNode().getMultiInstanceSpecification().setOutputDataItem(new DataDefinition(varRef, variableName, dataType.getStringType()));
    return this;
}
Also used : DataDefinition(org.jbpm.workflow.core.impl.DataDefinition)

Example 23 with DataDefinition

use of org.jbpm.workflow.core.impl.DataDefinition in project kogito-runtimes by kiegroup.

the class AbstractNodeHandler method decorateMultiInstanceSpecification.

protected ForEachNode decorateMultiInstanceSpecification(NodeImpl nodeTarget, MultiInstanceSpecification multiInstanceSpecification) {
    ForEachNode forEachNode = new ForEachNode();
    forEachNode.setId(nodeTarget.getId());
    forEachNode.setName(nodeTarget.getName());
    nodeTarget.setMetaData("hidden", true);
    forEachNode.setIoSpecification(nodeTarget.getIoSpecification());
    DataDefinition dataInput = multiInstanceSpecification.getInputDataItem();
    DataDefinition dataOutput = multiInstanceSpecification.getOutputDataItem();
    if (dataInput != null) {
        forEachNode.setInputRef(dataInput.getLabel());
        forEachNode.addContextVariable(dataInput.getId(), dataInput.getLabel(), fromType(dataInput.getType(), currentThread().getContextClassLoader()));
        forEachNode.getIoSpecification().getDataInputAssociation().stream().filter(e -> !e.getSources().isEmpty() && e.getSources().get(0).getId().equals(dataInput.getId())).forEach(da -> {
            da.getSources().clear();
            da.getSources().add(dataInput);
        });
    }
    if (dataOutput != null) {
        forEachNode.setOutputRef(dataOutput.getLabel());
        forEachNode.addContextVariable(dataOutput.getId(), dataOutput.getLabel(), fromType(dataOutput.getType(), currentThread().getContextClassLoader()));
        forEachNode.getIoSpecification().getDataOutputAssociation().stream().filter(e -> e.getTarget().getId().equals(dataOutput.getId())).forEach(da -> {
            da.setTarget(dataOutput);
        });
    }
    if (multiInstanceSpecification.hasLoopDataInputRef()) {
        DataDefinition dataInputRef = multiInstanceSpecification.getLoopDataInputRef();
        // inputs and outputs are still processes so we need to get rid of the input of belonging to the
        // loop
        nodeTarget.getMetaData().put("MICollectionInput", dataInputRef.getLabel());
        // this is a correction as the input collection is the source of the expr (target)
        // so target is the input collection of the node
        // so we look in the source of the data input a target is equal to the data input getting the source we get the source
        // collection at context level (subprocess or activity)
        forEachNode.getIoSpecification().getDataInputAssociation().stream().filter(e -> e.getTarget().getId().equals(dataInputRef.getId())).findAny().ifPresent(pVar -> {
            String expr = pVar.getSources().get(0).getLabel();
            forEachNode.setCollectionExpression(expr);
        });
    }
    if (multiInstanceSpecification.hasLoopDataOutputRef()) {
        // same correction as input
        // we determine the output ref and locate the source. if set the target we get the variable at that level.
        DataDefinition dataOutputRef = multiInstanceSpecification.getLoopDataOutputRef();
        nodeTarget.getMetaData().put("MICollectionOutput", dataOutputRef.getLabel());
        forEachNode.getIoSpecification().getDataOutputAssociation().stream().filter(e -> e.getSources().get(0).getId().equals(dataOutputRef.getId())).findAny().ifPresent(e -> {
            forEachNode.setOutputCollectionExpression(e.getTarget().getLabel());
        });
        // another correction colletion output is not being stored in the composite context multiinstance
        // we use foreach_output
        Iterator<DataAssociation> iterator = forEachNode.getIoSpecification().getDataOutputAssociation().iterator();
        while (iterator.hasNext()) {
            DataAssociation current = iterator.next();
            if (!current.getSources().isEmpty() && current.getSources().get(0).equals(dataOutputRef)) {
                iterator.remove();
            }
        }
    }
    // this is just an expression
    forEachNode.setCompletionConditionExpression(multiInstanceSpecification.getCompletionCondition());
    forEachNode.setMultiInstanceSpecification(multiInstanceSpecification);
    // This variable is used for adding items computed by each subcontext.
    // after foreach is finished it will be moved to the data output ref collection of the multiinstance
    // this is the context of each subprocess
    VariableScope foreachContext = ((VariableScope) forEachNode.getCompositeNode().getDefaultContext(VariableScope.VARIABLE_SCOPE));
    Variable forEach = new Variable();
    forEach.setId("foreach_output");
    forEach.setName("foreach_output");
    forEach.setType(DataTypeResolver.fromType(Collection.class.getCanonicalName(), Thread.currentThread().getContextClassLoader()));
    foreachContext.addVariable(forEach);
    return forEachNode;
}
Also used : SequenceFlow(org.jbpm.bpmn2.core.SequenceFlow) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) LoggerFactory(org.slf4j.LoggerFactory) BaseAbstractHandler(org.jbpm.compiler.xml.core.BaseAbstractHandler) PatternConstants(org.jbpm.util.PatternConstants) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) Thread.currentThread(java.lang.Thread.currentThread) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) Assignment(org.jbpm.workflow.core.node.Assignment) Association(org.jbpm.bpmn2.core.Association) StateNode(org.jbpm.workflow.core.node.StateNode) Matcher(java.util.regex.Matcher) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Signal(org.jbpm.bpmn2.core.Signal) Transformation(org.jbpm.workflow.core.node.Transformation) IOSpecification(org.jbpm.workflow.core.impl.IOSpecification) MultiInstanceSpecification(org.jbpm.workflow.core.impl.MultiInstanceSpecification) CatchLinkNode(org.jbpm.workflow.core.node.CatchLinkNode) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) Collection(java.util.Collection) XmlDumper(org.jbpm.compiler.xml.compiler.XmlDumper) Set(java.util.Set) UUID(java.util.UUID) VariableScope(org.jbpm.process.core.context.variable.VariableScope) List(java.util.List) Error(org.jbpm.bpmn2.core.Error) ContextContainer(org.jbpm.process.core.ContextContainer) Node(org.jbpm.workflow.core.Node) JavaDialect(org.drools.mvel.java.JavaDialect) SAXException(org.xml.sax.SAXException) Optional(java.util.Optional) MAPPING_VARIABLE_INPUT(org.jbpm.ruleflow.core.Metadata.MAPPING_VARIABLE_INPUT) VARIABLE(org.jbpm.ruleflow.core.Metadata.VARIABLE) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) DataDefinition(org.jbpm.workflow.core.impl.DataDefinition) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Lane(org.jbpm.bpmn2.core.Lane) TimerNode(org.jbpm.workflow.core.node.TimerNode) HashSet(java.util.HashSet) DataTypeResolver.fromType(org.jbpm.process.core.datatype.DataTypeResolver.fromType) NodeContainer(org.jbpm.workflow.core.NodeContainer) DataAssociation(org.jbpm.workflow.core.impl.DataAssociation) Parser(org.jbpm.compiler.xml.Parser) Attributes(org.xml.sax.Attributes) FaultNode(org.jbpm.workflow.core.node.FaultNode) DroolsAction(org.jbpm.workflow.core.DroolsAction) Variable(org.jbpm.process.core.context.variable.Variable) DataTransformer(org.kie.api.runtime.process.DataTransformer) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) Logger(org.slf4j.Logger) NodeList(org.w3c.dom.NodeList) Iterator(java.util.Iterator) EventNode(org.jbpm.workflow.core.node.EventNode) ExtensibleXmlParser(org.jbpm.compiler.xml.core.ExtensibleXmlParser) COMPLETION_CONDITION(org.jbpm.ruleflow.core.Metadata.COMPLETION_CONDITION) Handler(org.jbpm.compiler.xml.Handler) DataTypeResolver(org.jbpm.process.core.datatype.DataTypeResolver) SAXParseException(org.xml.sax.SAXParseException) Element(org.w3c.dom.Element) DataTransformerRegistry(org.jbpm.process.core.impl.DataTransformerRegistry) MAPPING_VARIABLE(org.jbpm.ruleflow.core.Metadata.MAPPING_VARIABLE) Definitions(org.jbpm.bpmn2.core.Definitions) ExtendedNodeImpl(org.jbpm.workflow.core.impl.ExtendedNodeImpl) Variable(org.jbpm.process.core.context.variable.Variable) DataAssociation(org.jbpm.workflow.core.impl.DataAssociation) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) DataDefinition(org.jbpm.workflow.core.impl.DataDefinition) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Example 24 with DataDefinition

use of org.jbpm.workflow.core.impl.DataDefinition in project kogito-runtimes by kiegroup.

the class AbstractNodeHandler method readAssignments.

private List<Assignment> readAssignments(Element parent, DataDefinition dst, Function<String, DataDefinition> sourceResolver, Function<String, DataDefinition> targetResolver) {
    List<Assignment> assignments = new ArrayList<>();
    readChildrenElementsByTag(parent, "assignment").forEach(element -> {
        Optional<Element> from = readSingleChildElementByTag(element, "from");
        Optional<Element> to = readSingleChildElementByTag(element, "to");
        String language = element.getAttribute("expressionLanguage");
        if (language == null || language.isEmpty()) {
            language = element.getAttribute("language");
        }
        String source = from.get().getTextContent();
        String target = to.get().getTextContent();
        if (!language.isEmpty()) {
            assignments.add(new Assignment(language, toDataExpression(source), toDataExpression(target)));
        } else {
            source = cleanUp(source);
            target = cleanUp(target);
            DataDefinition sourceDataSpec = isExpr(source) ? toDataExpression(source) : sourceResolver.apply(source);
            if (sourceDataSpec == null) {
                // it is constant source
                sourceDataSpec = toDataExpression(source);
            }
            DataDefinition targetDataSpec = isExpr(target) ? toDataExpression(target) : targetResolver.apply(target);
            if (targetDataSpec == null) {
                targetDataSpec = toDataExpression(target);
            }
            logger.debug("No language set for assignment {} to {}. Applying heuristics", sourceDataSpec, targetDataSpec);
            assignments.add(new Assignment(language.isEmpty() ? null : language, sourceDataSpec, targetDataSpec));
        }
    });
    return assignments;
}
Also used : Assignment(org.jbpm.workflow.core.node.Assignment) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) DataDefinition(org.jbpm.workflow.core.impl.DataDefinition)

Example 25 with DataDefinition

use of org.jbpm.workflow.core.impl.DataDefinition in project kogito-runtimes by kiegroup.

the class AbstractNodeHandler method writeThrow.

protected void writeThrow(IOSpecification ioSpecification, StringBuilder xmlDump) {
    for (DataDefinition input : ioSpecification.getDataInput().values()) {
        xmlDump.append("        <dataInput id=\"" + input.getId() + "\" name=\"" + input.getLabel() + "\" />" + EOL);
    }
    for (DataAssociation input : ioSpecification.getDataInputAssociation()) {
        xmlDump.append("      <dataInputAssociation>" + EOL);
        writeDataAssociation(input, xmlDump);
        xmlDump.append("      </dataInputAssociation>" + EOL);
    }
}
Also used : DataAssociation(org.jbpm.workflow.core.impl.DataAssociation) DataDefinition(org.jbpm.workflow.core.impl.DataDefinition)

Aggregations

DataDefinition (org.jbpm.workflow.core.impl.DataDefinition)31 DataAssociation (org.jbpm.workflow.core.impl.DataAssociation)12 ArrayList (java.util.ArrayList)9 Assignment (org.jbpm.workflow.core.node.Assignment)9 VariableScope (org.jbpm.process.core.context.variable.VariableScope)8 Element (org.w3c.dom.Element)7 Node (org.jbpm.workflow.core.Node)6 Transformation (org.jbpm.workflow.core.node.Transformation)6 ItemDefinition (org.jbpm.bpmn2.core.ItemDefinition)5 MultiInstanceSpecification (org.jbpm.workflow.core.impl.MultiInstanceSpecification)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 Variable (org.jbpm.process.core.context.variable.Variable)4 DataTransformerRegistry (org.jbpm.process.core.impl.DataTransformerRegistry)4 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)3 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)3 Thread.currentThread (java.lang.Thread.currentThread)3 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3