Search in sources :

Example 1 with InputDataNodeImpl

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

the class MultiInstanceDecisionLogicTest method input.

private DMNBaseNode input(String id) {
    InputDataNodeImpl input = mock(InputDataNodeImpl.class);
    doReturn(id).when(input).getId();
    doReturn(input).when(model).getInputById(id);
    return input;
}
Also used : InputDataNodeImpl(org.kie.dmn.core.ast.InputDataNodeImpl)

Example 2 with InputDataNodeImpl

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

the class DecisionServiceCompiler method checkFnConsistency.

private void checkFnConsistency(DMNModelImpl model, DecisionServiceNodeImpl ni, DMNType type, List<DecisionNode> outputDecisions) {
    SimpleFnTypeImpl fnType = ((SimpleFnTypeImpl) type);
    FunctionItem fi = fnType.getFunctionItem();
    if (fi.getParameters().size() != ni.getInputParameters().size()) {
        MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.PARAMETER_COUNT_MISMATCH_COMPILING, ni.getName(), fi.getParameters().size(), ni.getInputParameters().size());
        return;
    }
    for (int i = 0; i < fi.getParameters().size(); i++) {
        InformationItem fiII = fi.getParameters().get(i);
        String fpName = ni.getInputParameters().keySet().stream().skip(i).findFirst().orElse(null);
        if (!fiII.getName().equals(fpName)) {
            List<String> fiParamNames = fi.getParameters().stream().map(InformationItem::getName).collect(Collectors.toList());
            List<String> funcDefParamNames = ni.getInputParameters().keySet().stream().collect(Collectors.toList());
            MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.PARAMETER_NAMES_MISMATCH_COMPILING, ni.getName(), fiParamNames, funcDefParamNames);
            return;
        }
        QName fiQname = fiII.getTypeRef();
        QName fdQname = null;
        DMNNode fpDMNNode = ni.getInputParameters().get(fpName);
        if (fpDMNNode instanceof InputDataNodeImpl) {
            fdQname = ((InputDataNodeImpl) fpDMNNode).getInputData().getVariable().getTypeRef();
        } else if (fpDMNNode instanceof DecisionNodeImpl) {
            fdQname = ((DecisionNodeImpl) fpDMNNode).getDecision().getVariable().getTypeRef();
        }
        if (fiQname != null && fdQname != null && !fiQname.equals(fdQname)) {
            MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.PARAMETER_TYPEREF_MISMATCH_COMPILING, ni.getName(), fiII.getName(), fiQname, fdQname);
        }
    }
    QName fiReturnType = fi.getOutputTypeRef();
    if (ni.getDecisionService().getOutputDecision().size() == 1) {
        QName fdReturnType = outputDecisions.get(0).getDecision().getVariable().getTypeRef();
        if (fiReturnType != null && fdReturnType != null && !fiReturnType.equals(fdReturnType)) {
            MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.RETURNTYPE_TYPEREF_MISMATCH_COMPILING, ni.getName(), fiReturnType, fdReturnType);
        }
    } else if (ni.getDecisionService().getOutputDecision().size() > 1) {
        final Function<QName, QName> lookupFn = (in) -> DMNCompilerImpl.getNamespaceAndName(ni.getDecisionService(), model.getImportAliasesForNS(), in, model.getNamespace());
        LinkedHashMap<String, QName> fdComposite = new LinkedHashMap<>();
        for (DecisionNode dn : outputDecisions) {
            fdComposite.put(dn.getName(), lookupFn.apply(dn.getDecision().getVariable().getTypeRef()));
        }
        final QName lookup = lookupFn.apply(fiReturnType);
        Optional<ItemDefNodeImpl> composite = model.getItemDefinitions().stream().filter(id -> id.getModelNamespace().equals(lookup.getNamespaceURI()) && id.getName().equals(lookup.getLocalPart())).map(ItemDefNodeImpl.class::cast).findFirst();
        if (!composite.isPresent()) {
            MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.RETURNTYPE_TYPEREF_MISMATCH_COMPILING, ni.getName(), lookup, fdComposite);
            return;
        }
        LinkedHashMap<String, QName> fiComposite = new LinkedHashMap<>();
        for (ItemDefinition ic : composite.get().getItemDef().getItemComponent()) {
            fiComposite.put(ic.getName(), lookupFn.apply(ic.getTypeRef()));
        }
        if (!fiComposite.equals(fdComposite)) {
            MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.RETURNTYPE_TYPEREF_MISMATCH_COMPILING, ni.getName(), fiComposite, fdComposite);
        }
    }
}
Also used : MsgUtil(org.kie.dmn.core.util.MsgUtil) DMNType(org.kie.dmn.api.core.DMNType) DMNElementReference(org.kie.dmn.model.api.DMNElementReference) DMNMessage(org.kie.dmn.api.core.DMNMessage) SimpleFnTypeImpl(org.kie.dmn.core.impl.SimpleFnTypeImpl) LoggerFactory(org.slf4j.LoggerFactory) ItemDefNodeImpl(org.kie.dmn.core.ast.ItemDefNodeImpl) Function(java.util.function.Function) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) DecisionServiceNodeImpl(org.kie.dmn.core.ast.DecisionServiceNodeImpl) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) DMNDecisionServiceFunctionDefinitionEvaluator(org.kie.dmn.core.ast.DMNDecisionServiceFunctionDefinitionEvaluator) DMNBaseNode(org.kie.dmn.core.ast.DMNBaseNode) InputDataNodeImpl(org.kie.dmn.core.ast.InputDataNodeImpl) Logger(org.slf4j.Logger) DMNNode(org.kie.dmn.api.core.ast.DMNNode) DMNModelImpl(org.kie.dmn.core.impl.DMNModelImpl) Collectors(java.util.stream.Collectors) FunctionItem(org.kie.dmn.model.api.FunctionItem) List(java.util.List) DSFormalParameter(org.kie.dmn.core.ast.DMNDecisionServiceFunctionDefinitionEvaluator.DSFormalParameter) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) Optional(java.util.Optional) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) QName(javax.xml.namespace.QName) DRGElement(org.kie.dmn.model.api.DRGElement) InformationItem(org.kie.dmn.model.api.InformationItem) Msg(org.kie.dmn.core.util.Msg) DecisionService(org.kie.dmn.model.api.DecisionService) DecisionNodeImpl(org.kie.dmn.core.ast.DecisionNodeImpl) Optional(java.util.Optional) QName(javax.xml.namespace.QName) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) InformationItem(org.kie.dmn.model.api.InformationItem) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) DecisionNodeImpl(org.kie.dmn.core.ast.DecisionNodeImpl) SimpleFnTypeImpl(org.kie.dmn.core.impl.SimpleFnTypeImpl) LinkedHashMap(java.util.LinkedHashMap) Function(java.util.function.Function) DMNNode(org.kie.dmn.api.core.ast.DMNNode) FunctionItem(org.kie.dmn.model.api.FunctionItem) InputDataNodeImpl(org.kie.dmn.core.ast.InputDataNodeImpl) ItemDefNodeImpl(org.kie.dmn.core.ast.ItemDefNodeImpl)

