Author: paristote
Date: 2011-05-10 08:01:51 -0400 (Tue, 10 May 2011)
New Revision: 4355
Added:
jcr/branches/1.12.x/patch/1.12.9-GA/JCR-1613/readme.txt
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/ItemDataMoveVisitor.java
jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/writing/TestOrderBefore.java
jcr/branches/1.12.x/exo.jcr.component.core/src/test/resources/conf/test/nodetypes-usecase.xml
Log:
JCR-1613
This bug happens randomly (like EXOJCR-1234) when a node is ordered after it was moved at
the same parent (to rename it).
For instance let's suppose we have an ordered list ("a","b") and
we want to rename "a" to "c" and keep the same order then the JCR
operations to do it are:
session.move(parent.getPath() + "/a", parent.getPath() + "/c");
parent.orderBefore("c", "b");
How is the problem fixed?
New node is added to the end of the list of parent node as implementation says
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2011-05-10
09:21:30 UTC (rev 4354)
+++
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2011-05-10
12:01:51 UTC (rev 4355)
@@ -2441,11 +2441,6 @@
protected void doOrderBefore(QPath srcPath, QPath destPath) throws
RepositoryException
{
- if (!getPrimaryNodeType().hasOrderableChildNodes())
- {
- throw new UnsupportedRepositoryOperationException("child node ordering not
supported on node " + getPath());
- }
-
if (srcPath.equals(destPath))
{
return;
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/ItemDataMoveVisitor.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/ItemDataMoveVisitor.java 2011-05-10
09:21:30 UTC (rev 4354)
+++
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/ItemDataMoveVisitor.java 2011-05-10
12:01:51 UTC (rev 4355)
@@ -133,18 +133,23 @@
NodeData srcParent;
destIndex = 1;
+
+ // If ordering is supported by the node
+ // type of the parent node of the new location, then the
+ // newly moved node is appended to the end of the child
+ // node list.
destOrderNum = destChilds.size() > 0 ? destChilds.get(destChilds.size() -
1).getOrderNumber() + 1 : 0;
if (parent.getIdentifier().equals(node.getParentIdentifier()))
{
- // move to another dest
+ // move to same parent
srcChilds = destChilds;
srcParent = parent;
}
else
{
- // move of SNSes on same parent
- // find index and orederNum on destination
+ // move to another parent
+ // find index on destination
for (NodeData dchild : destChilds)
{
if (dchild.getQPath().getName().equals(qname))
@@ -154,16 +159,17 @@
// for fix SNSes on source
srcParent = (NodeData)dataManager.getItemData(node.getParentIdentifier());
if (srcParent == null)
+ {
throw new RepositoryException("FATAL: parent Node not for " +
node.getQPath().getAsString()
+ ", parent id: " + node.getParentIdentifier());
+ }
srcChilds = dataManager.getChildNodesData(srcParent);
}
- int srcOrderNum = 0;
int srcIndex = 1;
- // Calculate SNS index on source
+ // Fix SNS on source
for (int i = 0; i < srcChilds.size(); i++)
{
NodeData child = srcChilds.get(i);
@@ -173,22 +179,21 @@
{
QPath siblingPath = QPath.makeChildPath(srcParent.getQPath(),
child.getQPath().getName(), srcIndex);
TransientNodeData sibling =
- new TransientNodeData(siblingPath, child.getIdentifier(),
child.getPersistedVersion() + 1, child
- .getPrimaryTypeName(), child.getMixinTypeNames(), srcOrderNum, //
orderNum
+ new TransientNodeData(siblingPath, child.getIdentifier(),
child.getPersistedVersion() + 1,
+ child.getPrimaryTypeName(), child.getMixinTypeNames(),
child.getOrderNumber(),
child.getParentIdentifier(), child.getACL());
+
addStates.add(new ItemState(sibling, ItemState.UPDATED, true,
ancestorToSave, false, true));
srcIndex++;
}
-
- srcOrderNum++;
}
}
+ // in case of moving to the same parent destination index is calculated above
if (srcChilds == destChilds)
{
destIndex = srcIndex;
- destOrderNum = srcOrderNum;
}
}
else
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/writing/TestOrderBefore.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/writing/TestOrderBefore.java 2011-05-10
09:21:30 UTC (rev 4354)
+++
jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/writing/TestOrderBefore.java 2011-05-10
12:01:51 UTC (rev 4355)
@@ -19,6 +19,9 @@
package org.exoplatform.services.jcr.api.writing;
import org.exoplatform.services.jcr.JcrAPIBaseTest;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.impl.core.NodeImpl;
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
import org.exoplatform.services.jcr.impl.util.EntityCollection;
import java.util.ArrayList;
@@ -1032,6 +1035,76 @@
}
}
+ public void testOrderBeforeAfterMove() throws Exception
+ {
+ SessionImpl session = (SessionImpl)repository.login(credentials, WORKSPACE);
+ Node list = session.getRootNode().addNode("list2", "list");
+ assertEquals("list", list.getPrimaryNodeType().getName());
+ assertTrue(list.getPrimaryNodeType().hasOrderableChildNodes());
+
+ String path = list.addNode("1").getPath();
+ list.addNode("2");
+ session.save();
+ session.logout();
+
+ session = (SessionImpl)repository.login(credentials, WORKSPACE);
+ list = session.getRootNode().getNode("list2");
+ session.move(path, list.getPath() + "/3");
+ list.orderBefore("3", "2");
+ session.save();
+ session.logout();
+
+ session = (SessionImpl)repository.login(credentials, WORKSPACE);
+ NodeIterator it = session.getRootNode().getNode("list2").getNodes();
+ NodeImpl node1 = (NodeImpl)it.nextNode();
+ NodeImpl node2 = (NodeImpl)it.nextNode();
+ assertEquals("3", node1.getName());
+ assertEquals("2", node2.getName());
+ assertTrue(((NodeData)node1.getData()).getOrderNumber() <
((NodeData)node2.getData()).getOrderNumber());
+
+ session.logout();
+ }
+
+ public void testOrderBeforeAfterMove2() throws Exception
+ {
+ SessionImpl session = (SessionImpl)repository.login(credentials, WORKSPACE);
+ Node list = session.getRootNode().addNode("list2", "list");
+ assertEquals("list", list.getPrimaryNodeType().getName());
+ assertTrue(list.getPrimaryNodeType().hasOrderableChildNodes());
+
+ list.addNode("1");
+ list.addNode("2");
+ list.addNode("3");
+ list.addNode("4");
+ session.save();
+ session.logout();
+
+ session = (SessionImpl)repository.login(credentials, WORKSPACE);
+ list = session.getRootNode().getNode("list2");
+ session.move(list.getPath() + "/2", list.getPath() + "/5");
+ list.orderBefore("5", "1");
+ session.save();
+ session.logout();
+
+ session = (SessionImpl)repository.login(credentials, WORKSPACE);
+ NodeIterator it = session.getRootNode().getNode("list2").getNodes();
+ NodeImpl node1 = (NodeImpl)it.nextNode();
+ NodeImpl node2 = (NodeImpl)it.nextNode();
+ NodeImpl node3 = (NodeImpl)it.nextNode();
+ NodeImpl node4 = (NodeImpl)it.nextNode();
+
+ assertEquals("5", node1.getName());
+ assertEquals("1", node2.getName());
+ assertEquals("3", node3.getName());
+ assertEquals("4", node4.getName());
+
+ assertTrue(((NodeData)node1.getData()).getOrderNumber() <
((NodeData)node2.getData()).getOrderNumber());
+ assertTrue(((NodeData)node2.getData()).getOrderNumber() <
((NodeData)node3.getData()).getOrderNumber());
+ assertTrue(((NodeData)node3.getData()).getOrderNumber() <
((NodeData)node4.getData()).getOrderNumber());
+
+ session.logout();
+ }
+
private EntityCollection getEntityCollection(NodeIterator nodes)
{
List result = new ArrayList();
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/test/resources/conf/test/nodetypes-usecase.xml
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.core/src/test/resources/conf/test/nodetypes-usecase.xml 2011-05-10
09:21:30 UTC (rev 4354)
+++
jcr/branches/1.12.x/exo.jcr.component.core/src/test/resources/conf/test/nodetypes-usecase.xml 2011-05-10
12:01:51 UTC (rev 4355)
@@ -253,4 +253,18 @@
</propertyDefinitions>
</nodeType>
+ <nodeType name="list" isMixin="false"
hasOrderableChildNodes="true" primaryItemName="">
+ <supertypes>
+ <supertype>nt:base</supertype>
+ </supertypes>
+ <childNodeDefinitions>
+ <childNodeDefinition name="*"
defaultPrimaryType="nt:unstructured" autoCreated="false"
mandatory="false" onParentVersion="COPY" protected="false"
sameNameSiblings="false">
+ <requiredPrimaryTypes>
+ <requiredPrimaryType>nt:unstructured</requiredPrimaryType>
+ </requiredPrimaryTypes>
+ </childNodeDefinition>
+ </childNodeDefinitions>
+ </nodeType>
+
+
</nodeTypes>
Added: jcr/branches/1.12.x/patch/1.12.9-GA/JCR-1613/readme.txt
===================================================================
--- jcr/branches/1.12.x/patch/1.12.9-GA/JCR-1613/readme.txt (rev
0)
+++ jcr/branches/1.12.x/patch/1.12.9-GA/JCR-1613/readme.txt 2011-05-10 12:01:51 UTC (rev
4355)
@@ -0,0 +1,67 @@
+Summary
+
+ Status: Backporting EXOJCR-1305 to JCR 1.12.x
+ CCP Issue: CPP-915, Product Jira Issue: JCR-1613.
+ Complexity: Low
+
+The Proposal
+Problem description
+
+This bug happens randomly (like EXOJCR-1234) when a node is ordered after it was moved at
the same parent (to rename it).
+For instance let's suppose we have an ordered list ("a","b") and
we want to rename "a" to "c" and keep the same order then the JCR
operations to do it are:
+
+session.move(parent.getPath() + "/a", parent.getPath() + "/c");
+parent.orderBefore("c", "b");
+
+Fix description
+
+How is the problem fixed?
+
+ New node is added to the end of the list of parent node as implementation says
+
+Patch information:
+Patch files: JCR-1613.patch
+
+Tests to perform
+
+Reproduction test
+ * TestOrderBefore.java
+
+Tests performed at DevLevel
+ * Functional tests
+
+Tests performed at QA/Support Level
+*
+
+Documentation changes
+
+Documentation changes:
+ * No
+
+Configuration changes
+
+Configuration changes:
+ * No
+
+Will previous configuration continue to work?
+ * Yes
+
+Risks and impacts
+
+Can this bug fix have any side effects on current client projects?
+ No
+
+Is there a performance risk/cost?
+ * No
+
+Validation (PM/Support/QA)
+
+PM Comment
+* Patch approved
+
+Support Comment
+* Patch validated
+
+QA Feedbacks
+*
+