Search in sources :

Example 11 with DecisionRule

use of org.kie.dmn.model.api.DecisionRule in project drools by kiegroup.

the class DecisionTableConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    DecisionTable dt = (DecisionTable) parent;
    for (InputClause i : dt.getInput()) {
        writeChildrenNode(writer, context, i, INPUT);
    }
    for (OutputClause o : dt.getOutput()) {
        writeChildrenNode(writer, context, o, OUTPUT);
    }
    for (RuleAnnotationClause a : dt.getAnnotation()) {
        writeChildrenNode(writer, context, a, ANNOTATION);
    }
    for (DecisionRule r : dt.getRule()) {
        writeChildrenNode(writer, context, r, RULE);
    }
}
Also used : OutputClause(org.kie.dmn.model.api.OutputClause) DecisionTable(org.kie.dmn.model.api.DecisionTable) TDecisionTable(org.kie.dmn.model.v1_4.TDecisionTable) RuleAnnotationClause(org.kie.dmn.model.api.RuleAnnotationClause) InputClause(org.kie.dmn.model.api.InputClause) DecisionRule(org.kie.dmn.model.api.DecisionRule)

Example 12 with DecisionRule

use of org.kie.dmn.model.api.DecisionRule in project drools by kiegroup.

the class TableCellParser method parseCells.

public TableCells parseCells(DecisionTable decisionTable, DTQNameToTypeResolver resolver, String decisionTableName) {
    List<DecisionRule> rows = decisionTable.getRule();
    List<InputClause> columns = decisionTable.getInput();
    TableCells tableCells = new TableCells(rows.size(), columns.size());
    parseColumnDefinition(decisionTableName, columns, tableCells);
    for (int rowIndex = 0; rowIndex < rows.size(); rowIndex++) {
        DecisionRule row = rows.get(rowIndex);
        for (int inputColumnIndex = 0; inputColumnIndex < row.getInputEntry().size(); inputColumnIndex++) {
            String input = row.getInputEntry().get(inputColumnIndex).getText();
            TableIndex tableIndex = new TableIndex(rowIndex, inputColumnIndex);
            InputClause column = tableIndex.getColumn(columns);
            final String columnName = column.getInputExpression().getText();
            final Type columnType = resolver.resolve(column.getInputExpression().getTypeRef());
            TableCell cell = tableCellFactory.createInputCell(tableIndex, input, columnName, columnType);
            tableCells.add(cell);
            if (inputColumnIndex == row.getInputEntry().size() - 1) {
                // last column
                tableCells.initialiseOutputColumnsCollection(row.getOutputEntry().size());
                List<LiteralExpression> outputEntry = row.getOutputEntry();
                for (int outputColumnIndex = 0; outputColumnIndex < outputEntry.size(); outputColumnIndex++) {
                    TableIndex outputColumnTableIndex = tableIndex.outputTableIndex(outputColumnIndex);
                    LiteralExpression outputExpression = outputEntry.get(outputColumnIndex);
                    String outputRawText = outputExpression.getText();
                    String outputColumnName = Optional.ofNullable(decisionTable.getOutput().get(outputColumnIndex).getName()).orElse("");
                    TableCell outputCell = tableCellFactory.createOutputCell(outputColumnTableIndex, outputRawText, outputColumnName, columnType);
                    tableCells.addOutputCell(outputCell);
                }
            }
        }
    }
    return tableCells;
}
Also used : DMNType(org.kie.dmn.api.core.DMNType) Type(org.kie.dmn.feel.lang.Type) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) DecisionRule(org.kie.dmn.model.api.DecisionRule) InputClause(org.kie.dmn.model.api.InputClause)

Aggregations

DecisionRule (org.kie.dmn.model.api.DecisionRule)12 LiteralExpression (org.kie.dmn.model.api.LiteralExpression)7 InputClause (org.kie.dmn.model.api.InputClause)6 UnaryTests (org.kie.dmn.model.api.UnaryTests)6 DecisionTable (org.kie.dmn.model.api.DecisionTable)5 OutputClause (org.kie.dmn.model.api.OutputClause)5 RuleAnnotation (org.kie.dmn.model.api.RuleAnnotation)3 ArrayList (java.util.ArrayList)2 DMNType (org.kie.dmn.api.core.DMNType)2 RuleAnnotationClause (org.kie.dmn.model.api.RuleAnnotationClause)2 TDecisionRule (org.kie.dmn.model.v1_2.TDecisionRule)2 Collections (java.util.Collections)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 QName (javax.xml.namespace.QName)1