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