Example 3 with InputDataNodeImpl

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

the class DMNRuntimeImpl method checkDependencyValueIsValid.

private boolean checkDependencyValueIsValid(DMNNode dep, DMNResultImpl result) {
    if (dep instanceof InputDataNode) {
        InputDataNodeImpl inputDataNode = (InputDataNodeImpl) dep;
        BaseDMNTypeImpl dmnType = (BaseDMNTypeImpl) inputDataNode.getType();
        return dmnType.isAssignableValue(result.getContext().get(dep.getName()));
    }
    // if the dependency is NOT an InputData, the type coherence was checked at evaluation result assignment.
    return true;
}
Also used : InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) InputDataNodeImpl(org.kie.dmn.core.ast.InputDataNodeImpl)

Example 4 with InputDataNodeImpl

use of org.kie.dmn.core.ast.InputDataNodeImpl in project drools-wb by kiegroup.

the class AbstractDMNTest method getInputDataNode.

protected InputDataNode getInputDataNode(DMNType dmnType, String name) {
    TInputData inputData = new TInputData();
    inputData.setName(name);
    InputDataNode toReturn = new InputDataNodeImpl(inputData, dmnType);
    return toReturn;
}
Also used : TInputData(org.kie.dmn.model.v1_2.TInputData) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) InputDataNodeImpl(org.kie.dmn.core.ast.InputDataNodeImpl)

Example 5 with InputDataNodeImpl

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

the class InputDataCompiler method compileNode.

@Override
public void compileNode(DRGElement de, DMNCompilerImpl compiler, DMNModelImpl model) {
    InputData input = (InputData) de;
    InputDataNodeImpl idn = new InputDataNodeImpl(input);
    if (input.getVariable() != null) {
        DMNCompilerHelper.checkVariableName(model, input, input.getName());
        DMNType type = compiler.resolveTypeRef(model, de, input.getVariable(), input.getVariable().getTypeRef());
        idn.setType(type);
    } else {
        idn.setType(model.getTypeRegistry().unknown());
        DMNCompilerHelper.reportMissingVariable(model, de, input, Msg.MISSING_VARIABLE_FOR_INPUT);
    }
    model.addInput(idn);
}
Also used : InputData(org.kie.dmn.model.api.InputData) InputDataNodeImpl(org.kie.dmn.core.ast.InputDataNodeImpl) DMNType(org.kie.dmn.api.core.DMNType)

Aggregations

InputDataNodeImpl (org.kie.dmn.core.ast.InputDataNodeImpl)5 InputDataNode (org.kie.dmn.api.core.ast.InputDataNode)3 DMNType (org.kie.dmn.api.core.DMNType)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 QName (javax.xml.namespace.QName)1 DMNMessage (org.kie.dmn.api.core.DMNMessage)1 DMNNode (org.kie.dmn.api.core.ast.DMNNode)1 DecisionNode (org.kie.dmn.api.core.ast.DecisionNode)1 DMNBaseNode (org.kie.dmn.core.ast.DMNBaseNode)1 DMNDecisionServiceFunctionDefinitionEvaluator (org.kie.dmn.core.ast.DMNDecisionServiceFunctionDefinitionEvaluator)1 DSFormalParameter (org.kie.dmn.core.ast.DMNDecisionServiceFunctionDefinitionEvaluator.DSFormalParameter)1 DecisionNodeImpl (org.kie.dmn.core.ast.DecisionNodeImpl)1 DecisionServiceNodeImpl (org.kie.dmn.core.ast.DecisionServiceNodeImpl)1 ItemDefNodeImpl (org.kie.dmn.core.ast.ItemDefNodeImpl)1 DMNModelImpl (org.kie.dmn.core.impl.DMNModelImpl)1