mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
RM-978 (Unable to navigate to copied folder from a collaboration site to RM site)
* Added copy behaviour and tests git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/BRANCHES/V2.3@94263 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -23,6 +23,7 @@ import static org.alfresco.util.ParameterCheck.mandatory;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
|
||||
import org.alfresco.repo.copy.CopyServicePolicies;
|
||||
import org.alfresco.repo.node.NodeServicePolicies;
|
||||
import org.alfresco.repo.policy.annotation.Behaviour;
|
||||
import org.alfresco.repo.policy.annotation.BehaviourBean;
|
||||
@@ -41,7 +42,7 @@ import org.alfresco.service.namespace.QName;
|
||||
(
|
||||
defaultType = "cm:cmobject"
|
||||
)
|
||||
public class ObjectType extends BaseBehaviourBean implements NodeServicePolicies.OnMoveNodePolicy//, CopyServicePolicies.BeforeCopyPolicy
|
||||
public class ObjectType extends BaseBehaviourBean implements NodeServicePolicies.OnMoveNodePolicy, CopyServicePolicies.BeforeCopyPolicy
|
||||
{
|
||||
/**
|
||||
* @see org.alfresco.repo.node.NodeServicePolicies.OnMoveNodePolicy#onMoveNode(org.alfresco.service.cmr.repository.ChildAssociationRef, org.alfresco.service.cmr.repository.ChildAssociationRef)
|
||||
@@ -85,34 +86,34 @@ public class ObjectType extends BaseBehaviourBean implements NodeServicePolicies
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @see org.alfresco.repo.copy.CopyServicePolicies.BeforeCopyPolicy#beforeCopy(org.alfresco.service.namespace.QName, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
|
||||
// */
|
||||
// @Override
|
||||
// @Behaviour
|
||||
// (
|
||||
// kind = BehaviourKind.CLASS
|
||||
// )
|
||||
// public void beforeCopy(QName classRef, NodeRef sourceNodeRef, NodeRef targetNodeRef)
|
||||
// {
|
||||
// mandatory("sourceNodeRef", sourceNodeRef);
|
||||
// mandatory("targetNodeRef", targetNodeRef);
|
||||
//
|
||||
// NodeRef sourceParentNodeRef = nodeService.getPrimaryParent(sourceNodeRef).getParentRef();
|
||||
// boolean isSourceParentFilePlanComponent = isFilePlanComponent(sourceParentNodeRef);
|
||||
// boolean isTargetNodeFilePlanComponent = isFilePlanComponent(targetNodeRef);
|
||||
//
|
||||
// // If we are doing the copy operation within the RM site then we can stop here
|
||||
// // The method should just check copy operations from outside of RM into the RM site
|
||||
// if (isSourceParentFilePlanComponent && isTargetNodeFilePlanComponent)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // Do not allow to copy anything outside of RM site into the RM site
|
||||
// if (!isSourceParentFilePlanComponent && isTargetNodeFilePlanComponent)
|
||||
// {
|
||||
// throw new AlfrescoRuntimeException("Nothing can be copied from a collaboration site into a RM site.");
|
||||
// }
|
||||
// }
|
||||
/**
|
||||
* @see org.alfresco.repo.copy.CopyServicePolicies.BeforeCopyPolicy#beforeCopy(org.alfresco.service.namespace.QName, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
@Behaviour
|
||||
(
|
||||
kind = BehaviourKind.CLASS
|
||||
)
|
||||
public void beforeCopy(QName classRef, NodeRef sourceNodeRef, NodeRef targetNodeRef)
|
||||
{
|
||||
mandatory("sourceNodeRef", sourceNodeRef);
|
||||
mandatory("targetNodeRef", targetNodeRef);
|
||||
|
||||
NodeRef sourceParentNodeRef = nodeService.getPrimaryParent(sourceNodeRef).getParentRef();
|
||||
boolean isSourceParentFilePlanComponent = isFilePlanComponent(sourceParentNodeRef);
|
||||
boolean isTargetNodeFilePlanComponent = isFilePlanComponent(targetNodeRef);
|
||||
|
||||
// If we are doing the copy operation within the RM site then we can stop here
|
||||
// The method should just check copy operations from outside of RM into the RM site
|
||||
if (isSourceParentFilePlanComponent && isTargetNodeFilePlanComponent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Do not allow to copy anything outside of RM site into the RM site
|
||||
if (!isSourceParentFilePlanComponent && isTargetNodeFilePlanComponent)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Nothing can be copied from a collaboration site into a RM site.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -100,13 +100,13 @@ public class RM978Test extends BaseRMTestCase
|
||||
public void given()
|
||||
{
|
||||
folder1 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
document1 = fileFolderService.create(folder1, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
document1 = fileFolderService.create(folder1, document1Name, ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
folder2 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
}
|
||||
|
||||
public void when() throws FileExistsException, FileNotFoundException
|
||||
{
|
||||
fileFolderService.move(document1, folder2, document1Name);
|
||||
fileFolderService.move(document1, folder2, null);
|
||||
}
|
||||
|
||||
public void then()
|
||||
@@ -482,4 +482,387 @@ public class RM978Test extends BaseRMTestCase
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testCopyDocumentToFolderInCollabSite()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(user)
|
||||
{
|
||||
private NodeRef folder1;
|
||||
private NodeRef folder2;
|
||||
private NodeRef document1;
|
||||
private String document1Name = GUID.generate();
|
||||
|
||||
public void given()
|
||||
{
|
||||
folder1 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
document1 = fileFolderService.create(folder1, document1Name, ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
folder2 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
}
|
||||
|
||||
public void when() throws FileExistsException, FileNotFoundException
|
||||
{
|
||||
fileFolderService.copy(document1, folder2, null);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
List<ChildAssociationRef> folder1ChildAssocs = nodeService.getChildAssocs(folder1);
|
||||
assertEquals(1, folder1ChildAssocs.size());
|
||||
|
||||
List<ChildAssociationRef> folder2ChildAssocs = nodeService.getChildAssocs(folder2);
|
||||
assertNotNull(folder2ChildAssocs);
|
||||
assertEquals(1, folder2ChildAssocs.size());
|
||||
NodeRef movedDocument = folder2ChildAssocs.iterator().next().getChildRef();
|
||||
String movedDocumentName = (String) nodeService.getProperty(movedDocument, ContentModel.PROP_NAME);
|
||||
assertEquals(document1Name, movedDocumentName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testCopyDocumentToDocumentLibraryInCollabSite()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(user)
|
||||
{
|
||||
private NodeRef folder1;
|
||||
private NodeRef document1;
|
||||
private String document1Name = GUID.generate();
|
||||
|
||||
public void given()
|
||||
{
|
||||
folder1 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
document1 = fileFolderService.create(folder1, document1Name, ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
}
|
||||
|
||||
public void when() throws FileExistsException, FileNotFoundException
|
||||
{
|
||||
fileFolderService.copy(document1, documentLibrary, null);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
List<ChildAssociationRef> folder1ChildAssocs = nodeService.getChildAssocs(folder1);
|
||||
assertEquals(1, folder1ChildAssocs.size());
|
||||
|
||||
List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(documentLibrary);
|
||||
assertNotNull(childAssocs);
|
||||
|
||||
List<String> childNames = new ArrayList<String>();
|
||||
for (ChildAssociationRef childAssociationRef : childAssocs)
|
||||
{
|
||||
NodeRef childRef = childAssociationRef.getChildRef();
|
||||
childNames.add((String) nodeService.getProperty(childRef, ContentModel.PROP_NAME));
|
||||
}
|
||||
|
||||
assertTrue(childNames.contains(document1Name));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testCopyFolderToFolderInCollabSite()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(user)
|
||||
{
|
||||
private NodeRef folder1;
|
||||
private NodeRef folder2;
|
||||
private String folder1Name = GUID.generate();
|
||||
|
||||
public void given()
|
||||
{
|
||||
folder1 = fileFolderService.create(documentLibrary, folder1Name, ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
folder2 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
}
|
||||
|
||||
public void when() throws FileExistsException, FileNotFoundException
|
||||
{
|
||||
fileFolderService.copy(folder1, folder2, null);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
List<ChildAssociationRef> folder2ChildAssocs = nodeService.getChildAssocs(folder2);
|
||||
assertEquals(1, folder2ChildAssocs.size());
|
||||
NodeRef movedFolder = folder2ChildAssocs.iterator().next().getChildRef();
|
||||
String movedDocumentName = (String) nodeService.getProperty(movedFolder, ContentModel.PROP_NAME);
|
||||
assertEquals(folder1Name, movedDocumentName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testCopyDocumentToFolderInDifferentCollabSite()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(user)
|
||||
{
|
||||
private NodeRef folder1;
|
||||
private NodeRef folder2;
|
||||
private NodeRef document1;
|
||||
private String document1Name = GUID.generate();
|
||||
|
||||
public void given()
|
||||
{
|
||||
folder1 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
document1 = fileFolderService.create(folder1, document1Name, ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
folder2 = fileFolderService.create(documentLibrary2, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
}
|
||||
|
||||
public void when() throws FileExistsException, FileNotFoundException
|
||||
{
|
||||
fileFolderService.copy(document1, folder2, null);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
List<ChildAssociationRef> folder1ChildAssocs = nodeService.getChildAssocs(folder1);
|
||||
assertEquals(1, folder1ChildAssocs.size());
|
||||
|
||||
List<ChildAssociationRef> folder2ChildAssocs = nodeService.getChildAssocs(folder2);
|
||||
assertNotNull(folder2ChildAssocs);
|
||||
assertEquals(1, folder2ChildAssocs.size());
|
||||
NodeRef movedDocument = folder2ChildAssocs.iterator().next().getChildRef();
|
||||
String movedDocumentName = (String) nodeService.getProperty(movedDocument, ContentModel.PROP_NAME);
|
||||
assertEquals(document1Name, movedDocumentName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testCopyDocumentToDocumentLibraryInDifferentCollabSite()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(user)
|
||||
{
|
||||
private NodeRef folder1;
|
||||
private NodeRef document1;
|
||||
private String document1Name = GUID.generate();
|
||||
|
||||
public void given()
|
||||
{
|
||||
folder1 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
document1 = fileFolderService.create(folder1, document1Name, ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
}
|
||||
|
||||
public void when() throws FileExistsException, FileNotFoundException
|
||||
{
|
||||
fileFolderService.copy(document1, documentLibrary2, null);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
List<ChildAssociationRef> folder1ChildAssocs = nodeService.getChildAssocs(folder1);
|
||||
assertEquals(1, folder1ChildAssocs.size());
|
||||
|
||||
List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(documentLibrary2);
|
||||
assertNotNull(childAssocs);
|
||||
|
||||
List<String> childNames = new ArrayList<String>();
|
||||
for (ChildAssociationRef childAssociationRef : childAssocs)
|
||||
{
|
||||
NodeRef childRef = childAssociationRef.getChildRef();
|
||||
childNames.add((String) nodeService.getProperty(childRef, ContentModel.PROP_NAME));
|
||||
}
|
||||
|
||||
assertTrue(childNames.contains(document1Name));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testCopyFolderToFolderInDifferentCollabSite()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(user)
|
||||
{
|
||||
private NodeRef folder1;
|
||||
private NodeRef folder2;
|
||||
private String folder1Name = GUID.generate();
|
||||
|
||||
public void given()
|
||||
{
|
||||
folder1 = fileFolderService.create(documentLibrary, folder1Name, ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
folder2 = fileFolderService.create(documentLibrary2, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
}
|
||||
|
||||
public void when() throws FileExistsException, FileNotFoundException
|
||||
{
|
||||
fileFolderService.copy(folder1, folder2, null);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
List<ChildAssociationRef> folder2ChildAssocs = nodeService.getChildAssocs(folder2);
|
||||
assertEquals(1, folder2ChildAssocs.size());
|
||||
NodeRef movedFolder = folder2ChildAssocs.iterator().next().getChildRef();
|
||||
String movedDocumentName = (String) nodeService.getProperty(movedFolder, ContentModel.PROP_NAME);
|
||||
assertEquals(folder1Name, movedDocumentName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testCopyDocumentInFilePlanInRmSite()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(AlfrescoRuntimeException.class, user)
|
||||
{
|
||||
private NodeRef folder1;
|
||||
private NodeRef document1;
|
||||
|
||||
public void given()
|
||||
{
|
||||
folder1 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
document1 = fileFolderService.create(folder1, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
}
|
||||
|
||||
public void when() throws FileExistsException, FileNotFoundException
|
||||
{
|
||||
fileFolderService.copy(document1, filePlan, GUID.generate());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testCopyDocumentInCategoryInRmSite()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(AlfrescoRuntimeException.class, user)
|
||||
{
|
||||
private NodeRef folder1;
|
||||
private NodeRef document1;
|
||||
private NodeRef rmCategory;
|
||||
|
||||
public void given()
|
||||
{
|
||||
folder1 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
document1 = fileFolderService.create(folder1, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
|
||||
runAs(new RunAsWork<Void>()
|
||||
{
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
rmCategory = filePlanService.createRecordCategory(filePlan, GUID.generate());
|
||||
|
||||
return null;
|
||||
}
|
||||
}, getAdminUserName());
|
||||
}
|
||||
|
||||
public void when() throws FileExistsException, FileNotFoundException
|
||||
{
|
||||
fileFolderService.copy(document1, rmCategory, GUID.generate());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testCopyDocumentInFolderInRmSite()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(AlfrescoRuntimeException.class, user)
|
||||
{
|
||||
private NodeRef folder1;
|
||||
private NodeRef document1;
|
||||
private String document1Name = GUID.generate();
|
||||
private NodeRef rmCategory;
|
||||
private NodeRef rmFolder;
|
||||
|
||||
public void given()
|
||||
{
|
||||
folder1 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
document1 = fileFolderService.create(folder1, document1Name, ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
|
||||
runAs(new RunAsWork<Void>()
|
||||
{
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
rmCategory = filePlanService.createRecordCategory(filePlan, GUID.generate());
|
||||
rmFolder = recordFolderService.createRecordFolder(rmCategory, GUID.generate());
|
||||
|
||||
return null;
|
||||
}
|
||||
}, getAdminUserName());
|
||||
}
|
||||
|
||||
public void when() throws FileExistsException, FileNotFoundException
|
||||
{
|
||||
runAs(new RunAsWork<Void>()
|
||||
{
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
filePlanPermissionService.setPermission(rmFolder, user, RMPermissionModel.FILING);
|
||||
|
||||
return null;
|
||||
}
|
||||
}, getAdminUserName());
|
||||
|
||||
fileFolderService.copy(document1, rmFolder, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testCopyFolderInFilePlanInRmSite()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(AlfrescoRuntimeException.class, user)
|
||||
{
|
||||
private NodeRef folder1;
|
||||
|
||||
public void given()
|
||||
{
|
||||
folder1 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
}
|
||||
|
||||
public void when() throws FileExistsException, FileNotFoundException
|
||||
{
|
||||
fileFolderService.copy(folder1, filePlan, GUID.generate());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testCopyFolderInCategoryInRmSite()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(AlfrescoRuntimeException.class, user)
|
||||
{
|
||||
private NodeRef folder1;
|
||||
private NodeRef rmCategory;
|
||||
|
||||
public void given()
|
||||
{
|
||||
folder1 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
|
||||
runAs(new RunAsWork<Void>()
|
||||
{
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
rmCategory = filePlanService.createRecordCategory(filePlan, GUID.generate());
|
||||
|
||||
return null;
|
||||
}
|
||||
}, getAdminUserName());
|
||||
}
|
||||
|
||||
public void when() throws FileExistsException, FileNotFoundException
|
||||
{
|
||||
fileFolderService.copy(folder1, rmCategory, GUID.generate());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testCopyFolderInFolderInRmSite()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(AlfrescoRuntimeException.class, user)
|
||||
{
|
||||
private NodeRef folder1;
|
||||
private NodeRef rmCategory;
|
||||
private NodeRef rmFolder;
|
||||
|
||||
public void given()
|
||||
{
|
||||
folder1 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
|
||||
runAs(new RunAsWork<Void>()
|
||||
{
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
rmCategory = filePlanService.createRecordCategory(filePlan, GUID.generate());
|
||||
rmFolder = recordFolderService.createRecordFolder(rmCategory, GUID.generate());
|
||||
|
||||
return null;
|
||||
}
|
||||
}, getAdminUserName());
|
||||
}
|
||||
|
||||
public void when() throws FileExistsException, FileNotFoundException
|
||||
{
|
||||
fileFolderService.copy(folder1, rmFolder, GUID.generate());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user