Fixed an embarassing not so corner case failure. Non primary

layered directories cannot be just linked in for update, but must instead
be recursively linked in.  


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3801 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-09-15 03:04:57 +00:00
parent 5eca8bd6e0
commit 83b4cdb76d
6 changed files with 85 additions and 20 deletions

View File

@@ -35,6 +35,7 @@ import org.alfresco.repo.avm.util.BulkLoader;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.transaction.TransactionUtil;
import org.alfresco.service.cmr.avm.AVMBadArgumentException;
import org.alfresco.service.cmr.avm.AVMException;
import org.alfresco.service.cmr.avm.AVMExistsException;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
@@ -359,6 +360,16 @@ public class AVMServiceTest extends AVMServiceTestBase
{
// Do nothing.
}
// Try to link /layer/b to /frinx. It should fail.
try
{
fService.link("main:/", "frinx", fService.lookup(-1, "main:/layer/b"));
fail();
}
catch (AVMBadArgumentException ba)
{
// Do nothing.
}
// Delete /layer/b/bar and redo. It should work.
fService.removeNode("main:/layer/b", "bar");
fService.link("main:/layer/b", "bar", fService.lookup(-1, "main:/layer/b/c/bar"));

View File

@@ -1146,6 +1146,6 @@ public class AVMStoreImpl implements AVMStore, Serializable
{
Lookup lPath = lookupDirectory(-1, parentPath, true);
DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode();
dir.link(lPath, name, toLink.getId());
dir.link(lPath, name, toLink);
}
}

View File

@@ -308,11 +308,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
case AVMDifference.NEWER :
{
// You can't delete what isn't there.
if (dstDesc != null)
{
fAVMService.removeNode(dstParts[0], dstParts[1]);
}
fAVMService.link(dstParts[0], dstParts[1], srcDesc);
linkIn(dstParts[0], dstParts[1], srcDesc, dstDesc != null);
continue;
}
case AVMDifference.OLDER :
@@ -320,8 +316,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
// You can force it.
if (overrideOlder)
{
fAVMService.removeNode(dstParts[0], dstParts[1]);
fAVMService.link(dstParts[0], dstParts[1], srcDesc);
linkIn(dstParts[0], dstParts[1], srcDesc, true);
continue;
}
// You can ignore it.
@@ -337,8 +332,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
// You can force it.
if (overrideConflicts)
{
fAVMService.removeNode(dstParts[0], dstParts[1]);
fAVMService.link(dstParts[0], dstParts[1], srcDesc);
linkIn(dstParts[0], dstParts[1], srcDesc, true);
continue;
}
// You can ignore it.
@@ -367,6 +361,56 @@ public class AVMSyncServiceImpl implements AVMSyncService
}
}
/**
* Do the actual work of connecting nodes to the destination tree.
* @param parentPath The parent path the node will go in.
* @param name The name it will have.
* @param toLink The node descriptor.
* @param removeFirst Whether to do a removeNode before linking in.
*/
private void linkIn(String parentPath, String name, AVMNodeDescriptor toLink, boolean removeFirst)
{
if (removeFirst)
{
fAVMService.removeNode(parentPath, name);
}
if (toLink.isLayeredDirectory() && !toLink.isPrimary())
{
recursiveCopy(parentPath, name, toLink);
return;
}
fAVMService.link(parentPath, name, toLink);
}
// TODO doesn't handle copies from non head nodes.
/**
* Recursively copy a node into the given position.
* @param parentPath The place to put it.
* @param name The name to give it.
* @param toCopy The it to put.
*/
private void recursiveCopy(String parentPath, String name, AVMNodeDescriptor toCopy)
{
// TODO Can we just do a link if it's a plain directory.
// If it's a file or deleted simply link it in.
if (toCopy.isFile() || toCopy.isDeleted())
{
fAVMService.link(parentPath, name, toCopy);
return;
}
// Otherwise make a directory in the target parent, and recursiveCopy all the source
// children into it.
fAVMService.createDirectory(parentPath, name);
String newParentPath = AVMNodeConverter.ExtendAVMPath(parentPath, name);
Map<String, AVMNodeDescriptor> children =
fAVMService.getDirectoryListing(-1, toCopy.getPath(), true);
for (Map.Entry<String, AVMNodeDescriptor> entry : children.entrySet())
{
recursiveCopy(newParentPath, entry.getKey(), entry.getValue());
}
}
/**
* The workhorse of comparison and updating. Determine the versioning relationship
* of two nodes.

View File

@@ -119,7 +119,7 @@ public interface DirectoryNode extends AVMNode
* Link a node with the given id into this directory.
* @param lPath The Lookup for this node.
* @param name The name to give the node.
* @param id The id of the node to insert.
* @param toLink The node to link in.
*/
public void link(Lookup lPath, String name, long id);
public void link(Lookup lPath, String name, AVMNodeDescriptor toLink);
}

View File

@@ -772,14 +772,19 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
* Link a node with the given id into this directory.
* @param lPath The Lookup for this.
* @param name The name to give the node.
* @param id The id of the node to insert.
* @param toLink The node to link in.
*/
public void link(Lookup lPath, String name, long id)
public void link(Lookup lPath, String name, AVMNodeDescriptor toLink)
{
AVMNode node = AVMContext.fgInstance.fAVMNodeDAO.getByID(id);
AVMNode node = AVMContext.fgInstance.fAVMNodeDAO.getByID(toLink.getId());
if (node == null)
{
throw new AVMNotFoundException("Not Found: " + id);
throw new AVMNotFoundException("Not Found: " + toLink.getId());
}
if (node.getType() == AVMNodeType.LAYERED_DIRECTORY &&
!((LayeredDirectoryNode)node).getPrimaryIndirection())
{
throw new AVMBadArgumentException("Non primary layered directories cannot be linked.");
}
// Look for an existing child of that name.
AVMNode existing = lookupChild(lPath, name, -1, false, true);

View File

@@ -407,15 +407,20 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory
* Link a node with the given id into this directory.
* @param lPath The Lookup for this directory.
* @param name The name to give the node.
* @param id The id of the node to insert.
* @param toLink The node to link in.
*/
public void link(Lookup lPath, String name, long id)
public void link(Lookup lPath, String name, AVMNodeDescriptor toLink)
{
// Assure that the incoming node exists.
AVMNode node = AVMContext.fgInstance.fAVMNodeDAO.getByID(id);
AVMNode node = AVMContext.fgInstance.fAVMNodeDAO.getByID(toLink.getId());
if (node == null)
{
throw new AVMNotFoundException("Node not found: " + id);
throw new AVMNotFoundException("Node not found: " + toLink.getId());
}
if (node.getType() == AVMNodeType.LAYERED_DIRECTORY &&
!((LayeredDirectoryNode)node).getPrimaryIndirection())
{
throw new AVMBadArgumentException("Non primary layered directories cannot be linked.");
}
// Check for an existing child by the given name.
ChildEntry child = AVMContext.fgInstance.fChildEntryDAO.getByNameParent(name, this);