mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Merged DEV/CHECK_EXISTS to HEAD
svn merge svn://www.alfresco.org:3691/alfresco/BRANCHES/DEV/CHECK_EXISTS@3442 svn://www.alfresco.org:3691/alfresco/BRANCHES/DEV/CHECK_EXISTS@3590 . TODO: Fix bug raising incorrect exception during UI paste of same-named file Note: - Added a new method to NodeService to get child by name - Added a new method to FileFolderService to perform fast, direct lookups based on name git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3591 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -331,16 +331,16 @@ public class FileFolderPerformanceTester extends TestCase
|
||||
// 100,
|
||||
// new double[] {0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90});
|
||||
// }
|
||||
public void test_1_shuffled_10_400() throws Exception
|
||||
{
|
||||
buildStructure(
|
||||
rootFolderRef,
|
||||
1,
|
||||
true,
|
||||
10,
|
||||
400,
|
||||
new double[] {0.05, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90});
|
||||
}
|
||||
// public void test_1_shuffled_10_400() throws Exception
|
||||
// {
|
||||
// buildStructure(
|
||||
// rootFolderRef,
|
||||
// 1,
|
||||
// true,
|
||||
// 10,
|
||||
// 400,
|
||||
// new double[] {0.05, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90});
|
||||
// }
|
||||
public void test_4_shuffled_10_100() throws Exception
|
||||
{
|
||||
buildStructure(
|
||||
@@ -351,4 +351,14 @@ public class FileFolderPerformanceTester extends TestCase
|
||||
100,
|
||||
new double[] {0.05, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90});
|
||||
}
|
||||
// public void test_1_ordered_1_50000() throws Exception
|
||||
// {
|
||||
// buildStructure(
|
||||
// rootFolderRef,
|
||||
// 1,
|
||||
// false,
|
||||
// 1,
|
||||
// 50000,
|
||||
// new double[] {0.01, 0.02, 0.03, 0.04, 0.05, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90});
|
||||
// }
|
||||
}
|
||||
|
@@ -39,6 +39,7 @@ import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.CopyService;
|
||||
import org.alfresco.service.cmr.repository.DuplicateChildNodeNameException;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.MimetypeService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
@@ -205,27 +206,6 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that a file or folder with the given name does not already exist
|
||||
*
|
||||
* @throws FileExistsException if a same-named file or folder already exists
|
||||
*/
|
||||
private void checkExists(NodeRef parentFolderRef, String name)
|
||||
throws FileExistsException
|
||||
{
|
||||
// the name is never a wildcard, so we can perform an exact search
|
||||
List<NodeRef> nodeRefs = searchInternal(parentFolderRef, name, true, true, false);
|
||||
if (nodeRefs.size() == 0)
|
||||
{
|
||||
// no match
|
||||
return;
|
||||
}
|
||||
// we found a match, so raise the exception
|
||||
NodeRef duplicateNodeRef = nodeRefs.get(0);
|
||||
FileInfo duplicateFileInfo = toFileInfo(duplicateNodeRef);
|
||||
throw new FileExistsException(duplicateFileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception when the type is not a valid File or Folder type
|
||||
*
|
||||
@@ -321,6 +301,20 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public NodeRef searchSimple(NodeRef contextNodeRef, String name)
|
||||
{
|
||||
NodeRef childNodeRef = nodeService.getChildByName(contextNodeRef, ContentModel.ASSOC_CONTAINS, name);
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug(
|
||||
"Simple name search results: \n" +
|
||||
" parent: " + contextNodeRef + "\n" +
|
||||
" name: " + name + "\n" +
|
||||
" result: " + childNodeRef);
|
||||
}
|
||||
return childNodeRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #search(NodeRef, String, boolean, boolean, boolean)
|
||||
@@ -378,7 +372,7 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
* file info objects. This allows {@link #checkExists(NodeRef, String)} to
|
||||
* bypass the retrieval of node properties.
|
||||
*/
|
||||
public List<NodeRef> searchInternal(
|
||||
private List<NodeRef> searchInternal(
|
||||
NodeRef contextNodeRef,
|
||||
String namePattern,
|
||||
boolean fileSearch,
|
||||
@@ -547,7 +541,6 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
}
|
||||
|
||||
// there is nothing to do if both the name and parent folder haven't changed
|
||||
boolean checkExists = true;
|
||||
if (targetParentRef.equals(assocRef.getParentRef()))
|
||||
{
|
||||
if (newName.equals(beforeFileInfo.getName()))
|
||||
@@ -563,16 +556,9 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
}
|
||||
else if (newName.equalsIgnoreCase(beforeFileInfo.getName()))
|
||||
{
|
||||
checkExists = false;
|
||||
}
|
||||
}
|
||||
|
||||
// check for existing file or folder
|
||||
if (checkExists)
|
||||
{
|
||||
checkExists(targetParentRef, newName);
|
||||
}
|
||||
|
||||
QName qname = QName.createQName(
|
||||
NamespaceService.CONTENT_MODEL_1_0_URI,
|
||||
QName.createValidLocalName(newName));
|
||||
@@ -613,8 +599,15 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
String currentName = (String)nodeService.getProperty(targetNodeRef, ContentModel.PROP_NAME);
|
||||
if (currentName.equals(newName) == false)
|
||||
{
|
||||
// changed the name property
|
||||
nodeService.setProperty(targetNodeRef, ContentModel.PROP_NAME, newName);
|
||||
try
|
||||
{
|
||||
// changed the name property
|
||||
nodeService.setProperty(targetNodeRef, ContentModel.PROP_NAME, newName);
|
||||
}
|
||||
catch (DuplicateChildNodeNameException e)
|
||||
{
|
||||
throw new FileExistsException(targetParentRef, newName);
|
||||
}
|
||||
}
|
||||
|
||||
// get the details after the operation
|
||||
@@ -658,9 +651,6 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
throw new AlfrescoRuntimeException("The type is not supported by this service: " + typeQName);
|
||||
}
|
||||
|
||||
// check for existing file or folder
|
||||
checkExists(parentNodeRef, name);
|
||||
|
||||
// set up initial properties
|
||||
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(11);
|
||||
properties.put(ContentModel.PROP_NAME, (Serializable) name);
|
||||
@@ -676,12 +666,21 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
QName qname = QName.createQName(
|
||||
NamespaceService.CONTENT_MODEL_1_0_URI,
|
||||
QName.createValidLocalName(name));
|
||||
ChildAssociationRef assocRef = nodeService.createNode(
|
||||
parentNodeRef,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
qname,
|
||||
typeQName,
|
||||
properties);
|
||||
ChildAssociationRef assocRef = null;
|
||||
try
|
||||
{
|
||||
assocRef = nodeService.createNode(
|
||||
parentNodeRef,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
qname,
|
||||
typeQName,
|
||||
properties);
|
||||
}
|
||||
catch (DuplicateChildNodeNameException e)
|
||||
{
|
||||
throw new FileExistsException(parentNodeRef, name);
|
||||
}
|
||||
|
||||
NodeRef nodeRef = assocRef.getChildRef();
|
||||
FileInfo fileInfo = toFileInfo(nodeRef);
|
||||
// done
|
||||
@@ -716,31 +715,25 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
|
||||
NodeRef currentParentRef = parentNodeRef;
|
||||
// just loop and create if necessary
|
||||
FileInfo lastFileInfo = null;
|
||||
for (String pathElement : pathElements)
|
||||
{
|
||||
try
|
||||
// does it exist?
|
||||
NodeRef nodeRef = searchSimple(currentParentRef, pathElement);
|
||||
if (nodeRef == null)
|
||||
{
|
||||
// not present - make it
|
||||
FileInfo createdFileInfo = create(currentParentRef, pathElement, folderTypeQName);
|
||||
currentParentRef = createdFileInfo.getNodeRef();
|
||||
lastFileInfo = createdFileInfo;
|
||||
}
|
||||
catch (FileExistsException e)
|
||||
else
|
||||
{
|
||||
// it exists - just get it
|
||||
List<FileInfo> fileInfos = search(currentParentRef, pathElement, false, true, false);
|
||||
if (fileInfos.size() == 0)
|
||||
{
|
||||
// ? It must have been removed
|
||||
throw new AlfrescoRuntimeException("Path element has just been removed: " + pathElement);
|
||||
}
|
||||
currentParentRef = fileInfos.get(0).getNodeRef();
|
||||
lastFileInfo = fileInfos.get(0);
|
||||
// it exists
|
||||
currentParentRef = nodeRef;
|
||||
}
|
||||
}
|
||||
// done
|
||||
return lastFileInfo;
|
||||
FileInfo fileInfo = toFileInfo(currentParentRef);
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
public List<FileInfo> getNamePath(NodeRef rootNodeRef, NodeRef nodeRef) throws FileNotFoundException
|
||||
|
@@ -66,7 +66,8 @@ public class FileFolderServiceImplTest extends TestCase
|
||||
private static final String NAME_L1_FILE_A = "L1- File A";
|
||||
private static final String NAME_L1_FILE_B = "L1- File B";
|
||||
private static final String NAME_L1_FILE_C = "L1- File C (%_)";
|
||||
private static final String NAME_DUPLICATE = "DUPLICATE";
|
||||
private static final String NAME_CHECK_FILE = "CHECK_FILE";
|
||||
private static final String NAME_CHECK_FOLDER = "CHECK_FOLDER";
|
||||
|
||||
private static final ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
|
||||
|
||||
@@ -258,11 +259,11 @@ public class FileFolderServiceImplTest extends TestCase
|
||||
*/
|
||||
public void testGetByName() throws Exception
|
||||
{
|
||||
FileInfo fileInfo = getByName(NAME_DUPLICATE, true);
|
||||
FileInfo fileInfo = getByName(NAME_CHECK_FOLDER, true);
|
||||
assertNotNull(fileInfo);
|
||||
assertTrue(fileInfo.isFolder());
|
||||
|
||||
fileInfo = getByName(NAME_DUPLICATE, false);
|
||||
fileInfo = getByName(NAME_CHECK_FILE, false);
|
||||
assertNotNull(fileInfo);
|
||||
assertFalse(fileInfo.isFolder());
|
||||
}
|
||||
@@ -308,6 +309,10 @@ public class FileFolderServiceImplTest extends TestCase
|
||||
// make sure that it is an immediate child of the root
|
||||
List<FileInfo> checkFileInfos = fileFolderService.search(workingRootNodeRef, NAME_L1_FOLDER_A, false);
|
||||
assertEquals("Folder not moved to root", 1, checkFileInfos.size());
|
||||
// rename properly
|
||||
FileInfo checkFileInfo = fileFolderService.move(folderToMoveRef, null, "new name");
|
||||
checkFileInfos = fileFolderService.search(workingRootNodeRef, checkFileInfo.getName(), false);
|
||||
assertEquals("Folder not renamed in root", 1, checkFileInfos.size());
|
||||
// attempt illegal rename (existing)
|
||||
try
|
||||
{
|
||||
@@ -318,10 +323,6 @@ public class FileFolderServiceImplTest extends TestCase
|
||||
{
|
||||
// expected
|
||||
}
|
||||
// rename properly
|
||||
FileInfo checkFileInfo = fileFolderService.move(folderToMoveRef, null, "new name");
|
||||
checkFileInfos = fileFolderService.search(workingRootNodeRef, checkFileInfo.getName(), false);
|
||||
assertEquals("Folder not renamed in root", 1, checkFileInfos.size());
|
||||
}
|
||||
|
||||
public void testCopy() throws Exception
|
||||
@@ -495,6 +496,22 @@ public class FileFolderServiceImplTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public void testSearchSimple() throws Exception
|
||||
{
|
||||
FileInfo folderInfo = getByName(NAME_L0_FOLDER_A, true);
|
||||
assertNotNull(folderInfo);
|
||||
NodeRef folderNodeRef = folderInfo.getNodeRef();
|
||||
// search for a file that is not there
|
||||
NodeRef phantomNodeRef = fileFolderService.searchSimple(folderNodeRef, "aaaaaaa");
|
||||
assertNull("Found non-existent node by name", phantomNodeRef);
|
||||
// search for a file that is there
|
||||
NodeRef fileNodeRef = fileFolderService.searchSimple(folderNodeRef, NAME_L1_FILE_A);
|
||||
assertNotNull("Didn't find file", fileNodeRef);
|
||||
// double check
|
||||
FileInfo checkInfo = getByName(NAME_L1_FILE_A, false);
|
||||
assertEquals("Incorrect node found", checkInfo.getNodeRef(), fileNodeRef);
|
||||
}
|
||||
|
||||
public void testResolveNamePath() throws Exception
|
||||
{
|
||||
FileInfo fileInfo = getByName(NAME_L1_FILE_A, false);
|
||||
@@ -546,4 +563,20 @@ public class FileFolderServiceImplTest extends TestCase
|
||||
String checkContent = reader.getContentString();
|
||||
assertEquals("Content mismatch", content, checkContent);
|
||||
}
|
||||
|
||||
public void testLongFileNames() throws Exception
|
||||
{
|
||||
String fileName =
|
||||
"12345678901234567890123456789012345678901234567890" +
|
||||
"12345678901234567890123456789012345678901234567890" +
|
||||
"12345678901234567890123456789012345678901234567890" +
|
||||
"12345678901234567890123456789012345678901234567890" +
|
||||
"12345678901234567890123456789012345678901234567890" +
|
||||
"12345678901234567890123456789012345678901234567890";
|
||||
FileInfo fileInfo = fileFolderService.create(workingRootNodeRef, fileName, ContentModel.TYPE_CONTENT);
|
||||
// see if we can get it again
|
||||
NodeRef fileNodeRef = fileFolderService.searchSimple(workingRootNodeRef, fileName);
|
||||
assertNotNull("Long filename not found", fileNodeRef);
|
||||
assertEquals(fileInfo.getNodeRef(), fileNodeRef);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user