Search in sources :

Example 11 with DMNType

use of org.kie.dmn.api.core.DMNType in project drools by kiegroup.

the class InputDataCompiler method compileNode.

@Override
public void compileNode(DRGElement de, DMNCompilerImpl compiler, DMNModelImpl model) {
    InputData input = (InputData) de;
    InputDataNodeImpl idn = new InputDataNodeImpl(input);
    if (input.getVariable() != null) {
        DMNCompilerHelper.checkVariableName(model, input, input.getName());
        DMNType type = compiler.resolveTypeRef(model, idn, de, input.getVariable(), input.getVariable().getTypeRef());
        idn.setType(type);
    } else {
        idn.setType(DMNTypeRegistry.UNKNOWN);
        DMNCompilerHelper.reportMissingVariable(model, de, input, Msg.MISSING_VARIABLE_FOR_INPUT);
    }
    model.addInput(idn);
}
Also used : InputData(org.kie.dmn.model.v1_1.InputData) InputDataNodeImpl(org.kie.dmn.core.ast.InputDataNodeImpl) DMNType(org.kie.dmn.api.core.DMNType)

Example 12 with DMNType

use of org.kie.dmn.api.core.DMNType in project drools by kiegroup.

the class DMNCompilerTest method testItemDefAllowedValuesString.

@Test
public void testItemDefAllowedValuesString() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0003-input-data-string-allowed-values.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0003-input-data-string-allowed-values");
    assertThat(dmnModel, notNullValue());
    ItemDefNode itemDef = dmnModel.getItemDefinitionByName("tEmploymentStatus");
    assertThat(itemDef.getName(), is("tEmploymentStatus"));
    assertThat(itemDef.getId(), is(nullValue()));
    DMNType type = itemDef.getType();
    assertThat(type, is(notNullValue()));
    assertThat(type.getName(), is("tEmploymentStatus"));
    assertThat(type.getId(), is(nullValue()));
    assertThat(type, is(instanceOf(SimpleTypeImpl.class)));
    SimpleTypeImpl feelType = (SimpleTypeImpl) type;
    EvaluationContext ctx = new EvaluationContextImpl(null);
    assertThat(feelType.getFeelType(), is(BuiltInType.STRING));
    assertThat(feelType.getAllowedValuesFEEL().size(), is(4));
    assertThat(feelType.getAllowedValuesFEEL().get(0).apply(ctx, "UNEMPLOYED"), is(true));
    assertThat(feelType.getAllowedValuesFEEL().get(1).apply(ctx, "EMPLOYED"), is(true));
    assertThat(feelType.getAllowedValuesFEEL().get(2).apply(ctx, "SELF-EMPLOYED"), is(true));
    assertThat(feelType.getAllowedValuesFEEL().get(3).apply(ctx, "STUDENT"), is(true));
}
Also used : EvaluationContextImpl(org.kie.dmn.feel.lang.impl.EvaluationContextImpl) SimpleTypeImpl(org.kie.dmn.core.impl.SimpleTypeImpl) ItemDefNode(org.kie.dmn.api.core.ast.ItemDefNode) EvaluationContext(org.kie.dmn.feel.lang.EvaluationContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) DMNType(org.kie.dmn.api.core.DMNType) Test(org.junit.Test)

Example 13 with DMNType

use of org.kie.dmn.api.core.DMNType in project drools by kiegroup.

the class DMNCompilerTest method testCompositeItemDefinition.

