use of org.kie.dmn.model.api.DecisionTable 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.DecisionTable in project drools by kiegroup.
the class DMNDTAnalyser method analyse.
@Override
public List<DTAnalysis> analyse(DMNModel model, Set<DMNValidator.Validation> flags) {
if (!flags.contains(Validation.ANALYZE_DECISION_TABLE)) {
throw new IllegalArgumentException();
}
List<DTAnalysis> results = new ArrayList<>();
List<? extends DecisionTable> decisionTables = model.getDefinitions().findAllChildren(DecisionTable.class);
for (DecisionTable dt : decisionTables) {
try {
DTAnalysis result = dmnDTAnalysis(model, dt, flags);
results.add(result);
} catch (Throwable t) {
LOG.debug("Skipped dmnDTAnalysis for table: {}", dt.getId(), t);
DTAnalysis result = DTAnalysis.ofError(dt, t);
results.add(result);
}
}
return results;
}
use of org.kie.dmn.model.api.DecisionTable in project drools by kiegroup.
the class DecisionTableConverter method writeAttributes.
@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
super.writeAttributes(writer, parent);
DecisionTable dt = (DecisionTable) parent;
if (dt.getHitPolicy() != null)
writer.addAttribute(HIT_POLICY, dt.getHitPolicy().value());
if (dt.getAggregation() != null)
writer.addAttribute(AGGREGATION, dt.getAggregation().value());
if (dt.getPreferredOrientation() != null)
writer.addAttribute(PREFERRED_ORIENTATION, dt.getPreferredOrientation().value());
if (dt.getOutputLabel() != null)
writer.addAttribute(OUTPUT_LABEL, dt.getOutputLabel());
}
use of org.kie.dmn.model.api.DecisionTable in project drools by kiegroup.
the class DMNDTAnalysisExceptionTest method smokeTest.
@Test
public void smokeTest() {
DecisionTable dtRef = new TDecisionTable();
DMNDTAnalysisException ut = new DMNDTAnalysisException("smoke test", dtRef);
Assertions.assertThat(ut.getDt()).isEqualTo(dtRef);
}
use of org.kie.dmn.model.api.DecisionTable in project drools by kiegroup.
the class OverlapHitPolicyTest method testOverlapHitPolicy.
@Test
public void testOverlapHitPolicy() {
Definitions definitions = getDefinitions("OverlapHitPolicy.dmn", "https://github.com/kiegroup/drools/kie-dmn/_3010653A-DD3F-4C88-89DA-3FDD845F6604", "OverlapHitPolicy");
// mutates XML file in the Hit Policy, accordingly to this test parameter.
((DecisionTable) ((Decision) definitions.getDrgElement().get(0)).getExpression()).setHitPolicy(hp);
List<DMNMessage> validate = validator.validate(definitions, VALIDATE_COMPILATION, ANALYZE_DECISION_TABLE);
checkAnalysis(validate);
if (hp == HitPolicy.UNIQUE) {
assertTrue("It should contain at least 1 DMNMessage for the type", validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_OVERLAP_HITPOLICY_UNIQUE)));
} else if (hp == HitPolicy.ANY) {
assertTrue("It should contain at least 1 DMNMessage for the type", validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_OVERLAP_HITPOLICY_ANY)));
} else {
LOG.debug("Testing for {} I am expecting there is NOT DMNMessage pertaining to Overlaps", hp);
assertTrue(validate.stream().noneMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_OVERLAP_HITPOLICY_UNIQUE)) && validate.stream().noneMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_OVERLAP_HITPOLICY_ANY)) && validate.stream().noneMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_OVERLAP)));
}
}
Aggregations