mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged 5.0.N (5.0.4) to 5.1.N (5.1.2)
123996 sglover: MNT-15655 "Possible to violate child cm:name uniqueness constraint via NodeService.addAspect" git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.1.N/root@124096 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -817,6 +817,8 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
|
|||||||
|
|
||||||
// Add aspect and defaults
|
// Add aspect and defaults
|
||||||
Pair<Long, NodeRef> nodePair = getNodePairNotNull(nodeRef);
|
Pair<Long, NodeRef> nodePair = getNodePairNotNull(nodeRef);
|
||||||
|
// SetProperties common tasks
|
||||||
|
setPropertiesCommonWork(nodePair, aspectProperties);
|
||||||
boolean modified = addAspectsAndProperties(
|
boolean modified = addAspectsAndProperties(
|
||||||
nodePair,
|
nodePair,
|
||||||
aspectTypeQName,
|
aspectTypeQName,
|
||||||
|
@@ -21,6 +21,7 @@ package org.alfresco.repo.node.db;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -36,22 +37,27 @@ import org.alfresco.repo.domain.schema.SchemaBootstrap;
|
|||||||
import org.alfresco.repo.node.BaseNodeServiceTest;
|
import org.alfresco.repo.node.BaseNodeServiceTest;
|
||||||
import org.alfresco.repo.node.cleanup.NodeCleanupRegistry;
|
import org.alfresco.repo.node.cleanup.NodeCleanupRegistry;
|
||||||
import org.alfresco.repo.node.db.NodeStringLengthWorker.NodeStringLengthWorkResult;
|
import org.alfresco.repo.node.db.NodeStringLengthWorker.NodeStringLengthWorkResult;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||||
import org.alfresco.repo.transaction.TransactionListenerAdapter;
|
import org.alfresco.repo.transaction.TransactionListenerAdapter;
|
||||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
|
import org.alfresco.service.cmr.repository.DuplicateChildNodeNameException;
|
||||||
import org.alfresco.service.cmr.repository.MLText;
|
import org.alfresco.service.cmr.repository.MLText;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||||
import org.alfresco.service.transaction.TransactionService;
|
import org.alfresco.service.transaction.TransactionService;
|
||||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||||
import org.alfresco.util.Pair;
|
import org.alfresco.util.Pair;
|
||||||
import org.junit.experimental.categories.Category;
|
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.dialect.MySQLInnoDBDialect;
|
import org.hibernate.dialect.MySQLInnoDBDialect;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.experimental.categories.Category;
|
||||||
import org.springframework.context.event.ContextRefreshedEvent;
|
import org.springframework.context.event.ContextRefreshedEvent;
|
||||||
import org.springframework.extensions.surf.util.I18NUtil;
|
import org.springframework.extensions.surf.util.I18NUtil;
|
||||||
|
|
||||||
@@ -785,4 +791,111 @@ public class DbNodeServiceImplTest extends BaseNodeServiceTest
|
|||||||
});
|
});
|
||||||
assertEquals("String manipulation corrupted the long string value. ", longString, checkLongString);
|
assertEquals("String manipulation corrupted the long string value. ", longString, checkLongString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMNT15655() throws Exception {
|
||||||
|
class TestData
|
||||||
|
{
|
||||||
|
NodeRef rootFolderNodeRef;
|
||||||
|
NodeRef folder1NodeRef;
|
||||||
|
NodeRef folder2NodeRef;
|
||||||
|
String folder1Name;
|
||||||
|
String folder2Name;
|
||||||
|
}
|
||||||
|
final TestData testData = new TestData();
|
||||||
|
|
||||||
|
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Void>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Void execute() throws Throwable
|
||||||
|
{
|
||||||
|
AuthenticationUtil.runAs(new RunAsWork<Void>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Void doWork() throws Exception {
|
||||||
|
Map<QName, Serializable> properties = new HashMap<>();
|
||||||
|
|
||||||
|
StoreRef storeRef = nodeService.createStore(
|
||||||
|
StoreRef.PROTOCOL_WORKSPACE,
|
||||||
|
"Test_" + System.currentTimeMillis());
|
||||||
|
NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
|
||||||
|
|
||||||
|
testData.rootFolderNodeRef = nodeService.createNode(
|
||||||
|
rootNodeRef,
|
||||||
|
ContentModel.ASSOC_CHILDREN,
|
||||||
|
QName.createQName(NAMESPACE, "rootFolder"),
|
||||||
|
ContentModel.TYPE_FOLDER,
|
||||||
|
properties).getChildRef();
|
||||||
|
|
||||||
|
properties.clear();
|
||||||
|
properties.put(ContentModel.PROP_NAME, "folder");
|
||||||
|
testData.folder1NodeRef = nodeService.createNode(
|
||||||
|
testData.rootFolderNodeRef,
|
||||||
|
ContentModel.ASSOC_CONTAINS,
|
||||||
|
QName.createQName(NAMESPACE, "folder"),
|
||||||
|
ContentModel.TYPE_FOLDER,
|
||||||
|
properties).getChildRef();
|
||||||
|
|
||||||
|
properties.clear();
|
||||||
|
properties.put(ContentModel.PROP_NAME, "folder1");
|
||||||
|
testData.folder2NodeRef = nodeService.createNode(
|
||||||
|
testData.rootFolderNodeRef,
|
||||||
|
ContentModel.ASSOC_CONTAINS,
|
||||||
|
QName.createQName(NAMESPACE, "folder1"),
|
||||||
|
ContentModel.TYPE_FOLDER,
|
||||||
|
properties).getChildRef();
|
||||||
|
|
||||||
|
String name1 = (String)nodeService.getProperty(
|
||||||
|
testData.folder1NodeRef,
|
||||||
|
ContentModel.PROP_NAME);
|
||||||
|
String name2 = (String)nodeService.getProperty(
|
||||||
|
testData.folder2NodeRef,
|
||||||
|
ContentModel.PROP_NAME);
|
||||||
|
|
||||||
|
assertEquals("folder", name1);
|
||||||
|
assertEquals("folder1", name2);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}, AuthenticationUtil.SYSTEM_USER_NAME);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, false, true);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Void>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Void execute() throws Throwable
|
||||||
|
{
|
||||||
|
AuthenticationUtil.runAs(new RunAsWork<Void>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Void doWork() throws Exception {
|
||||||
|
Map<QName, Serializable> aspectProperties = new HashMap<>();
|
||||||
|
aspectProperties.put(ContentModel.PROP_NAME, "folder");
|
||||||
|
nodeService.addAspect(
|
||||||
|
testData.folder2NodeRef,
|
||||||
|
ContentModel.ASPECT_AUTHOR,
|
||||||
|
aspectProperties);
|
||||||
|
|
||||||
|
fail("Should have generated a DuplicateChildNodeNameException");
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}, AuthenticationUtil.SYSTEM_USER_NAME);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, false, true);
|
||||||
|
}
|
||||||
|
catch(DuplicateChildNodeNameException e)
|
||||||
|
{
|
||||||
|
// ok
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user