mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
MNT-22715 - Document Version Issue (#831)
* MNT-22715 - Document Version Issue - Unexpected: current version does not appear to be 1st version in the list * Set association index on new version creation * Unit test to verify the child assoc index is set on versions * Set association index on new version creation on AGS create record from version
This commit is contained in:
@@ -434,6 +434,7 @@ public class RecordableVersionServiceImpl extends Version2ServiceImpl
|
||||
QName.createQName(Version2Model.NAMESPACE_URI, Version2Model.CHILD_VERSIONS + "-" + versionNumber),
|
||||
sourceTypeRef,
|
||||
null);
|
||||
nodeService.setChildAssociationIndex(childAssocRef, getAllVersions(versionHistoryRef).size());
|
||||
versionNodeRef = childAssocRef.getChildRef();
|
||||
|
||||
// add aspect with the standard version properties to the 'version' node
|
||||
@@ -808,6 +809,7 @@ public class RecordableVersionServiceImpl extends Version2ServiceImpl
|
||||
QName.createQName(Version2Model.NAMESPACE_URI, Version2Model.CHILD_VERSIONS + "-" + versionNumber),
|
||||
sourceTypeRef,
|
||||
null);
|
||||
nodeService.setChildAssociationIndex(childAssocRef, getAllVersions(versionHistoryRef).size());
|
||||
NodeRef versionNodeRef = childAssocRef.getChildRef();
|
||||
|
||||
// add aspect with the standard version properties to the 'version' node
|
||||
|
@@ -508,6 +508,7 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
|
||||
nodeDetails.getProperties());
|
||||
|
||||
versionNodeRef = childAssocRef.getChildRef();
|
||||
nodeService.setChildAssociationIndex(childAssocRef, getAllVersions(versionHistoryRef).size());
|
||||
|
||||
// NOTE: special ML case - see also MultilingualContentServiceImpl.makeMLContainer
|
||||
if (sourceTypeRef.equals(ContentModel.TYPE_MULTILINGUAL_CONTAINER))
|
||||
|
@@ -39,7 +39,6 @@ import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.transaction.UserTransaction;
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
import org.alfresco.model.ApplicationModel;
|
||||
import org.alfresco.model.ContentModel;
|
||||
@@ -94,6 +93,8 @@ import org.springframework.test.annotation.Commit;
|
||||
import org.springframework.test.context.transaction.TestTransaction;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
/**
|
||||
* versionService test class.
|
||||
*
|
||||
@@ -575,6 +576,46 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When IDs are out of order the comparator only fixes the order we retrieve versions. Any operation fails due to
|
||||
* the head version not being the latest. (MNT-22715)
|
||||
*/
|
||||
@Test
|
||||
public void testVersionIndex()
|
||||
{
|
||||
NodeRef versionableNode = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN,
|
||||
QName.createQName("{test}MyVersionableNodeTestIndex"), ContentModel.TYPE_CONTENT, null).getChildRef();
|
||||
nodeService.addAspect(versionableNode, ContentModel.ASPECT_VERSIONABLE, new HashMap<QName, Serializable>());
|
||||
Version version1 = createVersion(versionableNode);
|
||||
Version version2 = createVersion(versionableNode);
|
||||
Version version3 = createVersion(versionableNode);
|
||||
|
||||
VersionHistory vh = versionService.getVersionHistory(versionableNode);
|
||||
assertEquals("Version History does not contain 3 versions", 3, vh.getAllVersions().size());
|
||||
|
||||
NodeRef root = nodeService.getPrimaryParent(vh.getRootVersion().getFrozenStateNodeRef()).getParentRef();
|
||||
NodeRef versionHistoryNode = dbNodeService.getChildByName(root, Version2Model.CHILD_QNAME_VERSION_HISTORIES,
|
||||
versionableNode.getId());
|
||||
|
||||
// getChildAssocs orders by assoc_index first and then by ID. Version History relies on this.
|
||||
List<ChildAssociationRef> vhChildAssocs = nodeService.getChildAssocs(versionHistoryNode);
|
||||
int index = 0;
|
||||
for (ChildAssociationRef vhChildAssoc : vhChildAssocs)
|
||||
{
|
||||
// Unset indexes are -1
|
||||
assertFalse("Index is not set", vhChildAssoc.getNthSibling() < 0);
|
||||
assertTrue("Index is not increasing as expected", vhChildAssoc.getNthSibling() > index);
|
||||
index = vhChildAssoc.getNthSibling();
|
||||
}
|
||||
|
||||
assertEquals("1st version is not 1st assoc", version1.getFrozenStateNodeRef().getId(),
|
||||
vhChildAssocs.get(0).getChildRef().getId());
|
||||
assertEquals("2nd version is not 2nd assoc", version2.getFrozenStateNodeRef().getId(),
|
||||
vhChildAssocs.get(1).getChildRef().getId());
|
||||
assertEquals("3rd version is not 3rd assoc", version3.getFrozenStateNodeRef().getId(),
|
||||
vhChildAssocs.get(2).getChildRef().getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the versionService to be one that has is db ids out of order
|
||||
* so would normally have versions displayed in the wrong order.
|
||||
|
Reference in New Issue
Block a user