use of org.kie.dmn.feel.runtime.events.InvalidParametersEvent in project drools by kiegroup.
the class AppendFunction method invoke.
public FEELFnResult<List<Object>> invoke(@ParameterName("list") Object appendTo, @ParameterName("item") Object[] items) {
if (appendTo == null) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "list", "cannot be null"));
}
if (items == null) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "item", "cannot be null"));
}
// spec requires us to return a new list
final List<Object> result = new ArrayList<>();
if (appendTo instanceof Collection) {
result.addAll((Collection) appendTo);
} else {
result.add(appendTo);
}
result.addAll(Arrays.asList(items));
return FEELFnResult.ofResult(result);
}
use of org.kie.dmn.feel.runtime.events.InvalidParametersEvent in project drools by kiegroup.
the class MatchesFunction method invoke.
public FEELFnResult<Boolean> invoke(@ParameterName("input") String input, @ParameterName("pattern") String pattern, @ParameterName("flags") String flags) {
if (input == null) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "input", "cannot be null"));
}
if (pattern == null) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "pattern", "cannot be null"));
}
try {
int f = processFlags(flags);
Pattern p = Pattern.compile(pattern, f);
Matcher m = p.matcher(input);
return FEELFnResult.ofResult(m.find());
} catch (PatternSyntaxException e) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "pattern", "is invalid and can not be compiled", e));
} catch (IllegalArgumentException t) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "flags", "contains unknown flags", t));
} catch (Throwable t) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "pattern", "is invalid and can not be compiled", t));
}
}
use of org.kie.dmn.feel.runtime.events.InvalidParametersEvent in project drools by kiegroup.
the class MeanFunction method invoke.
public FEELFnResult<BigDecimal> invoke(@ParameterName("list") List list) {
if (list == null) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "list", "cannot be null"));
}
FEELFnResult<BigDecimal> s = sum.invoke(list);
Function<FEELEvent, FEELFnResult<BigDecimal>> ifLeft = (event) -> {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "list", "unable to sum the elements which is required to calculate the mean"));
};
Function<BigDecimal, FEELFnResult<BigDecimal>> ifRight = (sum) -> {
try {
return FEELFnResult.ofResult(sum.divide(BigDecimal.valueOf(list.size()), MathContext.DECIMAL128));
} catch (Exception e) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "unable to perform division to calculate the mean", e));
}
};
return s.cata(ifLeft, ifRight);
}
use of org.kie.dmn.feel.runtime.events.InvalidParametersEvent in project drools by kiegroup.
the class ReverseFunction method invoke.
public FEELFnResult<List<Object>> invoke(@ParameterName("list") List list) {
if (list == null) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "list", "cannot be null"));
}
// spec requires us to return a new list
final List<Object> result = new ArrayList<>(list);
Collections.reverse(result);
return FEELFnResult.ofResult(result);
}
use of org.kie.dmn.feel.runtime.events.InvalidParametersEvent in project drools by kiegroup.
the class YearsAndMonthsFunction method invoke.
public FEELFnResult<TemporalAmount> invoke(@ParameterName("from") Temporal from, @ParameterName("to") Temporal to) {
if (from == null) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "from", "cannot be null"));
}
if (to == null) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "to", "cannot be null"));
}
final LocalDate fromDate = getLocalDateFromTemporal(from);
if (fromDate == null) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "from", "is of type not suitable for years and months function"));
}
final LocalDate toDate = getLocalDateFromTemporal(to);
if (toDate == null) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "to", "is of type not suitable for years and months function"));
}
return FEELFnResult.ofResult(Period.between(fromDate, toDate).withDays(0));
}
Aggregations