diff --git a/infra/schema/src/main/java/com/evolveum/midpoint/schema/constants/ObjectTypes.java b/infra/schema/src/main/java/com/evolveum/midpoint/schema/constants/ObjectTypes.java index 66e7e3c11b2..03e0bf13892 100644 --- a/infra/schema/src/main/java/com/evolveum/midpoint/schema/constants/ObjectTypes.java +++ b/infra/schema/src/main/java/com/evolveum/midpoint/schema/constants/ObjectTypes.java @@ -1,25 +1,22 @@ /* - * Copyright (c) 2010-2019 Evolveum and contributors + * Copyright (c) 2010-2020 Evolveum and contributors * * This work is dual-licensed under the Apache License 2.0 * and European Union Public License. See LICENSE file for details. */ package com.evolveum.midpoint.schema.constants; -import com.evolveum.midpoint.schema.SchemaConstantsGenerated; -import com.evolveum.midpoint.util.QNameUtil; -import com.evolveum.midpoint.xml.ns._public.common.common_3.*; +import java.util.ArrayList; +import java.util.List; +import javax.xml.namespace.QName; + import org.apache.commons.lang.Validate; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import javax.xml.namespace.QName; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Locale; -import java.util.ResourceBundle; +import com.evolveum.midpoint.schema.SchemaConstantsGenerated; +import com.evolveum.midpoint.util.QNameUtil; +import com.evolveum.midpoint.xml.ns._public.common.common_3.*; /** * @author lazyman @@ -73,10 +70,10 @@ public enum ObjectTypes { REPORT(ReportType.COMPLEX_TYPE, SchemaConstants.C_REPORT, ReportType.class, ObjectManager.MODEL, "reports"), REPORT_OUTPUT(ReportOutputType.COMPLEX_TYPE, SchemaConstants.C_REPORT_OUTPUT, ReportOutputType.class, - ObjectManager.MODEL, "reportOutputs"), + ObjectManager.MODEL, "reportOutputs"), SECURITY_POLICY(SecurityPolicyType.COMPLEX_TYPE, SchemaConstants.C_SECURITY_POLICY, SecurityPolicyType.class, - ObjectManager.MODEL, "securityPolicies"), + ObjectManager.MODEL, "securityPolicies"), LOOKUP_TABLE(LookupTableType.COMPLEX_TYPE, SchemaConstantsGenerated.C_LOOKUP_TABLE, LookupTableType.class, ObjectManager.MODEL, "lookupTables"), @@ -132,6 +129,10 @@ public enum ObjectManager { } @NotNull private final QName type; + + /** + * As of 2020-06, this is used only for ObjectTypeUtil#toShortString+getShortTypeName. + */ @NotNull private final QName elementName; @NotNull private final Class classDefinition; @NotNull private final ObjectManager objectManager; @@ -205,7 +206,7 @@ public static ObjectTypes getObjectTypeFromTypeQName(QName typeQName) { // HACK WARNING! FIXME // UGLY HORRIBLE TERRIBLE AWFUL HACK FOLLOWS // The JAXB fails to correctly process QNames in default namespace (no prefix) - // e.g it will not understand this: type="RoleType", even if defatult namespace + // e.g it will not understand this: type="RoleType", even if default namespace // is set, it will parse it as null namespace. // Therefore substitute null namespace with common namespace if (typeQName.getNamespaceURI() == null || typeQName.getNamespaceURI().isEmpty()) { @@ -249,13 +250,13 @@ public static Class getObjectTypeClass(String typeNameLoca public static Class getObjectTypeClass(QName typeName) { for (ObjectTypes type : values()) { if (QNameUtil.match(type.getTypeQName(), typeName)) { + //noinspection unchecked return (Class) type.getClassDefinition(); } } throw new IllegalArgumentException("Unsupported object type " + typeName); } - @SuppressWarnings("unchecked") @NotNull public static ObjectTypes getObjectType(@NotNull Class objectType) { ObjectTypes rv = getObjectTypeIfKnown(objectType); @@ -390,4 +391,3 @@ public static QName canonizeObjectType(QName inputQName) { return new QName(SchemaConstants.NS_C, inputQName.getLocalPart()); } } - diff --git a/infra/util/src/main/java/com/evolveum/midpoint/util/QNameUtil.java b/infra/util/src/main/java/com/evolveum/midpoint/util/QNameUtil.java index 004223ba898..862dce4aa72 100644 --- a/infra/util/src/main/java/com/evolveum/midpoint/util/QNameUtil.java +++ b/infra/util/src/main/java/com/evolveum/midpoint/util/QNameUtil.java @@ -94,9 +94,15 @@ public static QName qualifyIfNeeded(QName name, String defaultNamespace) { return hasNamespace(name) ? name : new QName(defaultNamespace, name.getLocalPart()); + } - public static V getKey(@NotNull Map map, @NotNull QName key) { + /** + * Finds value in the map by QName key using {@link #match(QName, QName)}. + * Fails if multiple matches are found. + * Returns {@code null} if no match is found. + */ + public static V getByQName(@NotNull Map map, @NotNull QName key) { if (hasNamespace(key)) { return map.get(key); } diff --git a/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/query/QueryDefinitionRegistry.java b/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/query/QueryDefinitionRegistry.java index 2af44e6277b..234aaa4096b 100644 --- a/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/query/QueryDefinitionRegistry.java +++ b/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/query/QueryDefinitionRegistry.java @@ -152,7 +152,7 @@ public String debugDump(int indent) { public JpaEntityDefinition findEntityDefinition(QName typeName) { Objects.requireNonNull(typeName, "Type name must not be null."); - JpaEntityDefinition def = QNameUtil.getKey(DEFINITIONS, typeName); + JpaEntityDefinition def = QNameUtil.getByQName(DEFINITIONS, typeName); if (def == null) { throw new IllegalStateException("Type " + typeName + " couldn't be found in type registry"); }