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/09 21:53:54 UTC

svn commit: r1593608 - 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: Fri May  9 19:53:53 2014
New Revision: 1593608

URL: http://svn.apache.org/r1593608
Log:
SLING-3551 - Content sync does not propagate mixin types

Sync mixin types whenever a node is created or updated.

Added:
    sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrFullCoverageAggregatesDeploymentTest.java   (with props)
    sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/content-nested-structure.xml   (with props)
Modified:
    sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java

Added: 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=1593608&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrFullCoverageAggregatesDeploymentTest.java (added)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrFullCoverageAggregatesDeploymentTest.java Fri May  9 19:53:53 2014
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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.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 java.io.InputStream;
+import java.util.concurrent.Callable;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.sling.ide.test.impl.helpers.DisableDebugStatusHandlers;
+import org.apache.sling.ide.test.impl.helpers.ExternalSlingLaunchpad;
+import org.apache.sling.ide.test.impl.helpers.LaunchpadConfig;
+import org.apache.sling.ide.test.impl.helpers.Poller;
+import org.apache.sling.ide.test.impl.helpers.ProjectAdapter;
+import org.apache.sling.ide.test.impl.helpers.RepositoryAccessor;
+import org.apache.sling.ide.test.impl.helpers.ServerAdapter;
+import org.apache.sling.ide.test.impl.helpers.SlingWstServer;
+import org.apache.sling.ide.test.impl.helpers.TemporaryProject;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.Path;
+import org.hamcrest.Matcher;
+import org.junit.After;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TestRule;
+
+/**
+ * The <tt>JcrFullCoverageAggregatesDeploymentTest</tt> validates deployment of full-coverage aggregates
+ * 
+ * @see <a href="https://jackrabbit.apache.org/filevault/vaultfs.html">Vault FS</a>
+ *
+ */
+public class JcrFullCoverageAggregatesDeploymentTest {
+
+    private final LaunchpadConfig config = LaunchpadConfig.getInstance();
+
+    private final SlingWstServer wstServer = new SlingWstServer(config);
+
+    @Rule
+    public TestRule chain = RuleChain.outerRule(new ExternalSlingLaunchpad(config)).around(wstServer);
+
+    @Rule
+    public TemporaryProject projectRule = new TemporaryProject();
+
+    @Rule
+    public DisableDebugStatusHandlers disableDebugHandlers = new DisableDebugStatusHandlers();
+
+    @Test
+    public void deployNestedFullCoverageAggregate() 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 postConditions = allOf(hasPath("/content/test-root/en"), hasPrimaryType("sling:Folder"),
+                hasMixinTypes("mix:language"), hasChildrenCount(3));
+
+        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);
+    }
+
+    @After
+    public void cleanup() throws Exception {
+        new RepositoryAccessor(config).tryDeleteResource("/content/test-root");
+    }
+}

Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrFullCoverageAggregatesDeploymentTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrFullCoverageAggregatesDeploymentTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/content-nested-structure.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/content-nested-structure.xml?rev=1593608&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/content-nested-structure.xml (added)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/content-nested-structure.xml Fri May  9 19:53:53 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:Folder"
+    jcr:language="en">
+    <message
+        jcr:primaryType="nt:unstructured"
+        sling:key="message"
+        sling:value="Message">
+    </message>
+    <error
+        jcr:primaryType="nt:unstructured"
+        sling:key="error"
+        sling:value="Error">
+    </error>
+    <warning
+        jcr:primaryType="nt:unstructured"
+        sling:key="warning"
+        sling:value="Warning">
+    </warning>
+</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.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/content-nested-structure.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=1593608&r1=1593607&r2=1593608&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 Fri May  9 19:53:53 2014
@@ -28,8 +28,11 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Calendar;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
@@ -47,6 +50,7 @@ import javax.jcr.Value;
 import javax.jcr.ValueFactory;
 import javax.jcr.nodetype.NodeType;
 
+import org.apache.jackrabbit.vault.util.JcrConstants;
 import org.apache.jackrabbit.vault.util.Text;
 import org.apache.sling.ide.transport.FileInfo;
 import org.apache.sling.ide.transport.ResourceProxy;
@@ -141,9 +145,15 @@ public class AddOrUpdateNodeCommand exte
         
         propertiesToRemove.removeAll(resource.getProperties().keySet());
 
-
         Session session = node.getSession();
 
+        // update the mixin types ahead of type as contraints are enforced before
+        // the session is committed
+        Object mixinTypes = resource.getProperties().get(JcrConstants.JCR_MIXINTYPES);
+        if (mixinTypes != null) {
+            updateMixins(node, mixinTypes);
+        }
+
         // TODO - review for completeness and filevault compatibility
         for (Map.Entry<String, Object> entry : resource.getProperties().entrySet()) {
 
@@ -248,6 +258,35 @@ public class AddOrUpdateNodeCommand exte
 
     }
 
+    private void updateMixins(Node node, Object mixinValue) throws RepositoryException {
+
+        List<String> newMixins = new ArrayList<String>();
+
+        if (mixinValue instanceof String) {
+            newMixins.add((String) mixinValue);
+        } else {
+            newMixins.addAll(Arrays.asList((String[]) mixinValue));
+        }
+
+        List<String> oldMixins = new ArrayList<String>();
+        for (NodeType mixinNT : node.getMixinNodeTypes()) {
+            oldMixins.add(mixinNT.getName());
+        }
+
+        List<String> mixinsToAdd = new ArrayList<String>(newMixins);
+        mixinsToAdd.removeAll(oldMixins);
+        List<String> mixinsToRemove = new ArrayList<String>(oldMixins);
+        mixinsToRemove.removeAll(newMixins);
+
+        for (String mixinToAdd : mixinsToAdd) {
+            node.addMixin(mixinToAdd);
+        }
+
+        for (String mixinToRemove : mixinsToRemove) {
+            node.removeMixin(mixinToRemove);
+        }
+    }
+
     private void updateFileLikeNodeTypes(Node node) throws RepositoryException, IOException {
         // TODO - better handling of file-like nodes - perhaps we need to know the SerializationKind here
         // TODO - avoid IO