Big honkin' merge from head. Sheesh!

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3617 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-08-27 01:01:30 +00:00
parent e2c66899cc
commit 8031cc6574
322 changed files with 20776 additions and 6550 deletions

View File

@@ -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();

View File

@@ -442,6 +442,15 @@ public class NodeServiceImpl implements NodeService, VersionModel
return result;
}
/**
* @throws UnsupportedOperationException always
*/
public NodeRef getChildByName(NodeRef nodeRef, QName assocTypeQName, String childName)
{
// This operation is not supported for a verion store
throw new UnsupportedOperationException(MSG_UNSUPPORTED);
}
/**
* Simulates the node begin attached ot the root node of the version store.
*/

View File

@@ -373,6 +373,9 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl
ContentModel.PROP_VERSION_LABEL,
version.getVersionLabel());
// Invoke the policy behaviour
invokeAfterCreateVersion(nodeRef, version);
// Return the data object representing the newly created version
return version;
}
@@ -384,15 +387,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 +1081,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);

View File

@@ -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;
}
});
}
}

View File

@@ -46,11 +46,37 @@ public interface VersionServicePolicies
}
/**
* After create version policy interface
*
*/
public interface AfterCreateVersionPolicy extends ClassPolicy
{
/**
* Called after the version has been created
*
* @param versionableNode the node that has been versioned
* @param version the created version
*/
public void afterCreateVersion(NodeRef versionableNode, Version version);
}
/**
* On create version policy interface
*/
public interface OnCreateVersionPolicy extends ClassPolicy
{
/**
* Called during the creation of the version to determine what the versioning policy for a
* perticular type may be.
* WARNING: implementing behaviour for this policy effects the versioning behaviour of the
* type the behaviour is registered against.
*
* @param classRef
* @param versionableNode
* @param versionProperties
* @param nodeDetails
*/
public void onCreateVersion(
QName classRef,
NodeRef versionableNode,

View File

@@ -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,14 +45,16 @@ import org.alfresco.service.namespace.QName;
*/
public class VersionableAspect implements ContentServicePolicies.OnContentUpdatePolicy,
NodeServicePolicies.OnAddAspectPolicy,
NodeServicePolicies.OnRemoveAspectPolicy
NodeServicePolicies.OnRemoveAspectPolicy,
NodeServicePolicies.OnDeleteNodePolicy,
VersionServicePolicies.AfterCreateVersionPolicy
{
/** The i18n'ized messages */
private static final String MSG_INITIAL_VERSION = "create_version.initial_version";
private static final String MSG_AUTO_VERSION = "create_version.auto_version";
/** Transaction resource key */
private static final String KEY_INITIAL_VERSION = "initial_version_";
private static final String KEY_VERSIONED_NODEREFS = "versioned_noderefs";
/** The policy component */
private PolicyComponent policyComponent;
@@ -108,6 +111,14 @@ 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));
this.policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "afterCreateVersion"),
ContentModel.ASPECT_VERSIONABLE,
new JavaBehaviour(this, "afterCreateVersion", Behaviour.NotificationFrequency.EVERY_EVENT));
autoVersionBehaviour = new JavaBehaviour(this, "onContentUpdate", Behaviour.NotificationFrequency.TRANSACTION_COMMIT);
this.policyComponent.bindClassBehaviour(
@@ -122,6 +133,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>
@@ -154,7 +178,7 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
*/
public void onAddAspect(NodeRef nodeRef, QName aspectTypeQName)
{
if (aspectTypeQName.equals(ContentModel.ASPECT_VERSIONABLE) == true)
if (this.nodeService.exists(nodeRef) == true && aspectTypeQName.equals(ContentModel.ASPECT_VERSIONABLE) == true)
{
boolean initialVersion = true;
Boolean value = (Boolean)this.nodeService.getProperty(nodeRef, ContentModel.PROP_INITIAL_VERSION);
@@ -166,13 +190,14 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
if (initialVersion == true)
{
// Queue create version action
Map<String, Serializable> versionDetails = new HashMap<String, Serializable>(1);
versionDetails.put(Version.PROP_DESCRIPTION, I18NUtil.getMessage(MSG_INITIAL_VERSION));
this.versionService.createVersion(nodeRef, versionDetails);
// Keep track of the fact that the initial version has been created
AlfrescoTransactionSupport.bindResource(KEY_INITIAL_VERSION + nodeRef.toString(), nodeRef);
Map<NodeRef, NodeRef> versionedNodeRefs = (Map)AlfrescoTransactionSupport.getResource(KEY_VERSIONED_NODEREFS);
if (versionedNodeRefs == null || versionedNodeRefs.containsKey(nodeRef) == false)
{
// Queue create version action
Map<String, Serializable> versionDetails = new HashMap<String, Serializable>(1);
versionDetails.put(Version.PROP_DESCRIPTION, I18NUtil.getMessage(MSG_INITIAL_VERSION));
this.versionService.createVersion(nodeRef, versionDetails);
}
}
}
}
@@ -191,12 +216,13 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
*
* @param nodeRef the node reference
*/
public void onContentUpdate(NodeRef nodeRef, boolean newContent)
@SuppressWarnings("unchecked")
public void onContentUpdate(NodeRef nodeRef, boolean newContent)
{
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == true)
{
// Determine whether we have already created an initial version during this transaction
if (AlfrescoTransactionSupport.getResource(KEY_INITIAL_VERSION + nodeRef.toString()) == null)
if (this.nodeService.exists(nodeRef) == true && this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == true)
{
Map<NodeRef, NodeRef> versionedNodeRefs = (Map)AlfrescoTransactionSupport.getResource(KEY_VERSIONED_NODEREFS);
if (versionedNodeRefs == null || versionedNodeRefs.containsKey(nodeRef) == false)
{
// Determine whether the node is auto versionable or not
boolean autoVersion = false;
@@ -218,22 +244,19 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
}
}
}
/**
* Enable the auto version behaviour
*
* @see org.alfresco.repo.version.VersionServicePolicies.OnCreateVersionPolicy#onCreateVersion(org.alfresco.service.namespace.QName, org.alfresco.service.cmr.repository.NodeRef, java.util.Map, org.alfresco.repo.policy.PolicyScope)
*/
public void enableAutoVersion()
{
this.autoVersionBehaviour.enable();
}
/**
* Disable the auto version behaviour
*
*/
public void disableAutoVersion()
{
this.autoVersionBehaviour.disable();
}
@SuppressWarnings("unchecked")
public void afterCreateVersion(NodeRef versionableNode, Version version)
{
Map<NodeRef, NodeRef> versionedNodeRefs = (Map<NodeRef, NodeRef>)AlfrescoTransactionSupport.getResource(KEY_VERSIONED_NODEREFS);
if (versionedNodeRefs == null)
{
versionedNodeRefs = new HashMap<NodeRef, NodeRef>();
AlfrescoTransactionSupport.bindResource(KEY_VERSIONED_NODEREFS, versionedNodeRefs);
}
versionedNodeRefs.put(versionableNode, versionableNode);
}
}

