Search in sources :

Example 26 with InvalidParametersEvent

use of org.kie.dmn.feel.runtime.events.InvalidParametersEvent in project drools by kiegroup.

the class MonthDiffFunction method invoke.

public FEELFnResult<BigDecimal> invoke(@ParameterName("datetime1") String datetime1, @ParameterName("datetime2") String datetime2) {
    if (datetime1 == null) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "datetime1", "cannot be null"));
    }
    if (datetime2 == null) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "datetime2", "cannot be null"));
    }
    try {
        TemporalAccessor dt1 = BuiltInFunctions.getFunction(DateAndTimeFunction.class).invoke(datetime1).cata(BuiltInType.justNull(), Function.identity());
        TemporalAccessor dt2 = BuiltInFunctions.getFunction(DateAndTimeFunction.class).invoke(datetime2).cata(BuiltInType.justNull(), Function.identity());
        return invoke(dt1, dt2);
    } catch (DateTimeException e) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "datetime", "invalid 'date' or 'date and time' parameter", e));
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeException(java.time.DateTimeException) InvalidParametersEvent(org.kie.dmn.feel.runtime.events.InvalidParametersEvent)

Example 27 with InvalidParametersEvent

use of org.kie.dmn.feel.runtime.events.InvalidParametersEvent in project drools by kiegroup.

the class TrimFunction method invoke.

public FEELFnResult<String> invoke(@ParameterName("text") String text) {
    if (text == null) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "text", "cannot be null"));
    }
    String trimmed = text.trim();
    String result = trimmed.replaceAll(" +", " ");
    return FEELFnResult.ofResult(result);
}
Also used : InvalidParametersEvent(org.kie.dmn.feel.runtime.events.InvalidParametersEvent)

Aggregations

InvalidParametersEvent (org.kie.dmn.feel.runtime.events.InvalidParametersEvent)27 DateTimeException (java.time.DateTimeException)7 TemporalAccessor (java.time.temporal.TemporalAccessor)6 ArrayList (java.util.ArrayList)6 BigDecimal (java.math.BigDecimal)4 FEELEvent (org.kie.dmn.api.feel.runtime.events.FEELEvent)3 List (java.util.List)2 Map (java.util.Map)2 Pattern (java.util.regex.Pattern)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 FEELEventBase (org.kie.dmn.feel.runtime.events.FEELEventBase)2 MathContext (java.math.MathContext)1 DecimalFormat (java.text.DecimalFormat)1 LocalDate (java.time.LocalDate)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Function (java.util.function.Function)1 Matcher (java.util.regex.Matcher)1 DMNContext (org.kie.dmn.api.core.DMNContext)1