Search in sources :

Example 51 with List

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);
    }
}
Also used : Relation(org.kie.dmn.model.v1_1.Relation) InformationItem(org.kie.dmn.model.v1_1.InformationItem)

Example 52 with List

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);
    }
}
Also used : DMNCompilerImpl(org.kie.dmn.core.compiler.DMNCompilerImpl) Import(org.kie.dmn.model.v1_1.Import) DMNMarshaller(org.kie.dmn.api.marshalling.v1_1.DMNMarshaller) QName(javax.xml.namespace.QName) Definitions(org.kie.dmn.model.v1_1.Definitions) ArrayList(java.util.ArrayList) ResourceWithConfiguration(org.kie.api.io.ResourceWithConfiguration) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) DMNModel(org.kie.dmn.api.core.DMNModel)

Example 53 with List

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);
    }
}
Also used : ItemDefinition(org.kie.dmn.model.v1_1.ItemDefinition) ItemDefNodeImpl(org.kie.dmn.core.ast.ItemDefNodeImpl) DMNType(org.kie.dmn.api.core.DMNType)

Example 54 with List

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;
}
Also used : Context(org.kie.dmn.model.v1_1.Context) DMNContextEvaluator(org.kie.dmn.core.ast.DMNContextEvaluator) DMNExpressionEvaluator(org.kie.dmn.core.api.DMNExpressionEvaluator) BusinessKnowledgeModelNode(org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) ContextEntry(org.kie.dmn.model.v1_1.ContextEntry) DMNType(org.kie.dmn.api.core.DMNType)

Example 55 with List

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;
}
Also used : Relation(org.kie.dmn.model.v1_1.Relation) DMNExpressionEvaluator(org.kie.dmn.core.api.DMNExpressionEvaluator) LiteralExpression(org.kie.dmn.model.v1_1.LiteralExpression) CompiledExpression(org.kie.dmn.feel.lang.CompiledExpression) Expression(org.kie.dmn.model.v1_1.Expression) DMNRelationEvaluator(org.kie.dmn.core.ast.DMNRelationEvaluator) ArrayList(java.util.ArrayList) InformationItem(org.kie.dmn.model.v1_1.InformationItem)

Aggregations

Test (org.junit.Test)54 List (org.kie.workbench.common.dmn.api.definition.v1_1.List)26 ItemDefinition (org.kie.dmn.model.v1_1.ItemDefinition)21 QName (javax.xml.namespace.QName)17 ArrayList (java.util.ArrayList)15 List (java.util.List)14 DMNMessage (org.kie.dmn.api.core.DMNMessage)14 Import (org.kie.dmn.model.v1_1.Import)13 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)13 CoreMatchers.is (org.hamcrest.CoreMatchers.is)11 DMNMessageType (org.kie.dmn.api.core.DMNMessageType)11 DMNGridRow (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow)11 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)10 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)10 Definitions (org.kie.dmn.model.v1_1.Definitions)9 IOException (java.io.IOException)8 Collectors (java.util.stream.Collectors)8 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)8 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)8 Reader (java.io.Reader)7