mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-22 15:12:38 +00:00
REPO-1682 / MNT-15447: getCurrentVersion(node) throws ConcurrencyFailureException after creating multiple versions of a node
- Throw IllegalArgumentException when not a 'live' noderef is used for retrieving the current version. - Added Junit test. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@133884 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -862,29 +862,35 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets current version of the passed node ref
|
||||
* Gets current version of the passed node reference. The node reference is expected to be the 'live' node.
|
||||
*
|
||||
* This uses the version label as a mechanism for looking up the version node.
|
||||
*/
|
||||
private Pair<Boolean, Version> getCurrentVersionImpl(NodeRef versionHistoryRef, NodeRef nodeRef)
|
||||
{
|
||||
// The noderef should not be a version type node.
|
||||
if (Version2Model.STORE_ID.equals(nodeRef.getStoreRef().getIdentifier()))
|
||||
{
|
||||
throw new IllegalArgumentException("The node reference " + nodeRef + " is pointing to a version node, when a reference to a live node is expected.");
|
||||
}
|
||||
|
||||
Pair<Boolean, Version> result = null;
|
||||
|
||||
String versionLabel = (String)this.nodeService.getProperty(nodeRef, ContentModel.PROP_VERSION_LABEL);
|
||||
|
||||
// note: resultant list is ordered by (a) explicit index and (b) association creation time
|
||||
// Note: resultant list is ordered by (a) explicit index and (b) association creation time
|
||||
List<ChildAssociationRef> versionAssocs = getVersionAssocs(versionHistoryRef, false);
|
||||
|
||||
// Current version should be head version (since no branching)
|
||||
int cnt = versionAssocs.size();
|
||||
for (int i = cnt; i > 0; i--)
|
||||
int versionCount = versionAssocs.size();
|
||||
for (int i = versionCount; i > 0; i--)
|
||||
{
|
||||
ChildAssociationRef versionAssoc = versionAssocs.get(i-1);
|
||||
|
||||
String tempLabel = (String)this.dbNodeService.getProperty(versionAssoc.getChildRef(), Version2Model.PROP_QNAME_VERSION_LABEL);
|
||||
if (tempLabel != null && tempLabel.equals(versionLabel) == true)
|
||||
{
|
||||
boolean headVersion = (i == cnt);
|
||||
boolean headVersion = (i == versionCount);
|
||||
|
||||
if (!headVersion)
|
||||
{
|
||||
@@ -902,7 +908,7 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
|
||||
/**
|
||||
* Check if versions are marked with invalid version label, if true > apply default serial version label (e.g. "1.0", "1.1")
|
||||
*
|
||||
* @param versionHistory a version histore node reference
|
||||
* @param versionHistory a version history node reference
|
||||
* @param nodeRef a node reference
|
||||
*/
|
||||
private void checkForCorruptedVersions(NodeRef versionHistory, NodeRef nodeRef)
|
||||
|
||||
@@ -169,11 +169,10 @@ public interface VersionService
|
||||
throws AspectMissingException;
|
||||
|
||||
/**
|
||||
* Gets the version object for the current version of the node reference
|
||||
* passed.
|
||||
* Gets the version object for the current version of the node reference passed.
|
||||
* <p>
|
||||
* Returns null if the node is not versionable or has not been versioned.
|
||||
* @param nodeRef the node reference
|
||||
* @param nodeRef the node reference of the 'live' node
|
||||
* @return the version object for the current version
|
||||
*/
|
||||
@Auditable(parameters = {"nodeRef"})
|
||||
|
||||
@@ -336,10 +336,41 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
|
||||
createVersion(node);
|
||||
}
|
||||
|
||||
// TODO test versioning numberious times with branchs implies by different workspaces
|
||||
/**
|
||||
* Test retrieving the current version for a node with multiple versions
|
||||
*/
|
||||
public void testGetCurrentVersion()
|
||||
{
|
||||
NodeRef versionableNode = createNewVersionableNode();
|
||||
createVersion(versionableNode);
|
||||
createVersion(versionableNode);
|
||||
createVersion(versionableNode);
|
||||
|
||||
VersionHistory vh = this.versionService.getVersionHistory(versionableNode);
|
||||
Version version = vh.getRootVersion();
|
||||
|
||||
// Get current version from live node
|
||||
NodeRef node = version.getVersionedNodeRef();
|
||||
Version currentVersion = versionService.getCurrentVersion(node);
|
||||
assertNotNull("Failed to retrieve the current version from the head", currentVersion);
|
||||
|
||||
try
|
||||
{
|
||||
// Get current version from the version node (frozen state version node) - not allowed (MNT-15447)
|
||||
node = version.getFrozenStateNodeRef();
|
||||
currentVersion = versionService.getCurrentVersion(node);
|
||||
fail("Getting the current version is only allowed on live nodes, not on version nodes.");
|
||||
}
|
||||
catch (IllegalArgumentException ex)
|
||||
{
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
// TODO test versioning numberious times with branches implies by different workspaces
|
||||
|
||||
/**
|
||||
* Test versioning the children of a verionable node
|
||||
* Test versioning the children of a versionable node
|
||||
*/
|
||||
public void testVersioningChildren()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user