mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged DEV to HEAD:
54373: MNT-2641 : User can delete or move a working copy 54469: Compilation fix for MNT-2641 test 54470: Removed thousands of tabs 54523: Fixed ALF-19843: Integrity checking does not enforce mandatory aspects on aspects 54525: Pull IntegrityChecker properties into property file (ALF-19843) 54527: Fixed Eclipse warning about potentially unclosed file 54528: Prevent cm:workingcopy aspect from being removed directly (MNT-2641) 54529: Nail down behaviour around cm:workingcopy git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@54798 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -162,30 +162,14 @@
|
||||
|
||||
<!-- ensures model-compliance of node structures -->
|
||||
<bean id="integrityChecker" class="org.alfresco.repo.node.integrity.IntegrityChecker" init-method="init">
|
||||
<property name="policyComponent">
|
||||
<ref bean="policyComponent"/>
|
||||
</property>
|
||||
<property name="dictionaryService">
|
||||
<ref bean="dictionaryService" />
|
||||
</property>
|
||||
<property name="nodeService">
|
||||
<ref bean="nodeService" />
|
||||
</property>
|
||||
<property name="tenantService">
|
||||
<ref bean="tenantService" />
|
||||
</property>
|
||||
<property name="enabled">
|
||||
<value>true</value> <!-- on/off switch -->
|
||||
</property>
|
||||
<property name="traceOn">
|
||||
<value>false</value> <!-- use only to trace problems -->
|
||||
</property>
|
||||
<property name="failOnViolation" >
|
||||
<value>true</value>
|
||||
</property>
|
||||
<property name="maxErrorsPerTransaction" >
|
||||
<value>5</value> <!-- limit output (exception and log) to the first N violation messages -->
|
||||
</property>
|
||||
<property name="policyComponent" ref="policyComponent"/>
|
||||
<property name="dictionaryService" ref="dictionaryService" />
|
||||
<property name="nodeService" ref="nodeService" />
|
||||
<property name="tenantService" ref="tenantService" />
|
||||
<property name="enabled" value="${system.integrity.enabled}" />
|
||||
<property name="traceOn" value="${system.integrity.trace}" />
|
||||
<property name="failOnViolation" value="${system.integrity.failOnViolation}" />
|
||||
<property name="maxErrorsPerTransaction" value="5" />
|
||||
<property name="storesToIgnore">
|
||||
<list>
|
||||
<value>${version.store.version2Store}</value>
|
||||
|
@@ -217,6 +217,19 @@ system.hibernateMaxExecutions=20000
|
||||
# 'propagateTimestamps' element in the dictionary definition.
|
||||
system.enableTimestampPropagation=true
|
||||
|
||||
#
|
||||
# Enable system model integrity checking.
|
||||
# WARNING: Changing this is unsupported; bugs may corrupt data
|
||||
system.integrity.enabled=true
|
||||
# Do integrity violations fail transactions
|
||||
# WARNING: Changing this is unsupported; bugs may corrupt data
|
||||
system.integrity.failOnViolation=true
|
||||
# The number of errors to report when violations are detected
|
||||
system.integrity.maxErrorsPerTransaction=5
|
||||
# Add call stacks to integrity events so that errors are logged with possible causes
|
||||
# WARNING: This is expensive and should only be switched on for diagnostic purposes
|
||||
system.integrity.trace=false
|
||||
|
||||
#
|
||||
# Decide if content should be removed from the system immediately after being orphaned.
|
||||
# Do not change this unless you have examined the impact it has on your backup procedures.
|
||||
|
@@ -229,6 +229,7 @@ public class CopiedFromAspectPatch extends AbstractPatch
|
||||
}
|
||||
finally
|
||||
{
|
||||
try { outputFile.close(); } catch (IOException e) {}
|
||||
try { file.close(); } catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ package org.alfresco.repo.coci;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
@@ -34,12 +35,13 @@ import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
|
||||
import org.alfresco.service.cmr.lock.LockService;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
|
||||
public class WorkingCopyAspect implements CopyServicePolicies.OnCopyNodePolicy
|
||||
public class WorkingCopyAspect implements CopyServicePolicies.OnCopyNodePolicy, NodeServicePolicies.OnRemoveAspectPolicy
|
||||
{
|
||||
private PolicyComponent policyComponent;
|
||||
private NodeService nodeService;
|
||||
@@ -117,7 +119,12 @@ public class WorkingCopyAspect implements CopyServicePolicies.OnCopyNodePolicy
|
||||
NodeServicePolicies.BeforeDeleteNodePolicy.QNAME,
|
||||
ContentModel.ASPECT_WORKING_COPY,
|
||||
new JavaBehaviour(this, "beforeDeleteWorkingCopy"));
|
||||
// register onBeforeDelete class behaviour for the checked-out aspect
|
||||
|
||||
// Watch for removal of the aspect and ensure that the cm:workingcopylink assoc is removed
|
||||
this.policyComponent.bindClassBehaviour(
|
||||
NodeServicePolicies.OnRemoveAspectPolicy.QNAME,
|
||||
ContentModel.ASPECT_WORKING_COPY,
|
||||
new JavaBehaviour(this, "onRemoveAspect"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,6 +150,13 @@ public class WorkingCopyAspect implements CopyServicePolicies.OnCopyNodePolicy
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemoveAspect(NodeRef nodeRef, QName aspectTypeQName)
|
||||
{
|
||||
// This is simply not allowed.
|
||||
throw new UnsupportedOperationException("Use CheckOutCheckInservice to manipulate working copies.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns {@link WorkingCopyAspectCopyBehaviourCallback}
|
||||
*/
|
||||
|
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.alfresco.repo.node.integrity;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -77,7 +78,9 @@ public class AspectsIntegrityEvent extends AbstractIntegrityEvent
|
||||
QName nodeTypeQName = nodeService.getType(nodeRef);
|
||||
// get the aspects that should exist
|
||||
TypeDefinition typeDef = dictionaryService.getType(nodeTypeQName);
|
||||
List<AspectDefinition> mandatoryAspectDefs = typeDef.getDefaultAspects();
|
||||
List<AspectDefinition> mandatoryAspectDefs = (typeDef == null)
|
||||
? Collections.<AspectDefinition>emptyList()
|
||||
: typeDef.getDefaultAspects();
|
||||
|
||||
// check
|
||||
for (AspectDefinition aspect : mandatoryAspectDefs)
|
||||
@@ -96,6 +99,32 @@ public class AspectsIntegrityEvent extends AbstractIntegrityEvent
|
||||
// next one
|
||||
continue;
|
||||
}
|
||||
|
||||
// Now, each aspect's mandatory aspects have to be checked
|
||||
for (QName aspectQName : aspects)
|
||||
{
|
||||
AspectDefinition aspectDef = dictionaryService.getAspect(aspectQName);
|
||||
mandatoryAspectDefs = (aspectDef == null)
|
||||
? Collections.<AspectDefinition>emptyList()
|
||||
: aspectDef.getDefaultAspects();
|
||||
for (AspectDefinition aspect : mandatoryAspectDefs)
|
||||
{
|
||||
if (aspects.contains(aspect.getName()))
|
||||
{
|
||||
// it's fine
|
||||
continue;
|
||||
}
|
||||
IntegrityRecord result = new IntegrityRecord(
|
||||
"Mandatory aspect (aspect-declared) not set: \n" +
|
||||
" Node: " + nodeRef + "\n" +
|
||||
" Aspect: " + aspectQName + "\n" +
|
||||
" Missing: " + aspect.getName());
|
||||
eventResults.add(result);
|
||||
// next one
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// done
|
||||
}
|
||||
}
|
||||
|
@@ -26,14 +26,21 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.acegisecurity.AccessDeniedException;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.node.integrity.IntegrityException;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.repo.version.VersionModel;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
|
||||
import org.alfresco.service.cmr.lock.LockService;
|
||||
import org.alfresco.service.cmr.lock.NodeLockedException;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
@@ -41,11 +48,13 @@ 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.MLText;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.version.Version;
|
||||
import org.alfresco.service.cmr.version.VersionService;
|
||||
import org.alfresco.service.cmr.version.VersionType;
|
||||
@@ -54,6 +63,7 @@ import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.BaseSpringTest;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.PropertyMap;
|
||||
import org.alfresco.util.TestWithUserUtils;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
@@ -76,6 +86,8 @@ public class CheckOutCheckInServiceImplTest extends BaseSpringTest
|
||||
private TransactionService transactionService;
|
||||
private PermissionService permissionService;
|
||||
private CopyService copyService;
|
||||
private PersonService personService;
|
||||
private FileFolderService fileFolderService;
|
||||
|
||||
/**
|
||||
* Data used by the tests
|
||||
@@ -113,7 +125,6 @@ public class CheckOutCheckInServiceImplTest extends BaseSpringTest
|
||||
throws Exception
|
||||
{
|
||||
// Set the services
|
||||
this.nodeService = (NodeService)this.applicationContext.getBean("nodeService");
|
||||
this.cociService = (CheckOutCheckInService)this.applicationContext.getBean("checkOutCheckInService");
|
||||
this.contentService = (ContentService)this.applicationContext.getBean("contentService");
|
||||
this.versionService = (VersionService)this.applicationContext.getBean("versionService");
|
||||
@@ -122,6 +133,10 @@ public class CheckOutCheckInServiceImplTest extends BaseSpringTest
|
||||
this.transactionService = (TransactionService)this.applicationContext.getBean("transactionComponent");
|
||||
this.permissionService = (PermissionService)this.applicationContext.getBean("permissionService");
|
||||
this.copyService = (CopyService)this.applicationContext.getBean("copyService");
|
||||
this.personService = (PersonService) this.applicationContext.getBean("PersonService");
|
||||
ServiceRegistry serviceRegistry = (ServiceRegistry) this.applicationContext.getBean("ServiceRegistry");
|
||||
this.fileFolderService = serviceRegistry.getFileFolderService();
|
||||
this.nodeService = serviceRegistry.getNodeService();
|
||||
|
||||
// Authenticate as system to create initial test data set
|
||||
AuthenticationComponent authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");
|
||||
@@ -1051,4 +1066,371 @@ public class CheckOutCheckInServiceImplTest extends BaseSpringTest
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* MNT-2641
|
||||
* <p/>
|
||||
* Creating a document and working copy. Then try to move working copy to another place. Test is passed, if a working copy was moved to another place with original
|
||||
* document. Only the lock owner can move documents.
|
||||
*/
|
||||
public void testMoveOriginalWithWorkingCopy()
|
||||
{
|
||||
// Create a FolderA
|
||||
final NodeRef folderA = createFolder("MoveOriginalWithWorkingCopy_" + GUID.generate());
|
||||
|
||||
// Create a FolderB
|
||||
final NodeRef folderB = createFolder("MoveOriginalWithWorkingCopy_" + GUID.generate());
|
||||
|
||||
// Create content in FolderA, that allowed to move for current user
|
||||
NodeRef origAllowed = createContent("original_" + GUID.generate(), folderA);
|
||||
|
||||
// Check out the document, that allowed to move for current user
|
||||
NodeRef workingCopyAllowed = this.cociService.checkout(origAllowed);
|
||||
assertNotNull(workingCopyAllowed);
|
||||
|
||||
// Create content in FolderA, that doesn't allowed to move for other users
|
||||
final NodeRef origDenied = createContent("original_" + GUID.generate(), folderA);
|
||||
|
||||
// Check out the document, that doesn't allowed to move for other users
|
||||
final NodeRef workingCopyDenied = this.cociService.checkout(origDenied);
|
||||
assertNotNull(workingCopyDenied);
|
||||
|
||||
// Move working copy to folderB
|
||||
NodeRef movedWorkingCopyAllowed = null;
|
||||
try
|
||||
{
|
||||
movedWorkingCopyAllowed = fileFolderService.moveFrom(workingCopyAllowed, folderA, folderB, null).getNodeRef();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// do nothing. Assert condition checks it further
|
||||
}
|
||||
|
||||
assertNotNull(movedWorkingCopyAllowed);
|
||||
|
||||
// check a parent of moved working copy - it must be folderB
|
||||
assertEquals(folderB, nodeService.getPrimaryParent(movedWorkingCopyAllowed).getParentRef());
|
||||
|
||||
boolean thrown = false;
|
||||
|
||||
// check a parent of original document - it must be folderA
|
||||
assertEquals(folderA, nodeService.getPrimaryParent(origAllowed).getParentRef());
|
||||
|
||||
// try to move original - action must be denied
|
||||
try
|
||||
{
|
||||
fileFolderService.moveFrom(origAllowed, folderA, folderB, null).getNodeRef();
|
||||
}
|
||||
catch (NodeLockedException e1)
|
||||
{
|
||||
thrown = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// do nothing. Assert condition checks it further
|
||||
}
|
||||
assertTrue(thrown);
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// testing "move" actions with non-owner user //
|
||||
////////////////////////////////////////////////
|
||||
|
||||
// create another person
|
||||
final String denyUser = "COCITestUser123";
|
||||
createPerson(denyUser);
|
||||
|
||||
// try to move a working copy. User hasn't permissions to move
|
||||
thrown = false;
|
||||
try
|
||||
{
|
||||
AuthenticationUtil.runAs(new RunAsWork<NodeRef>()
|
||||
{
|
||||
@Override
|
||||
public NodeRef doWork() throws Exception
|
||||
{
|
||||
return fileFolderService.moveFrom(workingCopyDenied, folderA, folderB, null).getNodeRef();
|
||||
}
|
||||
}, denyUser);
|
||||
}
|
||||
catch (AccessDeniedException e)
|
||||
{
|
||||
thrown = true;
|
||||
}
|
||||
catch (org.alfresco.repo.security.permissions.AccessDeniedException e)
|
||||
{
|
||||
thrown = true;
|
||||
}
|
||||
assertTrue(thrown);
|
||||
|
||||
//try to move a original file. User hasn't permissions to move
|
||||
thrown = false;
|
||||
try
|
||||
{
|
||||
AuthenticationUtil.runAs(new RunAsWork<NodeRef>()
|
||||
{
|
||||
@Override
|
||||
public NodeRef doWork() throws Exception
|
||||
{
|
||||
return fileFolderService.moveFrom(origDenied, folderA, folderB, null).getNodeRef();
|
||||
}
|
||||
}, denyUser);
|
||||
}
|
||||
catch (AccessDeniedException e)
|
||||
{
|
||||
thrown = true;
|
||||
}
|
||||
catch (org.alfresco.repo.security.permissions.AccessDeniedException e)
|
||||
{
|
||||
thrown = true;
|
||||
}
|
||||
assertTrue(thrown);
|
||||
}
|
||||
|
||||
/**
|
||||
* MNT-2641
|
||||
* <p/>
|
||||
* Original cannot be deleted while it is checked out. No one should be able to delete or update the original.
|
||||
*/
|
||||
public void testDeleteUpdateOriginalOfCheckedOutDocument()
|
||||
{
|
||||
// Create a FolderA
|
||||
final NodeRef folderA = createFolder("DeleteUpdateOriginalOfCheckedOutDocument_" + GUID.generate());
|
||||
|
||||
// Create content in FolderA
|
||||
final NodeRef orig = createContent("original_" + GUID.generate(), folderA);
|
||||
|
||||
// Check out the document
|
||||
NodeRef workingCopy = this.cociService.checkout(orig);
|
||||
assertNotNull(workingCopy);
|
||||
|
||||
boolean thrown = false;
|
||||
|
||||
// try to delete original, that has working copy - must be denied
|
||||
try
|
||||
{
|
||||
fileFolderService.delete(orig);
|
||||
}
|
||||
catch (NodeLockedException e)
|
||||
{
|
||||
thrown = true;
|
||||
}
|
||||
assertTrue("No one should be able to delete the original", thrown);
|
||||
|
||||
// creating a properties
|
||||
final Map<QName, Serializable> propsToPersist = new HashMap<QName, Serializable>(3);
|
||||
MLText value = new MLText(Locale.ENGLISH, GUID.generate() + "");
|
||||
propsToPersist.put(ContentModel.PROP_DESCRIPTION, value);
|
||||
value = new MLText(Locale.ENGLISH, null);
|
||||
propsToPersist.put(ContentModel.PROP_TITLE, value);
|
||||
|
||||
// try to modify properties of original, that has working copy - must be denied
|
||||
thrown = false;
|
||||
try
|
||||
{
|
||||
nodeService.addProperties(orig, propsToPersist);
|
||||
}
|
||||
catch (NodeLockedException e)
|
||||
{
|
||||
thrown = true;
|
||||
}
|
||||
assertTrue("No one should be able to update the original", thrown);
|
||||
|
||||
// ////////////////////////////////////////////////////////////
|
||||
// testing "delete" and "update" actions with non-owner user //
|
||||
// ////////////////////////////////////////////////////////////
|
||||
|
||||
// create another person
|
||||
final String denyUser = "COCITestUser123";
|
||||
createPerson(denyUser);
|
||||
|
||||
// try to delete original, that has working copy - must be denied
|
||||
thrown = false;
|
||||
try
|
||||
{
|
||||
AuthenticationUtil.runAs(new RunAsWork<NodeRef>()
|
||||
{
|
||||
@Override
|
||||
public NodeRef doWork() throws Exception
|
||||
{
|
||||
fileFolderService.delete(orig);
|
||||
return null;
|
||||
}
|
||||
}, denyUser);
|
||||
}
|
||||
catch (AccessDeniedException e)
|
||||
{
|
||||
thrown = true;
|
||||
}
|
||||
catch (org.alfresco.repo.security.permissions.AccessDeniedException e)
|
||||
{
|
||||
thrown = true;
|
||||
}
|
||||
assertTrue(thrown);
|
||||
|
||||
// try to delete original, that has working copy - must be denied
|
||||
thrown = false;
|
||||
try
|
||||
{
|
||||
AuthenticationUtil.runAs(new RunAsWork<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
nodeService.addProperties(orig, propsToPersist);
|
||||
return null;
|
||||
}
|
||||
}, denyUser);
|
||||
}
|
||||
catch (AccessDeniedException e)
|
||||
{
|
||||
thrown = true;
|
||||
}
|
||||
catch (org.alfresco.repo.security.permissions.AccessDeniedException e)
|
||||
{
|
||||
thrown = true;
|
||||
}
|
||||
catch (NodeLockedException e) {
|
||||
thrown = true;
|
||||
}
|
||||
assertTrue(thrown);
|
||||
}
|
||||
|
||||
/**
|
||||
* MNT-2641
|
||||
* The working copy delete is equivalent to "cancelCheckout". This should fail for everyone except the lock owner.
|
||||
*/
|
||||
public void testDeleteOfWorkingCopy()
|
||||
{
|
||||
// Create a FolderA
|
||||
final NodeRef folderA = createFolder("DeleteOfWorkingCopy_" + GUID.generate());
|
||||
|
||||
// Create content in FolderA
|
||||
final NodeRef orig = createContent("original_" + GUID.generate(), folderA);
|
||||
|
||||
// Check out the document
|
||||
NodeRef workingCopy = this.cociService.checkout(orig);
|
||||
assertNotNull(workingCopy);
|
||||
|
||||
// deleting of working copy
|
||||
fileFolderService.delete(workingCopy);
|
||||
assertFalse(nodeService.exists(workingCopy));
|
||||
|
||||
assertNull(cociService.getWorkingCopy(orig));
|
||||
assertFalse(cociService.isCheckedOut(orig));
|
||||
}
|
||||
|
||||
/**
|
||||
* MNT-2641: The {@link ContentModel#ASPECT_WORKING_COPY} aspect cannot be removed from a working copy
|
||||
*/
|
||||
public void testDeleteWorkingCopyAspect()
|
||||
{
|
||||
// Create a FolderA
|
||||
final NodeRef folderA = createFolder("DeleteCopiedFromAspectFromWorkingCopy_" + GUID.generate());
|
||||
|
||||
// Create content in FolderA
|
||||
final NodeRef orig = createContent("original_" + GUID.generate(), folderA);
|
||||
|
||||
// Check out the document
|
||||
NodeRef workingCopy = this.cociService.checkout(orig);
|
||||
assertNotNull(workingCopy);
|
||||
|
||||
assertTrue("cm:workingCopy aspect not found on working copy.",
|
||||
nodeService.hasAspect(workingCopy, ContentModel.ASPECT_WORKING_COPY));
|
||||
assertTrue("cm:copiedFrom aspect not found on working copy.",
|
||||
nodeService.hasAspect(workingCopy, ContentModel.ASPECT_COPIEDFROM));
|
||||
|
||||
setComplete();
|
||||
endTransaction();
|
||||
|
||||
// try to delete cm:copiedfrom aspect from working copy - must be allowed
|
||||
nodeService.removeAspect(workingCopy, ContentModel.ASPECT_COPIEDFROM);
|
||||
// Try to delete cm:workingcopy aspect from working copy - must be denied
|
||||
try
|
||||
{
|
||||
nodeService.removeAspect(workingCopy, ContentModel.ASPECT_WORKING_COPY);
|
||||
fail("Should not be able to remove cm:workingcopy");
|
||||
}
|
||||
catch (UnsupportedOperationException e)
|
||||
{
|
||||
// Expected
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MNT-2641 The cm:workingcopylink association cannot be removed
|
||||
*/
|
||||
public void testDeleteWorkingCopyLinkAssociation()
|
||||
{
|
||||
// Create a FolderA
|
||||
final NodeRef folderA = createFolder("DeleteOriginalAssociationFromCopy_" + GUID.generate());
|
||||
|
||||
// Create content in FolderA
|
||||
final NodeRef orig = createContent("original_" + GUID.generate(), folderA);
|
||||
|
||||
// Check out the document
|
||||
NodeRef workingCopy = this.cociService.checkout(orig);
|
||||
assertNotNull(workingCopy);
|
||||
|
||||
// Check that the cm:original association is present
|
||||
assertEquals("Did not find cm:workingcopylink",
|
||||
1, nodeService.getSourceAssocs(workingCopy, ContentModel.ASSOC_WORKING_COPY_LINK).size());
|
||||
|
||||
setComplete();
|
||||
endTransaction();
|
||||
|
||||
// try to delete cm:workingcopylink association - must be denied
|
||||
try
|
||||
{
|
||||
nodeService.removeAssociation(orig, workingCopy, ContentModel.ASSOC_WORKING_COPY_LINK);
|
||||
fail("Should not have been allowed to remove the association from working copy to original");
|
||||
}
|
||||
catch (IntegrityException e)
|
||||
{
|
||||
// Expected
|
||||
}
|
||||
}
|
||||
|
||||
private NodeRef createFolder(String fName)
|
||||
{
|
||||
return nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(fName), ContentModel.TYPE_FOLDER).getChildRef();
|
||||
}
|
||||
|
||||
private NodeRef createContent(String contentName, NodeRef parentRef)
|
||||
{
|
||||
return nodeService.createNode(parentRef, ContentModel.ASSOC_CONTAINS, QName.createQName(contentName), ContentModel.TYPE_CONTENT).getChildRef();
|
||||
}
|
||||
|
||||
private void createPerson(String userName)
|
||||
{
|
||||
// if user with given user name doesn't already exist then create user
|
||||
if (this.authenticationService.authenticationExists(userName) == false)
|
||||
{
|
||||
// create user
|
||||
this.authenticationService.createAuthentication(userName, "password".toCharArray());
|
||||
}
|
||||
|
||||
// if person node with given user name doesn't already exist then create
|
||||
// person
|
||||
if (this.personService.personExists(userName) == false)
|
||||
{
|
||||
// create person properties
|
||||
final PropertyMap personProps = new PropertyMap();
|
||||
personProps.put(ContentModel.PROP_USERNAME, userName);
|
||||
personProps.put(ContentModel.PROP_FIRSTNAME, userName);
|
||||
personProps.put(ContentModel.PROP_LASTNAME, userName);
|
||||
personProps.put(ContentModel.PROP_EMAIL, userName + "@gmail.com");
|
||||
personProps.put(ContentModel.PROP_JOBTITLE, "jobtitle");
|
||||
personProps.put(ContentModel.PROP_ORGANIZATION, "org");
|
||||
|
||||
// create person node for user
|
||||
AuthenticationUtil.runAsSystem(new RunAsWork<NodeRef>()
|
||||
{
|
||||
@Override
|
||||
public NodeRef doWork() throws Exception
|
||||
{
|
||||
return personService.createPerson(personProps);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -80,6 +80,7 @@ public class IntegrityTest extends TestCase
|
||||
|
||||
public static final QName TEST_ASPECT_WITH_PROPERTIES = QName.createQName(NAMESPACE, "aspectWithProperties");
|
||||
public static final QName TEST_ASPECT_WITH_ASSOC = QName.createQName(NAMESPACE, "aspectWithAssoc");
|
||||
public static final QName TEST_ASPECT_WITH_ASPECT = QName.createQName(NAMESPACE, "aspectWithAspect");
|
||||
|
||||
public static final QName TEST_PROP_TEXT_A = QName.createQName(NAMESPACE, "prop-text-a");
|
||||
public static final QName TEST_PROP_TEXT_B = QName.createQName(NAMESPACE, "prop-text-b");
|
||||
@@ -289,6 +290,19 @@ public class IntegrityTest extends TestCase
|
||||
checkIntegrityExpectFailure("Failed to removal of mandatory aspect", 1);
|
||||
}
|
||||
|
||||
public void testCreateWithAspectForAspect() throws Exception
|
||||
{
|
||||
NodeRef nodeRef = createNode("abc", TEST_TYPE_WITHOUT_ANYTHING, null);
|
||||
// Add the aspect
|
||||
nodeService.addAspect(nodeRef, TEST_ASPECT_WITH_ASPECT, allProperties);
|
||||
assertTrue("Mandatory aspect missing", nodeService.hasAspect(nodeRef, TEST_ASPECT_WITH_PROPERTIES));
|
||||
checkIntegrityNoFailure();
|
||||
|
||||
// Remove the implied mandatory aspect
|
||||
nodeService.removeAspect(nodeRef, TEST_ASPECT_WITH_PROPERTIES);
|
||||
checkIntegrityExpectFailure("Failed to detect missing aspect for aspect", 1);
|
||||
}
|
||||
|
||||
public void testCreateTargetOfAssocsWithMandatorySourcesPresent() throws Exception
|
||||
{
|
||||
// this is the target of 3 assoc types where the source cardinality is 1..1
|
||||
@@ -383,35 +397,29 @@ public class IntegrityTest extends TestCase
|
||||
checkIntegrityExpectFailure("Failed to detect missing assoc targets", 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Reactivate once cascade delete notifications are back on
|
||||
* <p>
|
||||
* <b>Does nothing</b>.
|
||||
*/
|
||||
public void testRemoveTargetsOfMandatoryAssocs() throws Exception
|
||||
{
|
||||
// NodeRef source = createNode("abc", TEST_TYPE_WITH_ASSOCS, null);
|
||||
// NodeRef target = createNode("target", TEST_TYPE_WITHOUT_ANYTHING, null);
|
||||
// nodeService.createAssociation(source, target, TEST_ASSOC_NODE_ONE_ONE);
|
||||
//
|
||||
// NodeRef parent = createNode("parent", TEST_TYPE_WITH_CHILD_ASSOCS, null);
|
||||
// NodeRef child = createNode("child", TEST_TYPE_WITHOUT_ANYTHING, null);
|
||||
// nodeService.addChild(parent, child, TEST_ASSOC_CHILD_ONE_ONE, QName.createQName(NAMESPACE, "one-to-one"));
|
||||
//
|
||||
// NodeRef aspectSource = createNode("aspectSource", TEST_TYPE_WITHOUT_ANYTHING, null);
|
||||
// nodeService.addAspect(aspectSource, TEST_ASPECT_WITH_ASSOC, null);
|
||||
// NodeRef aspectTarget = createNode("aspectTarget", TEST_TYPE_WITHOUT_ANYTHING, null);
|
||||
// nodeService.createAssociation(aspectSource, aspectTarget, TEST_ASSOC_ASPECT_ONE_ONE);
|
||||
//
|
||||
// checkIntegrityNoFailure();
|
||||
//
|
||||
// // remove target nodes
|
||||
// nodeService.deleteNode(target);
|
||||
// nodeService.deleteNode(child);
|
||||
// nodeService.deleteNode(aspectTarget);
|
||||
//
|
||||
// checkIntegrityExpectFailure("Failed to detect removal of mandatory assoc targets", 3);
|
||||
logger.error("Method commented out: testRemoveTargetsOfMandatoryAssocs");
|
||||
NodeRef source = createNode("abc", TEST_TYPE_WITH_ASSOCS, null);
|
||||
NodeRef target = createNode("target", TEST_TYPE_WITHOUT_ANYTHING, null);
|
||||
nodeService.createAssociation(source, target, TEST_ASSOC_NODE_ONE_ONE);
|
||||
|
||||
NodeRef parent = createNode("parent", TEST_TYPE_WITH_CHILD_ASSOCS, null);
|
||||
NodeRef child = createNode("child", TEST_TYPE_WITHOUT_ANYTHING, null);
|
||||
nodeService.addChild(parent, child, TEST_ASSOC_CHILD_ONE_ONE, QName.createQName(NAMESPACE, "one-to-one"));
|
||||
|
||||
NodeRef aspectSource = createNode("aspectSource", TEST_TYPE_WITHOUT_ANYTHING, null);
|
||||
nodeService.addAspect(aspectSource, TEST_ASPECT_WITH_ASSOC, null);
|
||||
NodeRef aspectTarget = createNode("aspectTarget", TEST_TYPE_WITHOUT_ANYTHING, null);
|
||||
nodeService.createAssociation(aspectSource, aspectTarget, TEST_ASSOC_ASPECT_ONE_ONE);
|
||||
|
||||
checkIntegrityNoFailure();
|
||||
|
||||
// remove target nodes
|
||||
nodeService.deleteNode(target);
|
||||
nodeService.deleteNode(child);
|
||||
nodeService.deleteNode(aspectTarget);
|
||||
|
||||
checkIntegrityExpectFailure("Failed to detect removal of mandatory assoc targets", 3);
|
||||
}
|
||||
|
||||
public void testExcessTargetsOfOneToOneAssocs() throws Exception
|
||||
|
@@ -191,6 +191,13 @@
|
||||
</association>
|
||||
</associations>
|
||||
</aspect>
|
||||
<!-- aspect with aspects -->
|
||||
<aspect name="test:aspectWithAspect">
|
||||
<title>Aspect with aspects</title>
|
||||
<mandatory-aspects>
|
||||
<aspect>test:aspectWithProperties</aspect>
|
||||
</mandatory-aspects>
|
||||
</aspect>
|
||||
</aspects>
|
||||
|
||||
</model>
|
||||
|
Reference in New Issue
Block a user