ALF-7260: fixed diffs to work against multiple matching db objects

It is possible that multiple database objects, e.g. indexes, match a given object as described in the schema reference file. This fix means that diffs will be provided against all the matching items, where previously only the first matching item was reported against.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32864 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Matt Ward
2011-12-19 16:29:27 +00:00
parent f38f3d62e1
commit fb13db6c4c
3 changed files with 117 additions and 90 deletions

View File

@@ -36,32 +36,12 @@ import org.apache.commons.collections.Predicate;
* @author Matt Ward
*/
public class DefaultComparisonUtils implements ComparisonUtils
{
/**
* @param objToFind
* @return
*/
{
@Override
public DbObject findSameObjectAs(Collection<? extends DbObject> objects, final DbObject objToFind)
{
return (DbObject) CollectionUtils.find(objects, new Predicate()
{
@Override
public boolean evaluate(Object o)
{
DbObject object = (DbObject) o;
return object.sameAs(objToFind);
}
});
}
@Override
public List<DbObject> findEquivalentObjects(Schema schema, DbObject objToMatch)
public List<DbObject> findEquivalentObjects(DbObject rootObject, DbObject objToMatch)
{
EquivalentObjectSeeker objectSeeker = new EquivalentObjectSeeker(objToMatch);
schema.accept(objectSeeker);
rootObject.accept(objectSeeker);
return objectSeeker.getMatches();
}
@@ -147,17 +127,27 @@ public class DefaultComparisonUtils implements ComparisonUtils
Results differences = ctx.getComparisonResults();
for (DbObject leftObj : leftCollection)
{
DbObject rightObj = findSameObjectAs(rightCollection, leftObj);
if (rightObj != null)
{
// There is an equivalent object in the right hand collection as
// in the left.
leftObj.diff(rightObj, ctx, strength);
boolean foundMatch = false;
for (DbObject rootObject : rightCollection)
{
List<DbObject> matches = findEquivalentObjects(rootObject, leftObj);
for (DbObject match : matches)
{
// There is an equivalent object in the right hand collection as in the left.
leftObj.diff(match, ctx, strength);
}
if (matches.size() > 0)
{
foundMatch = true;
}
}
else
if (!foundMatch)
{
// No equivalent object in the right hand collection.
// No equivalent object in the target collection.
differences.add(Where.ONLY_IN_REFERENCE, new DbProperty(leftObj, null), null, strength);
}
}
@@ -165,9 +155,19 @@ public class DefaultComparisonUtils implements ComparisonUtils
// Identify objects in the right collection but not the left
for (DbObject rightObj : rightCollection)
{
DbObject leftObj = findSameObjectAs(leftCollection, rightObj);
boolean foundMatch = false;
if (leftObj == null)
for (DbObject rootObject : leftCollection)
{
List<DbObject> matches = findEquivalentObjects(rootObject, rightObj);
if (matches.size() > 0)
{
foundMatch = true;
break;
}
}
if (!foundMatch)
{
// No equivalent object in the left hand collection.
differences.add(Where.ONLY_IN_TARGET, null, new DbProperty(rightObj, null), strength);
@@ -251,7 +251,7 @@ public class DefaultComparisonUtils implements ComparisonUtils
}
private static class EquivalentObjectSeeker implements DbObjectVisitor
public static class EquivalentObjectSeeker implements DbObjectVisitor
{
private final List<DbObject> matches = new ArrayList<DbObject>();
private final DbObject objToMatch;