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:
@@ -542,6 +542,11 @@
|
|||||||
<type>d:text</type>
|
<type>d:text</type>
|
||||||
<protected>true</protected>
|
<protected>true</protected>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="cm:initialVersion">
|
||||||
|
<title>Initial Version</title>
|
||||||
|
<type>d:boolean</type>
|
||||||
|
<default>true</default>
|
||||||
|
</property>
|
||||||
<property name="cm:autoVersion">
|
<property name="cm:autoVersion">
|
||||||
<title>Auto Version</title>
|
<title>Auto Version</title>
|
||||||
<type>d:boolean</type>
|
<type>d:boolean</type>
|
||||||
|
@@ -106,6 +106,7 @@ public interface ContentModel
|
|||||||
// version aspect
|
// version aspect
|
||||||
static final QName ASPECT_VERSIONABLE = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "versionable");
|
static final QName ASPECT_VERSIONABLE = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "versionable");
|
||||||
static final QName PROP_VERSION_LABEL = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "versionLabel");
|
static final QName PROP_VERSION_LABEL = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "versionLabel");
|
||||||
|
static final QName PROP_INITIAL_VERSION = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "initialVersion");
|
||||||
static final QName PROP_AUTO_VERSION = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "autoVersion");
|
static final QName PROP_AUTO_VERSION = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "autoVersion");
|
||||||
|
|
||||||
// folders
|
// folders
|
||||||
|
@@ -16,7 +16,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.version;
|
package org.alfresco.repo.version;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
@@ -435,20 +437,71 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAutoVersion()
|
public void testAutoVersionOnInitialVersionOn()
|
||||||
{
|
{
|
||||||
// Create a versionable node
|
// Create a versionable node
|
||||||
final NodeRef versionableNode = createNewVersionableNode();
|
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();
|
setComplete();
|
||||||
endTransaction();
|
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
|
// 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>()
|
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 java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.action.evaluator.HasVersionHistoryEvaluator;
|
|
||||||
import org.alfresco.repo.action.executer.CreateVersionActionExecuter;
|
import org.alfresco.repo.action.executer.CreateVersionActionExecuter;
|
||||||
import org.alfresco.repo.policy.Behaviour;
|
import org.alfresco.repo.policy.Behaviour;
|
||||||
import org.alfresco.repo.policy.BehaviourDefinition;
|
|
||||||
import org.alfresco.repo.policy.JavaBehaviour;
|
import org.alfresco.repo.policy.JavaBehaviour;
|
||||||
import org.alfresco.repo.policy.PolicyComponent;
|
import org.alfresco.repo.policy.PolicyComponent;
|
||||||
import org.alfresco.repo.policy.PolicyScope;
|
import org.alfresco.repo.policy.PolicyScope;
|
||||||
import org.alfresco.repo.rule.RuntimeRuleService;
|
import org.alfresco.repo.rule.RuntimeRuleService;
|
||||||
import org.alfresco.service.cmr.action.Action;
|
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.action.ActionService;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
@@ -136,12 +133,6 @@ public class VersionableAspect
|
|||||||
QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyNode"),
|
QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyNode"),
|
||||||
ContentModel.ASPECT_VERSIONABLE,
|
ContentModel.ASPECT_VERSIONABLE,
|
||||||
new JavaBehaviour(this, "onCopy"));
|
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)
|
if (aspectTypeQName.equals(ContentModel.ASPECT_VERSIONABLE) == true)
|
||||||
{
|
{
|
||||||
// Queue create version action
|
boolean initialVersion = true;
|
||||||
queueCreateVersionAction(nodeRef);
|
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)
|
if (this.rule == null)
|
||||||
{
|
{
|
||||||
|
// Create the version action rule
|
||||||
this.rule = this.ruleService.createRule("inbound");
|
this.rule = this.ruleService.createRule("inbound");
|
||||||
Action action = this.actionService.createAction(CreateVersionActionExecuter.NAME);
|
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);
|
this.rule.addAction(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stash the rule pending execution at the end of the transaction
|
||||||
((RuntimeRuleService)this.ruleService).addRulePendingExecution(nodeRef, nodeRef, this.rule, true);
|
((RuntimeRuleService)this.ruleService).addRulePendingExecution(nodeRef, nodeRef, this.rule, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user