Skip to content

Commit

Permalink
Fixed MID-3392: Type query works with qualified type names only
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Dec 5, 2016
1 parent 2fc8207 commit 68fe045
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 19 additions & 0 deletions infra/util/src/main/java/com/evolveum/midpoint/util/QNameUtil.java
Expand Up @@ -18,6 +18,9 @@

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.xml.namespace.QName;

Expand Down Expand Up @@ -102,6 +105,22 @@ public static QName qualifyIfNeeded(QName name, String defaultNamespace) {
: new QName(defaultNamespace, name.getLocalPart());
}

public static <V> V getKey(@NotNull Map<QName, V> map, @NotNull QName key) {
if (hasNamespace(key)) {
return map.get(key);
}
List<Map.Entry<QName, V>> matching = map.entrySet().stream()
.filter(e -> match(e.getKey(), key))
.collect(Collectors.toList());
if (matching.isEmpty()) {
return null;
} else if (matching.size() == 1) {
return matching.get(0).getValue();
} else {
throw new IllegalStateException("More than one matching value for key " + key + ": " + matching);
}
}

public static class QNameInfo {
@NotNull public final QName name;
public final boolean explicitEmptyNamespace;
Expand Down
Expand Up @@ -30,6 +30,7 @@
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType;
Expand Down Expand Up @@ -163,7 +164,7 @@ public String debugDump(int indent) {
public JpaEntityDefinition findEntityDefinition(QName typeName) {
Validate.notNull(typeName, "Type name must not be null.");

JpaEntityDefinition def = definitions.get(typeName);
JpaEntityDefinition def = QNameUtil.getKey(definitions, typeName);
if (def == null) {
throw new IllegalStateException("Type " + typeName + " couldn't be found in type registry");
}
Expand Down

0 comments on commit 68fe045

Please sign in to comment.