You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2021/10/27 09:29:14 UTC

[sling-org-apache-sling-jcr-resource] branch feature/reorder-resources created (now e562144)

This is an automated email from the ASF dual-hosted git repository.

kwin pushed a change to branch feature/reorder-resources
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-resource.git.


      at e562144  SLING-7975 support ordering of resources

This branch includes the following new commits:

     new e562144  SLING-7975 support ordering of resources

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[sling-org-apache-sling-jcr-resource] 01/01: SLING-7975 support ordering of resources

Posted by kw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch feature/reorder-resources
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-resource.git

commit e5621442fa8c83e4f9f091fed5476323bf56a106
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Wed Oct 27 11:28:23 2021 +0200

    SLING-7975 support ordering of resources
---
 pom.xml                                                |  2 +-
 .../internal/helper/jcr/JcrResourceProvider.java       | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index ef4c393..feebd5a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -145,7 +145,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.api</artifactId>
-            <version>2.18.2</version>
+            <version>2.23.7-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
diff --git a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
index e40afb6..ea020e8 100644
--- a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
+++ b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
@@ -479,6 +479,24 @@ public class JcrResourceProvider extends ResourceProvider<JcrProviderState> {
     }
 
     @Override
+    public boolean orderBefore(@NotNull ResolveContext<JcrProviderState> ctx, @NotNull Resource parent, @NotNull String name,
+            @Nullable String followingSiblingName) throws PersistenceException {
+        Node node = parent.adaptTo(Node.class);
+        try {
+            // TODO: when can adaption fail here?
+            if (node == null) {
+                final String jcrPath = parent.getPath();
+                node = ctx.getProviderState().getSession().getNode(jcrPath);
+            }
+            node.orderBefore(name, followingSiblingName);
+            // TODO: check if really reordered
+            return true;
+        } catch (final RepositoryException e) {
+            throw new PersistenceException("Unable to reorder children below ", e, parent.getPath(), null);
+        }
+    }
+
+    @Override
     public void delete(final @NotNull ResolveContext<JcrProviderState> ctx, final @NotNull Resource resource)
     throws PersistenceException {
         // try to adapt to Item