Search in sources :

Example 16 with OutputClause

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

the class OutputClauseConverter method writeAttributes.

@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
    super.writeAttributes(writer, parent);
    OutputClause oc = (OutputClause) parent;
    if (oc.getName() != null)
        writer.addAttribute(NAME, oc.getName());
    if (oc.getTypeRef() != null) {
        writer.addAttribute(TYPE_REF, MarshallingUtils.formatQName(oc.getTypeRef(), oc));
    }
}
Also used : TOutputClause(org.kie.dmn.model.v1_2.TOutputClause) OutputClause(org.kie.dmn.model.api.OutputClause)

Example 17 with OutputClause

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

the class DMNCompilerImpl method resolveTypeRef.

/**
 * Resolve the QName typeRef accordingly to definition of builtin (FEEL) types, local model ItemDef or imported definitions.
 * If the typeRef cannot be resolved, (FEEL) UNKNOWN is returned and an error logged using standard DMN message logging.
 */
public DMNType resolveTypeRef(DMNModelImpl dmnModel, NamedElement model, DMNModelInstrumentedBase localElement, QName typeRef) {
    if (typeRef != null) {
        QName nsAndName = getNamespaceAndName(localElement, dmnModel.getImportAliasesForNS(), typeRef, dmnModel.getNamespace());
        DMNType type = dmnModel.getTypeRegistry().resolveType(nsAndName.getNamespaceURI(), nsAndName.getLocalPart());
        if (type == null && localElement.getURIFEEL().equals(nsAndName.getNamespaceURI())) {
            if (model instanceof Decision && ((Decision) model).getExpression() instanceof DecisionTable) {
                DecisionTable dt = (DecisionTable) ((Decision) model).getExpression();
                if (dt.getOutput().size() > 1) {
                    // implicitly define a type for the decision table result
                    CompositeTypeImpl compType = new CompositeTypeImpl(dmnModel.getNamespace(), model.getName() + "_Type", model.getId(), dt.getHitPolicy().isMultiHit());
                    for (OutputClause oc : dt.getOutput()) {
                        DMNType fieldType = resolveTypeRef(dmnModel, model, oc, oc.getTypeRef());
                        compType.addField(oc.getName(), fieldType);
                    }
                    dmnModel.getTypeRegistry().registerType(compType);
                    return compType;
                } else if (dt.getOutput().size() == 1) {
                    return resolveTypeRef(dmnModel, model, dt.getOutput().get(0), dt.getOutput().get(0).getTypeRef());
                }
            }
        } else if (type == null) {
            MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, localElement, dmnModel, null, null, Msg.UNKNOWN_TYPE_REF_ON_NODE, typeRef.toString(), localElement.getParentDRDElement().getIdentifierString());
            type = dmnModel.getTypeRegistry().unknown();
        }
        return type;
    }
    return dmnModel.getTypeRegistry().unknown();
}
Also used : OutputClause(org.kie.dmn.model.api.OutputClause) DecisionTable(org.kie.dmn.model.api.DecisionTable) QName(javax.xml.namespace.QName) Decision(org.kie.dmn.model.api.Decision) CompositeTypeImpl(org.kie.dmn.core.impl.CompositeTypeImpl) DMNType(org.kie.dmn.api.core.DMNType)

Example 18 with OutputClause

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

the class OutputClauseConverter method writeAttributes.

@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
    super.writeAttributes(writer, parent);
    OutputClause oc = (OutputClause) parent;
    if (oc.getName() != null)
        writer.addAttribute(NAME, oc.getName());
    if (oc.getTypeRef() != null) {
        writer.addAttribute(TYPE_REF, MarshallingUtils.formatQName(oc.getTypeRef(), oc));
    }
}
Also used : TOutputClause(org.kie.dmn.model.v1_4.TOutputClause) OutputClause(org.kie.dmn.model.api.OutputClause)

Example 19 with OutputClause

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

the class OutputClauseConverter method assignAttributes.

@Override
protected void assignAttributes(HierarchicalStreamReader reader, Object parent) {
    super.assignAttributes(reader, parent);
    OutputClause oc = (OutputClause) parent;
    String name = reader.getAttribute(NAME);
    String typeRefValue = reader.getAttribute(TYPE_REF);
    oc.setName(name);
    if (typeRefValue != null)
        oc.setTypeRef(MarshallingUtils.parseQNameString(typeRefValue));
}
Also used : TOutputClause(org.kie.dmn.model.v1_4.TOutputClause) OutputClause(org.kie.dmn.model.api.OutputClause)

Example 20 with OutputClause

use of org.kie.dmn.model.api.OutputClause 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)

Aggregations

OutputClause (org.kie.dmn.model.api.OutputClause)22 DecisionTable (org.kie.dmn.model.api.DecisionTable)7 InputClause (org.kie.dmn.model.api.InputClause)7 DecisionRule (org.kie.dmn.model.api.DecisionRule)5 QName (javax.xml.namespace.QName)4 TOutputClause (org.kie.dmn.model.v1_2.TOutputClause)4 ArrayList (java.util.ArrayList)3 Decision (org.kie.dmn.model.api.Decision)3 TOutputClause (org.kie.dmn.model.v1_1.TOutputClause)3 TOutputClause (org.kie.dmn.model.v1_3.TOutputClause)3 DMNType (org.kie.dmn.api.core.DMNType)2 BaseDMNTypeImpl (org.kie.dmn.core.impl.BaseDMNTypeImpl)2 InformationItem (org.kie.dmn.model.api.InformationItem)2 LiteralExpression (org.kie.dmn.model.api.LiteralExpression)2 RuleAnnotationClause (org.kie.dmn.model.api.RuleAnnotationClause)2 TDecisionTable (org.kie.dmn.model.v1_2.TDecisionTable)2 TOutputClause (org.kie.dmn.model.v1_4.TOutputClause)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1