Search in sources :

Example 11 with InformationItem

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

the class DMNEvaluatorCompiler method compileFunctionDefinitionJAVA.

private DMNExpressionEvaluator compileFunctionDefinitionJAVA(DMNCompilerContext ctx, DMNModelImpl model, DMNBaseNode node, String functionName, FunctionDefinition funcDef) {
    if (funcDef.getExpression() instanceof Context) {
        // proceed
        Context context = (Context) funcDef.getExpression();
        String clazz = null;
        String method = null;
        for (ContextEntry ce : context.getContextEntry()) {
            if (ce.getVariable() != null && ce.getVariable().getName() != null && ce.getExpression() != null && ce.getExpression() instanceof LiteralExpression) {
                if (ce.getVariable().getName().equals("class")) {
                    clazz = stripQuotes(((LiteralExpression) ce.getExpression()).getText().trim());
                } else if (ce.getVariable().getName().equals("method signature")) {
                    method = stripQuotes(((LiteralExpression) ce.getExpression()).getText().trim());
                }
            }
        }
        if (clazz != null && method != null) {
            String params = funcDef.getFormalParameter().stream().map(p -> p.getName()).collect(Collectors.joining(","));
            String expr = String.format("function(%s) external { java: { class: \"%s\", method signature: \"%s\" }}", params, clazz, method);
            try {
                FEELFunction feelFunction = ctx.getFeelHelper().evaluateFunctionDef(ctx, expr, model, funcDef, Msg.FUNC_DEF_COMPILATION_ERR, functionName, node.getIdentifierString());
                if (feelFunction != null) {
                    ((BaseFEELFunction) feelFunction).setName(functionName);
                }
                DMNInvocationEvaluator invoker = new DMNInvocationEvaluator(node.getName(), node.getSource(), functionName, null, (fctx, fname) -> feelFunction, // feel can be null as anyway is hardcoded to `feelFunction`
                null);
                DMNFunctionDefinitionEvaluator func = new DMNFunctionDefinitionEvaluator(node, funcDef);
                for (InformationItem p : funcDef.getFormalParameter()) {
                    DMNCompilerHelper.checkVariableName(model, p, p.getName());
                    DMNType dmnType = compiler.resolveTypeRef(model, p, p, p.getTypeRef());
                    func.addParameter(p.getName(), dmnType);
                    invoker.addParameter(p.getName(), dmnType, (em, dr) -> new EvaluatorResultImpl(dr.getContext().get(p.getName()), EvaluatorResult.ResultType.SUCCESS));
                }
                func.setEvaluator(invoker);
                return func;
            } catch (Throwable e) {
                MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, funcDef, model, e, null, Msg.FUNC_DEF_COMPILATION_ERR, functionName, node.getIdentifierString(), "Exception raised: " + e.getClass().getSimpleName());
            }
        } else {
            MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, funcDef, model, null, null, Msg.FUNC_DEF_MISSING_ENTRY, functionName, node.getIdentifierString());
        }
    } else {
        // error, java function definitions require a context
        MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, funcDef, model, null, null, Msg.FUNC_DEF_BODY_NOT_CONTEXT, node.getIdentifierString());
    }
    return new DMNFunctionDefinitionEvaluator(node, funcDef);
}
Also used : Context(org.kie.dmn.model.api.Context) PMMLModelInfo(org.kie.dmn.core.pmml.PMMLModelInfo) DMNConditionalEvaluator(org.kie.dmn.core.ast.DMNConditionalEvaluator) DecisionTable(org.kie.dmn.model.api.DecisionTable) DMNMessage(org.kie.dmn.api.core.DMNMessage) Quantified(org.kie.dmn.model.api.Quantified) LoggerFactory(org.slf4j.LoggerFactory) DMNExpressionEvaluator(org.kie.dmn.core.api.DMNExpressionEvaluator) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) DMNElement(org.kie.dmn.model.api.DMNElement) DTDecisionRule(org.kie.dmn.feel.runtime.decisiontables.DTDecisionRule) EvaluatorResult(org.kie.dmn.core.api.EvaluatorResult) DMNIteratorEvaluator(org.kie.dmn.core.ast.DMNIteratorEvaluator) UnaryTest(org.kie.dmn.feel.runtime.UnaryTest) DMNNode(org.kie.dmn.api.core.ast.DMNNode) BaseDMNTypeImpl(org.kie.dmn.core.impl.BaseDMNTypeImpl) OutputClause(org.kie.dmn.model.api.OutputClause) DMNModelImpl(org.kie.dmn.core.impl.DMNModelImpl) Import(org.kie.dmn.model.api.Import) UUID(java.util.UUID) FunctionKind(org.kie.dmn.model.api.FunctionKind) DMNRelationEvaluator(org.kie.dmn.core.ast.DMNRelationEvaluator) Collectors(java.util.stream.Collectors) BusinessKnowledgeModelNode(org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode) HitPolicy(org.kie.dmn.model.api.HitPolicy) Objects(java.util.Objects) Resource(org.kie.api.io.Resource) List(java.util.List) DMNDTExpressionEvaluator(org.kie.dmn.core.ast.DMNDTExpressionEvaluator) Filter(org.kie.dmn.model.api.Filter) CompiledExpression(org.kie.dmn.feel.lang.CompiledExpression) Expression(org.kie.dmn.model.api.Expression) Entry(java.util.Map.Entry) Optional(java.util.Optional) QName(javax.xml.namespace.QName) InformationItem(org.kie.dmn.model.api.InformationItem) Iterator(org.kie.dmn.model.api.Iterator) DMNLiteralExpressionEvaluator(org.kie.dmn.core.ast.DMNLiteralExpressionEvaluator) RootExecutionFrame(org.kie.dmn.feel.lang.impl.RootExecutionFrame) Relation(org.kie.dmn.model.api.Relation) FEEL(org.kie.dmn.feel.FEEL) MsgUtil(org.kie.dmn.core.util.MsgUtil) DMNType(org.kie.dmn.api.core.DMNType) DMNContextEvaluator(org.kie.dmn.core.ast.DMNContextEvaluator) Binding(org.kie.dmn.model.api.Binding) InputClause(org.kie.dmn.model.api.InputClause) DTOutputClause(org.kie.dmn.feel.runtime.decisiontables.DTOutputClause) EvaluatorResultImpl(org.kie.dmn.core.ast.EvaluatorResultImpl) DTInputClause(org.kie.dmn.feel.runtime.decisiontables.DTInputClause) ArrayList(java.util.ArrayList) DecisionRule(org.kie.dmn.model.api.DecisionRule) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) DMNFilterEvaluator(org.kie.dmn.core.ast.DMNFilterEvaluator) FEELFunction(org.kie.dmn.feel.runtime.FEELFunction) For(org.kie.dmn.model.api.For) DMNBaseNode(org.kie.dmn.core.ast.DMNBaseNode) Decision(org.kie.dmn.model.api.Decision) FunctionDefinition(org.kie.dmn.model.api.FunctionDefinition) DMNInvocationEvaluator(org.kie.dmn.core.ast.DMNInvocationEvaluator) Logger(org.slf4j.Logger) DMNListEvaluator(org.kie.dmn.core.ast.DMNListEvaluator) AbstractPMMLInvocationEvaluator(org.kie.dmn.core.pmml.AbstractPMMLInvocationEvaluator) DTInvokerFunction(org.kie.dmn.feel.runtime.functions.DTInvokerFunction) ContextEntry(org.kie.dmn.model.api.ContextEntry) Invocation(org.kie.dmn.model.api.Invocation) DMNAlphaNetworkEvaluatorCompiler(org.kie.dmn.core.compiler.alphanetbased.DMNAlphaNetworkEvaluatorCompiler) Collectors.toList(java.util.stream.Collectors.toList) PMMLInvocationEvaluatorFactory(org.kie.dmn.core.pmml.AbstractPMMLInvocationEvaluator.PMMLInvocationEvaluatorFactory) DMNImportPMMLInfo(org.kie.dmn.core.pmml.DMNImportPMMLInfo) BusinessKnowledgeModel(org.kie.dmn.model.api.BusinessKnowledgeModel) DMNFunctionDefinitionEvaluator(org.kie.dmn.core.ast.DMNFunctionDefinitionEvaluator) UnaryTests(org.kie.dmn.model.api.UnaryTests) CompositeTypeImpl(org.kie.dmn.core.impl.CompositeTypeImpl) Conditional(org.kie.dmn.model.api.Conditional) Msg(org.kie.dmn.core.util.Msg) DecisionTableImpl(org.kie.dmn.feel.runtime.decisiontables.DecisionTableImpl) Collections(java.util.Collections) Context(org.kie.dmn.model.api.Context) BaseFEELFunction(org.kie.dmn.feel.runtime.functions.BaseFEELFunction) BaseFEELFunction(org.kie.dmn.feel.runtime.functions.BaseFEELFunction) FEELFunction(org.kie.dmn.feel.runtime.FEELFunction) BaseFEELFunction(org.kie.dmn.feel.runtime.functions.BaseFEELFunction) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) InformationItem(org.kie.dmn.model.api.InformationItem) ContextEntry(org.kie.dmn.model.api.ContextEntry) DMNFunctionDefinitionEvaluator(org.kie.dmn.core.ast.DMNFunctionDefinitionEvaluator) EvaluatorResultImpl(org.kie.dmn.core.ast.EvaluatorResultImpl) DMNInvocationEvaluator(org.kie.dmn.core.ast.DMNInvocationEvaluator) DMNType(org.kie.dmn.api.core.DMNType)

