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);
}
}
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;
}
Aggregations