Skip to content

Commit

Permalink
Fixed matching of allowedValues (for enums) + other fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Oct 27, 2016
1 parent 40d74bb commit 3d32ebb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
Expand Up @@ -347,12 +347,26 @@ private <T> PrismPropertyValue<T> parsePropertyValue(@NotNull XNode node,
}
}

private <T> boolean isValueAllowed(T realValue, PrismPropertyDefinition<T> definition) {
private <T> boolean isValueAllowed(T realValue, PrismPropertyDefinition<T> 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<String> prim = (PrimitiveXNode<String>) 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
Expand Down Expand Up @@ -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();
}

Expand Down
Expand Up @@ -68,14 +68,14 @@ public EqualFilter(@NotNull ItemPath path, @Nullable PrismPropertyDefinition<T>

// empty (different from values as it generates filter with null 'values' attribute)
@NotNull
public static <T> EqualFilter<T> createEqual(@NotNull ItemPath path, @NotNull PrismPropertyDefinition<T> definition,
public static <T> EqualFilter<T> createEqual(@NotNull ItemPath path, @Nullable PrismPropertyDefinition<T> definition,
@Nullable QName matchingRule) {
return new EqualFilter<T>(path, definition, matchingRule, null, null, null, null);
}

// values
@NotNull
public static <T> EqualFilter<T> createEqual(@NotNull ItemPath path, @NotNull PrismPropertyDefinition<T> definition,
public static <T> EqualFilter<T> createEqual(@NotNull ItemPath path, @Nullable PrismPropertyDefinition<T> definition,
@Nullable QName matchingRule, @NotNull PrismContext prismContext, Object... values) {
List<PrismPropertyValue<T>> propertyValues = anyArrayToPropertyValueList(prismContext, values);
return new EqualFilter<T>(path, definition, matchingRule, propertyValues, null, null, null);
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -177,12 +178,13 @@ public static Class<?> getTypeFromClass(Class<?> clazz) {
return null;
}

@NotNull
@Nullable
public static <T> Class<T> toJavaType(@NotNull QName xsdType) {
//noinspection ConstantConditions
return toJavaType(xsdToJavaTypeMap, xsdType, true);
}

@Nullable
public static <T> Class<T> toJavaTypeIfKnown(@NotNull QName xsdType) {
return toJavaType(xsdToJavaTypeMap, xsdType, false);
}
Expand All @@ -197,6 +199,7 @@ public static <T> Class<T> toJavaTypeIfKnownExt(@NotNull QName xsdType) {
}
}

@Nullable
private static <T> Class<T> toJavaType(Map<QName, Class> map, @NotNull QName xsdType, boolean errorIfNoMapping) {
Class<?> javaType = map.get(xsdType);
if (javaType == null && StringUtils.isEmpty(xsdType.getNamespaceURI())) {
Expand Down

0 comments on commit 3d32ebb

Please sign in to comment.