use of org.kie.dmn.model.v1_1.Invocation in project drools by kiegroup.
the class InvocationConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
Invocation i = (Invocation) parent;
if (i.getExpression() != null)
writeChildrenNode(writer, context, i.getExpression(), MarshallingUtils.defineExpressionNodeName(i.getExpression()));
for (Binding b : i.getBinding()) {
writeChildrenNode(writer, context, b, BINDING);
}
}
use of org.kie.dmn.model.v1_1.Invocation in project drools by kiegroup.
the class XStreamMarshaller method newXStream.
private XStream newXStream() {
XStream xStream = createTrustingXStream(staxDriver, Definitions.class.getClassLoader());
xStream.alias("artifact", Artifact.class);
xStream.alias("definitions", Definitions.class);
xStream.alias("inputData", InputData.class);
xStream.alias("decision", Decision.class);
xStream.alias("variable", InformationItem.class);
xStream.alias("informationRequirement", InformationRequirement.class);
xStream.alias("requiredInput", DMNElementReference.class);
xStream.alias("literalExpression", LiteralExpression.class);
// TODO will need to remove dups and find missing element not captured?
xStream.alias("DMNElement", DMNElement.class);
xStream.alias("allowedValues", UnaryTests.class);
xStream.alias("artifact", Artifact.class);
xStream.alias("association", Association.class);
xStream.alias("authorityRequirement", AuthorityRequirement.class);
xStream.alias("authorityRequirement", AuthorityRequirement.class);
xStream.alias("authorityRequirement", AuthorityRequirement.class);
xStream.alias("binding", Binding.class);
xStream.alias("businessContextElement", BusinessContextElement.class);
xStream.alias("businessKnowledgeModel", BusinessKnowledgeModel.class);
xStream.alias("column", InformationItem.class);
xStream.alias("context", Context.class);
xStream.alias("contextEntry", ContextEntry.class);
xStream.alias("decision", Decision.class);
xStream.alias("decisionMade", DMNElementReference.class);
xStream.alias("decisionMaker", DMNElementReference.class);
xStream.alias("decisionOwned", DMNElementReference.class);
xStream.alias("decisionOwner", DMNElementReference.class);
xStream.alias("decisionService", DecisionService.class);
xStream.alias("decisionTable", DecisionTable.class);
xStream.alias("defaultOutputEntry", LiteralExpression.class);
xStream.alias("definitions", Definitions.class);
xStream.alias("drgElement", DMNElementReference.class);
// xStream.alias("drgElement", DRGElement.class ); ambiguity, also referring to top-level xsd element just under xsd root.
xStream.alias("elementCollection", ElementCollection.class);
xStream.alias("elementCollection", ElementCollection.class);
xStream.alias("encapsulatedDecision", DMNElementReference.class);
xStream.alias("encapsulatedLogic", FunctionDefinition.class);
xStream.alias("expression", Expression.class);
xStream.alias("formalParameter", InformationItem.class);
xStream.alias("functionDefinition", FunctionDefinition.class);
xStream.alias("impactedPerformanceIndicator", DMNElementReference.class);
xStream.alias("impactingDecision", DMNElementReference.class);
xStream.alias("import", Import.class);
xStream.alias("import", Import.class);
// TODO where?
xStream.alias("importedElement", String.class);
xStream.alias("importedValues", ImportedValues.class);
xStream.alias("informationItem", InformationItem.class);
xStream.alias("informationRequirement", InformationRequirement.class);
xStream.alias("input", InputClause.class);
xStream.alias("inputData", DMNElementReference.class);
xStream.alias("inputData", InputData.class);
xStream.alias("inputDecision", DMNElementReference.class);
xStream.alias("inputEntry", UnaryTests.class);
xStream.alias("inputExpression", LiteralExpression.class);
xStream.alias("inputValues", UnaryTests.class);
xStream.alias("invocation", Invocation.class);
xStream.alias("itemComponent", ItemDefinition.class);
xStream.alias("itemDefinition", ItemDefinition.class);
xStream.alias("itemDefinition", ItemDefinition.class);
xStream.alias("knowledgeRequirement", KnowledgeRequirement.class);
xStream.alias("knowledgeRequirement", KnowledgeRequirement.class);
xStream.alias("knowledgeSource", KnowledgeSource.class);
xStream.alias("literalExpression", LiteralExpression.class);
xStream.alias("namedElement", NamedElement.class);
xStream.alias("organizationUnit", OrganizationUnit.class);
xStream.alias("output", OutputClause.class);
xStream.alias("outputDecision", DMNElementReference.class);
xStream.alias("outputEntry", LiteralExpression.class);
xStream.alias("outputValues", UnaryTests.class);
xStream.alias("owner", DMNElementReference.class);
xStream.alias("parameter", InformationItem.class);
xStream.alias("performanceIndicator", PerformanceIndicator.class);
xStream.alias("relation", Relation.class);
xStream.alias("requiredAuthority", DMNElementReference.class);
xStream.alias("requiredDecision", DMNElementReference.class);
xStream.alias("requiredDecision", DMNElementReference.class);
xStream.alias("requiredInput", DMNElementReference.class);
xStream.alias("requiredInput", DMNElementReference.class);
xStream.alias("requiredKnowledge", DMNElementReference.class);
xStream.alias("rule", DecisionRule.class);
xStream.alias("sourceRef", DMNElementReference.class);
xStream.alias("supportedObjective", DMNElementReference.class);
xStream.alias("targetRef", DMNElementReference.class);
xStream.alias("textAnnotation", TextAnnotation.class);
// TODO where?
xStream.alias("type", String.class);
xStream.alias("typeRef", QName.class);
xStream.alias("usingProcess", DMNElementReference.class);
xStream.alias("usingTask", DMNElementReference.class);
xStream.alias("variable", InformationItem.class);
xStream.alias("variable", InformationItem.class);
xStream.alias("variable", InformationItem.class);
xStream.alias("variable", InformationItem.class);
// xStream.alias("allowedAnswers", xsd:string.class );
// xStream.alias("description", xsd:string.class );
// xStream.alias("question", xsd:string.class );
// xStream.alias("text", xsd:string.class );
// xStream.alias("text", xsd:string.class );
// xStream.alias("text", xsd:string.class );
xStream.alias("row", org.kie.dmn.model.v1_1.List.class);
xStream.alias("list", org.kie.dmn.model.v1_1.List.class);
xStream.alias("extensionElements", DMNElement.ExtensionElements.class);
// Manually imported TEXT = String
xStream.alias(LiteralExpressionConverter.TEXT, String.class);
xStream.alias(TextAnnotationConverter.TEXT, String.class);
xStream.alias(UnaryTestsConverter.TEXT, String.class);
xStream.alias(DecisionConverter.QUESTION, String.class);
xStream.alias(DecisionConverter.ALLOWED_ANSWERS, String.class);
xStream.alias(DMNElementConverter.DESCRIPTION, String.class);
xStream.registerConverter(new AssociationConverter(xStream));
xStream.registerConverter(new AuthorityRequirementConverter(xStream));
xStream.registerConverter(new BindingConverter(xStream));
xStream.registerConverter(new BusinessKnowledgeModelConverter(xStream));
xStream.registerConverter(new ContextConverter(xStream));
xStream.registerConverter(new ContextEntryConverter(xStream));
xStream.registerConverter(new DecisionConverter(xStream));
xStream.registerConverter(new DecisionRuleConverter(xStream));
xStream.registerConverter(new DecisionServiceConverter(xStream));
xStream.registerConverter(new DecisionTableConverter(xStream));
xStream.registerConverter(new DefinitionsConverter(xStream));
xStream.registerConverter(new DMNElementReferenceConverter(xStream));
xStream.registerConverter(new FunctionDefinitionConverter(xStream));
xStream.registerConverter(new ImportConverter(xStream));
xStream.registerConverter(new ImportedValuesConverter(xStream));
xStream.registerConverter(new InformationItemConverter(xStream));
xStream.registerConverter(new InformationRequirementConverter(xStream));
xStream.registerConverter(new InputClauseConverter(xStream));
xStream.registerConverter(new InputDataConverter(xStream));
xStream.registerConverter(new InvocationConverter(xStream));
xStream.registerConverter(new ItemDefinitionConverter(xStream));
xStream.registerConverter(new KnowledgeRequirementConverter(xStream));
xStream.registerConverter(new KnowledgeSourceConverter(xStream));
xStream.registerConverter(new LiteralExpressionConverter(xStream));
xStream.registerConverter(new OrganizationUnitConverter(xStream));
xStream.registerConverter(new OutputClauseConverter(xStream));
xStream.registerConverter(new PerformanceIndicatorConverter(xStream));
xStream.registerConverter(new RelationConverter(xStream));
xStream.registerConverter(new TextAnnotationConverter(xStream));
xStream.registerConverter(new UnaryTestsConverter(xStream));
xStream.registerConverter(new QNameConverter());
xStream.registerConverter(new DMNListConverter(xStream));
xStream.registerConverter(new ElementCollectionConverter(xStream));
xStream.registerConverter(new ExtensionElementsConverter(xStream, extensionRegisters));
xStream.ignoreUnknownElements();
for (DMNExtensionRegister extensionRegister : extensionRegisters) {
extensionRegister.registerExtensionConverters(xStream);
}
return xStream;
}
use of org.kie.dmn.model.v1_1.Invocation in project drools by kiegroup.
the class DMNEvaluatorCompiler method compileFunctionDefinition.
private DMNExpressionEvaluator compileFunctionDefinition(DMNCompilerContext ctx, DMNModelImpl model, DMNBaseNode node, String functionName, FunctionDefinition expression) {
FunctionDefinition funcDef = expression;
String kindStr = funcDef.getAdditionalAttributes().get(FunctionDefinition.KIND_QNAME);
FunctionDefinition.Kind kind = kindStr != null ? FunctionDefinition.Kind.determineFromString(kindStr) : FunctionDefinition.Kind.FEEL;
if (kind == null) {
// unknown function kind
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, funcDef, model, null, null, Msg.FUNC_DEF_INVALID_KIND, kindStr, node.getIdentifierString());
return new DMNFunctionDefinitionEvaluator(node.getName(), funcDef);
} else if (kind.equals(FunctionDefinition.Kind.FEEL)) {
ctx.enterFrame();
try {
DMNFunctionDefinitionEvaluator func = new DMNFunctionDefinitionEvaluator(node.getName(), funcDef);
for (InformationItem p : funcDef.getFormalParameter()) {
DMNCompilerHelper.checkVariableName(model, p, p.getName());
DMNType dmnType = compiler.resolveTypeRef(model, node, p, p, p.getTypeRef());
func.addParameter(p.getName(), dmnType);
ctx.setVariable(p.getName(), dmnType);
}
DMNExpressionEvaluator eval = compileExpression(ctx, model, node, functionName, funcDef.getExpression());
if (eval instanceof DMNLiteralExpressionEvaluator && ((DMNLiteralExpressionEvaluator) eval).isFunctionDefinition()) {
// we need to resolve the function and eliminate the indirection
CompiledExpression fexpr = ((DMNLiteralExpressionEvaluator) eval).getExpression();
FEELFunction feelFunction = feel.evaluateFunctionDef(ctx, fexpr, model, funcDef, Msg.FUNC_DEF_COMPILATION_ERR, functionName, node.getIdentifierString());
DMNInvocationEvaluator invoker = new DMNInvocationEvaluator(node.getName(), node.getSource(), functionName, new Invocation(), (fctx, fname) -> feelFunction, // feel can be null as anyway is hardcoded to `feelFunction`
null);
for (InformationItem p : funcDef.getFormalParameter()) {
invoker.addParameter(p.getName(), func.getParameterType(p.getName()), (em, dr) -> new EvaluatorResultImpl(dr.getContext().get(p.getName()), EvaluatorResult.ResultType.SUCCESS));
}
eval = invoker;
}
func.setEvaluator(eval);
return func;
} finally {
ctx.exitFrame();
}
} else if (kind.equals(FunctionDefinition.Kind.JAVA)) {
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 = feel.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, new Invocation(), (fctx, fname) -> feelFunction, // feel can be null as anyway is hardcoded to `feelFunction`
null);
DMNFunctionDefinitionEvaluator func = new DMNFunctionDefinitionEvaluator(node.getName(), funcDef);
for (InformationItem p : funcDef.getFormalParameter()) {
DMNCompilerHelper.checkVariableName(model, p, p.getName());
DMNType dmnType = compiler.resolveTypeRef(model, node, 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, expression, model, e, null, Msg.FUNC_DEF_COMPILATION_ERR, functionName, node.getIdentifierString(), "Exception raised: " + e.getClass().getSimpleName());
}
} else {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, expression, 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());
}
} else if (kind.equals(FunctionDefinition.Kind.PMML)) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.WARN, funcDef, model, null, null, Msg.FUNC_DEF_PMML_NOT_SUPPORTED, node.getIdentifierString());
} else {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, funcDef, model, null, null, Msg.FUNC_DEF_INVALID_KIND, kindStr, node.getIdentifierString());
}
return new DMNFunctionDefinitionEvaluator(node.getName(), funcDef);
}
use of org.kie.dmn.model.v1_1.Invocation in project drools by kiegroup.
the class DMNEvaluatorCompiler method compileInvocation.
private DMNExpressionEvaluator compileInvocation(DMNCompilerContext ctx, DMNModelImpl model, DMNBaseNode node, Invocation expression) {
Invocation invocation = expression;
// expression must be a literal text with the name of the function
String functionName = ((LiteralExpression) invocation.getExpression()).getText();
DMNInvocationEvaluator invEval = new DMNInvocationEvaluator(node.getName(), node.getSource(), functionName, invocation, null, feel.newFEELInstance());
for (Binding binding : invocation.getBinding()) {
if (binding.getParameter() == null) {
// error, missing binding parameter
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, binding, model, null, null, Msg.MISSING_PARAMETER_FOR_INVOCATION, node.getIdentifierString());
return null;
}
if (binding.getExpression() == null) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, binding, model, null, null, Msg.MISSING_PARAMETER_FOR_INVOCATION, node.getIdentifierString());
return null;
}
invEval.addParameter(binding.getParameter().getName(), compiler.resolveTypeRef(model, node, binding.getParameter(), binding.getParameter(), binding.getParameter().getTypeRef()), compileExpression(ctx, model, node, binding.getParameter().getName(), binding.getExpression()));
}
return invEval;
}
Aggregations