use of org.kie.dmn.model.api.InformationItem in project drools by kiegroup.
the class DMNEvaluatorCompiler method compileRelation.
private DMNExpressionEvaluator compileRelation(DMNCompilerContext ctx, DMNModelImpl model, DMNBaseNode node, String relationName, Relation expression) {
Relation relationDef = expression;
DMNRelationEvaluator relationEval = new DMNRelationEvaluator(node.getName(), node.getSource(), relationDef);
for (InformationItem col : relationDef.getColumn()) {
DMNCompilerHelper.checkVariableName(model, col, col.getName());
relationEval.addColumn(col.getName());
}
for (org.kie.dmn.model.api.List row : relationDef.getRow()) {
java.util.List<DMNExpressionEvaluator> values = new ArrayList<>();
for (Expression expr : row.getExpression()) {
if (expr instanceof LiteralExpression) {
// DROOLS-2439
LiteralExpression literalExpression = (LiteralExpression) expr;
if (literalExpression.getText() == null || literalExpression.getText().isEmpty()) {
LiteralExpression nullProxy = (literalExpression instanceof org.kie.dmn.model.v1_1.TLiteralExpression) ? new org.kie.dmn.model.v1_1.TLiteralExpression() : new org.kie.dmn.model.v1_2.TLiteralExpression();
nullProxy.setText("null");
nullProxy.setImportedValues(literalExpression.getImportedValues());
nullProxy.setExpressionLanguage(literalExpression.getExpressionLanguage());
nullProxy.setTypeRef(literalExpression.getTypeRef());
nullProxy.setId(literalExpression.getId());
nullProxy.setLabel(literalExpression.getLabel());
nullProxy.setDescription(literalExpression.getDescription());
nullProxy.setExtensionElements(literalExpression.getExtensionElements());
nullProxy.setParent(literalExpression.getParent());
nullProxy.getNsContext().putAll(literalExpression.getNsContext());
nullProxy.setAdditionalAttributes(literalExpression.getAdditionalAttributes());
nullProxy.setLocation(literalExpression.getLocation());
// do not add `temp` as child of parent.
expr = nullProxy;
}
}
values.add(compileExpression(ctx, model, node, relationName, expr));
}
relationEval.addRow(values);
}
return relationEval;
}
use of org.kie.dmn.model.api.InformationItem in project drools by kiegroup.
the class DMNEvaluatorCompiler method compileFunctionDefinitionPMML.
private DMNExpressionEvaluator compileFunctionDefinitionPMML(DMNCompilerContext ctx, DMNModelImpl model, DMNBaseNode node, String functionName, FunctionDefinition funcDef) {
if (funcDef.getExpression() instanceof Context) {
Context context = (Context) funcDef.getExpression();
String pmmlDocument = null;
String pmmlModel = null;
for (ContextEntry ce : context.getContextEntry()) {
if (ce.getVariable() != null && ce.getVariable().getName() != null && ce.getExpression() instanceof LiteralExpression) {
LiteralExpression ceLitExpr = (LiteralExpression) ce.getExpression();
if (ce.getVariable().getName().equals("document")) {
if (ceLitExpr.getText() != null) {
pmmlDocument = stripQuotes(ceLitExpr.getText().trim());
}
} else if (ce.getVariable().getName().equals("model")) {
if (ceLitExpr.getText() != null) {
pmmlModel = stripQuotes(ceLitExpr.getText().trim());
}
}
}
}
final String nameLookup = pmmlDocument;
Optional<Import> lookupImport = model.getDefinitions().getImport().stream().filter(x -> x.getName().equals(nameLookup)).findFirst();
if (lookupImport.isPresent()) {
Import theImport = lookupImport.get();
logger.trace("theImport: {}", theImport);
Resource pmmlResource = DMNCompilerImpl.resolveRelativeResource(getRootClassLoader(), model, theImport, funcDef, ctx.getRelativeResolver());
logger.trace("pmmlResource: {}", pmmlResource);
DMNImportPMMLInfo pmmlInfo = model.getPmmlImportInfo().get(pmmlDocument);
logger.trace("pmmlInfo: {}", pmmlInfo);
if (pmmlModel == null || pmmlModel.isEmpty()) {
List<String> pmmlModelNames = pmmlInfo.getModels().stream().map(PMMLModelInfo::getName).filter(x -> x != null).collect(Collectors.toList());
if (pmmlModelNames.size() > 0) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.WARN, funcDef, model, null, null, Msg.FUNC_DEF_PMML_MISSING_MODEL_NAME, pmmlModelNames.stream().collect(Collectors.joining(",")));
}
}
AbstractPMMLInvocationEvaluator invoker = PMMLInvocationEvaluatorFactory.newInstance(model, getRootClassLoader(), funcDef, pmmlResource, pmmlModel, pmmlInfo);
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);
}
func.setEvaluator(invoker);
return func;
} else {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, funcDef, model, null, null, Msg.FUNC_DEF_PMML_MISSING_ENTRY, functionName, node.getIdentifierString());
}
} else {
// error, PMML 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);
}
use of org.kie.dmn.model.api.InformationItem in project drools by kiegroup.
the class DMNEvaluatorCompiler method compileFunctionDefinitionFEEL.
private DMNExpressionEvaluator compileFunctionDefinitionFEEL(DMNCompilerContext ctx, DMNModelImpl model, DMNBaseNode node, String functionName, FunctionDefinition funcDef) {
ctx.enterFrame();
try {
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);
ctx.setVariable(p.getName(), dmnType);
}
DMNExpressionEvaluator eval = compileExpression(ctx, model, node, functionName, funcDef.getExpression());
func.setEvaluator(eval);
return func;
} finally {
ctx.exitFrame();
}
}
use of org.kie.dmn.model.api.InformationItem in project drools by kiegroup.
the class BusinessKnowledgeModelCompiler method checkFnConsistency.
private void checkFnConsistency(DMNModelImpl model, BusinessKnowledgeModelNodeImpl bkmi, DMNType type, FunctionDefinition funcDef) {
SimpleFnTypeImpl fnType = ((SimpleFnTypeImpl) type);
FunctionItem fi = fnType.getFunctionItem();
if (fi.getParameters().size() != funcDef.getFormalParameter().size()) {
MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, bkmi.getBusinessKnowledModel(), model, null, null, Msg.PARAMETER_COUNT_MISMATCH_COMPILING, bkmi.getName(), fi.getParameters().size(), funcDef.getFormalParameter().size());
return;
}
for (int i = 0; i < fi.getParameters().size(); i++) {
InformationItem fiII = fi.getParameters().get(i);
InformationItem fdII = funcDef.getFormalParameter().get(i);
if (!fiII.getName().equals(fdII.getName())) {
List<String> fiParamNames = fi.getParameters().stream().map(InformationItem::getName).collect(Collectors.toList());
List<String> funcDefParamNames = funcDef.getFormalParameter().stream().map(InformationItem::getName).collect(Collectors.toList());
MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, bkmi.getBusinessKnowledModel(), model, null, null, Msg.PARAMETER_NAMES_MISMATCH_COMPILING, bkmi.getName(), fiParamNames, funcDefParamNames);
return;
}
QName fiQname = fiII.getTypeRef();
QName fdQname = fdII.getTypeRef();
if (fiQname != null && fdQname != null && !fiQname.equals(fdQname)) {
MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, bkmi.getBusinessKnowledModel(), model, null, null, Msg.PARAMETER_TYPEREF_MISMATCH_COMPILING, bkmi.getName(), fiII.getName(), fiQname, fdQname);
}
}
QName fiReturnType = fi.getOutputTypeRef();
QName fdReturnType = funcDef.getExpression().getTypeRef();
if (fiReturnType != null && fdReturnType != null && !fiReturnType.equals(fdReturnType)) {
MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, bkmi.getBusinessKnowledModel(), model, null, null, Msg.RETURNTYPE_TYPEREF_MISMATCH_COMPILING, bkmi.getName(), fiReturnType, fdReturnType);
}
}
use of org.kie.dmn.model.api.InformationItem in project drools by kiegroup.
the class RelationConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
Relation r = (Relation) parent;
for (InformationItem c : r.getColumn()) {
writeChildrenNode(writer, context, c, COLUMN);
}
for (org.kie.dmn.model.api.List row : r.getRow()) {
writeChildrenNode(writer, context, row, ROW);
}
}
Aggregations