Search in sources :

Example 11 with InputClause

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

Example 12 with InputClause

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);
            }
        }
    }
}
Also used : QName(javax.xml.namespace.QName) DDTAInputClause(org.kie.dmn.validation.dtanalysis.model.DDTAInputClause) InputClause(org.kie.dmn.model.api.InputClause) Interval(org.kie.dmn.validation.dtanalysis.model.Interval)

Example 13 with InputClause

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);
}
Also used : InputClause(org.kie.dmn.model.api.InputClause) TInputClause(org.kie.dmn.model.v1_4.TInputClause)

Example 14 with InputClause

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"));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CreationHelper(org.apache.poi.ss.usermodel.CreationHelper) PosNegBlock(org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.PosNegBlock) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Font(org.apache.poi.ss.usermodel.Font) OutputClause(org.kie.dmn.model.api.OutputClause) FileOutputStream(java.io.FileOutputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Record(org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.Record) CellStyle(org.apache.poi.ss.usermodel.CellStyle) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) File(java.io.File) InputClause(org.kie.dmn.model.api.InputClause)

Example 15 with InputClause

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);
}
Also used : InputClause(org.kie.dmn.model.api.InputClause) TInputClause(org.kie.dmn.model.v1_3.TInputClause)

Aggregations

InputClause (org.kie.dmn.model.api.InputClause)17 DecisionTable (org.kie.dmn.model.api.DecisionTable)8 OutputClause (org.kie.dmn.model.api.OutputClause)7 DecisionRule (org.kie.dmn.model.api.DecisionRule)6 QName (javax.xml.namespace.QName)4 LiteralExpression (org.kie.dmn.model.api.LiteralExpression)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 DMNType (org.kie.dmn.api.core.DMNType)3 HitPolicy (org.kie.dmn.model.api.HitPolicy)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 DMNMessage (org.kie.dmn.api.core.DMNMessage)2 Msg (org.kie.dmn.core.util.Msg)2 MsgUtil (org.kie.dmn.core.util.MsgUtil)2 Decision (org.kie.dmn.model.api.Decision)2 InformationItem (org.kie.dmn.model.api.InformationItem)2 RuleAnnotationClause (org.kie.dmn.model.api.RuleAnnotationClause)2 TDecisionTable (org.kie.dmn.model.v1_2.TDecisionTable)2 Logger (org.slf4j.Logger)2