Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)

98998: Merged 5.0.N (5.0.2) to HEAD-BUG-FIX (5.1/Cloud)
      98976: Merged V4.2-BUG-FIX (4.2.5) to 5.0.N (5.0.2)
         98929: Reverse Merge V4.2-BUG-FIX (4.2.5)
            98859: Merged V4.1-BUG-FIX (4.1.10) to V4.2-BUG-FIX (4.2.5)
               98757: Merged DEV to V4.1-BUG-FIX (4.1.10)
                  94378 : MNT-6400: Issue with versioning and comments
                     - Ignore comments properties/aspects/children
                  96791 : MNT-6400: Issue with versioning and comments
                     - Added a test


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@99001 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2015-03-07 16:36:10 +00:00
parent af76d879cb
commit f764bfec04
2 changed files with 8 additions and 138 deletions

View File

@@ -31,7 +31,6 @@ import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.model.ForumModel;
import org.alfresco.repo.policy.PolicyScope;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.version.VersionRevertCallback.RevertAspectAction;
@@ -53,7 +52,6 @@ import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionHistory;
import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.cmr.version.VersionServiceException;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.util.Pair;
@@ -1014,26 +1012,6 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
// The frozen (which will become new) values
// Get the node that represents the frozen state
NodeRef versionNodeRef = version.getFrozenStateNodeRef();
boolean needToRestoreDiscussion = !this.nodeService.hasAspect(versionNodeRef, ForumModel.ASPECT_DISCUSSABLE)
&& this.nodeService.hasAspect(nodeRef, ForumModel.ASPECT_DISCUSSABLE);
Map<QName, Serializable> forumProps = null;
// Collect forum properties
// only if previous version hasn't discussable aspect
if (needToRestoreDiscussion)
{
Map<QName, Serializable> currentVersionProp = this.nodeService.getProperties(nodeRef);
forumProps = new HashMap<QName, Serializable>();
for (QName key : currentVersionProp.keySet())
{
if (key.getNamespaceURI().equals(NamespaceService.FORUMS_MODEL_1_0_URI))
{
forumProps.put(key, currentVersionProp.get(key));
}
}
}
Map<QName, Serializable> newProps = this.nodeService.getProperties(versionNodeRef);
VersionUtil.convertFrozenToOriginalProps(newProps);
Set<QName> newAspectQNames = this.nodeService.getAspects(versionNodeRef);
@@ -1087,12 +1065,6 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
}
this.nodeService.setProperties(nodeRef, newProps);
//Restore forum properties
if (needToRestoreDiscussion)
{
this.nodeService.addProperties(nodeRef, forumProps);
}
Set<QName> aspectsToRemove = new HashSet<QName>(oldAspectQNames);
aspectsToRemove.removeAll(newAspectQNames);
@@ -1107,19 +1079,6 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
{
this.nodeService.addAspect(nodeRef, aspect, null);
}
}
// Don't remove forum aspects
if (needToRestoreDiscussion)
{
Set<QName> ignoredAspects = new HashSet<QName>();
for (QName aspectForCheck : aspects)
{
if (aspectForCheck.getNamespaceURI().equals(NamespaceService.FORUMS_MODEL_1_0_URI))
{
ignoredAspects.add(aspectForCheck);
}
}
aspects.removeAll(ignoredAspects);
}
// remove aspects that are not on the frozen node
@@ -1216,19 +1175,6 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
children.remove(versionedChild);
}
}
// Don't remove forum children
if (needToRestoreDiscussion)
{
List<ChildAssociationRef> ignoredChildren = new ArrayList<ChildAssociationRef>();
for (ChildAssociationRef childForCheck : children)
{
if (childForCheck.getTypeQName().getNamespaceURI().equals(NamespaceService.FORUMS_MODEL_1_0_URI))
{
ignoredChildren.add(childForCheck);
}
}
children.removeAll(ignoredChildren);
}
for (ChildAssociationRef ref : children)
{
if (!assocsToLeaveAlone.contains(ref.getTypeQName()))

View File

@@ -117,66 +117,23 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
// NOOP
}
/**
* MNT-6400 : Issue with versioning and comments
*
* Test scenarios:
* 1) Create three versions with comments. Then revert to v1. All comments must be exist.
* 2) Create three versions. Add comment to the latest two versions (v2 and v3). Then revert to v1. Comments must be exist.
*/
// MNT-6400 Reverted node must not have fm:discussable aspect
// from next version
public void testDiscussableAspect()
{
final String V1_COMMENT = "<p>Comment for version 1</p>";
final String V2_COMMENT = "<p>Comment for version 2</p>";
final String V3_COMMENT = "Comment for third version";
NodeRef versionableNode = createNewVersionableNode();
// Test scenario 1
Version v1 = createVersion(versionableNode);
addComment(versionableNode, V1_COMMENT, false);
Version v2 = createVersion(versionableNode);
createVersion(versionableNode);
VersionHistory vh = this.versionService.getVersionHistory(versionableNode);
assertEquals(2, vh.getAllVersions().size());
addComment(versionableNode, V2_COMMENT, false);
addComment(versionableNode, "<p>Comm123</p>", false);
Set<QName> aspects = nodeService.getAspects(versionableNode);
assertTrue(aspects.contains(ForumModel.ASPECT_DISCUSSABLE));
assertTrue(isCommentExist(versionableNode, V2_COMMENT));
Version v3 = createVersion(versionableNode);
vh = this.versionService.getVersionHistory(versionableNode);
assertEquals(3, vh.getAllVersions().size());
addComment(versionableNode, V3_COMMENT, false);
assertTrue(isCommentExist(versionableNode, V3_COMMENT));
this.versionService.revert(versionableNode, v1);
assertTrue(isCommentExist(versionableNode, V3_COMMENT));
assertTrue(isCommentExist(versionableNode, V2_COMMENT));
assertTrue(isCommentExist(versionableNode, V1_COMMENT));
// Test scenario 2
versionableNode = createNewVersionableNode();
v1 = createVersion(versionableNode);
vh = this.versionService.getVersionHistory(versionableNode);
assertEquals(1, vh.getAllVersions().size());
v2 = createVersion(versionableNode);
vh = this.versionService.getVersionHistory(versionableNode);
assertEquals(2, vh.getAllVersions().size());
addComment(versionableNode, V2_COMMENT, false);
assertTrue(isCommentExist(versionableNode, V2_COMMENT));
v3 = createVersion(versionableNode);
vh = this.versionService.getVersionHistory(versionableNode);
assertEquals(3, vh.getAllVersions().size());
addComment(versionableNode, V3_COMMENT, false);
assertTrue(isCommentExist(versionableNode, V3_COMMENT));
this.versionService.revert(versionableNode, v1);
assertTrue(isCommentExist(versionableNode, V3_COMMENT));
assertTrue(isCommentExist(versionableNode, V2_COMMENT));
assertFalse(isCommentExist(versionableNode, V1_COMMENT));
aspects = nodeService.getAspects(versionableNode);
assertFalse(aspects.contains(ForumModel.ASPECT_DISCUSSABLE));
}
private NodeRef addComment(NodeRef nr, String comment, boolean suppressRollups)
@@ -215,39 +172,6 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
return postNode;
}
private boolean isCommentExist(NodeRef nr, String commentForCheck)
{
if (!nodeService.hasAspect(nr, ForumModel.ASPECT_DISCUSSABLE))
{
return false;
}
NodeRef forumNode = nodeService.getChildAssocs(nr, ForumModel.ASSOC_DISCUSSION, QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "discussion")).get(0).getChildRef();
final List<ChildAssociationRef> existingTopics = nodeService.getChildAssocs(forumNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Comments"));
if (existingTopics.isEmpty())
{
return false;
}
NodeRef topicNode = existingTopics.get(0).getChildRef();
Collection<ChildAssociationRef> comments = nodeService.getChildAssocsWithoutParentAssocsOfType(topicNode, ContentModel.ASSOC_CONTAINS);
for (ChildAssociationRef comment : comments)
{
NodeRef commentRef = comment.getChildRef();
ContentReader reader = contentService.getReader(commentRef, ContentModel.PROP_CONTENT);
if (reader == null)
{
continue;
}
String contentString = reader.getContentString();
if (commentForCheck.equals(contentString))
{
return true;
}
}
return false;
}
/**
* Tests the creation of the initial version of a versionable node
*/
@@ -751,7 +675,7 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
//Revert to a version that has no comments.
this.versionService.revert(versionableNode, version1);
assertEquals("I am before version", this.dbNodeService.getProperty(versionableNode, PROP_1));
assertTrue(nodeService.hasAspect(versionableNode, ForumModel.ASPECT_DISCUSSABLE));
assertFalse(nodeService.hasAspect(versionableNode, ForumModel.ASPECT_DISCUSSABLE));
//Revert to a version that has comments.
this.versionService.revert(versionableNode, version3);
@@ -775,7 +699,7 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
//Revert to version without comments
this.versionService.revert(clearNode, clearVersion1);
assertTrue(nodeService.hasAspect(clearNode, ForumModel.ASPECT_DISCUSSABLE));
assertFalse(nodeService.hasAspect(clearNode, ForumModel.ASPECT_DISCUSSABLE));
//Create new version with comments
createComment(clearNode, "my comment", "Do great work", false);