Added removeNode(String path) to AVMService as a convenience and to

reduce my shame.  Beefed up path robustness in AVMNodeConverter.SplitBase().
Removed an unneeded import from AVMNodeService.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3862 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-09-20 13:54:53 +00:00
parent dda6d72701
commit 6f565e2be1
6 changed files with 55 additions and 2 deletions

View File

@@ -114,6 +114,11 @@ public class AVMNodeConverter
*/ */
public static String [] SplitBase(String path) public static String [] SplitBase(String path)
{ {
path = path.replaceAll("/+", "/");
while (path.endsWith("/") && !path.endsWith(":/"))
{
path = path.substring(0, path.length() - 1);
}
if (path.endsWith(":/")) if (path.endsWith(":/"))
{ {
String [] res = new String[2]; String [] res = new String[2];

View File

@@ -37,7 +37,6 @@ import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.avm.AVMNotFoundException; import org.alfresco.service.cmr.avm.AVMNotFoundException;
import org.alfresco.service.cmr.avm.AVMService; import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.avm.AVMStoreDescriptor; import org.alfresco.service.cmr.avm.AVMStoreDescriptor;
import org.alfresco.service.cmr.avm.AVMWrongTypeException;
import org.alfresco.service.cmr.dictionary.AspectDefinition; import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition; import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.InvalidAspectException; import org.alfresco.service.cmr.dictionary.InvalidAspectException;

View File

@@ -385,6 +385,24 @@ public class AVMServiceImpl implements AVMService
fAVMRepository.remove(parent, name); fAVMRepository.remove(parent, name);
} }
/**
* Remove a node by full path.
* @param path The full path to the node.
*/
public void removeNode(String path)
{
if (path == null)
{
throw new AVMBadArgumentException("Illegal null argument.");
}
String [] basePath = AVMNodeConverter.SplitBase(path);
if (basePath[0] == null)
{
throw new AVMBadArgumentException("Cannot remove root node.");
}
fAVMRepository.remove(basePath[0], basePath[1]);
}
/** /**
* Rename a node. * Rename a node.
* @param srcParent The path to the source parent. * @param srcParent The path to the source parent.

View File

@@ -59,6 +59,32 @@ import org.alfresco.service.transaction.TransactionService;
*/ */
public class AVMServiceTest extends AVMServiceTestBase public class AVMServiceTest extends AVMServiceTestBase
{ {
/**
* Test one argument remove.
*/
public void testOneArgRemove()
{
try
{
setupBasicTree();
fService.removeNode("main:/a/b/c/foo/");
fService.removeNode("main://d");
try
{
fService.removeNode("main://");
fail();
}
catch (AVMException e)
{
// Do nothing.
}
}
catch (Exception e)
{
e.printStackTrace(System.err);
}
}
/** /**
* Test that non head version sources are update correctly. * Test that non head version sources are update correctly.
*/ */

View File

@@ -19,7 +19,6 @@ package org.alfresco.repo.avm;
import java.util.List; import java.util.List;
import org.alfresco.service.cmr.avm.AVMException;
import org.alfresco.service.cmr.avm.AVMStoreDescriptor; import org.alfresco.service.cmr.avm.AVMStoreDescriptor;
import org.springframework.context.support.FileSystemXmlApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext;

View File

@@ -261,6 +261,12 @@ public interface AVMService
*/ */
public void removeNode(String parent, String name); public void removeNode(String parent, String name);
/**
* Remove a node from by its full path.
* @param path The full path to the node to remove.
*/
public void removeNode(String path);
/** /**
* Rename a node. * Rename a node.
* @param srcParent The simple absolute path to the parent folder. * @param srcParent The simple absolute path to the parent folder.