Search in sources :

Example 1 with RelationKindType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.RelationKindType in project midpoint by Evolveum.

the class IndexedRelationDefinitions method computeDefaultRelationByKind.

private Map<RelationKindType, QName> computeDefaultRelationByKind() {
    Map<RelationKindType, QName> rv = new HashMap<>();
    for (RelationKindType kind : RelationKindType.values()) {
        Set<QName> relationNames = relationsByKind.get(kind);
        if (relationNames.isEmpty()) {
            LOGGER.warn("No relations defined for kind {}, please define at least one", kind);
            continue;
        }
        Set<QName> defaultRelationNames = new HashSet<>();
        Set<QName> userDefinedDefaultRelationNames = new HashSet<>();
        for (QName relationName : relationNames) {
            RelationDefinitionType definition = relationDefinitionsByRelationName.get(relationName);
            assert definition != null;
            if (definition.getDefaultFor() == kind) {
                defaultRelationNames.add(relationName);
                if (BooleanUtils.isNotTrue(definition.isStaticallyDefined())) {
                    userDefinedDefaultRelationNames.add(relationName);
                }
            }
        }
        QName chosen;
        if (defaultRelationNames.size() > 1) {
            if (userDefinedDefaultRelationNames.size() == 1) {
                // i.e. we ignore statically defined relations here
                chosen = userDefinedDefaultRelationNames.iterator().next();
            } else if (userDefinedDefaultRelationNames.size() > 1) {
                // i.e. we choose only from user-defined relations
                chosen = userDefinedDefaultRelationNames.iterator().next();
                LOGGER.error("More than one default relation set up for kind '{}': {}. Please choose one! Temporarily selecting '{}'", kind, defaultRelationNames, chosen);
            } else {
                throw new AssertionError("Multiple default relations set up for kind '" + kind + "' among statically defined relations: " + defaultRelationNames);
            }
        } else if (defaultRelationNames.size() == 1) {
            chosen = defaultRelationNames.iterator().next();
        } else {
            // maybe we could select org:xxx here but let's not bother now
            chosen = relationNames.iterator().next();
            LOGGER.warn("No default relation set up for kind '{}'. Please choose one! Temporarily selecting '{}'", kind, chosen);
        }
        rv.put(kind, chosen);
    }
    return rv;
}
Also used : RelationDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.RelationDefinitionType) HashSetValuedHashMap(org.apache.commons.collections4.multimap.HashSetValuedHashMap) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) QName(javax.xml.namespace.QName) RelationKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.RelationKindType)

Aggregations

RelationDefinitionType (com.evolveum.midpoint.xml.ns._public.common.common_3.RelationDefinitionType)1 RelationKindType (com.evolveum.midpoint.xml.ns._public.common.common_3.RelationKindType)1 QName (javax.xml.namespace.QName)1 ArrayListValuedHashMap (org.apache.commons.collections4.multimap.ArrayListValuedHashMap)1 HashSetValuedHashMap (org.apache.commons.collections4.multimap.HashSetValuedHashMap)1