use of org.kie.dmn.api.core.DMNType in project drools by kiegroup.
the class BusinessKnowledgeModelCompiler method compileNode.
@Override
public void compileNode(DRGElement de, DMNCompilerImpl compiler, DMNModelImpl model) {
BusinessKnowledgeModel bkm = (BusinessKnowledgeModel) de;
BusinessKnowledgeModelNodeImpl bkmn = new BusinessKnowledgeModelNodeImpl(bkm);
DMNType type = null;
if (bkm.getVariable() == null) {
DMNCompilerHelper.reportMissingVariable(model, de, bkm, Msg.MISSING_VARIABLE_FOR_BKM);
return;
}
DMNCompilerHelper.checkVariableName(model, bkm, bkm.getName());
if (bkm.getVariable() != null && bkm.getVariable().getTypeRef() != null) {
type = compiler.resolveTypeRef(model, bkmn, bkm, bkm.getVariable(), bkm.getVariable().getTypeRef());
} else {
// for now the call bellow will return type UNKNOWN
type = compiler.resolveTypeRef(model, bkmn, bkm, bkm, null);
}
bkmn.setResultType(type);
model.addBusinessKnowledgeModel(bkmn);
}
use of org.kie.dmn.api.core.DMNType in project drools by kiegroup.
the class DMNCompilerImpl method buildTypeDef.
private DMNType buildTypeDef(DMNCompilerContext ctx, DMNFEELHelper feel, DMNModelImpl dmnModel, DMNNode node, ItemDefinition itemDef, boolean topLevel) {
BaseDMNTypeImpl type = null;
if (itemDef.getTypeRef() != null) {
// this is a reference to an existing type, so resolve the reference
type = (BaseDMNTypeImpl) resolveTypeRef(dmnModel, node, itemDef, itemDef, itemDef.getTypeRef());
if (type != null) {
UnaryTests allowedValuesStr = itemDef.getAllowedValues();
// or if it changes the metadata for the base type
if (topLevel || allowedValuesStr != null || itemDef.isIsCollection() != type.isCollection()) {
// we have to clone this type definition into a new one
BaseDMNTypeImpl baseType = type;
type = type.clone();
type.setBaseType(baseType);
type.setNamespace(dmnModel.getNamespace());
type.setName(itemDef.getName());
type.setAllowedValues(null);
if (allowedValuesStr != null) {
List<UnaryTest> av = feel.evaluateUnaryTests(ctx, allowedValuesStr.getText(), dmnModel, itemDef, Msg.ERR_COMPILING_ALLOWED_VALUES_LIST_ON_ITEM_DEF, allowedValuesStr.getText(), node.getName());
type.setAllowedValues(av);
}
if (itemDef.isIsCollection()) {
type.setCollection(itemDef.isIsCollection());
}
}
if (topLevel) {
DMNType registered = dmnModel.getTypeRegistry().registerType(type);
if (registered != type) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, itemDef, dmnModel, null, null, Msg.DUPLICATED_ITEM_DEFINITION, itemDef.getName());
}
}
}
} else {
// this is a composite type
DMNCompilerHelper.checkVariableName(dmnModel, itemDef, itemDef.getName());
CompositeTypeImpl compType = new CompositeTypeImpl(dmnModel.getNamespace(), itemDef.getName(), itemDef.getId(), itemDef.isIsCollection());
for (ItemDefinition fieldDef : itemDef.getItemComponent()) {
DMNCompilerHelper.checkVariableName(dmnModel, fieldDef, fieldDef.getName());
DMNType fieldType = buildTypeDef(ctx, feel, dmnModel, node, fieldDef, false);
fieldType = fieldType != null ? fieldType : DMNTypeRegistry.UNKNOWN;
compType.addField(fieldDef.getName(), fieldType);
}
type = compType;
if (topLevel) {
DMNType registered = dmnModel.getTypeRegistry().registerType(type);
if (registered != type) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, itemDef, dmnModel, null, null, Msg.DUPLICATED_ITEM_DEFINITION, itemDef.getName());
}
}
}
return type;
}
use of org.kie.dmn.api.core.DMNType in project drools by kiegroup.
the class DMNFEELHelper method compileFeelExpression.
public CompiledExpression compileFeelExpression(DMNCompilerContext ctx, String expression, DMNModelImpl model, DMNElement element, Msg.Message errorMsg, Object... msgParams) {
CompilerContext feelctx = feel.newCompilerContext();
for (Map.Entry<String, DMNType> entry : ctx.getVariables().entrySet()) {
feelctx.addInputVariableType(entry.getKey(), ((BaseDMNTypeImpl) entry.getValue()).getFeelType());
}
CompiledExpression ce = feel.compile(expression, feelctx);
processEvents(model, element, errorMsg, msgParams);
return ce;
}
use of org.kie.dmn.api.core.DMNType in project drools by kiegroup.
the class DecisionCompiler method compileEvaluator.
@Override
public void compileEvaluator(DMNNode node, DMNCompilerImpl compiler, DMNCompilerContext ctx, DMNModelImpl model) {
DecisionNodeImpl di = (DecisionNodeImpl) node;
compiler.linkRequirements(model, di);
ctx.enterFrame();
try {
Map<String, DMNType> importedTypes = new HashMap<>();
for (DMNNode dep : di.getDependencies().values()) {
if (dep instanceof DecisionNode) {
ctx.setVariable(dep.getName(), ((DecisionNode) dep).getResultType());
} else if (dep instanceof InputDataNode) {
ctx.setVariable(dep.getName(), ((InputDataNode) dep).getType());
} else if (dep instanceof BusinessKnowledgeModelNode) {
if (dep.getModelNamespace().equals(model.getNamespace())) {
// might need to create a DMNType for "functions" and replace the type here by that
ctx.setVariable(dep.getName(), ((BusinessKnowledgeModelNode) dep).getResultType());
} else {
// then the BKM dependency is an imported BKM.
Optional<String> alias = model.getImportAliasFor(dep.getModelNamespace(), dep.getModelName());
if (alias.isPresent()) {
CompositeTypeImpl importedComposite = (CompositeTypeImpl) importedTypes.computeIfAbsent(alias.get(), a -> new CompositeTypeImpl());
importedComposite.addField(dep.getName(), ((BusinessKnowledgeModelNode) dep).getResultType());
}
}
}
}
for (Entry<String, DMNType> importedType : importedTypes.entrySet()) {
ctx.setVariable(importedType.getKey(), importedType.getValue());
}
DMNExpressionEvaluator evaluator = compiler.getEvaluatorCompiler().compileExpression(ctx, model, di, di.getName(), di.getDecision().getExpression());
di.setEvaluator(evaluator);
} finally {
ctx.exitFrame();
}
}
use of org.kie.dmn.api.core.DMNType in project drools by kiegroup.
the class DecisionCompiler method compileNode.
@Override
public void compileNode(DRGElement de, DMNCompilerImpl compiler, DMNModelImpl model) {
Decision decision = (Decision) de;
DecisionNodeImpl dn = new DecisionNodeImpl(decision);
DMNType type = null;
if (decision.getVariable() == null) {
DMNCompilerHelper.reportMissingVariable(model, de, decision, Msg.MISSING_VARIABLE_FOR_DECISION);
return;
}
DMNCompilerHelper.checkVariableName(model, decision, decision.getName());
if (decision.getVariable() != null && decision.getVariable().getTypeRef() != null) {
type = compiler.resolveTypeRef(model, dn, decision, decision.getVariable(), decision.getVariable().getTypeRef());
} else {
type = compiler.resolveTypeRef(model, dn, decision, decision, null);
}
dn.setResultType(type);
model.addDecision(dn);
}
Aggregations