View File

@@ -26,6 +26,7 @@ import org.alfresco.repo.policy.ClassPolicyDelegate;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.policy.PolicyScope;
import org.alfresco.repo.version.VersionServicePolicies;
import org.alfresco.repo.version.VersionServicePolicies.AfterCreateVersionPolicy;
import org.alfresco.repo.version.VersionServicePolicies.BeforeCreateVersionPolicy;
import org.alfresco.repo.version.VersionServicePolicies.CalculateVersionLabelPolicy;
import org.alfresco.repo.version.VersionServicePolicies.OnCreateVersionPolicy;
@@ -68,6 +69,7 @@ public abstract class AbstractVersionServiceImpl
* Policy delegates
*/
private ClassPolicyDelegate<BeforeCreateVersionPolicy> beforeCreateVersionDelegate;
private ClassPolicyDelegate<AfterCreateVersionPolicy> afterCreateVersionDelegate;
private ClassPolicyDelegate<OnCreateVersionPolicy> onCreateVersionDelegate;
private ClassPolicyDelegate<CalculateVersionLabelPolicy> calculateVersionLabelDelegate;
@@ -108,6 +110,7 @@ public abstract class AbstractVersionServiceImpl
{
// Register the policies
this.beforeCreateVersionDelegate = this.policyComponent.registerClassPolicy(VersionServicePolicies.BeforeCreateVersionPolicy.class);
this.afterCreateVersionDelegate = this.policyComponent.registerClassPolicy(VersionServicePolicies.AfterCreateVersionPolicy.class);
this.onCreateVersionDelegate = this.policyComponent.registerClassPolicy(VersionServicePolicies.OnCreateVersionPolicy.class);
this.calculateVersionLabelDelegate = this.policyComponent.registerClassPolicy(VersionServicePolicies.CalculateVersionLabelPolicy.class);
}
@@ -127,6 +130,22 @@ public abstract class AbstractVersionServiceImpl
this.beforeCreateVersionDelegate.get(nodeAspectQNames).beforeCreateVersion(nodeRef);
}
/**
* Invoke the after create version policy bahaviour
*
* @param nodeRef the nodeRef versioned
* @param version the created version
*/
protected void invokeAfterCreateVersion(NodeRef nodeRef, Version version)
{
// invoke for node type
QName nodeTypeQName = nodeService.getType(nodeRef);
this.afterCreateVersionDelegate.get(nodeTypeQName).afterCreateVersion(nodeRef, version);
// invoke for node aspects
Set<QName> nodeAspectQNames = nodeService.getAspects(nodeRef);
this.afterCreateVersionDelegate.get(nodeAspectQNames).afterCreateVersion(nodeRef, version);
}
/**
* Invoke the on create version policy behaviour
*