You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2021/11/03 20:17:22 UTC

[GitHub] [sling-org-apache-sling-jcr-resource] kwin commented on a change in pull request #18: SLING-7975 support ordering of resources

kwin commented on a change in pull request #18:
URL: https://github.com/apache/sling-org-apache-sling-jcr-resource/pull/18#discussion_r742298158



##########
File path: src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
##########
@@ -478,6 +479,44 @@ public Resource create(final @NotNull ResolveContext<JcrProviderState> ctx, fina
         }
     }
 
+    @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 {
+            if (node == null) {
+                throw new PersistenceException("The resource " + parent.getPath() + " cannot be adapted to Node. It is probably not provided by the JcrResourceProvider");
+            }
+            // check if reordering necessary
+            NodeIterator nodeIterator = node.getNodes();
+            long existingNodePosition = -1;
+            long index = 0;
+            while (nodeIterator.hasNext()) {
+                Node childNode = nodeIterator.nextNode();
+                if (childNode.getName().equals(name)) {
+                    existingNodePosition = index;
+                }
+                if (existingNodePosition >= 0) {

Review comment:
       No, not necessarily. I added some tests. Hopefully they proof that `true` is only returned in case the order is actually changed. Let me know if I missed a case.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org