Search in sources :

Example 1 with ImmutableFPAWrappingPOJO

use of org.kie.dmn.feel.lang.types.impl.ImmutableFPAWrappingPOJO in project drools by kiegroup.

the class ContextPutFunction method toMap.

public static FEELFnResult<Map<String, Object>> toMap(Object context) {
    Map<String, Object> result;
    if (context instanceof Map) {
        result = new HashMap<>();
        Map<?, ?> contextMap = (Map<?, ?>) context;
        for (Entry<?, ?> kv : contextMap.entrySet()) {
            if (kv.getKey() instanceof String) {
                result.put((String) kv.getKey(), kv.getValue());
            } else {
                FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "found a key which is not a string: " + kv.getKey()));
            }
        }
    } else if (BuiltInType.determineTypeFromInstance(context) == BuiltInType.UNKNOWN) {
        result = new ImmutableFPAWrappingPOJO(context).allFEELProperties();
    } else {
        return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "context", "is not a context"));
    }
    return FEELFnResult.ofResult(result);
}
Also used : ImmutableFPAWrappingPOJO(org.kie.dmn.feel.lang.types.impl.ImmutableFPAWrappingPOJO) InvalidParametersEvent(org.kie.dmn.feel.runtime.events.InvalidParametersEvent) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 ImmutableFPAWrappingPOJO (org.kie.dmn.feel.lang.types.impl.ImmutableFPAWrappingPOJO)1 InvalidParametersEvent (org.kie.dmn.feel.runtime.events.InvalidParametersEvent)1