use of org.kie.dmn.feel.runtime.functions.FEELFnResult in project drools by kiegroup.
the class ContextPutFunction method invoke.
public FEELFnResult<Map<String, Object>> invoke(@ParameterName("context") Object context, @ParameterName("keys") List keys, @ParameterName("value") Object value) {
if (context == null) {
return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "context", "cannot be null"));
}
if (keys == null) {
return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "keys", "cannot be null"));
} else if (keys.isEmpty()) {
return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "keys", "cannot be empty"));
}
Object head = keys.get(0);
if (!(head instanceof String)) {
return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "keys", "an element is not a key: " + head));
}
final String key0 = (String) head;
if (keys.size() == 1) {
return invoke(context, key0, value);
}
final List keysTail = keys.subList(1, keys.size());
final FEELFnResult<Map<String, Object>> result = toMap(context).flatMap(r -> invoke(r.get(key0), keysTail, value).map(rv -> put(r, key0, rv)));
return result;
}
Aggregations