This in theory makes AVMSyncService feature complete, by added flatten, which

essentially resets a users layer to be as much like the target tree as possible
to keep comparisons fast.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3797 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-09-14 19:59:08 +00:00
parent 1386cedef5
commit 348ec8b265
2 changed files with 52 additions and 5 deletions

View File

@@ -58,6 +58,43 @@ import org.alfresco.service.transaction.TransactionService;
*/ */
public class AVMServiceTest extends AVMServiceTestBase public class AVMServiceTest extends AVMServiceTestBase
{ {
/**
* Test the flatten operation, with a little bit of compare and update.
*/
public void testFlatten()
{
try
{
setupBasicTree();
fService.createLayeredDirectory("main:/a", "main:/", "layer");
fService.createSnapshot("main");
System.out.println(recursiveList("main", -1, true));
// Change some stuff.
fService.createFile("main:/layer/b", "fig").close();
fService.getFileOutputStream("main:/layer/b/c/foo").close();
fService.createSnapshot("main");
System.out.println(recursiveList("main", -1, true));
// Do a compare.
List<AVMDifference> diffs =
fSyncService.compare(-1, "main:/layer", -1, "main:/a");
for (AVMDifference diff : diffs)
{
System.out.println(diff);
}
// Update.
fSyncService.update(diffs, false, false, false, false);
System.out.println(recursiveList("main", -1, true));
// Flatten.
fSyncService.flatten("main:/layer", "main:/a");
System.out.println(recursiveList("main", -1, true));
}
catch (Exception e)
{
e.printStackTrace(System.err);
fail();
}
}
/** /**
* Test of Descriptor indirection field. * Test of Descriptor indirection field.
*/ */

View File

@@ -508,16 +508,16 @@ public class AVMSyncServiceImpl implements AVMSyncService
* @param layer The on top node. * @param layer The on top node.
* @param underlying The underlying node. * @param underlying The underlying node.
*/ */
private void flatten(AVMNodeDescriptor layer, AVMNodeDescriptor underlying) private boolean flatten(AVMNodeDescriptor layer, AVMNodeDescriptor underlying)
{ {
if (!layer.isLayeredDirectory()) if (!layer.isLayeredDirectory())
{ {
return; return false;
} }
// layer and underlying must match for flattening to be useful. // layer and underlying must match for flattening to be useful.
if (!layer.getIndirection().equals(underlying.getPath())) if (!layer.getIndirection().equals(underlying.getPath()))
{ {
return; return false;
} }
// The underlying thing must be a directory. // The underlying thing must be a directory.
if (!underlying.isDirectory()) if (!underlying.isDirectory())
@@ -529,11 +529,12 @@ public class AVMSyncServiceImpl implements AVMSyncService
// If the layer is empty (directly, that is) we're done. // If the layer is empty (directly, that is) we're done.
if (layerListing.size() == 0) if (layerListing.size() == 0)
{ {
return; return true;
} }
// Grab the listing // Grab the listing
Map<String, AVMNodeDescriptor> underListing = Map<String, AVMNodeDescriptor> underListing =
fAVMService.getDirectoryListing(-1, underlying.getPath(), true); fAVMService.getDirectoryListing(-1, underlying.getPath(), true);
boolean flattened = true;
for (String name : layerListing.keySet()) for (String name : layerListing.keySet())
{ {
AVMNodeDescriptor topNode = layerListing.get(name); AVMNodeDescriptor topNode = layerListing.get(name);
@@ -551,10 +552,19 @@ public class AVMSyncServiceImpl implements AVMSyncService
else else
{ {
// Otherwise recursively flatten the children. // Otherwise recursively flatten the children.
flatten(topNode, bottomNode); if (flatten(topNode, bottomNode))
{
fAVMService.removeNode(layer.getPath(), name);
fAVMService.uncover(layer.getPath(), name);
}
else
{
flattened = false;
} }
} }
} }
return flattened;
}
/** /**
* Takes a layer, deletes it and recreates it pointing at the same underlying * Takes a layer, deletes it and recreates it pointing at the same underlying