use of org.kie.dmn.feel.runtime.Range in project drools by kiegroup.
the class CompiledFEELSupport method invoke.
public static Object invoke(EvaluationContext feelExprCtx, Object function, Object params) {
if (function == null) {
feelExprCtx.notifyEvt(() -> new ASTEventBase(Severity.ERROR, Msg.createMessage(Msg.FUNCTION_NOT_FOUND, function), null));
return null;
}
if (function instanceof FEELFunction) {
Object[] invocationParams = toFunctionParams(params);
FEELFunction f = (FEELFunction) function;
if (function instanceof CompiledCustomFEELFunction) {
CompiledCustomFEELFunction ff = (CompiledCustomFEELFunction) function;
if (ff.isProperClosure()) {
return ff.invokeReflectively(ff.getEvaluationContext(), invocationParams);
}
}
return f.invokeReflectively(feelExprCtx, invocationParams);
} else if (function instanceof UnaryTest) {
return ((UnaryTest) function).apply(feelExprCtx, ((List) params).get(0));
} else if (function instanceof Range) {
// alignment to FunctionInvocationNode
List<?> ps = (List<?>) params;
if (ps.size() == 1) {
return ((Range) function).includes(ps.get(0));
} else {
feelExprCtx.notifyEvt(() -> new ASTEventBase(Severity.ERROR, Msg.createMessage(Msg.CAN_T_INVOKE_AN_UNARY_TEST_WITH_S_PARAMETERS_UNARY_TESTS_REQUIRE_1_SINGLE_PARAMETER, ps.size()), null));
}
}
feelExprCtx.notifyEvt(() -> new ASTEventBase(Severity.ERROR, Msg.createMessage(Msg.CANNOT_INVOKE, MsgUtil.clipToString(function, 50)), null));
return null;
}
use of org.kie.dmn.feel.runtime.Range in project drools by kiegroup.
the class FEELSchemaEnum method parseNumberAllowedValuesIntoSchema.
public static void parseNumberAllowedValuesIntoSchema(Schema schema, List<DMNUnaryTest> list) {
// we leverage the property of the *base* FEEL grammar(non visited by ASTVisitor, only the ParseTree->AST Visitor) that `>x` is a Range
List<Object> uts = evaluateUnaryTests(list);
if (uts.size() <= 2 && uts.stream().allMatch(o -> o instanceof Range)) {
// cast intentional.
Range range = consolidateRanges((List) uts);
if (range != null) {
if (range.getLowEndPoint() != null) {
schema.minimum((BigDecimal) range.getLowEndPoint());
schema.exclusiveMinimum(range.getLowBoundary() == RangeBoundary.OPEN);
}
if (range.getHighEndPoint() != null) {
schema.maximum((BigDecimal) range.getHighEndPoint());
schema.exclusiveMaximum(range.getHighBoundary() == RangeBoundary.OPEN);
}
}
} else if (uts.stream().allMatch(o -> o instanceof Number)) {
schema.enumeration(uts);
} else {
LOG.warn("Unable to parse generic allowed value into the JSON Schema for enumeration");
}
}
use of org.kie.dmn.feel.runtime.Range in project drools by kiegroup.
the class FEELSchemaEnumTest method testBasic.
@Test
public void testBasic() {
List<Range> list = new ArrayList<>();
list.add(new RangeImpl(RangeBoundary.CLOSED, 0, null, RangeBoundary.CLOSED));
list.add(new RangeImpl(RangeBoundary.CLOSED, null, 100, RangeBoundary.CLOSED));
Range result = FEELSchemaEnum.consolidateRanges(list);
Assertions.assertThat(result).isNotNull().isEqualTo(new RangeImpl(RangeBoundary.CLOSED, 0, 100, RangeBoundary.CLOSED));
}
Aggregations