Skip to content

Commit

Permalink
Polish dynamic relations (MID-3581)
Browse files Browse the repository at this point in the history
1. Kind of 'membership' changed to 'member'.
2. 'org:meta' is no longer a 'member'.
  • Loading branch information
mederly committed Sep 11, 2018
1 parent a7d010f commit 8d76d12
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 42 deletions.
Expand Up @@ -50,7 +50,7 @@ public RelationDefinitionType getRelationDefinition(QName relation) {

@Override
public boolean isOfKind(QName relation, RelationKindType kind) {
return kind == RelationKindType.MEMBERSHIP && (relation == null || QNameUtil.match(relation, ORG_DEFAULT));
return kind == RelationKindType.MEMBER && (relation == null || QNameUtil.match(relation, ORG_DEFAULT));
}

@Override
Expand All @@ -76,12 +76,12 @@ public QName getDefaultRelation() {
@NotNull
@Override
public Collection<QName> getAllRelationsFor(RelationKindType kind) {
return kind == RelationKindType.MEMBERSHIP ? singletonList(ORG_DEFAULT) : emptyList();
return kind == RelationKindType.MEMBER ? singletonList(ORG_DEFAULT) : emptyList();
}

@Override
public QName getDefaultRelationFor(RelationKindType kind) {
return kind == RelationKindType.MEMBERSHIP ? ORG_DEFAULT : null;
return kind == RelationKindType.MEMBER ? ORG_DEFAULT : null;
}

@NotNull
Expand Down
Expand Up @@ -55,14 +55,18 @@ public interface RelationRegistry {
*/
boolean isOfKind(QName relation, RelationKindType kind);

default boolean isMembership(QName relation) {
return isOfKind(relation, RelationKindType.MEMBERSHIP);
default boolean isMember(QName relation) {
return isOfKind(relation, RelationKindType.MEMBER);
}

default boolean isManager(QName relation) {
return isOfKind(relation, RelationKindType.MANAGER);
}

default boolean isMeta(QName relation) {
return isOfKind(relation, RelationKindType.META);
}

default boolean isDelegation(QName relation) {
return isOfKind(relation, RelationKindType.DELEGATION);
}
Expand All @@ -78,19 +82,19 @@ default boolean isOwner(QName relation) {
}

/**
* Whether this kind of relations is processed on login. Currently only relations of MEMBERSHIP and DELEGATION kinds are.
* Whether this kind of relations is processed on login. Currently only relations of MEMBER and DELEGATION kinds are.
* This is to be configured in the future (MID-3581).
*/
boolean processRelationOnLogin(QName relation);

/**
* Whether this kind of relations is processed on recompute. Currently only relations of MEMBERSHIP, MANAGER and DELEGATION kinds are.
* Whether this kind of relations is processed on recompute. Currently only relations of MEMBER, MANAGER and DELEGATION kinds are.
* This is to be configured in the future (MID-3581).
*/
boolean processRelationOnRecompute(QName relation);

/**
* Whether this kind of relations is included in parentOrgRef. Currently only relations of MEMBERSHIP but *not* META kinds are.
* Whether this kind of relations is included in parentOrgRef. Currently only relations of MEMBER but *not* META kinds are.
* This is to be configured in the future (MID-3581).
*/
boolean includeIntoParentOrgRef(QName relation);
Expand Down
Expand Up @@ -34,9 +34,9 @@
*/
public enum RelationTypes {

MEMBER(SchemaConstants.ORG_DEFAULT, "", RelationKindType.MEMBERSHIP, null, ADMINISTRATION, ORGANIZATION, SELF_SERVICE),
MANAGER(SchemaConstants.ORG_MANAGER, "Manager", RelationKindType.MANAGER, singletonList(RelationKindType.MEMBERSHIP), ADMINISTRATION, GOVERNANCE, ORGANIZATION, SELF_SERVICE),
META(SchemaConstants.ORG_META, "Meta", RelationKindType.META, singletonList(RelationKindType.MEMBERSHIP), POLICY),
MEMBER(SchemaConstants.ORG_DEFAULT, "", RelationKindType.MEMBER, null, ADMINISTRATION, ORGANIZATION, SELF_SERVICE),
MANAGER(SchemaConstants.ORG_MANAGER, "Manager", RelationKindType.MANAGER, singletonList(RelationKindType.MEMBER), ADMINISTRATION, GOVERNANCE, ORGANIZATION, SELF_SERVICE),
META(SchemaConstants.ORG_META, "Meta", RelationKindType.META, null, POLICY),
DEPUTY(SchemaConstants.ORG_DEPUTY, "Deputy", RelationKindType.DELEGATION, null /* no values */),
APPROVER(SchemaConstants.ORG_APPROVER, "Approver", RelationKindType.APPROVER, null, ADMINISTRATION, GOVERNANCE, ORGANIZATION, SELF_SERVICE),
OWNER(SchemaConstants.ORG_OWNER, "Owner", RelationKindType.OWNER, null, ADMINISTRATION, GOVERNANCE, ORGANIZATION, SELF_SERVICE),
Expand Down
Expand Up @@ -150,7 +150,7 @@ public abstract class SchemaConstants {

/**
* Default membership relation. Used as a relation value in object references.
* See RelationKind.MEMBERSHIP for more details.
* See RelationKind.MEMBER for more details.
*/
public static final QName ORG_DEFAULT = new QName(NS_ORG, "default");

Expand Down
Expand Up @@ -108,7 +108,7 @@ class IndexedRelationDefinitions {
}

private void addDefaultRelationToMaps() {
QName defaultRelation = defaultRelationByKind.get(RelationKindType.MEMBERSHIP);
QName defaultRelation = defaultRelationByKind.get(RelationKindType.MEMBER);
if (defaultRelation != null) {
relationDefinitionsByRelationName.put(null, relationDefinitionsByRelationName.get(defaultRelation));
kindsByRelationName.putAll(null, kindsByRelationName.get(defaultRelation));
Expand All @@ -129,7 +129,7 @@ private void logState() {

private List<RelationDefinitionType> validateDefinitions(@NotNull List<RelationDefinitionType> definitions) {
List<RelationDefinitionType> validatedDefinitions = new ArrayList<>(definitions.size());
boolean membershipRelationExists = false;
boolean memberRelationExists = false;
for (RelationDefinitionType definition : definitions) {
if (definition.getRef() == null) {
LOGGER.error("Relation definition with null ref; ignoring: {}", definition);
Expand All @@ -138,12 +138,12 @@ private List<RelationDefinitionType> validateDefinitions(@NotNull List<RelationD
LOGGER.warn("Unqualified relation name '{}'; please fix it as soon as possible; in {}", definition.getRef(), definition);
}
validatedDefinitions.add(definition);
if (!membershipRelationExists && definition.getKind().contains(RelationKindType.MEMBERSHIP)) {
membershipRelationExists = true;
if (!memberRelationExists && definition.getKind().contains(RelationKindType.MEMBER)) {
memberRelationExists = true;
}
}
}
if (!membershipRelationExists) {
if (!memberRelationExists) {
LOGGER.error("No 'member' relation was defined. This would be a fatal condition, so we define one.");
validatedDefinitions.add(RelationRegistryImpl.createRelationDefinitionFromStaticDefinition(RelationTypes.MEMBER));
}
Expand Down Expand Up @@ -265,15 +265,17 @@ private Map<RelationKindType, QName> computeDefaultRelationByKind() {
// We want to make this configurable in the future MID-3581
private Set<QName> computeRelationsToProcessOnLogin() {
HashSet<QName> rv = new HashSet<>();
rv.addAll(getAllRelationNamesFor(RelationKindType.MEMBERSHIP));
rv.addAll(getAllRelationNamesFor(RelationKindType.MEMBER));
rv.addAll(getAllRelationNamesFor(RelationKindType.META));
rv.addAll(getAllRelationNamesFor(RelationKindType.DELEGATION));
return rv;
}

// We want to make this configurable in the future MID-3581
private Set<QName> computeRelationsToProcessOnRecompute() {
HashSet<QName> rv = new HashSet<>();
rv.addAll(getAllRelationsFor(RelationKindType.MEMBERSHIP));
rv.addAll(getAllRelationsFor(RelationKindType.MEMBER));
rv.addAll(getAllRelationsFor(RelationKindType.META));
rv.addAll(getAllRelationsFor(RelationKindType.MANAGER));
rv.addAll(getAllRelationsFor(RelationKindType.DELEGATION));
return rv;
Expand Down Expand Up @@ -314,7 +316,7 @@ boolean processRelationOnRecompute(QName relation) {

// We want to make this configurable in the future MID-3581
public boolean includeIntoParentOrgRef(QName relation) {
return isOfKind(relation, RelationKindType.MEMBERSHIP) && !isOfKind(relation, RelationKindType.META);
return isOfKind(relation, RelationKindType.MEMBER);
}

QName getDefaultRelationFor(RelationKindType kind) {
Expand Down
Expand Up @@ -56,7 +56,7 @@ public void applyRelationConfiguration(SystemConfigurationType systemConfigurati
RelationsDefinitionType relationsDef = roleManagement != null ? roleManagement.getRelations() : null;
LOGGER.info("Applying relation configuration ({} entries)", relationsDef != null ? relationsDef.getRelation().size() : 0);
indexedRelationDefinitions = createAndIndexRelationDefinitions(relationsDef);
prismContext.setDefaultRelation(indexedRelationDefinitions.getDefaultRelationFor(RelationKindType.MEMBERSHIP));
prismContext.setDefaultRelation(indexedRelationDefinitions.getDefaultRelationFor(RelationKindType.MEMBER));
}

public List<RelationDefinitionType> getRelationDefinitions() {
Expand Down Expand Up @@ -152,7 +152,7 @@ public Collection<QName> getAllRelationsFor(RelationKindType kind) {

@Override
public QName getDefaultRelation() {
return getDefaultRelationFor(RelationKindType.MEMBERSHIP);
return getDefaultRelationFor(RelationKindType.MEMBER);
}

@NotNull
Expand Down
Expand Up @@ -16315,7 +16315,7 @@
</xsd:appinfo>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="membership">
<xsd:enumeration value="member">
<xsd:annotation>
<xsd:documentation>
Membership relation, usually meaning "has" or "is member of".
Expand All @@ -16327,7 +16327,7 @@
ref.relation is null).
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="MEMBERSHIP"/>
<jaxb:typesafeEnumMember name="MEMBER"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
Expand All @@ -16348,9 +16348,6 @@
Relations used for metarole assignments. Sometimes it is important to
distinguish metarole and member assignments. This kind of relation is used
for that purpose.

Relations of this kind should be also of MEMBERSHIP kind.
(Otherwise they would not provide metarole assignment functionality!)
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="META"/>
Expand All @@ -16360,7 +16357,7 @@
<xsd:enumeration value="delegation">
<xsd:annotation>
<xsd:documentation>
Relation of "is deputy of" kind. Specifies that the subject is a deputy of another user.
Relation "is deputy of" kind. Specifies that the subject is a deputy of another user.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="DELEGATION"/>
Expand Down Expand Up @@ -16389,7 +16386,7 @@
<xsd:enumeration value="owner">
<xsd:annotation>
<xsd:documentation>
Relation of "is owner of" kind.
Relation "is owner of" kind.

Specifies that the subject is a (business) owner of specified (abstract) role.
The owner will be asked for decision if the role is modified, when the associated
Expand Down
Expand Up @@ -133,7 +133,7 @@ private void resolveRoleReviewers(List<ObjectReferenceType> reviewers, Operation
private List<ObjectReferenceType> getMembers(ObjectReferenceType abstractRoleRef, OperationResult result)
throws SchemaException {
Collection<PrismReferenceValue> references = ObjectQueryUtil
.createReferences(abstractRoleRef.getOid(), RelationKindType.MEMBERSHIP, relationRegistry);
.createReferences(abstractRoleRef.getOid(), RelationKindType.MEMBER, relationRegistry);
ObjectQuery query = references.isEmpty()
? QueryBuilder.queryFor(UserType.class, prismContext).none().build()
: QueryBuilder.queryFor(UserType.class, prismContext)
Expand Down
Expand Up @@ -23,7 +23,6 @@

import com.evolveum.midpoint.model.api.context.EvaluationOrder;
import com.evolveum.midpoint.schema.RelationRegistry;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.DebugUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.MultiSet;
Expand Down Expand Up @@ -221,7 +220,8 @@ public void shortDump(StringBuilder sb) {
@Override
public Collection<QName> getExtraRelations() {
return orderMap.entrySet().stream()
.filter(e -> !relationRegistry.isMembership(e.getKey()) &&
.filter(e -> !relationRegistry.isMember(e.getKey()) &&
!relationRegistry.isMeta(e.getKey()) &&
!relationRegistry.isDelegation(e.getKey()) && e.getValue() > 0)
.map(e -> e.getKey())
.collect(Collectors.toSet());
Expand Down
Expand Up @@ -71,13 +71,13 @@ public void test100DefaultRelations() throws SchemaException {
assertFalse(relationRegistry.isManager(unqualify(SchemaConstants.ORG_DEFAULT)));
assertFalse(relationRegistry.isManager(null));

assertTrue(relationRegistry.isMembership(SchemaConstants.ORG_DEFAULT));
assertTrue(relationRegistry.isMembership(unqualify(SchemaConstants.ORG_DEFAULT)));
assertTrue(relationRegistry.isMembership(null));
assertTrue(relationRegistry.isMembership(SchemaConstants.ORG_MANAGER));
assertTrue(relationRegistry.isMembership(unqualify(SchemaConstants.ORG_MANAGER)));
assertFalse(relationRegistry.isMembership(SchemaConstants.ORG_APPROVER));
assertFalse(relationRegistry.isMembership(unqualify(SchemaConstants.ORG_APPROVER)));
assertTrue(relationRegistry.isMember(SchemaConstants.ORG_DEFAULT));
assertTrue(relationRegistry.isMember(unqualify(SchemaConstants.ORG_DEFAULT)));
assertTrue(relationRegistry.isMember(null));
assertTrue(relationRegistry.isMember(SchemaConstants.ORG_MANAGER));
assertTrue(relationRegistry.isMember(unqualify(SchemaConstants.ORG_MANAGER)));
assertFalse(relationRegistry.isMember(SchemaConstants.ORG_APPROVER));
assertFalse(relationRegistry.isMember(unqualify(SchemaConstants.ORG_APPROVER)));

// TODO
}
Expand Down
Expand Up @@ -90,10 +90,10 @@ private static List<PrismReferenceValue> getGroupsForUser(String userOid, Reposi
return rv;
}
userType.getRoleMembershipRef().stream()
.filter(ref -> relationRegistry.isMembership(ref.getRelation()))
.filter(ref -> relationRegistry.isMember(ref.getRelation()))
.forEach(ref -> rv.add(ref.clone().asReferenceValue()));
userType.getDelegatedRef().stream()
.filter(ref -> relationRegistry.isMembership(ref.getRelation()))
.filter(ref -> relationRegistry.isMember(ref.getRelation()))
.filter(ref -> !QNameUtil.match(ref.getType(), UserType.COMPLEX_TYPE)) // we are not interested in deputies (but this should be treated above)
.forEach(ref -> rv.add(ref.clone().asReferenceValue()));
return rv;
Expand Down
Expand Up @@ -406,7 +406,7 @@ public boolean isMemberOfActivitiGroup(UserType userType, String activitiGroupId
}

public boolean matches(ObjectReferenceType groupRef, ObjectReferenceType targetRef) {
return (relationRegistry.isMembership(targetRef.getRelation())) // TODO reconsider if we allow managers here
return relationRegistry.isMember(targetRef.getRelation())
&& targetRef.getOid().equals(groupRef.getOid());
}

Expand Down

0 comments on commit 8d76d12

Please sign in to comment.