use of org.kie.dmn.model.api.DecisionTable in project drools by kiegroup.
the class RecommenderHitPolicyTest method getRecommenderHitPolicy4.
private List<DMNMessage> getRecommenderHitPolicy4(HitPolicy hp) {
Definitions definitions = getDefinitions("RecommenderHitPolicy4.dmn", "http://www.trisotech.com/definitions/_50aea0bb-4482-48f6-acfe-4abc1a1bd0d6", "Drawing 1");
// mutates XML file in the Hit Policy, accordingly to this test parameter.
((DecisionTable) ((Decision) definitions.getDrgElement().get(1)).getExpression()).setHitPolicy(hp);
List<DMNMessage> validate = validator.validate(definitions, VALIDATE_COMPILATION, ANALYZE_DECISION_TABLE);
DTAnalysis analysis = getAnalysis(validate, "_3aa68aee-6314-482f-a0be-84c2411d65d7");
debugValidatorMsg(validate);
assertThat(analysis.getGaps(), hasSize(0));
assertThat(analysis.getOverlaps(), hasSize(1));
return validate;
}
use of org.kie.dmn.model.api.DecisionTable in project drools by kiegroup.
the class RecommenderHitPolicyTest method getRecommenderHitPolicy3.
private List<DMNMessage> getRecommenderHitPolicy3(HitPolicy hp) {
Definitions definitions = getDefinitions("RecommenderHitPolicy3.dmn", "http://www.trisotech.com/definitions/_50aea0bb-4482-48f6-acfe-4abc1a1bd0d6", "Drawing 1");
// mutates XML file in the Hit Policy, accordingly to this test parameter.
((DecisionTable) ((Decision) definitions.getDrgElement().get(1)).getExpression()).setHitPolicy(hp);
List<DMNMessage> validate = validator.validate(definitions, VALIDATE_COMPILATION, ANALYZE_DECISION_TABLE);
DTAnalysis analysis = getAnalysis(validate, "_3aa68aee-6314-482f-a0be-84c2411d65d7");
debugValidatorMsg(validate);
assertThat(analysis.getGaps(), hasSize(0));
assertThat(analysis.getOverlaps(), hasSize(1));
return validate;
}
use of org.kie.dmn.model.api.DecisionTable in project drools by kiegroup.
the class XLS2DMNParser method appendDecisionDT.
private void appendDecisionDT(Definitions definitions, Map<String, DTHeaderInfo> headerInfos) {
for (DTHeaderInfo hi : headerInfos.values()) {
Decision decision = new TDecision();
decision.setName(hi.getSheetName());
decision.setId("d_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
InformationItem variable = new TInformationItem();
variable.setName(hi.getSheetName());
variable.setId("dvar_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
variable.setTypeRef(new QName("Any"));
decision.setVariable(variable);
for (String ri : hi.getRequiredInput()) {
InformationRequirement ir = new TInformationRequirement();
DMNElementReference er = new TDMNElementReference();
er.setHref("#id_" + CodegenStringUtil.escapeIdentifier(ri));
ir.setRequiredInput(er);
decision.getInformationRequirement().add(ir);
}
for (String ri : hi.getRequiredDecision()) {
InformationRequirement ir = new TInformationRequirement();
DMNElementReference er = new TDMNElementReference();
er.setHref("#d_" + CodegenStringUtil.escapeIdentifier(ri));
ir.setRequiredDecision(er);
decision.getInformationRequirement().add(ir);
}
DecisionTable dt = new TDecisionTable();
dt.setOutputLabel(hi.getSheetName());
dt.setId("ddt_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
dt.setHitPolicy(HitPolicy.ANY);
for (String ri : hi.getRequiredInput()) {
InputClause ic = new TInputClause();
ic.setLabel(ri);
LiteralExpression le = new TLiteralExpression();
le.setText(ri);
ic.setInputExpression(le);
dt.getInput().add(ic);
}
for (String rd : hi.getRequiredDecision()) {
InputClause ic = new TInputClause();
ic.setLabel(rd);
LiteralExpression le = new TLiteralExpression();
le.setText(rd);
ic.setInputExpression(le);
dt.getInput().add(ic);
}
OutputClause oc = new TOutputClause();
dt.getOutput().add(oc);
decision.setExpression(dt);
definitions.getDrgElement().add(decision);
}
}
use of org.kie.dmn.model.api.DecisionTable in project drools by kiegroup.
the class DMNDecisionTableRuntimeTest method checkDTCollectOperatorsMultipleOutputs.
private void checkDTCollectOperatorsMultipleOutputs(BuiltinAggregator aggregator, int level, int a, int b) {
// DROOLS-6590 DMN composite output on DT Collect with operators - this is beyond the spec.
final KieServices ks = KieServices.Factory.get();
DMNMarshaller marshaller = DMNMarshallerFactory.newDefaultMarshaller();
final Definitions definitions = marshaller.unmarshal(new InputStreamReader(this.getClass().getResourceAsStream("multipleOutputsCollectDT.dmn")));
DRGElement drgElement1 = definitions.getDrgElement().get(1);
assertThat(drgElement1).describedAs("xml of the test changed, unable to locate Decision Node").isInstanceOf(Decision.class);
((DecisionTable) ((Decision) drgElement1).getExpression()).setAggregation(aggregator);
final String dmnXml = marshaller.marshal(definitions);
final ReleaseId kjarReleaseId = ks.newReleaseId("org.kie.dmn.core", "DMNDecisionTableRuntimeTest", UUID.randomUUID().toString());
final KieFileSystem kfs = ks.newKieFileSystem();
kfs.write("src/main/resources/multipleOutputsCollectDT.dmn", dmnXml);
kfs.generateAndWritePomXML(kjarReleaseId);
final KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertTrue(kieBuilder.getResults().getMessages().toString(), kieBuilder.getResults().getMessages().isEmpty());
final KieContainer container = ks.newKieContainer(kjarReleaseId);
final DMNRuntime runtime = KieRuntimeFactory.of(container.getKieBase()).get(DMNRuntime.class);
final DMNModel dmnModel = runtime.getModel("https://kiegroup.org/dmn/_943A3581-5FD1-4BCF-9A52-AC7242CC451C", "multipleOutputsCollectDT");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
final DMNContext context = DMNFactory.newContext();
context.set("level", level);
final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
LOG.debug("{}", dmnResult);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
Object decision1 = dmnResult.getDecisionResultByName("Decision-1").getResult();
assertThat(decision1).hasFieldOrPropertyWithValue("a", new BigDecimal(a));
assertThat(decision1).hasFieldOrPropertyWithValue("b", new BigDecimal(b));
}
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());
}
Aggregations