Search in sources :

Example 1 with DSFormalParameter

use of org.kie.dmn.core.ast.DMNDecisionServiceFunctionDefinitionEvaluator.DSFormalParameter in project drools by kiegroup.

the class DecisionServiceCompiler method compileEvaluator.

@Override
public void compileEvaluator(DMNNode node, DMNCompilerImpl compiler, DMNCompilerContext ctx, DMNModelImpl model) {
    DecisionServiceNodeImpl ni = (DecisionServiceNodeImpl) node;
    List<DSFormalParameter> parameters = new ArrayList<>();
    for (DMNElementReference er : ni.getDecisionService().getInputData()) {
        String id = DMNCompilerImpl.getId(er);
        InputDataNode input = model.getInputById(id);
        String inputNamePrefix = inputQualifiedNamePrefix(input, model);
        if (input != null) {
            ni.addInputParameter(inputNamePrefix != null ? inputNamePrefix + "." + input.getName() : input.getName(), input);
            parameters.add(new DSFormalParameter(inputNamePrefix, input.getName(), input.getType()));
        } else {
            MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.REFERENCE_NOT_FOUND_FOR_DS, id, node.getName());
        }
    }
    for (DMNElementReference er : ni.getDecisionService().getInputDecision()) {
        String id = DMNCompilerImpl.getId(er);
        DecisionNode input = model.getDecisionById(id);
        String inputNamePrefix = inputQualifiedNamePrefix(input, model);
        if (input != null) {
            ni.addInputParameter(inputNamePrefix != null ? inputNamePrefix + "." + input.getName() : input.getName(), input);
            parameters.add(new DSFormalParameter(inputNamePrefix, input.getName(), input.getResultType()));
        } else {
            MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.REFERENCE_NOT_FOUND_FOR_DS, id, node.getName());
        }
    }
    for (DMNElementReference er : ni.getDecisionService().getEncapsulatedDecision()) {
        String id = DMNCompilerImpl.getId(er);
        DecisionNode input = model.getDecisionById(id);
        if (input != null) {
        // nothing to do.
        } else {
            MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.REFERENCE_NOT_FOUND_FOR_DS, id, node.getName());
        }
    }
    List<DecisionNode> outputDecisions = new ArrayList<>();
    for (DMNElementReference er : ni.getDecisionService().getOutputDecision()) {
        String id = DMNCompilerImpl.getId(er);
        DecisionNode outDecision = model.getDecisionById(id);
        if (outDecision != null) {
            outputDecisions.add(outDecision);
        } else {
            MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.REFERENCE_NOT_FOUND_FOR_DS, id, node.getName());
        }
    }
    boolean coerceSingleton = ((DMNCompilerConfigurationImpl) compiler.getDmnCompilerConfig()).getOption(CoerceDecisionServiceSingletonOutputOption.class).isCoerceSingleton();
    DMNDecisionServiceFunctionDefinitionEvaluator exprEvaluator = new DMNDecisionServiceFunctionDefinitionEvaluator(ni, parameters, coerceSingleton);
    ni.setEvaluator(exprEvaluator);
    if (ni.getType() != null) {
        checkFnConsistency(model, ni, ni.getType(), outputDecisions);
    }
}
Also used : DMNElementReference(org.kie.dmn.model.api.DMNElementReference) DSFormalParameter(org.kie.dmn.core.ast.DMNDecisionServiceFunctionDefinitionEvaluator.DSFormalParameter) ArrayList(java.util.ArrayList) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) DMNDecisionServiceFunctionDefinitionEvaluator(org.kie.dmn.core.ast.DMNDecisionServiceFunctionDefinitionEvaluator) DecisionServiceNodeImpl(org.kie.dmn.core.ast.DecisionServiceNodeImpl)

Aggregations

ArrayList (java.util.ArrayList)1 DecisionNode (org.kie.dmn.api.core.ast.DecisionNode)1 InputDataNode (org.kie.dmn.api.core.ast.InputDataNode)1 DMNDecisionServiceFunctionDefinitionEvaluator (org.kie.dmn.core.ast.DMNDecisionServiceFunctionDefinitionEvaluator)1 DSFormalParameter (org.kie.dmn.core.ast.DMNDecisionServiceFunctionDefinitionEvaluator.DSFormalParameter)1 DecisionServiceNodeImpl (org.kie.dmn.core.ast.DecisionServiceNodeImpl)1 DMNElementReference (org.kie.dmn.model.api.DMNElementReference)1