mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)
78501: Merged V4.2-BUG-FIX (4.2.4) to HEAD-BUG-FIX (5.0/Cloud) 76817: MNT-11756: Merged DEV to V4.2-BUG-FIX (4.2.4) 76808: MNT-11756: Associated nodes deleted when reverting to older version. - Keep secondary association during revert if versioned and current node have child association with the same node git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@82573 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1275,6 +1275,7 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
|
|||||||
if (children.contains(versionedChild) == false)
|
if (children.contains(versionedChild) == false)
|
||||||
{
|
{
|
||||||
NodeRef childRef = null;
|
NodeRef childRef = null;
|
||||||
|
ChildAssociationRef assocToKeep = null;
|
||||||
if (this.nodeService.exists(versionedChild.getChildRef()) == true)
|
if (this.nodeService.exists(versionedChild.getChildRef()) == true)
|
||||||
{
|
{
|
||||||
// The node was a primary child of the parent, but that is no longer the case. Despite this
|
// The node was a primary child of the parent, but that is no longer the case. Despite this
|
||||||
@@ -1292,6 +1293,7 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
|
|||||||
if (children.contains(assocToCheck))
|
if (children.contains(assocToCheck))
|
||||||
{
|
{
|
||||||
childRef = assocToCheck.getChildRef();
|
childRef = assocToCheck.getChildRef();
|
||||||
|
assocToKeep = assocToCheck;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1325,10 +1327,17 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
|
|||||||
// the missing node as it was never owned by the node and we wouldn't know where to put it.
|
// the missing node as it was never owned by the node and we wouldn't know where to put it.
|
||||||
}
|
}
|
||||||
if (childRef != null)
|
if (childRef != null)
|
||||||
|
{
|
||||||
|
if (assocToKeep != null)
|
||||||
|
{
|
||||||
|
children.remove(assocToKeep);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
children.remove(nodeService.getPrimaryParent(childRef));
|
children.remove(nodeService.getPrimaryParent(childRef));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
children.remove(versionedChild);
|
children.remove(versionedChild);
|
||||||
|
@@ -111,6 +111,11 @@ public abstract class BaseVersionStoreTest extends BaseSpringTest
|
|||||||
protected static final QName TEST_CHILD_ASSOC_1 = QName.createQName(TEST_NAMESPACE, "childassoc1");
|
protected static final QName TEST_CHILD_ASSOC_1 = QName.createQName(TEST_NAMESPACE, "childassoc1");
|
||||||
protected static final QName TEST_CHILD_ASSOC_2 = QName.createQName(TEST_NAMESPACE, "childassoc2");
|
protected static final QName TEST_CHILD_ASSOC_2 = QName.createQName(TEST_NAMESPACE, "childassoc2");
|
||||||
protected static final QName TEST_ASSOC = QName.createQName(TEST_NAMESPACE, "assoc1");
|
protected static final QName TEST_ASSOC = QName.createQName(TEST_NAMESPACE, "assoc1");
|
||||||
|
protected static final QName TEST_ATS_PARENT_TYPE_QNAME = QName.createQName(TEST_NAMESPACE, "atsParent");
|
||||||
|
protected static final QName TEST_ATS_CHILD_TYPE_QNAME = QName.createQName(TEST_NAMESPACE, "atsChild");
|
||||||
|
protected static final QName TEST_ATS_RELATED_CHILDREN_QNAME = QName.createQName(TEST_NAMESPACE, "atsRelatedChildren");
|
||||||
|
protected static final QName PROP_ATS_PARENT_ID = QName.createQName(TEST_NAMESPACE, "atsParentID");
|
||||||
|
protected static final QName PROP_ATS_CHILD_ID = QName.createQName(TEST_NAMESPACE, "atsChildID");
|
||||||
|
|
||||||
protected Collection<String> multiValue = null;
|
protected Collection<String> multiValue = null;
|
||||||
protected static final String MULTI_VALUE_1 = "multi1";
|
protected static final String MULTI_VALUE_1 = "multi1";
|
||||||
|
@@ -714,6 +714,48 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that secondary association is present after revert, see MNT-11756
|
||||||
|
*/
|
||||||
|
public void testAssociationIsPresentAfterRevert()
|
||||||
|
{
|
||||||
|
// Create Order
|
||||||
|
NodeRef orderNodeRef = this.dbNodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN,
|
||||||
|
QName.createQName("{test}MyVersionableOrder"), TEST_ATS_PARENT_TYPE_QNAME, this.nodeProperties).getChildRef();
|
||||||
|
this.dbNodeService.addAspect(orderNodeRef, ContentModel.ASPECT_VERSIONABLE, new HashMap<QName, Serializable>());
|
||||||
|
assertNotNull(orderNodeRef);
|
||||||
|
this.dbNodeService.setProperty(orderNodeRef, PROP_ATS_PARENT_ID, 1);
|
||||||
|
|
||||||
|
// Create Order-Product association
|
||||||
|
NodeRef productNodeRef = this.dbNodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN,
|
||||||
|
QName.createQName("{test}MyProduct1"), TEST_ATS_CHILD_TYPE_QNAME, this.nodeProperties).getChildRef();
|
||||||
|
this.dbNodeService.setProperty(orderNodeRef, PROP_ATS_CHILD_ID, 1);
|
||||||
|
|
||||||
|
ChildAssociationRef childAssoc = this.dbNodeService.addChild(orderNodeRef, productNodeRef, TEST_ATS_RELATED_CHILDREN_QNAME, TEST_ATS_RELATED_CHILDREN_QNAME);
|
||||||
|
assertFalse("Order-product child association should not be primary", childAssoc.isPrimary());
|
||||||
|
|
||||||
|
// Create version
|
||||||
|
Version version1 = createVersion(orderNodeRef);
|
||||||
|
this.dbNodeService.setProperty(orderNodeRef, PROP_ATS_PARENT_ID, 2);
|
||||||
|
assertEquals("New property should be set", 2, this.dbNodeService.getProperty(orderNodeRef, PROP_ATS_PARENT_ID));
|
||||||
|
|
||||||
|
List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(orderNodeRef, TEST_ATS_RELATED_CHILDREN_QNAME, RegexQNamePattern.MATCH_ALL);
|
||||||
|
assertTrue("Order-Product association must exist", childAssocs.size() > 0);
|
||||||
|
assertTrue("Order should have Order-Product association", childAssocs.contains(childAssoc));
|
||||||
|
|
||||||
|
VersionHistory vh = this.versionService.getVersionHistory(orderNodeRef);
|
||||||
|
assertNotNull(vh);
|
||||||
|
assertEquals(1, vh.getAllVersions().size());
|
||||||
|
|
||||||
|
// Revert
|
||||||
|
this.versionService.revert(orderNodeRef, version1);
|
||||||
|
assertEquals("Old property should restore after revert", 1, this.dbNodeService.getProperty(orderNodeRef, PROP_ATS_PARENT_ID));
|
||||||
|
|
||||||
|
childAssocs = nodeService.getChildAssocs(orderNodeRef, TEST_ATS_RELATED_CHILDREN_QNAME, RegexQNamePattern.MATCH_ALL);
|
||||||
|
assertTrue("Order-Product association must exist after revert", childAssocs.size() > 0);
|
||||||
|
assertTrue("Order-Product association should remain the same", childAssocs.contains(childAssoc));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method was taken from the CommmentServiceImpl on the cloud branch
|
* This method was taken from the CommmentServiceImpl on the cloud branch
|
||||||
*
|
*
|
||||||
|
@@ -92,6 +92,40 @@
|
|||||||
</associations>
|
</associations>
|
||||||
</type>
|
</type>
|
||||||
|
|
||||||
|
<type name="test:atsChild">
|
||||||
|
<title>Product Document</title>
|
||||||
|
<parent>cm:content</parent>
|
||||||
|
<properties>
|
||||||
|
<property name="test:atsChildID">
|
||||||
|
<type>d:int</type>
|
||||||
|
</property>
|
||||||
|
</properties>
|
||||||
|
</type>
|
||||||
|
|
||||||
|
<type name="test:atsParent">
|
||||||
|
<title>Order Document</title>
|
||||||
|
<parent>cm:content</parent>
|
||||||
|
<properties>
|
||||||
|
<property name="test:atsParentID">
|
||||||
|
<type>d:int</type>
|
||||||
|
</property>
|
||||||
|
</properties>
|
||||||
|
<associations>
|
||||||
|
<child-association name="test:atsRelatedChildren">
|
||||||
|
<title>Related Product</title>
|
||||||
|
<source>
|
||||||
|
<mandatory>false</mandatory>
|
||||||
|
<many>true</many>
|
||||||
|
</source>
|
||||||
|
<target>
|
||||||
|
<class>test:atsChild</class>
|
||||||
|
<mandatory>false</mandatory>
|
||||||
|
<many>true</many>
|
||||||
|
</target>
|
||||||
|
</child-association>
|
||||||
|
</associations>
|
||||||
|
</type>
|
||||||
|
|
||||||
</types>
|
</types>
|
||||||
|
|
||||||
<aspects>
|
<aspects>
|
||||||
|
Reference in New Issue
Block a user