use of org.keycloak.models.map.common.EntityField in project keycloak by keycloak.
the class PerFieldDelegateProvider method get.
@Override
@SuppressWarnings("unchecked")
public <EF extends Enum<? extends EntityField<V>> & EntityField<V>> Object get(EF field) {
switch(node.isCacheFor(field, null).max(() -> node.isPrimarySourceFor(field, null))) {
case FULLY:
return field.get(entity);
case NOT_CONTAINED:
return field.get(getEntityFromDescendantNode());
}
// It has to be partial field. The only supported partial field is a Map
if (field.getMapKeyClass() == Void.class) {
throw new IllegalStateException("Field " + field + " expected to be a map but is " + field.getFieldClass());
}
Map<Object, Object> m1 = (Map<Object, Object>) field.get(entity);
Map m2 = (Map) field.get(getEntityFromDescendantNode());
if (m1 == null) {
return m2 == null ? null : new HashMap<>(m2);
}
Predicate<Map.Entry<Object, Object>> isInNode = me -> node.isCacheFor(field, me.getKey()).max(() -> node.isPrimarySourceFor(field, me.getKey())) == FieldContainedStatus.FULLY;
Stream<Map.Entry<Object, Object>> s = m1.entrySet().stream().filter(isInNode);
if (m2 == null) {
return s.collect(ENTRY_TO_HASH_MAP_OVERRIDING_KEYS_COLLECTOR);
}
return Stream.concat(s, m2.entrySet().stream().filter(isInNode.negate())).collect(ENTRY_TO_HASH_MAP_OVERRIDING_KEYS_COLLECTOR);
}
Aggregations