Skip to content

Commit

Permalink
Apply resource naming attribute changes to shadow name
Browse files Browse the repository at this point in the history
  • Loading branch information
bpowers1215 committed Jul 15, 2019
1 parent 275d4de commit 6f6c195
Showing 1 changed file with 37 additions and 0 deletions.
Expand Up @@ -26,6 +26,7 @@
import com.evolveum.midpoint.prism.delta.*;
import com.evolveum.midpoint.prism.match.MatchingRuleRegistry;
import com.evolveum.midpoint.prism.path.*;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.query.*;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.provisioning.api.*;
Expand Down Expand Up @@ -91,6 +92,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
* Shadow cache is a facade that covers all the operations with shadows. It
Expand Down Expand Up @@ -1417,6 +1419,41 @@ private PrismObject<ShadowType> refreshShadowAsyncStatus(ProvisioningContext ctx
}

if (pendingDelta.isModify()) {

// Apply shadow naming attribute modification
PrismContainer<ShadowAttributesType> shadowAttributesContainer = repoShadow.findContainer(ItemPath.create(ShadowType.F_ATTRIBUTES));
ResourceAttributeContainer resourceAttributeContainer = ResourceAttributeContainer.convertFromContainer(shadowAttributesContainer, ctx.getObjectClassDefinition());
ResourceAttributeContainerDefinition resourceAttrDefinition = resourceAttributeContainer.getDefinition();
if(resourceAttrDefinition != null) {

// If naming attribute is present in delta...
ResourceAttributeDefinition namingAttribute = resourceAttrDefinition.getNamingAttribute();
if (namingAttribute != null) {
if (pendingDelta.hasItemDelta(ItemPath.create(ShadowType.F_ATTRIBUTES, namingAttribute.getName()))) {

// Retrieve a possible changed name per the defined naming attribute for the resource
ItemDelta namingAttributeDelta = pendingDelta.findItemDelta(ItemPath.create(ShadowType.F_ATTRIBUTES, namingAttribute.getName()));
Collection<?> valuesToReplace = namingAttributeDelta.getValuesToReplace();
Optional<?> valueToReplace = valuesToReplace.stream().findFirst();

if (valueToReplace.isPresent()){
Object valueToReplaceObj = ((PrismPropertyValue)valueToReplace.get()).getValue();
if (valueToReplaceObj instanceof String) {

// Apply the new naming attribute value to the shadow name by adding the change to the modification set for shadow delta
PropertyDelta<PolyString> nameDelta = shadowDelta.createPropertyModification(ItemPath.create(ShadowType.F_NAME));
Collection<PolyString> modificationSet = new ArrayList<>();
PolyString nameAttributeReplacement = new PolyString((String) valueToReplaceObj);
modificationSet.add(nameAttributeReplacement);
nameDelta.setValuesToReplace(PrismValueCollectionsUtil.createCollection(prismContext, modificationSet));
shadowDelta.addModification(nameDelta);
}
}
}
}
}

// Apply shadow attribute modifications
for (ItemDelta<?, ?> pendingModification: pendingDelta.getModifications()) {
shadowDelta.addModification(pendingModification.clone());
}
Expand Down

0 comments on commit 6f6c195

Please sign in to comment.