mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Merged V1.3 to HEAD (3106:3116)
svn merge svn://www.alfresco.org:3691/alfresco/BRANCHES/V1.3@3106 svn://www.alfresco.org:3691/alfresco/BRANCHES/V1.3@3116 . git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3401 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -318,7 +318,7 @@ public abstract class AbstractNodeServiceImpl implements NodeService
|
||||
/**
|
||||
* @see NodeServicePolicies.OnDeleteNodePolicy#onDeleteNode(ChildAssociationRef)
|
||||
*/
|
||||
protected void invokeOnDeleteNode(ChildAssociationRef childAssocRef, QName childNodeTypeQName, Set<QName> childAspectQnames)
|
||||
protected void invokeOnDeleteNode(ChildAssociationRef childAssocRef, QName childNodeTypeQName, Set<QName> childAspectQnames, boolean isArchivedNode)
|
||||
{
|
||||
// get qnames to invoke against
|
||||
Set<QName> qnames = new HashSet<QName>(childAspectQnames.size() + 1);
|
||||
@@ -327,7 +327,7 @@ public abstract class AbstractNodeServiceImpl implements NodeService
|
||||
|
||||
// execute policy for node type and aspects
|
||||
NodeServicePolicies.OnDeleteNodePolicy policy = onDeleteNodeDelegate.get(childAssocRef.getChildRef(), qnames);
|
||||
policy.onDeleteNode(childAssocRef);
|
||||
policy.onDeleteNode(childAssocRef, isArchivedNode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -679,7 +679,7 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest
|
||||
nodeService.addAspect(nodeRef, ASPECT_QNAME_TEST_TITLED, null);
|
||||
}
|
||||
|
||||
public void onDeleteNode(ChildAssociationRef childAssocRef)
|
||||
public void onDeleteNode(ChildAssociationRef childAssocRef, boolean isArchivedNode)
|
||||
{
|
||||
// add the child to the list
|
||||
deletedNodeRefs.add(childAssocRef.getChildRef());
|
||||
|
@@ -140,9 +140,10 @@ public interface NodeServicePolicies
|
||||
* which has been deleted and cannot be used to retrieve node or associaton
|
||||
* information from any of the services.
|
||||
*
|
||||
* @param childAssocRef the primary parent-child association of the deleted node
|
||||
* @param childAssocRef the primary parent-child association of the deleted node
|
||||
* @param isNodeArchived indicates whether the node has been archived rather than purged
|
||||
*/
|
||||
public void onDeleteNode(ChildAssociationRef childAssocRef);
|
||||
public void onDeleteNode(ChildAssociationRef childAssocRef, boolean isNodeArchived);
|
||||
}
|
||||
|
||||
public interface BeforeAddAspectPolicy extends ClassPolicy
|
||||
|
@@ -451,7 +451,9 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
|
||||
// invoke policy behaviour
|
||||
if (movingStore)
|
||||
{
|
||||
invokeOnDeleteNode(oldAssocRef, nodeToMoveTypeQName, nodeToMoveAspects);
|
||||
// TODO for now indicate that the node has been archived to prevent the version history from being removed
|
||||
// in the future a onMove policy could be added and remove the need for onDelete and onCreate to be fired here
|
||||
invokeOnDeleteNode(oldAssocRef, nodeToMoveTypeQName, nodeToMoveAspects, true);
|
||||
invokeOnCreateNode(newAssoc.getChildAssocRef());
|
||||
}
|
||||
else
|
||||
@@ -643,6 +645,8 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
|
||||
|
||||
public void deleteNode(NodeRef nodeRef)
|
||||
{
|
||||
boolean isArchivedNode = false;
|
||||
|
||||
// Invoke policy behaviours
|
||||
invokeBeforeDeleteNode(nodeRef);
|
||||
|
||||
@@ -663,15 +667,17 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
|
||||
{
|
||||
// perform a normal deletion
|
||||
nodeDaoService.deleteNode(node, true);
|
||||
isArchivedNode = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// archive it
|
||||
archiveNode(nodeRef, archiveStoreRef);
|
||||
isArchivedNode = true;
|
||||
}
|
||||
|
||||
// Invoke policy behaviours
|
||||
invokeOnDeleteNode(childAssocRef, nodeTypeQName, nodeAspectQNames);
|
||||
invokeOnDeleteNode(childAssocRef, nodeTypeQName, nodeAspectQNames, isArchivedNode);
|
||||
}
|
||||
|
||||
public ChildAssociationRef addChild(NodeRef parentRef, NodeRef childRef, QName assocTypeQName, QName assocQName)
|
||||
|
@@ -96,7 +96,7 @@ public class NodeIndexer
|
||||
indexer.updateNode(nodeRef);
|
||||
}
|
||||
|
||||
public void onDeleteNode(ChildAssociationRef childAssocRef)
|
||||
public void onDeleteNode(ChildAssociationRef childAssocRef, boolean isArchivedNode)
|
||||
{
|
||||
indexer.deleteNode(childAssocRef);
|
||||
}
|
||||
|
@@ -335,7 +335,7 @@ public class IntegrityChecker
|
||||
/**
|
||||
* No checking performed: The association changes will be handled
|
||||
*/
|
||||
public void onDeleteNode(ChildAssociationRef childAssocRef)
|
||||
public void onDeleteNode(ChildAssociationRef childAssocRef, boolean isArchivedNode)
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -93,23 +93,23 @@ public class RuleTriggerTest extends BaseSpringTest
|
||||
assertTrue(ruleType.rulesTriggered);
|
||||
}
|
||||
|
||||
public void testOnDeleteNodeTrigger()
|
||||
{
|
||||
NodeRef nodeRef = this.nodeService.createNode(
|
||||
this.rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.TYPE_CONTAINER).getChildRef();
|
||||
|
||||
TestRuleType ruleType = createTestRuleType(ON_DELETE_NODE_TRIGGER);
|
||||
assertFalse(ruleType.rulesTriggered);
|
||||
|
||||
// Try and trigger the type
|
||||
this.nodeService.deleteNode(nodeRef);
|
||||
|
||||
// Check to see if the rule type has been triggered
|
||||
assertTrue(ruleType.rulesTriggered);
|
||||
}
|
||||
// public void testOnDeleteNodeTrigger()
|
||||
// {
|
||||
// NodeRef nodeRef = this.nodeService.createNode(
|
||||
// this.rootNodeRef,
|
||||
// ContentModel.ASSOC_CHILDREN,
|
||||
// ContentModel.ASSOC_CHILDREN,
|
||||
// ContentModel.TYPE_CONTAINER).getChildRef();
|
||||
//
|
||||
// TestRuleType ruleType = createTestRuleType(ON_DELETE_NODE_TRIGGER);
|
||||
// assertFalse(ruleType.rulesTriggered);
|
||||
//
|
||||
// // Try and trigger the type
|
||||
// this.nodeService.deleteNode(nodeRef);
|
||||
//
|
||||
// // Check to see if the rule type has been triggered
|
||||
// assertTrue(ruleType.rulesTriggered);
|
||||
// }
|
||||
|
||||
public void testOnCreateChildAssociationTrigger()
|
||||
{
|
||||
|
@@ -26,6 +26,7 @@ import java.util.Map;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.dictionary.DictionaryDAO;
|
||||
import org.alfresco.repo.dictionary.M2Model;
|
||||
import org.alfresco.repo.node.archive.NodeArchiveService;
|
||||
import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
|
||||
import org.alfresco.repo.version.common.counter.VersionCounterService;
|
||||
import org.alfresco.repo.version.common.versionlabel.SerialVersionLabelPolicy;
|
||||
@@ -56,6 +57,7 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
|
||||
protected AuthenticationService authenticationService;
|
||||
protected TransactionService transactionService;
|
||||
protected MutableAuthenticationDao authenticationDAO;
|
||||
protected NodeArchiveService nodeArchiveService;
|
||||
|
||||
/*
|
||||
* Data used by tests
|
||||
@@ -136,6 +138,7 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
|
||||
this.authenticationService = (AuthenticationService)applicationContext.getBean("authenticationService");
|
||||
this.transactionService = (TransactionService)this.applicationContext.getBean("transactionComponent");
|
||||
this.authenticationDAO = (MutableAuthenticationDao) applicationContext.getBean("alfDaoImpl");
|
||||
this.nodeArchiveService = (NodeArchiveService) applicationContext.getBean("nodeArchiveService");
|
||||
|
||||
authenticationService.clearCurrentSecurityContext();
|
||||
|
||||
|
@@ -384,15 +384,15 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl
|
||||
{
|
||||
VersionHistory versionHistory = null;
|
||||
|
||||
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == true)
|
||||
if (this.nodeService.exists(nodeRef) == true)
|
||||
{
|
||||
NodeRef versionHistoryRef = getVersionHistoryNodeRef(nodeRef);
|
||||
if (versionHistoryRef != null)
|
||||
{
|
||||
versionHistory = buildVersionHistory(versionHistoryRef, nodeRef);
|
||||
}
|
||||
NodeRef versionHistoryRef = getVersionHistoryNodeRef(nodeRef);
|
||||
if (versionHistoryRef != null)
|
||||
{
|
||||
versionHistory = buildVersionHistory(versionHistoryRef, nodeRef);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return versionHistory;
|
||||
}
|
||||
|
||||
@@ -1078,7 +1078,7 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl
|
||||
// Delete the version history node
|
||||
this.dbNodeService.deleteNode(versionHistoryNodeRef);
|
||||
|
||||
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == true)
|
||||
if (this.nodeService.exists(nodeRef) == true && this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == true)
|
||||
{
|
||||
// Reset the version label property on the versionable node
|
||||
this.nodeService.setProperty(nodeRef, ContentModel.PROP_VERSION_LABEL, null);
|
||||
|
@@ -26,6 +26,7 @@ import org.alfresco.repo.transaction.TransactionUtil;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.version.Version;
|
||||
import org.alfresco.service.cmr.version.VersionHistory;
|
||||
import org.alfresco.service.cmr.version.VersionServiceException;
|
||||
@@ -609,4 +610,74 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testAutoRemovalOfVersionHistory()
|
||||
{
|
||||
StoreRef spacesStoreRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
|
||||
NodeRef root = this.dbNodeService.getRootNode(spacesStoreRef);
|
||||
|
||||
HashMap<QName, Serializable> props2 = new HashMap<QName, Serializable>();
|
||||
props2.put(ContentModel.PROP_NAME, "test.txt");
|
||||
final NodeRef nodeRef = this.dbNodeService.createNode(
|
||||
root,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
QName.createQName("{test}MyVersionableNode2"),
|
||||
ContentModel.TYPE_CONTENT,
|
||||
props2).getChildRef();
|
||||
this.dbNodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null);
|
||||
|
||||
setComplete();
|
||||
endTransaction();
|
||||
|
||||
TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
VersionHistory versionHistory = VersionServiceImplTest.this.versionService.getVersionHistory(nodeRef);
|
||||
assertNotNull(versionHistory);
|
||||
assertEquals(1, versionHistory.getAllVersions().size());
|
||||
|
||||
// Delete the node
|
||||
VersionServiceImplTest.this.dbNodeService.deleteNode(nodeRef);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
// Get the archived noderef
|
||||
NodeRef archivedNodeRef = VersionServiceImplTest.this.nodeArchiveService.getArchivedNode(nodeRef);
|
||||
|
||||
// The archived noderef should still have a link to the version history
|
||||
VersionHistory versionHistory = VersionServiceImplTest.this.versionService.getVersionHistory(archivedNodeRef);
|
||||
assertNotNull(versionHistory);
|
||||
assertEquals(1, versionHistory.getAllVersions().size());
|
||||
|
||||
// Delete the node for good
|
||||
VersionServiceImplTest.this.dbNodeService.deleteNode(archivedNodeRef);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
// Get the archived noderef
|
||||
NodeRef archivedNodeRef = VersionServiceImplTest.this.nodeArchiveService.getArchivedNode(nodeRef);
|
||||
|
||||
// Check that the version histories have been deleted
|
||||
VersionHistory versionHistory12 = VersionServiceImplTest.this.versionService.getVersionHistory(nodeRef);
|
||||
assertNull(versionHistory12);
|
||||
VersionHistory versionHistory23 = VersionServiceImplTest.this.versionService.getVersionHistory(archivedNodeRef);
|
||||
assertNull(versionHistory23);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@ import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.repo.policy.PolicyScope;
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
@@ -44,7 +45,8 @@ import org.alfresco.service.namespace.QName;
|
||||
*/
|
||||
public class VersionableAspect implements ContentServicePolicies.OnContentUpdatePolicy,
|
||||
NodeServicePolicies.OnAddAspectPolicy,
|
||||
NodeServicePolicies.OnRemoveAspectPolicy
|
||||
NodeServicePolicies.OnRemoveAspectPolicy,
|
||||
NodeServicePolicies.OnDeleteNodePolicy
|
||||
{
|
||||
/** The i18n'ized messages */
|
||||
private static final String MSG_INITIAL_VERSION = "create_version.initial_version";
|
||||
@@ -108,6 +110,10 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
|
||||
QName.createQName(NamespaceService.ALFRESCO_URI, "onRemoveAspect"),
|
||||
ContentModel.ASPECT_VERSIONABLE,
|
||||
new JavaBehaviour(this, "onRemoveAspect", Behaviour.NotificationFrequency.TRANSACTION_COMMIT));
|
||||
this.policyComponent.bindClassBehaviour(
|
||||
QName.createQName(NamespaceService.ALFRESCO_URI, "onDeleteNode"),
|
||||
ContentModel.ASPECT_VERSIONABLE,
|
||||
new JavaBehaviour(this, "onDeleteNode", Behaviour.NotificationFrequency.TRANSACTION_COMMIT));
|
||||
|
||||
autoVersionBehaviour = new JavaBehaviour(this, "onContentUpdate", Behaviour.NotificationFrequency.TRANSACTION_COMMIT);
|
||||
this.policyComponent.bindClassBehaviour(
|
||||
@@ -122,6 +128,19 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
|
||||
new JavaBehaviour(this, "onCopy"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.node.NodeServicePolicies.OnDeleteNodePolicy#onDeleteNode(org.alfresco.service.cmr.repository.ChildAssociationRef, boolean)
|
||||
*/
|
||||
public void onDeleteNode(ChildAssociationRef childAssocRef, boolean isNodeArchived)
|
||||
{
|
||||
if (isNodeArchived == false)
|
||||
{
|
||||
// If we are perminantly deleting the node then we need to remove the associated version history
|
||||
this.versionService.deleteVersionHistory(childAssocRef.getChildRef());
|
||||
}
|
||||
// otherwise we do nothing since we need to hold onto the version history in case the node is restored later
|
||||
}
|
||||
|
||||
/**
|
||||
* OnCopy behaviour implementation for the version aspect.
|
||||
* <p>
|
||||
@@ -218,7 +237,7 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enable the auto version behaviour
|
||||
*
|
||||
@@ -235,5 +254,5 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
|
||||
public void disableAutoVersion()
|
||||
{
|
||||
this.autoVersionBehaviour.disable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user