Search in sources :

Example 6 with DecisionServiceNodeImpl

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

the class DMNCompilerImpl method processDrgElements.

private void processDrgElements(DMNCompilerContext ctx, DMNModelImpl model, Definitions dmndefs) {
    for (DRGElement e : dmndefs.getDrgElement()) {
        boolean foundIt = false;
        for (DRGElementCompiler dc : drgCompilers) {
            if (dc.accept(e)) {
                foundIt = true;
                dc.compileNode(e, this, model);
                continue;
            }
        }
        if (!foundIt) {
            MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, e, model, null, null, Msg.UNSUPPORTED_ELEMENT, e.getClass().getSimpleName(), e.getId());
        }
    }
    // in DMN v1.1 the DecisionService is not on the DRGElement but as an extension
    if (dmndefs.getExtensionElements() != null) {
        List<DecisionServices> decisionServices = dmndefs.getExtensionElements().getAny().stream().filter(DecisionServices.class::isInstance).map(DecisionServices.class::cast).collect(Collectors.toList());
        for (DecisionServices dss : decisionServices) {
            for (DecisionService ds : dss.getDecisionService()) {
                // compatibility with DMN v1.1, create Decision Service's variable:
                if (ds.getVariable() == null) {
                    InformationItem variable = new TInformationItem();
                    variable.setId(UUID.randomUUID().toString());
                    variable.setName(ds.getName());
                    variable.setParent(ds);
                    // the introduction of an on-the-fly ItemDefinition has been removed. The variable type will be evaluated as feel:any, or in v1.2 will receive the (user-defined, explicit) ItemDefinition type.
                    ds.setVariable(variable);
                }
                // continuing with normal compilation of Decision Service:
                boolean foundIt = false;
                for (DRGElementCompiler dc : drgCompilers) {
                    if (dc.accept(ds)) {
                        foundIt = true;
                        dc.compileNode(ds, this, model);
                        continue;
                    }
                }
            }
        }
    }
    for (DecisionServiceNode ds : model.getDecisionServices()) {
        DecisionServiceNodeImpl dsi = (DecisionServiceNodeImpl) ds;
        dsi.addModelImportAliases(model.getImportAliasesForNS());
        for (DRGElementCompiler dc : drgCompilers) {
            if (dsi.getEvaluator() == null && dc.accept(dsi)) {
                // will compile in fact all DS belonging to this model (not the imported ones).
                dc.compileEvaluator(dsi, this, ctx, model);
            }
        }
    }
    for (BusinessKnowledgeModelNode bkm : model.getBusinessKnowledgeModels()) {
        BusinessKnowledgeModelNodeImpl bkmi = (BusinessKnowledgeModelNodeImpl) bkm;
        bkmi.addModelImportAliases(model.getImportAliasesForNS());
        for (DRGElementCompiler dc : drgCompilers) {
            if (bkmi.getEvaluator() == null && dc.accept(bkm)) {
                dc.compileEvaluator(bkm, this, ctx, model);
            }
        }
    }
    for (DecisionNode d : model.getDecisions()) {
        DecisionNodeImpl di = (DecisionNodeImpl) d;
        di.addModelImportAliases(model.getImportAliasesForNS());
        for (DRGElementCompiler dc : drgCompilers) {
            if (di.getEvaluator() == null && dc.accept(d)) {
                dc.compileEvaluator(d, this, ctx, model);
            }
        }
    }
    for (AfterProcessDrgElements callback : afterDRGcallbacks) {
        logger.debug("About to invoke callback: {}", callback);
        callback.callback(this, ctx, model);
    }
    detectCycles(model);
}
Also used : DecisionServiceNode(org.kie.dmn.api.core.ast.DecisionServiceNode) DecisionServices(org.kie.dmn.model.v1_1.extensions.DecisionServices) TInformationItem(org.kie.dmn.model.v1_1.TInformationItem) InformationItem(org.kie.dmn.model.api.InformationItem) BusinessKnowledgeModelNode(org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) DecisionNodeImpl(org.kie.dmn.core.ast.DecisionNodeImpl) DecisionService(org.kie.dmn.model.api.DecisionService) TInformationItem(org.kie.dmn.model.v1_1.TInformationItem) BusinessKnowledgeModelNodeImpl(org.kie.dmn.core.ast.BusinessKnowledgeModelNodeImpl) DRGElement(org.kie.dmn.model.api.DRGElement) DecisionServiceNodeImpl(org.kie.dmn.core.ast.DecisionServiceNodeImpl)

