Search in sources :

Example 1 with Invocation

use of org.kie.dmn.model.api.Invocation in project drools by kiegroup.

the class InvocationConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    Invocation i = (Invocation) parent;
    if (i.getExpression() != null)
        writeChildrenNode(writer, context, i.getExpression(), MarshallingUtils.defineExpressionNodeName(i.getExpression()));
    for (Binding b : i.getBinding()) {
        writeChildrenNode(writer, context, b, BINDING);
    }
}
Also used : Binding(org.kie.dmn.model.api.Binding) Invocation(org.kie.dmn.model.api.Invocation) TInvocation(org.kie.dmn.model.v1_1.TInvocation)

Example 2 with Invocation

use of org.kie.dmn.model.api.Invocation in project drools by kiegroup.

the class InvocationConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    Invocation i = (Invocation) parent;
    if (i.getExpression() != null)
        writeChildrenNode(writer, context, i.getExpression(), MarshallingUtils.defineExpressionNodeName(xstream, i.getExpression()));
    for (Binding b : i.getBinding()) {
        writeChildrenNode(writer, context, b, BINDING);
    }
}
Also used : Binding(org.kie.dmn.model.api.Binding) Invocation(org.kie.dmn.model.api.Invocation) TInvocation(org.kie.dmn.model.v1_3.TInvocation)

Example 3 with Invocation

use of org.kie.dmn.model.api.Invocation in project drools by kiegroup.

the class InvocationConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    Invocation i = (Invocation) parent;
    if (i.getExpression() != null)
        writeChildrenNode(writer, context, i.getExpression(), MarshallingUtils.defineExpressionNodeName(xstream, i.getExpression()));
    for (Binding b : i.getBinding()) {
        writeChildrenNode(writer, context, b, BINDING);
    }
}
Also used : Binding(org.kie.dmn.model.api.Binding) Invocation(org.kie.dmn.model.api.Invocation) TInvocation(org.kie.dmn.model.v1_4.TInvocation)

Example 4 with Invocation

use of org.kie.dmn.model.api.Invocation in project drools by kiegroup.

the class InvocationConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    Invocation i = (Invocation) parent;
    if (i.getExpression() != null)
        writeChildrenNode(writer, context, i.getExpression(), MarshallingUtils.defineExpressionNodeName(i.getExpression()));
    for (Binding b : i.getBinding()) {
        writeChildrenNode(writer, context, b, BINDING);
    }
}
Also used : Binding(org.kie.dmn.model.api.Binding) Invocation(org.kie.dmn.model.api.Invocation) TInvocation(org.kie.dmn.model.v1_2.TInvocation)

Example 5 with Invocation

use of org.kie.dmn.model.api.Invocation in project drools by kiegroup.

the class DMNEvaluatorCompiler method compileInvocation.

private DMNExpressionEvaluator compileInvocation(DMNCompilerContext ctx, DMNModelImpl model, DMNBaseNode node, Invocation expression) {
    Invocation invocation = expression;
    // expression must be a literal text with the name of the function
    if (invocation.getExpression() == null || ((LiteralExpression) invocation.getExpression()).getText().isEmpty()) {
        MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, invocation, model, null, null, Msg.MISSING_EXPRESSION_FOR_INVOCATION, node.getIdentifierString());
        return null;
    }
    String functionName = ((LiteralExpression) invocation.getExpression()).getText();
    String[] fnameParts = functionName.split("\\.");
    Optional<DMNNode> findAsDep = Optional.empty();
    if (fnameParts.length > 1) {
        findAsDep = node.getDependencies().values().stream().filter(dmnNode -> dmnNode.getModelImportAliasFor(dmnNode.getModelNamespace(), dmnNode.getModelName()).map(alias -> Objects.equals(functionName, alias + "." + dmnNode.getName())).orElse(false)).findFirst();
    } else {
        findAsDep = node.getDependencies().values().stream().filter(d -> d.getName().equals(functionName)).findAny();
    }
    boolean findAsBuiltin = RootExecutionFrame.INSTANCE.getValue(functionName) != null;
    boolean findAsCustomFunction = ctx.getFeelHelper().newCompilerContext().getFEELFunctions().stream().anyMatch(f -> f.getName().equals(functionName));
    boolean findInContext = ctx.getVariables().get(functionName) != null;
    if (!findAsDep.isPresent() && !findAsBuiltin && !findAsCustomFunction && !findInContext) {
        MsgUtil.reportMessage(logger, DMNMessage.Severity.WARN, invocation, model, null, null, Msg.EXPRESSION_FOR_INVOCATION_NOT_RESOLVED, functionName, node.getIdentifierString(), node.getDependencies().values().stream().map(DMNNode::getName).collect(Collectors.toList()));
    }
    DMNInvocationEvaluator invEval = new DMNInvocationEvaluator(node.getName(), node.getSource(), functionName, invocation, null, ctx.getFeelHelper().newFEELInstance());
    for (Binding binding : invocation.getBinding()) {
        if (binding.getParameter() == null) {
            // error, missing binding parameter
            MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, binding, model, null, null, Msg.MISSING_PARAMETER_FOR_INVOCATION, node.getIdentifierString());
            return null;
        }
        if (binding.getExpression() == null) {
            MsgUtil.reportMessage(logger, DMNMessage.Severity.WARN, binding, model, null, null, Msg.MISSING_EXPRESSION_FOR_PARAM_OF_INVOCATION, binding.getParameter().getIdentifierString(), node.getIdentifierString());
            return null;
        }
        invEval.addParameter(binding.getParameter().getName(), compiler.resolveTypeRef(model, binding.getParameter(), binding.getParameter(), binding.getParameter().getTypeRef()), compileExpression(ctx, model, node, binding.getParameter().getName(), binding.getExpression()));
    }
    return invEval;
}
Also used : Binding(org.kie.dmn.model.api.Binding) Invocation(org.kie.dmn.model.api.Invocation) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) DMNNode(org.kie.dmn.api.core.ast.DMNNode) DMNInvocationEvaluator(org.kie.dmn.core.ast.DMNInvocationEvaluator)

Aggregations

Binding (org.kie.dmn.model.api.Binding)5 Invocation (org.kie.dmn.model.api.Invocation)5 DMNNode (org.kie.dmn.api.core.ast.DMNNode)1 DMNInvocationEvaluator (org.kie.dmn.core.ast.DMNInvocationEvaluator)1 LiteralExpression (org.kie.dmn.model.api.LiteralExpression)1 TInvocation (org.kie.dmn.model.v1_1.TInvocation)1 TInvocation (org.kie.dmn.model.v1_2.TInvocation)1 TInvocation (org.kie.dmn.model.v1_3.TInvocation)1 TInvocation (org.kie.dmn.model.v1_4.TInvocation)1