Example 12 with InformationItem

use of org.kie.dmn.model.api.InformationItem 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 13 with InformationItem

use of org.kie.dmn.model.api.InformationItem 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 14 with InformationItem

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

the class XLS2DMNParser method appendInputData.

private void appendInputData(Definitions definitions, Map<String, DTHeaderInfo> headerInfos) {
    Set<String> usedRI = new LinkedHashSet<>();
    for (DTHeaderInfo hi : headerInfos.values()) {
        for (String ri : hi.getRequiredInput()) {
            if (!usedRI.contains(ri)) {
                InputData id = new TInputData();
                id.setName(ri);
                id.setId("id_" + CodegenStringUtil.escapeIdentifier(ri));
                InformationItem variable = new TInformationItem();
                variable.setName(ri);
                variable.setId("idvar_" + CodegenStringUtil.escapeIdentifier(ri));
                variable.setTypeRef(new QName("Any"));
                id.setVariable(variable);
                definitions.getDrgElement().add(id);
            }
            usedRI.add(ri);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TInputData(org.kie.dmn.model.v1_2.TInputData) QName(javax.xml.namespace.QName) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) InformationItem(org.kie.dmn.model.api.InformationItem) TInputData(org.kie.dmn.model.v1_2.TInputData) InputData(org.kie.dmn.model.api.InputData)

Example 15 with InformationItem

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

the class XLS2DMNParser method appendDecisionDT.

private void appendDecisionDT(Definitions definitions, Map<String, DTHeaderInfo> headerInfos) {
    for (DTHeaderInfo hi : headerInfos.values()) {
        Decision decision = new TDecision();
        decision.setName(hi.getSheetName());
        decision.setId("d_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
        InformationItem variable = new TInformationItem();
        variable.setName(hi.getSheetName());
        variable.setId("dvar_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
        variable.setTypeRef(new QName("Any"));
        decision.setVariable(variable);
        for (String ri : hi.getRequiredInput()) {
            InformationRequirement ir = new TInformationRequirement();
            DMNElementReference er = new TDMNElementReference();
            er.setHref("#id_" + CodegenStringUtil.escapeIdentifier(ri));
            ir.setRequiredInput(er);
            decision.getInformationRequirement().add(ir);
        }
        for (String ri : hi.getRequiredDecision()) {
            InformationRequirement ir = new TInformationRequirement();
            DMNElementReference er = new TDMNElementReference();
            er.setHref("#d_" + CodegenStringUtil.escapeIdentifier(ri));
            ir.setRequiredDecision(er);
            decision.getInformationRequirement().add(ir);
        }
        DecisionTable dt = new TDecisionTable();
        dt.setOutputLabel(hi.getSheetName());
        dt.setId("ddt_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
        dt.setHitPolicy(HitPolicy.ANY);
        for (String ri : hi.getRequiredInput()) {
            InputClause ic = new TInputClause();
            ic.setLabel(ri);
            LiteralExpression le = new TLiteralExpression();
            le.setText(ri);
            ic.setInputExpression(le);
            dt.getInput().add(ic);
        }
        for (String rd : hi.getRequiredDecision()) {
            InputClause ic = new TInputClause();
            ic.setLabel(rd);
            LiteralExpression le = new TLiteralExpression();
            le.setText(rd);
            ic.setInputExpression(le);
            dt.getInput().add(ic);
        }
        OutputClause oc = new TOutputClause();
        dt.getOutput().add(oc);
        decision.setExpression(dt);
        definitions.getDrgElement().add(decision);
    }
}
Also used : TInformationRequirement(org.kie.dmn.model.v1_2.TInformationRequirement) QName(javax.xml.namespace.QName) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) InformationItem(org.kie.dmn.model.api.InformationItem) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) Decision(org.kie.dmn.model.api.Decision) TDecision(org.kie.dmn.model.v1_2.TDecision) OutputClause(org.kie.dmn.model.api.OutputClause) TOutputClause(org.kie.dmn.model.v1_2.TOutputClause) DecisionTable(org.kie.dmn.model.api.DecisionTable) TDecisionTable(org.kie.dmn.model.v1_2.TDecisionTable) DMNElementReference(org.kie.dmn.model.api.DMNElementReference) TDMNElementReference(org.kie.dmn.model.v1_2.TDMNElementReference) TInputClause(org.kie.dmn.model.v1_2.TInputClause) TInformationRequirement(org.kie.dmn.model.v1_2.TInformationRequirement) InformationRequirement(org.kie.dmn.model.api.InformationRequirement) TDecision(org.kie.dmn.model.v1_2.TDecision) TDecisionTable(org.kie.dmn.model.v1_2.TDecisionTable) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) TDMNElementReference(org.kie.dmn.model.v1_2.TDMNElementReference) TOutputClause(org.kie.dmn.model.v1_2.TOutputClause) TInputClause(org.kie.dmn.model.v1_2.TInputClause) InputClause(org.kie.dmn.model.api.InputClause)

Aggregations

InformationItem (org.kie.dmn.model.api.InformationItem)32 QName (javax.xml.namespace.QName)9 TInformationItem (org.kie.dmn.model.v1_2.TInformationItem)8 Relation (org.kie.dmn.model.api.Relation)7 FunctionDefinition (org.kie.dmn.model.api.FunctionDefinition)6 ArrayList (java.util.ArrayList)5 DMNType (org.kie.dmn.api.core.DMNType)5 DecisionNode (org.kie.dmn.api.core.ast.DecisionNode)5 List (java.util.List)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 DMNMessage (org.kie.dmn.api.core.DMNMessage)4 BusinessKnowledgeModelNode (org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode)4 DMNNode (org.kie.dmn.api.core.ast.DMNNode)4 DMNBaseNode (org.kie.dmn.core.ast.DMNBaseNode)4 DMNModelImpl (org.kie.dmn.core.impl.DMNModelImpl)4 Msg (org.kie.dmn.core.util.Msg)4 MsgUtil (org.kie.dmn.core.util.MsgUtil)4 DRGElement (org.kie.dmn.model.api.DRGElement)4 Decision (org.kie.dmn.model.api.Decision)4