sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsedd...@apache.org
Subject [sling-org-apache-sling-fsresource] 01/02: SLING-7463 - FS Resource Provider incorrectly deals with vault aggregate files
Date Thu, 01 Feb 2018 15:16:04 GMT
This is an automated email from the ASF dual-hosted git repository.

jsedding pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git

commit 2d658ef28864b48cca113d709bd38394ddad0d86
Author: Julian Sedding <jsedding@apache.org>
AuthorDate: Thu Feb 1 13:21:45 2018 +0100

    SLING-7463 - FS Resource Provider incorrectly deals with vault aggregate files
---
 .../internal/mapper/FileVaultResourceMapper.java   | 13 +++++++++-
 .../fsprovider/internal/FileVaultContentTest.java  | 30 +++++++++++++++++++++-
 .../content/samples/aggregates/.content.xml        | 21 +++++++++++++++
 .../samples/aggregates/_sling_aggregate.xml        | 26 +++++++++++++++++++
 4 files changed, 88 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java
b/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java
index 77c5554..24dc458 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java
@@ -113,7 +113,18 @@ public final class FileVaultResourceMapper implements FsResourceMapper
{
         if (parentFile != null && parentFile.isDirectory()) {
             for (File childFile : parentFile.listFiles()) {
                 String childPath = parentPath + "/" + PlatformNameFormat.getRepositoryName(childFile.getName());
-                if (pathMatches(childPath) && !childPaths.contains(childPath)) {
+                File file = getFile(childPath);
+                if (file != null && pathMatches(childPath) && !childPaths.contains(childPath))
{
+                    childPaths.add(childPath);
+                    continue;
+                }
+
+                // strip xml extension unless it's .content.xml - the xml extension is re-added
inside getContentFile
+                if (!childPath.endsWith('/' + DOT_CONTENT_XML)) {
+                    childPath = StringUtils.removeEnd(childPath, XML_SUFFIX);
+                }
+                ContentFile contentFile = getContentFile(childPath, null);
+                if (contentFile != null && pathMatches(childPath) && !childPaths.contains(childPath))
{
                     childPaths.add(childPath);
                 }
             }
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/FileVaultContentTest.java
b/src/test/java/org/apache/sling/fsprovider/internal/FileVaultContentTest.java
index 35b51d1..16ff018 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/FileVaultContentTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/FileVaultContentTest.java
@@ -25,13 +25,18 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
+import com.google.common.collect.Iterables;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.fsprovider.internal.TestUtils.RegisterFsResourcePlugin;
@@ -163,5 +168,28 @@ public class FileVaultContentTest {
         assertNotNull(binaryFile);
         assertEquals("nt:file", binaryFile.getResourceType());
     }
-    
+
+    @Test
+    public void testAggregateFilesDirectAccess() throws Exception {
+        Resource aggregate = sampleContent.getChild("aggregates/sling:aggregate");
+        assertNotNull("aggregate is null", aggregate);
+        assertEquals("Aggregate Test", aggregate.getValueMap().get("jcr:title", String.class));
+        assertTrue("sling:aggregate has no children", aggregate.hasChildren());
+        Resource child = aggregate.getChild("child");
+        assertNotNull("sling:aggregate has no child called 'child'", child);
+        assertEquals("Child of Aggregate", child.getValueMap().get("jcr:title", String.class));
+    }
+
+    @Test
+    public void testAggregateFilesAccessByChildIteration() throws Exception {
+        Resource aggregates = sampleContent.getChild("aggregates");
+        assertNotNull("aggregates folder is null", aggregates);
+        Map<String, Resource> childrenByName = new HashMap<>();
+        for (final Resource child : aggregates.getChildren()) {
+            childrenByName.put(child.getName(), child);
+        }
+
+        assertEquals("Wrong child count for 'aggregates'",1, childrenByName.size());
+        assertTrue("Child named 'sling:aggregate' does not exist", childrenByName.containsKey("sling:aggregate"));
+    }
 }
diff --git a/src/test/resources/vaultfs-test/jcr_root/content/samples/aggregates/.content.xml
b/src/test/resources/vaultfs-test/jcr_root/content/samples/aggregates/.content.xml
new file mode 100644
index 0000000..b4ba4f2
--- /dev/null
+++ b/src/test/resources/vaultfs-test/jcr_root/content/samples/aggregates/.content.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
+    jcr:primaryType="sling:Folder"/>
diff --git a/src/test/resources/vaultfs-test/jcr_root/content/samples/aggregates/_sling_aggregate.xml
b/src/test/resources/vaultfs-test/jcr_root/content/samples/aggregates/_sling_aggregate.xml
new file mode 100644
index 0000000..30637d2
--- /dev/null
+++ b/src/test/resources/vaultfs-test/jcr_root/content/samples/aggregates/_sling_aggregate.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
+          jcr:primaryType="sling:Folder"
+          jcr:title="Aggregate Test">
+    <child
+        jcr:primaryType="nt:unstructured"
+        jcr:title="Child of Aggregate"/>
+</jcr:root>

-- 
To stop receiving notification emails like this one, please contact
jsedding@apache.org.

Mime
View raw message