@Test
public void testCompositeItemDefinition() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0008-LX-arithmetic.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0008-LX-arithmetic");
    assertThat(dmnModel, notNullValue());
    ItemDefNode itemDef = dmnModel.getItemDefinitionByName("tLoan");
    assertThat(itemDef.getName(), is("tLoan"));
    assertThat(itemDef.getId(), is("tLoan"));
    DMNType type = itemDef.getType();
    assertThat(type, is(notNullValue()));
    assertThat(type.getName(), is("tLoan"));
    assertThat(type.getId(), is("tLoan"));
    assertThat(type, is(instanceOf(CompositeTypeImpl.class)));
    CompositeTypeImpl compType = (CompositeTypeImpl) type;
    assertThat(compType.getFields().size(), is(3));
    DMNType principal = compType.getFields().get("principal");
    assertThat(principal, is(notNullValue()));
    assertThat(principal.getName(), is("number"));
    assertThat(((SimpleTypeImpl) principal).getFeelType(), is(BuiltInType.NUMBER));
    DMNType rate = compType.getFields().get("rate");
    assertThat(rate, is(notNullValue()));
    assertThat(rate.getName(), is("number"));
    assertThat(((SimpleTypeImpl) rate).getFeelType(), is(BuiltInType.NUMBER));
    DMNType termMonths = compType.getFields().get("termMonths");
    assertThat(termMonths, is(notNullValue()));
    assertThat(termMonths.getName(), is("number"));
    assertThat(((SimpleTypeImpl) termMonths).getFeelType(), is(BuiltInType.NUMBER));
}
Also used : ItemDefNode(org.kie.dmn.api.core.ast.ItemDefNode) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) CompositeTypeImpl(org.kie.dmn.core.impl.CompositeTypeImpl) DMNType(org.kie.dmn.api.core.DMNType) Test(org.junit.Test)

Example 14 with DMNType

use of org.kie.dmn.api.core.DMNType in project drools by kiegroup.

the class DMNTypeTest method testAllowedValuesForASimpleTypeCollection.

@Test
public void testAllowedValuesForASimpleTypeCollection() {
    // DROOLS-2357
    final String testNS = "testDROOLS2357";
    FEEL feel = FEEL.newInstance();
    DMNType tDecision1 = typeRegistry.registerType(new SimpleTypeImpl(testNS, "tListOfVowels", null, true, feel.evaluateUnaryTests("\"a\",\"e\",\"i\",\"o\",\"u\""), FEEL_STRING, BuiltInType.STRING));
    assertTrue(tDecision1.isAssignableValue("a"));
    assertTrue(tDecision1.isAssignableValue(Arrays.asList("a")));
    assertFalse(tDecision1.isAssignableValue("z"));
    assertTrue(tDecision1.isAssignableValue(Arrays.asList("a", "e")));
    assertFalse(tDecision1.isAssignableValue(Arrays.asList("a", "e", "zzz")));
}
Also used : SimpleTypeImpl(org.kie.dmn.core.impl.SimpleTypeImpl) FEEL(org.kie.dmn.feel.FEEL) DMNType(org.kie.dmn.api.core.DMNType) Test(org.junit.Test)

Aggregations

DMNType (org.kie.dmn.api.core.DMNType)14 CompositeTypeImpl (org.kie.dmn.core.impl.CompositeTypeImpl)5 Test (org.junit.Test)4 Decision (org.kie.dmn.model.v1_1.Decision)4 Map (java.util.Map)3 BusinessKnowledgeModelNode (org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode)3 DecisionNode (org.kie.dmn.api.core.ast.DecisionNode)3 DMNExpressionEvaluator (org.kie.dmn.core.api.DMNExpressionEvaluator)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Optional (java.util.Optional)2 QName (javax.xml.namespace.QName)2 DMNModel (org.kie.dmn.api.core.DMNModel)2 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)2 ItemDefNode (org.kie.dmn.api.core.ast.ItemDefNode)2 DMNContextEvaluator (org.kie.dmn.core.ast.DMNContextEvaluator)2 DecisionNodeImpl (org.kie.dmn.core.ast.DecisionNodeImpl)2 BaseDMNTypeImpl (org.kie.dmn.core.impl.BaseDMNTypeImpl)2 DMNModelImpl (org.kie.dmn.core.impl.DMNModelImpl)2 SimpleTypeImpl (org.kie.dmn.core.impl.SimpleTypeImpl)2