use of org.kie.dmn.model.api.InputClause 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;
}
use of org.kie.dmn.model.api.InputClause in project drools by kiegroup.
the class DMNDTAnalyser method compileTableComputeColStringMissingEnum.
private void compileTableComputeColStringMissingEnum(DMNModel model, DecisionTable dt, DDTATable ddtaTable) {
for (int iColIdx = 0; iColIdx < ddtaTable.inputCols(); iColIdx++) {
InputClause ie = dt.getInput().get(iColIdx);
QName typeRef = DMNCompilerImpl.getNamespaceAndName(dt, ((DMNModelImpl) model).getImportAliasesForNS(), ie.getInputExpression().getTypeRef(), model.getNamespace());
if (SimpleType.STRING.equals(typeRef.getLocalPart()) && !ddtaTable.getInputs().get(iColIdx).isDiscreteDomain()) {
Interval infStringDomain = ddtaTable.getInputs().get(iColIdx).getDomainMinMax();
boolean areAllSinglePointOrAll = true;
for (int jRowIdx = 0; jRowIdx < dt.getRule().size() && areAllSinglePointOrAll; jRowIdx++) {
List<Interval> r = ddtaTable.getRule().get(jRowIdx).getInputEntry().get(iColIdx).getIntervals();
for (Interval interval : r) {
areAllSinglePointOrAll = areAllSinglePointOrAll && (infStringDomain.equals(interval) || interval.isSingularity());
}
}
if (areAllSinglePointOrAll) {
ddtaTable.addColIdStringWithoutEnum(iColIdx + 1);
}
}
}
}
use of org.kie.dmn.model.api.InputClause in project drools by kiegroup.
the class InputClauseConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
InputClause ic = (InputClause) parent;
writeChildrenNode(writer, context, ic.getInputExpression(), INPUT_EXPRESSION);
if (ic.getInputValues() != null)
writeChildrenNode(writer, context, ic.getInputValues(), INPUT_VALUES);
}
use of org.kie.dmn.model.api.InputClause in project drools by kiegroup.
the class ExampleMCDCTest method debugOutputAndOpenXLSX.
public static void debugOutputAndOpenXLSX(DecisionTable dt, List<PosNegBlock> selectedBlocks) {
XSSFWorkbook wb = new XSSFWorkbook();
CreationHelper ch = wb.getCreationHelper();
CellStyle styleColumn = wb.createCellStyle();
styleColumn.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex());
styleColumn.setFillPattern(FillPatternType.SOLID_FOREGROUND);
Font font = wb.createFont();
font.setColor(IndexedColors.RED.getIndex());
CellStyle styleRepeated = wb.createCellStyle();
styleRepeated.setFont(font);
Sheet sheet = wb.createSheet("MC DC Analysis");
int r = 0, c = 0;
Row row = sheet.createRow(r++);
row.createCell(c++).setCellValue(ch.createRichTextString("Rule:"));
for (InputClause input : dt.getInput()) {
row.createCell(c++).setCellValue(input.getInputExpression().getText());
}
for (OutputClause output : dt.getOutput()) {
row.createCell(c++).setCellValue(dt.getOutputLabel());
}
row.createCell(c++).setCellValue(ch.createRichTextString("Rule:"));
for (InputClause input : dt.getInput()) {
row.createCell(c++).setCellValue(input.getInputExpression().getText());
}
for (OutputClause output : dt.getOutput()) {
row.createCell(c++).setCellValue(dt.getOutputLabel());
}
Set<Record> mcdcRecords = new LinkedHashSet<>();
for (PosNegBlock b : selectedBlocks) {
row = sheet.createRow(r++);
c = 0;
boolean add = mcdcRecords.add(b.posRecord);
Cell ruleIdxCell = row.createCell(c++);
ruleIdxCell.setCellValue(b.posRecord.ruleIdx + 1);
if (!add) {
ruleIdxCell.setCellStyle(styleRepeated);
}
for (int i = 0; i < b.posRecord.enums.length; i++) {
Object en = b.posRecord.enums[i];
Cell enCell = row.createCell(c++);
enCell.setCellValue(en.toString());
if (!add) {
enCell.setCellStyle(styleRepeated);
}
if (b.cMarker == i) {
enCell.setCellStyle(styleColumn);
}
}
for (Object out : b.posRecord.output) {
Cell outCell = row.createCell(c++);
outCell.setCellValue(out.toString());
if (!add) {
outCell.setCellStyle(styleRepeated);
}
}
for (int i = 0; i < b.negRecords.size(); i++) {
Record negRecord = b.negRecords.get(i);
if (i != 0) {
row = sheet.createRow(r++);
c = 0 + 1 + b.posRecord.enums.length + b.posRecord.output.size();
}
add = mcdcRecords.add(negRecord);
ruleIdxCell = row.createCell(c++);
ruleIdxCell.setCellValue(negRecord.ruleIdx + 1);
if (!add) {
ruleIdxCell.setCellStyle(styleRepeated);
}
for (Object en : negRecord.enums) {
Cell enCell = row.createCell(c++);
enCell.setCellValue(en.toString());
if (!add) {
enCell.setCellStyle(styleRepeated);
}
}
for (Object out : negRecord.output) {
Cell outCell = row.createCell(c++);
outCell.setCellValue(out.toString());
if (!add) {
outCell.setCellStyle(styleRepeated);
}
}
}
}
File file;
try {
file = Files.createTempFile("mcdc " + dt.getOutputLabel(), ".xlsx").toFile();
OutputStream fileOut = new FileOutputStream(file);
wb.write(fileOut);
wb.close();
} catch (IOException e) {
e.printStackTrace();
// terminate early;
return;
}
if (Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().open(file);
} catch (IOException e) {
e.printStackTrace();
}
} else {
throw new UnsupportedOperationException();
}
LOG.trace(System.getProperty("java.io.tmpdir"));
}
use of org.kie.dmn.model.api.InputClause in project drools by kiegroup.
the class InputClauseConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
InputClause ic = (InputClause) parent;
writeChildrenNode(writer, context, ic.getInputExpression(), INPUT_EXPRESSION);
if (ic.getInputValues() != null)
writeChildrenNode(writer, context, ic.getInputValues(), INPUT_VALUES);
}
Aggregations