Example 7 with DecisionServiceNodeImpl

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

the class DMNRuntimeImpl method evaluateDecisionService.

private void evaluateDecisionService(DMNContext context, DMNResultImpl result, DecisionServiceNode d, boolean typeCheck) {
    DecisionServiceNodeImpl ds = (DecisionServiceNodeImpl) d;
    if (isNodeValueDefined(result, ds, ds)) {
        // already resolved
        return;
    }
    // Note: a Decision Service is expected to always have an evaluator, it does not depend on an xml expression, it is done always by the compiler.
    try {
        // a Decision Service when is evaluated as a function does not require any dependency check, as they will be passed as params.
        EvaluatorResult er = ds.getEvaluator().evaluate(this, result);
        if (er.getResultType() == EvaluatorResult.ResultType.SUCCESS) {
            FEELFunction resultFn = (FEELFunction) er.getResult();
            result.getContext().set(ds.getName(), resultFn);
        }
    } catch (Throwable t) {
        MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, ds.getSource(), result, t, null, Msg.ERROR_EVAL_DS_NODE, getIdentifier(ds), t.getMessage());
    }
}
Also used : EvaluatorResult(org.kie.dmn.core.api.EvaluatorResult) FEELFunction(org.kie.dmn.feel.runtime.FEELFunction) DecisionServiceNodeImpl(org.kie.dmn.core.ast.DecisionServiceNodeImpl)

Example 8 with DecisionServiceNodeImpl

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

the class DMNEventUtils method extractDSParameters.

public static Map<String, Object> extractDSParameters(BeforeEvaluateDecisionServiceEvent event) {
    Map<String, Object> results = new LinkedHashMap<String, Object>();
    DecisionServiceNodeImpl dsi = (DecisionServiceNodeImpl) event.getDecisionService();
    Map<String, DMNNode> params = dsi.getInputParameters();
    for (Entry<String, DMNNode> entry : params.entrySet()) {
        String name = entry.getKey();
        Object value = event.getResult().getContext().get(name);
        results.put(name, value);
    }
    return results;
}
Also used : DMNNode(org.kie.dmn.api.core.ast.DMNNode) LinkedHashMap(java.util.LinkedHashMap) DecisionServiceNodeImpl(org.kie.dmn.core.ast.DecisionServiceNodeImpl)

Aggregations

DecisionServiceNodeImpl (org.kie.dmn.core.ast.DecisionServiceNodeImpl)8 DecisionNode (org.kie.dmn.api.core.ast.DecisionNode)5 DMNNode (org.kie.dmn.api.core.ast.DMNNode)4 InputDataNode (org.kie.dmn.api.core.ast.InputDataNode)4 DMNType (org.kie.dmn.api.core.DMNType)3 DecisionServiceNode (org.kie.dmn.api.core.ast.DecisionServiceNode)3 DecisionNodeImpl (org.kie.dmn.core.ast.DecisionNodeImpl)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 QName (javax.xml.namespace.QName)2 DMNMessage (org.kie.dmn.api.core.DMNMessage)2 BusinessKnowledgeModelNode (org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode)2 BusinessKnowledgeModelNodeImpl (org.kie.dmn.core.ast.BusinessKnowledgeModelNodeImpl)2 DMNBaseNode (org.kie.dmn.core.ast.DMNBaseNode)2 DMNDecisionServiceFunctionDefinitionEvaluator (org.kie.dmn.core.ast.DMNDecisionServiceFunctionDefinitionEvaluator)2 DSFormalParameter (org.kie.dmn.core.ast.DMNDecisionServiceFunctionDefinitionEvaluator.DSFormalParameter)2 InputDataNodeImpl (org.kie.dmn.core.ast.InputDataNodeImpl)2