Skip to content

Commit

Permalink
fixing some case sensitivity issues..
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Aug 26, 2014
1 parent 76bb24f commit dd550ed
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
Expand Up @@ -1312,7 +1312,7 @@ private void forceRenameIfNeeded(ShadowType currentShadowType, ShadowType oldSha
ResourceAttribute newSecondaryIdentifier = newSecondaryIdentifiers.iterator().next();
Object newValue = newSecondaryIdentifier.getRealValue();

if (!shadowManager.compareAttribute(refinedObjectClassDefinition, newSecondaryIdentifier, oldValue)){
if (!shadowManager.compareAttribute(refinedObjectClassDefinition, newSecondaryIdentifier, oldSecondaryIdentifier)){
Collection<PropertyDelta> renameDeltas = new ArrayList<PropertyDelta>();


Expand Down Expand Up @@ -1524,6 +1524,7 @@ private PrismObject<ShadowType> completeShadow(ConnectorInstance connector, Pris
PrismObject<ShadowType> repoShadow, ResourceType resource, RefinedObjectClassDefinition objectClassDefinition,
OperationResult parentResult) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, SecurityViolationException, GenericConnectorException {


PrismObject<ShadowType> resultShadow = repoShadow.clone();
boolean resultIsResourceShadowClone = false;
if (resultShadow == null) {
Expand Down Expand Up @@ -1627,7 +1628,7 @@ private PrismObject<ShadowType> completeShadow(ConnectorInstance connector, Pris
assert resultName != null : "No name generated in "+resultShadow;
assert !StringUtils.isEmpty(resultName.getOrig()) : "No name (orig) in "+resultShadow;
assert !StringUtils.isEmpty(resultName.getNorm()) : "No name (norm) in "+resultShadow;

return resultShadow;
}

Expand Down
Expand Up @@ -557,6 +557,8 @@ public PrismObject<ShadowType> createRepositoryShadow(PrismObject<ShadowType> sh

ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(shadow);

normalizeAttributes(shadow, objectClassDefinition);

PrismObject<ShadowType> repoShadow = shadow.clone();
ResourceAttributeContainer repoAttributesContainer = ShadowUtil
.getAttributesContainer(repoShadow);
Expand Down Expand Up @@ -606,9 +608,7 @@ public PrismObject<ShadowType> createRepositoryShadow(PrismObject<ShadowType> sh
if (repoShadowType.isProtectedObject() != null){
repoShadowType.setProtectedObject(null);
}

normalizeAttributes(repoShadow, objectClassDefinition);


return repoShadow;
}

Expand All @@ -624,7 +624,7 @@ public void setIntentIfNecessary(ShadowType repoShadowType, RefinedObjectClassDe
}
}

private void normalizeAttributes(PrismObject<ShadowType> shadow, RefinedObjectClassDefinition objectClassDefinition) throws SchemaException {
public void normalizeAttributes(PrismObject<ShadowType> shadow, RefinedObjectClassDefinition objectClassDefinition) throws SchemaException {
for (ResourceAttribute<?> attribute: ShadowUtil.getAttributes(shadow)) {
RefinedAttributeDefinition rAttrDef = objectClassDefinition.findAttributeDefinition(attribute.getElementName());
normalizeAttribute(attribute, rAttrDef);
Expand Down Expand Up @@ -711,6 +711,16 @@ public <T> boolean compareAttribute(RefinedObjectClassDefinition refinedObjectCl
Collection<T> valuesA = getNormalizedAttributeValues(attributeA, refinedAttributeDefinition);
return MiscUtil.unorderedCollectionEquals(valuesA, Arrays.asList(valuesB));
}

public <T> boolean compareAttribute(RefinedObjectClassDefinition refinedObjectClassDefinition,
ResourceAttribute<T> attributeA, ResourceAttribute<T> attributeB) throws SchemaException {
RefinedAttributeDefinition refinedAttributeDefinition = refinedObjectClassDefinition.findAttributeDefinition(attributeA.getElementName());
Collection<T> valuesA = getNormalizedAttributeValues(attributeA, refinedAttributeDefinition);

refinedAttributeDefinition = refinedObjectClassDefinition.findAttributeDefinition(attributeA.getElementName());
Collection<T> valuesB = getNormalizedAttributeValues(attributeB, refinedAttributeDefinition);
return MiscUtil.unorderedCollectionEquals(valuesA, valuesB);
}



Expand Down
Expand Up @@ -49,11 +49,11 @@
import javax.xml.ws.Holder;

import com.evolveum.midpoint.prism.PrismContext;

import com.evolveum.midpoint.prism.xnode.PrimitiveXNode;
import com.evolveum.midpoint.prism.xnode.XNode;
import com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.opends.server.core.ModifyOperation;
Expand All @@ -78,6 +78,7 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition;
import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition;
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.model.test.AbstractModelIntegrationTest;
Expand All @@ -93,6 +94,7 @@
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.PropertyDelta;
import com.evolveum.midpoint.prism.match.StringIgnoreCaseMatchingRule;
import com.evolveum.midpoint.prism.parser.util.XNodeProcessorUtil;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.query.ObjectQuery;
Expand Down Expand Up @@ -1287,7 +1289,7 @@ public void test016ProvisioningSearchAccountsIterative() throws SchemaException,
OperationResult result = new OperationResult(TestSanity.class.getName() + ".test016ProvisioningSearchAccountsIterative");

RefinedResourceSchema refinedSchema = RefinedResourceSchema.getRefinedSchema(resourceTypeOpenDjrepo, prismContext);
RefinedObjectClassDefinition refinedAccountDefinition = refinedSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT);
final RefinedObjectClassDefinition refinedAccountDefinition = refinedSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT);

QName objectClass = refinedAccountDefinition.getObjectClassDefinition().getTypeName();
ObjectQuery q = ObjectQueryUtil.createResourceAndAccountQuery(resourceTypeOpenDjrepo.getOid(), objectClass, prismContext);
Expand All @@ -1310,10 +1312,11 @@ public boolean handle(PrismObject<ObjectType> prismObject, OperationResult paren
assertNotNull(shadow.getName());
assertEquals(new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeOpenDjrepo), "AccountObjectClass"), shadow.getObjectClass());
assertEquals(RESOURCE_OPENDJ_OID, shadow.getResourceRef().getOid());
String icfUid = getAttributeValue(shadow, new QName(ConnectorFactoryIcfImpl.NS_ICF_SCHEMA, "uid"));
String icfUid = getAttributeValue(shadow, SchemaConstants.ICFS_UID);
assertNotNull("No ICF UID", icfUid);
String icfName = getAttributeValue(shadow, new QName(ConnectorFactoryIcfImpl.NS_ICF_SCHEMA, "name"));
String icfName = getNormalizedAttributeValue(shadow, refinedAccountDefinition, SchemaConstants.ICFS_NAME);
assertNotNull("No ICF NAME", icfName);

assertEquals("Wrong shadow name", shadow.getName().getOrig(), icfName);
assertNotNull("Missing LDAP uid", getAttributeValue(shadow, new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeOpenDjrepo), "uid")));
assertNotNull("Missing LDAP cn", getAttributeValue(shadow, new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeOpenDjrepo), "cn")));
Expand Down Expand Up @@ -4053,5 +4056,17 @@ private void checkAllShadows() throws SchemaException, ObjectNotFoundException,
ObjectChecker<ShadowType> checker = null;
IntegrationTestTools.checkAllShadows(resourceTypeOpenDjrepo, repositoryService, checker, prismContext);
}

public static String getNormalizedAttributeValue(ShadowType repoShadow, RefinedObjectClassDefinition objClassDef, QName name) {

String value = getAttributeValue(repoShadow, name);

RefinedAttributeDefinition attrDef = objClassDef.findAttributeDefinition(SchemaConstants.ICFS_NAME);
if (attrDef.getMatchingRuleQName() != null && attrDef.getMatchingRuleQName().equals(StringIgnoreCaseMatchingRule.NAME)){
return value.toLowerCase();
}

return value;
}

}

0 comments on commit dd550ed

Please sign in to comment.