Skip to content

Commit

Permalink
Support for recurseUpOrgType in associationFromLink
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Mar 23, 2016
1 parent 4462ad6 commit 3c65fda
Show file tree
Hide file tree
Showing 8 changed files with 821 additions and 12 deletions.
Expand Up @@ -5813,9 +5813,33 @@
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="associationFromLink" type="tns:ShadowDiscriminatorExpressionEvaluatorType" substitutionGroup="tns:expressionEvaluator"/>
<xsd:element name="assignmentFromAssociation" type="tns:ShadowDiscriminatorExpressionEvaluatorType" substitutionGroup="tns:expressionEvaluator"/>

<xsd:complexType name="AssociationFromLinkExpressionEvaluatorType">
<xsd:annotation>
<xsd:documentation>
Definition of an expression that creates association from links (linkRefs)
</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="tns:ShadowDiscriminatorExpressionEvaluatorType">
<xsd:sequence>
<xsd:element name="recurseUpOrgType" type="xsd:string" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Specifies orgType of an organization tree to recurse upward.
In case that the expression applies to an org, it will recurse the org
tree upwards and create associations for all the orgs in the hierarchy.
Only orgs with the orgType mathing this specification will be processed.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="associationFromLink" type="tns:AssociationFromLinkExpressionEvaluatorType" substitutionGroup="tns:expressionEvaluator"/>

<xsd:complexType name="PopulateObjectType">
<xsd:annotation>
<xsd:documentation>TODO</xsd:documentation>
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015 Evolveum
* Copyright (c) 2014-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@
package com.evolveum.midpoint.model.common.expression.evaluator;

import java.util.Collection;
import java.util.List;

import javax.xml.namespace.QName;

Expand All @@ -39,9 +40,10 @@
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssociationFromLinkExpressionEvaluatorType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowDiscriminatorExpressionEvaluatorType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowDiscriminatorType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
Expand All @@ -56,12 +58,12 @@ public class AssociationFromLinkExpressionEvaluator

private static final Trace LOGGER = TraceManager.getTrace(AssociationFromLinkExpressionEvaluator.class);

private ShadowDiscriminatorExpressionEvaluatorType evaluatorType;
private AssociationFromLinkExpressionEvaluatorType evaluatorType;
private PrismContainerDefinition<ShadowAssociationType> outputDefinition;
private ObjectResolver objectResolver;
private PrismContext prismContext;

AssociationFromLinkExpressionEvaluator(ShadowDiscriminatorExpressionEvaluatorType evaluatorType,
AssociationFromLinkExpressionEvaluator(AssociationFromLinkExpressionEvaluatorType evaluatorType,
PrismContainerDefinition<ShadowAssociationType> outputDefinition, ObjectResolver objectResolver, PrismContext prismContext) {
this.evaluatorType = evaluatorType;
this.outputDefinition = outputDefinition;
Expand Down Expand Up @@ -107,6 +109,21 @@ public PrismValueDeltaSetTriple<PrismContainerValue<ShadowAssociationType>> eval
QName assocName = params.getMappingQName();
String resourceOid = rAssocTargetDef.getResourceType().getOid();
Collection<SelectorOptions<GetOperationOptions>> options = null;

// Always process the first role (myself) regardless of recursion setting
gatherAssociationsFromAbstractRole(thisRole, output, resourceOid, kind, intent, assocName, options, desc, params);

if (thisRole instanceof OrgType) {
gatherAssociationsFromAbstractRoleRecurse((OrgType)thisRole, output, resourceOid, kind, intent, assocName, options, desc, params);
}

return ItemDelta.toDeltaSetTriple(output, null);
}

private void gatherAssociationsFromAbstractRole(AbstractRoleType thisRole,
PrismContainer<ShadowAssociationType> output, String resourceOid, ShadowKindType kind,
String intent, QName assocName, Collection<SelectorOptions<GetOperationOptions>> options,
String desc, ExpressionEvaluationContext params) throws SchemaException {
for (ObjectReferenceType linkRef: thisRole.getLinkRef()) {
ShadowType shadowType;
try {
Expand All @@ -126,8 +143,28 @@ public PrismValueDeltaSetTriple<PrismContainerValue<ShadowAssociationType>> eval
shadowAssociationType.setShadowRef(shadowRef);
}
}
}

private void gatherAssociationsFromAbstractRoleRecurse(OrgType thisOrg,
PrismContainer<ShadowAssociationType> output, String resourceOid, ShadowKindType kind,
String intent, QName assocName, Collection<SelectorOptions<GetOperationOptions>> options,
String desc, ExpressionEvaluationContext params) throws SchemaException, ObjectNotFoundException {

return ItemDelta.toDeltaSetTriple(output, null);
if (!matchesForRecursion(thisOrg)) {
return;
}
for (ObjectReferenceType parentOrgRef: thisOrg.getParentOrgRef()) {
OrgType parent = objectResolver.resolve(parentOrgRef, OrgType.class, options, desc, params.getTask(), params.getResult());
gatherAssociationsFromAbstractRole(parent, output, resourceOid, kind, intent, assocName, options, desc, params);
}
}

private boolean matchesForRecursion(OrgType thisOrg) {
for (String recurseUpOrgType: evaluatorType.getRecurseUpOrgType()) {
thisOrg.getOrgType().contains(recurseUpOrgType);
return true;
}
return false;
}

/* (non-Javadoc)
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014 Evolveum
* Copyright (c) 2014-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,9 +32,9 @@
import com.evolveum.midpoint.schema.util.ObjectResolver;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssociationFromLinkExpressionEvaluatorType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowDiscriminatorExpressionEvaluatorType;
import org.apache.commons.lang.Validate;

/**
Expand All @@ -61,7 +61,7 @@ public AssociationFromLinkExpressionEvaluatorFactory(PrismContext prismContext,
*/
@Override
public QName getElementName() {
return new ObjectFactory().createAssociationFromLink(new ShadowDiscriminatorExpressionEvaluatorType()).getName();
return new ObjectFactory().createAssociationFromLink(new AssociationFromLinkExpressionEvaluatorType()).getName();
}

/* (non-Javadoc)
Expand All @@ -85,11 +85,11 @@ public <V extends PrismValue,D extends ItemDefinition> ExpressionEvaluator<V,D>
if (evaluatorElement != null) {
evaluatorTypeObject = evaluatorElement.getValue();
}
if (evaluatorTypeObject != null && !(evaluatorTypeObject instanceof ShadowDiscriminatorExpressionEvaluatorType)) {
if (evaluatorTypeObject != null && !(evaluatorTypeObject instanceof AssociationFromLinkExpressionEvaluatorType)) {
throw new SchemaException("Association expression evaluator cannot handle elements of type " + evaluatorTypeObject.getClass().getName()+" in "+contextDescription);
}
AssociationFromLinkExpressionEvaluator evaluator = new AssociationFromLinkExpressionEvaluator(
(ShadowDiscriminatorExpressionEvaluatorType)evaluatorTypeObject,
(AssociationFromLinkExpressionEvaluatorType)evaluatorTypeObject,
(PrismContainerDefinition<ShadowAssociationType>) outputDefinition, objectResolver, prismContext);
return (ExpressionEvaluator<V,D>) evaluator;
}
Expand Down

0 comments on commit 3c65fda

Please sign in to comment.