Search in sources :

Example 6 with LiteralExpression

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

the class DecisionRuleConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    DecisionRule dr = (DecisionRule) parent;
    for (UnaryTests ie : dr.getInputEntry()) {
        writeChildrenNode(writer, context, ie, INPUT_ENTRY);
    }
    for (LiteralExpression oe : dr.getOutputEntry()) {
        writeChildrenNode(writer, context, oe, OUTPUT_ENTRY);
    }
    for (RuleAnnotation a : dr.getAnnotationEntry()) {
        writeChildrenNode(writer, context, a, ANNOTATION_ENTRY);
    }
}
Also used : RuleAnnotation(org.kie.dmn.model.api.RuleAnnotation) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) UnaryTests(org.kie.dmn.model.api.UnaryTests) DecisionRule(org.kie.dmn.model.api.DecisionRule) TDecisionRule(org.kie.dmn.model.v1_4.TDecisionRule)

Example 7 with LiteralExpression

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

the class LiteralExpressionConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    LiteralExpression le = (LiteralExpression) parent;
    if (le.getText() != null)
        writeChildrenNodeAsValue(writer, context, le.getText(), TEXT);
    if (le.getImportedValues() != null)
        writeChildrenNode(writer, context, le.getImportedValues(), IMPORTED_VALUES);
}
Also used : LiteralExpression(org.kie.dmn.model.api.LiteralExpression) TLiteralExpression(org.kie.dmn.model.v1_3.TLiteralExpression)

Example 8 with LiteralExpression

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

the class LiteralExpressionConverter method assignAttributes.

@Override
protected void assignAttributes(HierarchicalStreamReader reader, Object parent) {
    super.assignAttributes(reader, parent);
    LiteralExpression le = (LiteralExpression) parent;
    String exprLanguage = reader.getAttribute(EXPR_LANGUAGE);
    le.setExpressionLanguage(exprLanguage);
}
Also used : LiteralExpression(org.kie.dmn.model.api.LiteralExpression) TLiteralExpression(org.kie.dmn.model.v1_3.TLiteralExpression)

Example 9 with LiteralExpression

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

the class LiteralExpressionConverter method writeAttributes.

@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
    super.writeAttributes(writer, parent);
    LiteralExpression le = (LiteralExpression) parent;
    if (le.getExpressionLanguage() != null)
        writer.addAttribute(EXPR_LANGUAGE, le.getExpressionLanguage());
}
Also used : LiteralExpression(org.kie.dmn.model.api.LiteralExpression) TLiteralExpression(org.kie.dmn.model.v1_3.TLiteralExpression)

Example 10 with LiteralExpression

use of org.kie.dmn.model.api.LiteralExpression 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)

Aggregations

LiteralExpression (org.kie.dmn.model.api.LiteralExpression)31 UnaryTests (org.kie.dmn.model.api.UnaryTests)11 DecisionRule (org.kie.dmn.model.api.DecisionRule)9 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)8 InputClause (org.kie.dmn.model.api.InputClause)6 ArrayList (java.util.ArrayList)5 QName (javax.xml.namespace.QName)5 InformationItem (org.kie.dmn.model.api.InformationItem)5 Collections (java.util.Collections)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Test (org.junit.Test)4 DMNMessage (org.kie.dmn.api.core.DMNMessage)4 DMNType (org.kie.dmn.api.core.DMNType)4 DMNNode (org.kie.dmn.api.core.ast.DMNNode)4 DMNExpressionEvaluator (org.kie.dmn.core.api.DMNExpressionEvaluator)4 Decision (org.kie.dmn.model.api.Decision)4 DecisionTable (org.kie.dmn.model.api.DecisionTable)4 Entry (java.util.Map.Entry)3 Objects (java.util.Objects)3