diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/marshaller/PrismUnmarshaller.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/marshaller/PrismUnmarshaller.java index 799fdfcb4ce..2c8323f6768 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/marshaller/PrismUnmarshaller.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/marshaller/PrismUnmarshaller.java @@ -347,12 +347,26 @@ private PrismPropertyValue parsePropertyValue(@NotNull XNode node, } } - private boolean isValueAllowed(T realValue, PrismPropertyDefinition definition) { + private boolean isValueAllowed(T realValue, PrismPropertyDefinition definition) throws SchemaException { if (definition == null || CollectionUtils.isEmpty(definition.getAllowedValues())) { return true; } + if (realValue == null) { + return true; // TODO: ok? + } + String serializedForm; + if (realValue instanceof Enum) { + PrimitiveXNode prim = (PrimitiveXNode) getBeanMarshaller().marshall(realValue); + serializedForm = prim.getValue(); + } else { + serializedForm = null; + } + return definition.getAllowedValues().stream() - .anyMatch(displayableValue -> realValue.equals(displayableValue.getValue())); + .anyMatch(displayableValue -> + realValue.equals(displayableValue.getValue()) + || serializedForm != null && serializedForm.equals(displayableValue.getValue()) + ); } @NotNull @@ -586,7 +600,11 @@ private BeanUnmarshaller getBeanUnmarshaller() { return ((PrismContextImpl) prismContext).getBeanUnmarshaller(); } - private SchemaRegistry getSchemaRegistry() { + private BeanMarshaller getBeanMarshaller() { + return ((PrismContextImpl) prismContext).getBeanMarshaller(); + } + + private SchemaRegistry getSchemaRegistry() { return prismContext.getSchemaRegistry(); } diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/EqualFilter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/EqualFilter.java index 35a748388b6..12b830161fc 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/EqualFilter.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/EqualFilter.java @@ -68,14 +68,14 @@ public EqualFilter(@NotNull ItemPath path, @Nullable PrismPropertyDefinition // empty (different from values as it generates filter with null 'values' attribute) @NotNull - public static EqualFilter createEqual(@NotNull ItemPath path, @NotNull PrismPropertyDefinition definition, + public static EqualFilter createEqual(@NotNull ItemPath path, @Nullable PrismPropertyDefinition definition, @Nullable QName matchingRule) { return new EqualFilter(path, definition, matchingRule, null, null, null, null); } // values @NotNull - public static EqualFilter createEqual(@NotNull ItemPath path, @NotNull PrismPropertyDefinition definition, + public static EqualFilter createEqual(@NotNull ItemPath path, @Nullable PrismPropertyDefinition definition, @Nullable QName matchingRule, @NotNull PrismContext prismContext, Object... values) { List> propertyValues = anyArrayToPropertyValueList(prismContext, values); return new EqualFilter(path, definition, matchingRule, propertyValues, null, null, null); diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/xml/XsdTypeMapper.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/xml/XsdTypeMapper.java index c7a1a604756..1a475d4551a 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/xml/XsdTypeMapper.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/xml/XsdTypeMapper.java @@ -32,6 +32,7 @@ import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.w3c.dom.Element; import com.evolveum.midpoint.prism.PrismConstants; @@ -177,12 +178,13 @@ public static Class getTypeFromClass(Class clazz) { return null; } - @NotNull + @Nullable public static Class toJavaType(@NotNull QName xsdType) { //noinspection ConstantConditions return toJavaType(xsdToJavaTypeMap, xsdType, true); } + @Nullable public static Class toJavaTypeIfKnown(@NotNull QName xsdType) { return toJavaType(xsdToJavaTypeMap, xsdType, false); } @@ -197,6 +199,7 @@ public static Class toJavaTypeIfKnownExt(@NotNull QName xsdType) { } } + @Nullable private static Class toJavaType(Map map, @NotNull QName xsdType, boolean errorIfNoMapping) { Class javaType = map.get(xsdType); if (javaType == null && StringUtils.isEmpty(xsdType.getNamespaceURI())) {