use of com.evolveum.midpoint.util.QNameUtil in project midpoint by Evolveum.
the class IndexedRelationDefinitions method initializeRelationDefinitionsByRelationName.
/**
* Removes duplicate definitions as well.
*/
@NotNull
private Map<QName, RelationDefinitionType> initializeRelationDefinitionsByRelationName(List<RelationDefinitionType> definitions) {
Map<QName, RelationDefinitionType> map = new HashMap<>();
ListValuedMap<String, QName> expansions = new ArrayListValuedHashMap<>();
for (Iterator<RelationDefinitionType> iterator = definitions.iterator(); iterator.hasNext(); ) {
RelationDefinitionType definition = iterator.next();
if (map.containsKey(definition.getRef())) {
LOGGER.error("Duplicate relation definition for '{}'; ignoring: {}", definition.getRef(), definition);
iterator.remove();
} else {
map.put(definition.getRef(), definition);
expansions.put(definition.getRef().getLocalPart(), definition.getRef());
}
}
// add entries for unqualified versions of the relation names
for (String unqualified : expansions.keySet()) {
List<QName> names = expansions.get(unqualified);
if (names.contains(new QName(unqualified))) {
// cannot expand unqualified if the expanded value is also unqualified
continue;
}
assert !names.isEmpty();
assert names.stream().allMatch(QNameUtil::isQualified);
@NotNull QName chosenExpansion;
if (names.size() == 1) {
chosenExpansion = names.get(0);
} else {
QName nameInOrgNamespace = names.stream().filter(n -> SchemaConstants.NS_ORG.equals(n.getNamespaceURI())).findFirst().orElse(null);
if (nameInOrgNamespace != null) {
// org:xxx expansion will be the default one
chosenExpansion = nameInOrgNamespace;
} else {
chosenExpansion = names.get(0);
LOGGER.warn("Multiple resolutions of unqualified relation name '{}' ({}); " + "using the first one as default: '{}'. Please reconsider this as it could lead to " + "unpredictable behavior.", unqualified, names, chosenExpansion);
}
}
assert QNameUtil.isQualified(chosenExpansion);
map.put(new QName(unqualified), map.get(chosenExpansion));
}
return map;
}
Aggregations