use of org.kie.dmn.model.v1_1.List 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.v1_1.List row : r.getRow()) {
writeChildrenNode(writer, context, row, ROW);
}
}
use of org.kie.dmn.model.v1_1.List in project drools by kiegroup.
the class DMNAssemblerService method addResources.
@Override
public void addResources(Object kbuilder, Collection<ResourceWithConfiguration> resources, ResourceType type) throws Exception {
KnowledgeBuilderImpl kbuilderImpl = (KnowledgeBuilderImpl) kbuilder;
DMNCompilerImpl dmnCompiler = (DMNCompilerImpl) kbuilderImpl.getCachedOrCreate(DMN_COMPILER_CACHE_KEY, () -> getCompiler(kbuilderImpl));
DMNMarshaller dmnMarshaller = dmnCompiler.getMarshaller();
if (resources.size() == 1) {
// quick path:
internalAddResource(kbuilderImpl, dmnCompiler, resources.iterator().next(), Collections.emptyList());
return;
}
List<DMNResource> dmnResources = new ArrayList<>();
for (ResourceWithConfiguration r : resources) {
Definitions definitions = dmnMarshaller.unmarshal(r.getResource().getReader());
QName modelID = new QName(definitions.getNamespace(), definitions.getName());
DMNResource dmnResource = new DMNResource(modelID, r, definitions);
dmnResources.add(dmnResource);
}
// enrich with imports
for (DMNResource r : dmnResources) {
for (Import i : r.getDefinitions().getImport()) {
if (ImportDMNResolverUtil.whichImportType(i) == ImportType.DMN) {
Either<String, DMNResource> resolvedResult = ImportDMNResolverUtil.resolveImportDMN(i, dmnResources, DMNResource::getModelID);
DMNResource located = resolvedResult.getOrElseThrow(RuntimeException::new);
r.addDependency(located.getModelID());
}
}
}
List<DMNResource> sortedDmnResources = DMNResourceDependenciesSorter.sort(dmnResources);
Collection<DMNModel> dmnModels = new ArrayList<>();
for (DMNResource dmnRes : sortedDmnResources) {
DMNModel dmnModel = internalAddResource(kbuilderImpl, dmnCompiler, dmnRes.getResAndConfig(), dmnModels);
dmnModels.add(dmnModel);
}
}
use of org.kie.dmn.model.v1_1.List in project drools by kiegroup.
the class DMNCompilerImpl method processItemDefinitions.
private void processItemDefinitions(DMNCompilerContext ctx, DMNFEELHelper feel, DMNModelImpl model, Definitions dmndefs) {
Definitions.normalize(dmndefs);
List<ItemDefinition> ordered = new ItemDefinitionDependenciesSorter(model.getNamespace()).sort(dmndefs.getItemDefinition());
for (ItemDefinition id : ordered) {
ItemDefNodeImpl idn = new ItemDefNodeImpl(id);
DMNType type = buildTypeDef(ctx, feel, model, idn, id, true);
idn.setType(type);
model.addItemDefinition(idn);
}
}
use of org.kie.dmn.model.v1_1.List in project drools by kiegroup.
the class DMNEvaluatorCompiler method compileContext.
private DMNExpressionEvaluator compileContext(DMNCompilerContext ctx, DMNModelImpl model, DMNBaseNode node, String contextName, Context expression) {
Context ctxDef = expression;
DMNContextEvaluator ctxEval = new DMNContextEvaluator(node.getName(), ctxDef);
ctx.enterFrame();
try {
for (ContextEntry ce : ctxDef.getContextEntry()) {
if (ce.getVariable() != null) {
String entryName = ce.getVariable().getName();
DMNCompilerHelper.checkVariableName(model, node.getSource(), entryName);
DMNType entryType = compiler.resolveTypeRef(model, node, ce.getVariable(), ce.getVariable(), ce.getVariable().getTypeRef());
// add context entry to the list of available variables for the following entries
ctx.setVariable(entryName, entryType);
DMNExpressionEvaluator evaluator = compileExpression(ctx, model, node, entryName, ce.getExpression());
ctxEval.addEntry(entryName, entryType, evaluator, ce);
} else {
// if the variable is not defined, then it should be the last
// entry in the context and the result of this context evaluation is the
// result of this expression itself
// TODO: if it is not the last entry, raise error message
DMNType type = null;
if (ctxDef.getParent() instanceof ContextEntry && ((ContextEntry) ctxDef.getParent()).getVariable() != null) {
ContextEntry parentEntry = (ContextEntry) ctxDef.getParent();
type = compiler.resolveTypeRef(model, node, parentEntry.getVariable(), parentEntry.getVariable(), parentEntry.getVariable().getTypeRef());
} else if (node instanceof BusinessKnowledgeModelNode) {
type = ((BusinessKnowledgeModelNode) node).getResultType();
} else if (node instanceof DecisionNode) {
type = ((DecisionNode) node).getResultType();
}
ctxEval.addEntry(DMNContextEvaluator.RESULT_ENTRY, type, compileExpression(ctx, model, node, contextName, ce.getExpression()), ce);
}
}
} finally {
ctx.exitFrame();
}
return ctxEval;
}
use of org.kie.dmn.model.v1_1.List 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.v1_1.List row : relationDef.getRow()) {
java.util.List<DMNExpressionEvaluator> values = new ArrayList<>();
for (Expression expr : row.getExpression()) {
values.add(compileExpression(ctx, model, node, relationName, expr));
}
relationEval.addRow(values);
}
return relationEval;
}
Aggregations