mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
- Fixed auto-version and added 'initialVersion' attribute to versionable aspect
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2150 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -16,7 +16,9 @@
|
||||
*/
|
||||
package org.alfresco.repo.version;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
@@ -435,19 +437,70 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
|
||||
|
||||
}
|
||||
|
||||
public void testAutoVersion()
|
||||
public void testAutoVersionOnInitialVersionOn()
|
||||
{
|
||||
// Create a versionable node
|
||||
final NodeRef versionableNode = createNewVersionableNode();
|
||||
|
||||
// Add some content
|
||||
ContentWriter contentWriter = this.contentService.getWriter(versionableNode, ContentModel.PROP_CONTENT, true);
|
||||
assertNotNull(contentWriter);
|
||||
contentWriter.putContent(UPDATED_CONTENT_1);
|
||||
|
||||
// Need to commit in order to get the auto version to fire ...
|
||||
setComplete();
|
||||
endTransaction();
|
||||
|
||||
TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
// Check that the initial version has not been created
|
||||
VersionHistory versionHistory = VersionServiceImplTest.this.versionService.getVersionHistory(versionableNode);
|
||||
assertNotNull(versionHistory);
|
||||
assertEquals(1, versionHistory.getAllVersions().size());
|
||||
|
||||
// Add some content
|
||||
ContentWriter contentWriter = VersionServiceImplTest.this.contentService.getWriter(versionableNode, ContentModel.PROP_CONTENT, true);
|
||||
assertNotNull(contentWriter);
|
||||
contentWriter.putContent(UPDATED_CONTENT_1);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
// Now lets have a look and make sure we have the correct number of entries in the version history
|
||||
TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
VersionHistory versionHistory = VersionServiceImplTest.this.versionService.getVersionHistory(versionableNode);
|
||||
assertNotNull(versionHistory);
|
||||
assertEquals(2, versionHistory.getAllVersions().size());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void testAutoVersionOff()
|
||||
{
|
||||
// Create a versionable node
|
||||
final NodeRef versionableNode = createNewVersionableNode();
|
||||
this.dbNodeService.setProperty(versionableNode, ContentModel.PROP_AUTO_VERSION, false);
|
||||
|
||||
setComplete();
|
||||
endTransaction();
|
||||
|
||||
// The initial version should have been created now
|
||||
|
||||
TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
// Add some content
|
||||
ContentWriter contentWriter = VersionServiceImplTest.this.contentService.getWriter(versionableNode, ContentModel.PROP_CONTENT, true);
|
||||
assertNotNull(contentWriter);
|
||||
contentWriter.putContent(UPDATED_CONTENT_1);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
// Now lets have a look and make sure we have the correct number of entries in the version history
|
||||
TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork<Object>()
|
||||
@@ -463,4 +516,37 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void testInitialVersionOff()
|
||||
{
|
||||
// Create node (this node has some content)
|
||||
HashMap<QName, Serializable> props = new HashMap<QName, Serializable>();
|
||||
props.put(ContentModel.PROP_INITIAL_VERSION, false);
|
||||
HashMap<QName, Serializable> props2 = new HashMap<QName, Serializable>();
|
||||
props2.put(ContentModel.PROP_NAME, "test.txt");
|
||||
final NodeRef nodeRef = this.dbNodeService.createNode(
|
||||
rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
QName.createQName("{test}MyVersionableNode2"),
|
||||
TEST_TYPE_QNAME,
|
||||
props2).getChildRef();
|
||||
this.dbNodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, props);
|
||||
|
||||
setComplete();
|
||||
endTransaction();
|
||||
|
||||
// The initial version should NOT have been created
|
||||
|
||||
TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
VersionHistory versionHistory = VersionServiceImplTest.this.versionService.getVersionHistory(nodeRef);
|
||||
assertNull(versionHistory);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -20,16 +20,13 @@ import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.action.evaluator.HasVersionHistoryEvaluator;
|
||||
import org.alfresco.repo.action.executer.CreateVersionActionExecuter;
|
||||
import org.alfresco.repo.policy.Behaviour;
|
||||
import org.alfresco.repo.policy.BehaviourDefinition;
|
||||
import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.repo.policy.PolicyScope;
|
||||
import org.alfresco.repo.rule.RuntimeRuleService;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ActionCondition;
|
||||
import org.alfresco.service.cmr.action.ActionService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
@@ -136,12 +133,6 @@ public class VersionableAspect
|
||||
QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyNode"),
|
||||
ContentModel.ASPECT_VERSIONABLE,
|
||||
new JavaBehaviour(this, "onCopy"));
|
||||
|
||||
// Register the onCreateVersion behavior for the version aspect
|
||||
//this.policyComponent.bindClassBehaviour(
|
||||
// QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateVersion"),
|
||||
// ContentModel.ASPECT_VERSIONABLE,
|
||||
// new JavaBehaviour(this, "onCreateVersion"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,8 +191,19 @@ public class VersionableAspect
|
||||
{
|
||||
if (aspectTypeQName.equals(ContentModel.ASPECT_VERSIONABLE) == true)
|
||||
{
|
||||
// Queue create version action
|
||||
queueCreateVersionAction(nodeRef);
|
||||
boolean initialVersion = true;
|
||||
Boolean value = (Boolean)this.nodeService.getProperty(nodeRef, ContentModel.PROP_INITIAL_VERSION);
|
||||
if (value != null)
|
||||
{
|
||||
initialVersion = value.booleanValue();
|
||||
}
|
||||
// else this means that the default vlaue has not been set the versionable aspect we applied pre-1.2
|
||||
|
||||
if (initialVersion == true)
|
||||
{
|
||||
// Queue create version action
|
||||
queueCreateVersionAction(nodeRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,15 +261,13 @@ public class VersionableAspect
|
||||
{
|
||||
if (this.rule == null)
|
||||
{
|
||||
// Create the version action rule
|
||||
this.rule = this.ruleService.createRule("inbound");
|
||||
Action action = this.actionService.createAction(CreateVersionActionExecuter.NAME);
|
||||
ActionCondition condition = this.actionService.createActionCondition(HasVersionHistoryEvaluator.NAME);
|
||||
condition.setInvertCondition(true);
|
||||
// conditions are only evaluated on the parent rule - not the contained actions
|
||||
rule.addActionCondition(condition);
|
||||
this.rule.addAction(action);
|
||||
}
|
||||
|
||||
// Stash the rule pending execution at the end of the transaction
|
||||
((RuntimeRuleService)this.ruleService).addRulePendingExecution(nodeRef, nodeRef, this.rule, true);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user