Merged V1.4 to HEAD

svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@3987 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4133 .
   Removed LicenseComponent reference from projects\repository\source\java\org\alfresco\repo\descriptor\DescriptorServiceImpl.java


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4135 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2006-10-17 22:42:59 +00:00
parent 4f1682e8d0
commit be167f60cf
106 changed files with 5379 additions and 2646 deletions

View File

@@ -25,6 +25,7 @@ import java.util.Map;
import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.policy.ClassPolicyDelegate;
import org.alfresco.repo.policy.JavaBehaviour;
@@ -43,6 +44,7 @@ import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.CopyService;
import org.alfresco.service.cmr.repository.CopyServiceException;
import org.alfresco.service.cmr.repository.DuplicateChildNodeNameException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
@@ -65,8 +67,12 @@ import org.alfresco.util.ParameterCheck;
*/
public class CopyServiceImpl implements CopyService
{
/** I18N labels */
private String COPY_OF_LABEL = "copy_service.copy_of_label";
/** The node service */
private NodeService nodeService;
private NodeService internalNodeService;
/** The dictionary service*/
private DictionaryService dictionaryService;
@@ -99,6 +105,16 @@ public class CopyServiceImpl implements CopyService
{
this.nodeService = nodeService;
}
/**
* Sets the internal node service
*
* @param internalNodeService the internal node service
*/
public void setInternalNodeService(NodeService internalNodeService)
{
this.internalNodeService = internalNodeService;
}
/**
* Sets the dictionary service
@@ -233,7 +249,32 @@ public class CopyServiceImpl implements CopyService
return copy;
}
public NodeRef copyAndRename(NodeRef sourceNodeRef, NodeRef destinationParent, QName destinationAssocTypeQName, QName destinationQName, boolean copyChildren)
{
// Make a note of the source name and do the copy
String sourceName = (String)this.internalNodeService.getProperty(sourceNodeRef, ContentModel.PROP_NAME);
NodeRef copy = copy(sourceNodeRef, destinationParent, destinationAssocTypeQName, destinationQName, copyChildren);
// Do the rename, iterating until a non-duplicate name is found
boolean bDone = false;
while (bDone == false)
{
try
{
this.internalNodeService.setProperty(copy, ContentModel.PROP_NAME, sourceName);
bDone = true;
}
catch(DuplicateChildNodeNameException exception)
{
sourceName = I18NUtil.getMessage(COPY_OF_LABEL, sourceName);
}
}
// Return the copy
return copy;
}
/**
* Invokes the copy complete policy for the node reference provided
*

View File

@@ -104,6 +104,7 @@ public class CopyServiceImplTest extends BaseSpringTest
private static final QName TEST_MANDATORY_ASPECT_QNAME = QName.createQName(TEST_TYPE_NAMESPACE, "testMandatoryAspect");
private static final QName PROP5_QNAME_MANDATORY = QName.createQName(TEST_TYPE_NAMESPACE, "prop5Mandatory");
private static final String TEST_NAME = "testName";
private static final String TEST_VALUE_1 = "testValue1";
private static final String TEST_VALUE_2 = "testValue2";
private static final String TEST_VALUE_3 = "testValue3";
@@ -239,6 +240,7 @@ public class CopyServiceImplTest extends BaseSpringTest
private Map<QName, Serializable> createTypePropertyBag()
{
Map<QName, Serializable> result = new HashMap<QName, Serializable>();
result.put(ContentModel.PROP_NAME, TEST_NAME);
result.put(PROP1_QNAME_MANDATORY, TEST_VALUE_1);
result.put(PROP2_QNAME_OPTIONAL, TEST_VALUE_2);
result.put(PROP5_QNAME_MANDATORY, TEST_VALUE_3);
@@ -624,6 +626,31 @@ public class CopyServiceImplTest extends BaseSpringTest
assertNotNull(value);
assertEquals(nodeTwoCopy, value);
}
public void testCopyAndRename()
{
// Check a normal copy with no dup restrictions
NodeRef copy = this.copyService.copyAndRename(
this.sourceNodeRef,
this.rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}copyAssoc"),
false);
checkCopiedNode(this.sourceNodeRef, copy, true, true, false);
assertTrue(TEST_NAME.equals(this.nodeService.getProperty(copy, ContentModel.PROP_NAME)));
// Create a folder and content node
Map<QName, Serializable> propsFolder = new HashMap<QName, Serializable>(1);
propsFolder.put(ContentModel.PROP_NAME, "tempFolder");
NodeRef folderNode = this.nodeService.createNode(this.rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}tempFolder"), ContentModel.TYPE_FOLDER, propsFolder).getChildRef();
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
props.put(ContentModel.PROP_NAME, TEST_NAME);
NodeRef contentNode = this.nodeService.createNode(folderNode, ContentModel.ASSOC_CONTAINS, QName.createQName("{test}renametest"), ContentModel.TYPE_CONTENT, props).getChildRef();
// Now copy the content node with the duplicate name restriction
NodeRef contentCopy = this.copyService.copy(contentNode, folderNode, ContentModel.ASSOC_CONTAINS, QName.createQName("{test}bobbins"), false);
assertFalse(TEST_NAME.equals(this.nodeService.getProperty(contentCopy, ContentModel.PROP_NAME)));
}
/**
* Check that the copied node contains the state we are expecting