use of org.kie.dmn.feel.FEEL in project drools by kiegroup.
the class DecisionTableFunction method toDecisionRule.
/**
* Convert row to DTDecisionRule
* @param mainCtx the main context is used to identify the hosted FEELEventManager
* @param embeddedFEEL a possibly cached embedded FEEL to compile the output expression, error will be reported up to the mainCtx
* @param index
* @param rule
* @param inputSize
* @return
*/
private static DTDecisionRule toDecisionRule(EvaluationContext mainCtx, FEEL embeddedFEEL, int index, List<?> rule, int inputSize) {
// TODO should be check indeed block of inputSize n inputs, followed by block of outputs.
DTDecisionRule dr = new DTDecisionRule(index);
for (int i = 0; i < rule.size(); i++) {
Object o = rule.get(i);
if (i < inputSize) {
dr.getInputEntry().add(toUnaryTest(mainCtx, o));
} else {
FEELEventListener ruleListener = event -> mainCtx.notifyEvt(() -> new FEELEventBase(event.getSeverity(), Msg.createMessage(Msg.ERROR_COMPILE_EXPR_DT_FUNCTION_RULE_IDX, index + 1, event.getMessage()), event.getSourceException()));
embeddedFEEL.addListener(ruleListener);
CompiledExpression compiledExpression = embeddedFEEL.compile((String) o, embeddedFEEL.newCompilerContext());
dr.getOutputEntry().add(compiledExpression);
embeddedFEEL.removeListener(ruleListener);
}
}
return dr;
}
use of org.kie.dmn.feel.FEEL 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")));
}
Aggregations