Search in sources :

Example 11 with DecisionTable

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;
}
Also used : DecisionTable(org.kie.dmn.model.api.DecisionTable) DMNMessage(org.kie.dmn.api.core.DMNMessage) Definitions(org.kie.dmn.model.api.Definitions) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis)

Example 12 with DecisionTable

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;
}
Also used : DecisionTable(org.kie.dmn.model.api.DecisionTable) DMNMessage(org.kie.dmn.api.core.DMNMessage) Definitions(org.kie.dmn.model.api.Definitions) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis)

Example 13 with DecisionTable

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);
    }
}
Also used : TInformationRequirement(org.kie.dmn.model.v1_2.TInformationRequirement) QName(javax.xml.namespace.QName) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) InformationItem(org.kie.dmn.model.api.InformationItem) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) Decision(org.kie.dmn.model.api.Decision) TDecision(org.kie.dmn.model.v1_2.TDecision) OutputClause(org.kie.dmn.model.api.OutputClause) TOutputClause(org.kie.dmn.model.v1_2.TOutputClause) DecisionTable(org.kie.dmn.model.api.DecisionTable) TDecisionTable(org.kie.dmn.model.v1_2.TDecisionTable) DMNElementReference(org.kie.dmn.model.api.DMNElementReference) TDMNElementReference(org.kie.dmn.model.v1_2.TDMNElementReference) TInputClause(org.kie.dmn.model.v1_2.TInputClause) TInformationRequirement(org.kie.dmn.model.v1_2.TInformationRequirement) InformationRequirement(org.kie.dmn.model.api.InformationRequirement) TDecision(org.kie.dmn.model.v1_2.TDecision) TDecisionTable(org.kie.dmn.model.v1_2.TDecisionTable) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) TDMNElementReference(org.kie.dmn.model.v1_2.TDMNElementReference) TOutputClause(org.kie.dmn.model.v1_2.TOutputClause) TInputClause(org.kie.dmn.model.v1_2.TInputClause) InputClause(org.kie.dmn.model.api.InputClause)

Example 14 with DecisionTable

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));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNMarshaller(org.kie.dmn.api.marshalling.DMNMarshaller) InputStreamReader(java.io.InputStreamReader) KieFileSystem(org.kie.api.builder.KieFileSystem) Definitions(org.kie.dmn.model.api.Definitions) DMNContext(org.kie.dmn.api.core.DMNContext) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) BigDecimal(java.math.BigDecimal) DecisionTable(org.kie.dmn.model.api.DecisionTable) KieBuilder(org.kie.api.builder.KieBuilder) DMNModel(org.kie.dmn.api.core.DMNModel) DRGElement(org.kie.dmn.model.api.DRGElement) KieContainer(org.kie.api.runtime.KieContainer)

Example 15 with DecisionTable

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());
}
Also used : DecisionTable(org.kie.dmn.model.api.DecisionTable) TDecisionTable(org.kie.dmn.model.v1_2.TDecisionTable)

Aggregations

DecisionTable (org.kie.dmn.model.api.DecisionTable)24 OutputClause (org.kie.dmn.model.api.OutputClause)7 Definitions (org.kie.dmn.model.api.Definitions)6 InputClause (org.kie.dmn.model.api.InputClause)6 DecisionRule (org.kie.dmn.model.api.DecisionRule)5 TDecisionTable (org.kie.dmn.model.v1_2.TDecisionTable)5 DTAnalysis (org.kie.dmn.validation.dtanalysis.model.DTAnalysis)5 DMNMessage (org.kie.dmn.api.core.DMNMessage)4 Decision (org.kie.dmn.model.api.Decision)4 TDecisionTable (org.kie.dmn.model.v1_3.TDecisionTable)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 QName (javax.xml.namespace.QName)3 Test (org.junit.Test)3 BigDecimal (java.math.BigDecimal)2 Collectors (java.util.stream.Collectors)2 DMNContext (org.kie.dmn.api.core.DMNContext)2 DMNModel (org.kie.dmn.api.core.DMNModel)2 DMNResult (org.kie.dmn.api.core.DMNResult)2 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)2