Skip to content

Commit

Permalink
implementing MID-2009
Browse files Browse the repository at this point in the history
* used existing resource schema attribute - naming attribute
* mapping this attribute to the shadow/name
* changed search filter from substring: shadow/attributes/secondaryIdentifier to shadow/attributes/namingAttribute..
  • Loading branch information
katkav committed Jul 28, 2014
1 parent 4bb2323 commit ecf5a31
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
Expand Up @@ -558,8 +558,10 @@ private ObjectQuery createQuery() {

if (dto.isName()) {
List<ResourceAttributeDefinition> secondaryIdentifiers = new ArrayList<>();
if (def.getSecondaryIdentifiers() != null) {
secondaryIdentifiers.addAll(def.getSecondaryIdentifiers());
if (def.getNamingAttribute() != null) {
secondaryIdentifiers.add(def.getNamingAttribute());
} else if (def.getSecondaryIdentifiers() != null){
secondaryIdentifiers.addAll(def.getSecondaryIdentifiers());
}
for (ResourceAttributeDefinition attrDef : secondaryIdentifiers) {
conditions.add(SubstringFilter.createSubstring(
Expand Down
Expand Up @@ -67,6 +67,18 @@ public static Collection<ResourceAttribute<?>> getSecondaryIdentifiers(PrismObje
return attributesContainer.getSecondaryIdentifiers();
}

public static ResourceAttribute<String> getNamingAttribute(ShadowType shadow){
return getNamingAttribute(shadow.asPrismObject());
}

public static ResourceAttribute<String> getNamingAttribute(PrismObject<? extends ShadowType> shadow) {
ResourceAttributeContainer attributesContainer = getAttributesContainer(shadow);
if (attributesContainer == null) {
return null;
}
return attributesContainer.getNamingAttribute();
}

public static Collection<ResourceAttribute<?>> getAttributes(ShadowType shadowType) {
return getAttributes(shadowType.asPrismObject());
}
Expand Down Expand Up @@ -148,7 +160,7 @@ public static String getSingleStringAttributeValue(ShadowType shadow, QName attr
}


private static String getSingleStringAttributeValue(PrismObject<ShadowType> shadow, QName attrName) {
public static String getSingleStringAttributeValue(PrismObject<ShadowType> shadow, QName attrName) {
PrismContainer<?> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
if (attributesContainer == null) {
return null;
Expand Down
Expand Up @@ -445,7 +445,7 @@ public String modifyShadow(PrismObject<ShadowType> shadow, ResourceType resource

afterModifyOnResource(shadow, modifications, parentResult);

Collection<PropertyDelta<?>> renameDeltas = distillRenameDeltas(modifications, shadow, objectClassDefinition);
Collection<PropertyDelta<?>> renameDeltas = distillRenameDeltas(modifications, shadow, objectClassDefinition, task, parentResult);

Collection<? extends ItemDelta> sideEffectDelta = convertToPropertyDelta(sideEffectChanges);
if (renameDeltas != null) {
Expand All @@ -472,7 +472,7 @@ public String modifyShadow(PrismObject<ShadowType> shadow, ResourceType resource
}

private Collection<PropertyDelta<?>> distillRenameDeltas(Collection<? extends ItemDelta> modifications,
PrismObject<ShadowType> shadow, RefinedObjectClassDefinition objectClassDefinition) throws SchemaException {
PrismObject<ShadowType> shadow, RefinedObjectClassDefinition objectClassDefinition, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
PropertyDelta<String> nameDelta = (PropertyDelta<String>) ItemDelta.findItemDelta(modifications, new ItemPath(ShadowType.F_ATTRIBUTES, ConnectorFactoryIcfImpl.ICFS_NAME), ItemDelta.class);
if (nameDelta == null){
return null;
Expand All @@ -493,8 +493,9 @@ private Collection<PropertyDelta<?>> distillRenameDeltas(Collection<? extends It
// $shadow/name
if (!newName.equals(shadow.asObjectable().getName().getOrig())){

PrismObject<ShadowType> fullShadow = getShadow(shadow.getOid(), shadow, null, task, parentResult);
PropertyDelta<?> shadowNameDelta = PropertyDelta.createModificationReplaceProperty(ShadowType.F_NAME, shadow.getDefinition(),
new PolyString(newName));
ProvisioningUtil.determineShadowName(fullShadow));
deltas.add(shadowNameDelta);
}

Expand Down
Expand Up @@ -17,6 +17,7 @@
package com.evolveum.midpoint.provisioning.util;

import com.evolveum.midpoint.common.StaticExpressionUtil;
import com.evolveum.midpoint.common.Utils;
import com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition;
import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition;
import com.evolveum.midpoint.prism.*;
Expand Down Expand Up @@ -129,7 +130,8 @@ public static <T extends ShadowType> PolyString determineShadowName(PrismObject<

public static <T extends ShadowType> String determineShadowStringName(PrismObject<T> shadow) throws SchemaException {
ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(shadow);
if (attributesContainer.getNamingAttribute() == null) {
ResourceAttribute<String> namingAttribute = attributesContainer.getNamingAttribute();
if (namingAttribute == null || namingAttribute.isEmpty()) {
// No naming attribute defined. Try to fall back to identifiers.
Collection<ResourceAttribute<?>> identifiers = attributesContainer.getIdentifiers();
// We can use only single identifiers (not composite)
Expand All @@ -153,7 +155,20 @@ public static <T extends ShadowType> String determineShadowStringName(PrismObjec
throw new SchemaException("No naming attribute defined (and identifier not usable)");
}
// TODO: Error handling
return attributesContainer.getNamingAttribute().getValue().getValue();
List<PrismPropertyValue<String>> possibleValues = namingAttribute.getValues();

if (possibleValues.size() > 1){
throw new SchemaException("Cannot determine name of shadow. Found more than one value for naming attribute (attr: "+namingAttribute.getElementName()+", values: {}"+possibleValues+")" );
}

PrismPropertyValue<String> value = possibleValues.iterator().next();

if (value == null){
throw new SchemaException("Naming attribute has no value. Could not determine shadow name.");
}

return value.getValue();
// return attributesContainer.getNamingAttribute().getValue().getValue();
}


Expand Down

0 comments on commit ecf5a31

Please sign in to comment.