You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2014/05/12 17:35:56 UTC
svn commit: r1594004 - in /sling/trunk/tooling/ide:
eclipse-test/src/org/apache/sling/ide/test/impl/
impl-vlt/src/org/apache/sling/ide/impl/vlt/
Author: rombert
Date: Mon May 12 15:35:56 2014
New Revision: 1594004
URL: http://svn.apache.org/r1594004
Log:
SLING-3117 - Node order changes made in .content.xml files are not
persisted
Persist node order changes.
Added:
sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/content-nested-structure-reordered-nodes.xml (with props)
Modified:
sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrFullCoverageAggregatesDeploymentTest.java
sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java
Modified: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrFullCoverageAggregatesDeploymentTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrFullCoverageAggregatesDeploymentTest.java?rev=1594004&r1=1594003&r2=1594004&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrFullCoverageAggregatesDeploymentTest.java (original)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrFullCoverageAggregatesDeploymentTest.java Mon May 12 15:35:56 2014
@@ -17,15 +17,18 @@
package org.apache.sling.ide.test.impl;
import static org.apache.sling.ide.test.impl.helpers.jcr.JcrMatchers.hasChildrenCount;
+import static org.apache.sling.ide.test.impl.helpers.jcr.JcrMatchers.hasChildrenNames;
import static org.apache.sling.ide.test.impl.helpers.jcr.JcrMatchers.hasMixinTypes;
import static org.apache.sling.ide.test.impl.helpers.jcr.JcrMatchers.hasPath;
import static org.apache.sling.ide.test.impl.helpers.jcr.JcrMatchers.hasPrimaryType;
import static org.hamcrest.CoreMatchers.allOf;
+import static org.junit.Assert.assertThat;
import java.io.InputStream;
import java.util.concurrent.Callable;
import javax.jcr.Node;
+import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import org.apache.commons.io.IOUtils;
@@ -166,6 +169,66 @@ public class JcrFullCoverageAggregatesDe
}, postConditions);
}
+ @Test
+ public void reorderNodesFromNestedFullCoverageAggregate() throws Exception {
+
+ wstServer.waitForServerToStart();
+
+ // create faceted project
+ IProject contentProject = projectRule.getProject();
+
+ ProjectAdapter project = new ProjectAdapter(contentProject);
+ project.addNatures("org.eclipse.wst.common.project.facet.core.nature");
+
+ // create .content.xml structure
+ InputStream contentXml = getClass().getResourceAsStream("content-nested-structure.xml");
+ try {
+ project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/en.xml"), contentXml);
+ } finally {
+ IOUtils.closeQuietly(contentXml);
+ }
+
+ // install content facet
+ project.installFacet("sling.content", "1.0");
+
+ ServerAdapter server = new ServerAdapter(wstServer.getServer());
+ server.installModule(contentProject);
+
+ Matcher<Node> postConditions = allOf(hasPath("/content/test-root/en"), hasPrimaryType("sling:Folder"),
+ hasMixinTypes("mix:language"), hasChildrenNames("message", "error", "warning"));
+
+ final RepositoryAccessor repo = new RepositoryAccessor(config);
+ Poller poller = new Poller();
+ poller.pollUntil(new Callable<Node>() {
+ @Override
+ public Node call() throws RepositoryException {
+ return repo.getNode("/content/test-root/en");
+
+ }
+ }, postConditions);
+
+ // update .content.xml structure
+ InputStream updatedContentXml = getClass().getResourceAsStream("content-nested-structure-reordered-nodes.xml");
+ try {
+ project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/en.xml"), updatedContentXml);
+ } finally {
+ IOUtils.closeQuietly(updatedContentXml);
+ }
+
+ // poll until we have the child nodes reordered
+ postConditions = allOf(hasPath("/content/test-root/en"), hasPrimaryType("sling:OrderedFolder"),
+ hasMixinTypes("mix:language"), hasChildrenNames("message", "warning", "error"));
+
+ poller.pollUntil(new Callable<Node>() {
+ @Override
+ public Node call() throws RepositoryException {
+ return repo.getNode("/content/test-root/en");
+
+ }
+ }, postConditions);
+
+ }
+
@After
public void cleanup() throws Exception {
new RepositoryAccessor(config).tryDeleteResource("/content/test-root");
Added: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/content-nested-structure-reordered-nodes.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/content-nested-structure-reordered-nodes.xml?rev=1594004&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/content-nested-structure-reordered-nodes.xml (added)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/content-nested-structure-reordered-nodes.xml Mon May 12 15:35:56 2014
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:vlt="http://www.day.com/jcr/vault/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
+ jcr:mixinTypes="[mix:language]"
+ jcr:primaryType="sling:OrderedFolder"
+ jcr:language="en">
+ <message
+ jcr:primaryType="nt:unstructured"
+ sling:key="message"
+ sling:value="Message">
+ </message>
+ <warning
+ jcr:primaryType="nt:unstructured"
+ sling:key="warning"
+ sling:value="Warning">
+ </warning>
+ <error
+ jcr:primaryType="nt:unstructured"
+ sling:key="error"
+ sling:value="Error">
+ </error>
+</jcr:root>
\ No newline at end of file
Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/content-nested-structure-reordered-nodes.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/content-nested-structure-reordered-nodes.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified: sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java?rev=1594004&r1=1594003&r2=1594004&view=diff
==============================================================================
--- sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java (original)
+++ sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java Mon May 12 15:35:56 2014
@@ -33,7 +33,9 @@ import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
+import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
@@ -62,6 +64,7 @@ public class AddOrUpdateNodeCommand exte
private ResourceProxy resource;
private FileInfo fileInfo;
+ private boolean primaryTypeHasChanged;
public AddOrUpdateNodeCommand(Repository jcrRepo, Credentials credentials, FileInfo fileInfo,
ResourceProxy resource) {
@@ -97,6 +100,17 @@ public class AddOrUpdateNodeCommand exte
for (ResourceProxy child : getCoveredChildren(resource)) {
update(child, session);
}
+
+ // save the changes so that the primary node type is propagated
+ // however, we can't do that too early, since required properties might not be set
+ // so we save right before checking for orderable child nodes
+ if (primaryTypeHasChanged) {
+ session.save();
+ }
+ NodeType primaryNodeType = node.getPrimaryNodeType();
+ if (primaryNodeType.hasOrderableChildNodes()) {
+ reorderChildNodes(node, resource);
+ }
}
private void processDeletedNodes(Node node, ResourceProxy resource2) throws RepositoryException {
@@ -124,6 +138,45 @@ public class AddOrUpdateNodeCommand exte
}
}
+ private void reorderChildNodes(Node node, ResourceProxy resource2) throws RepositoryException {
+
+ ListIterator<ResourceProxy> coveredResourceChildren = getCoveredChildren(resource2).listIterator();
+ List<Node> nodeChildren = new LinkedList<Node>();
+ NodeIterator nodeChildrenIt = node.getNodes();
+ while ( nodeChildrenIt.hasNext() ) {
+ nodeChildren.add(nodeChildrenIt.nextNode());
+ }
+ ListIterator<Node> nodeChildrenListIt = nodeChildren.listIterator();
+
+ // in here we should really have equal count of elements, but allow a NSEE
+ // to be raised if one of the iterators has too many
+ boolean changed = false;
+ while (coveredResourceChildren.hasNext() || nodeChildrenListIt.hasNext()) {
+
+ ResourceProxy rp = coveredResourceChildren.next();
+ Node n = nodeChildrenListIt.next();
+
+ reorderChildNodes(n, rp);
+
+ if (Text.getName(rp.getPath()).equals(n.getName())) {
+ continue;
+ }
+
+ String expectedParentName = coveredResourceChildren.hasPrevious() ?
+ Text.getName(coveredResourceChildren.previous().getPath()) : null;
+ node.orderBefore(expectedParentName, n.getName());
+ changed = true;
+ break;
+ }
+
+ // re-read the data and run the ordering again
+ // this makes sure that we don't have inconsistent data in the node list
+ if (changed) {
+ reorderChildNodes(node, resource2);
+ }
+
+ }
+
private List<ResourceProxy> getCoveredChildren(ResourceProxy resource) {
// TODO - this is a workaround for partial coverage nodes being sent here
// when a .content.xml file with partial coverage is added here, the children are listed with no properties
@@ -194,6 +247,7 @@ public class AddOrUpdateNodeCommand exte
String primaryType = (String) resource.getProperties().get(JcrConstants.JCR_PRIMARYTYPE);
if (!node.getPrimaryNodeType().getName().equals(primaryType)) {
node.setPrimaryType(primaryType);
+ primaryTypeHasChanged = true;
}
// TODO - review for completeness and filevault compatibility