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/10/27 09:29:50 UTC

[GitHub] [sling-org-apache-sling-jcr-resource] kwin opened a new pull request #18: SLING-7975 support ordering of resources

kwin opened a new pull request #18:
URL: https://github.com/apache/sling-org-apache-sling-jcr-resource/pull/18


   This depends upon https://github.com/apache/sling-org-apache-sling-api/pull/36


-- 
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



[GitHub] [sling-org-apache-sling-jcr-resource] kwin merged pull request #18: SLING-7975 support ordering of resources

Posted by GitBox <gi...@apache.org>.
kwin merged pull request #18:
URL: https://github.com/apache/sling-org-apache-sling-jcr-resource/pull/18


   


-- 
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



[GitHub] [sling-org-apache-sling-jcr-resource] sonarcloud[bot] commented on pull request #18: SLING-7975 support ordering of resources

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on pull request #18:
URL: https://github.com/apache/sling-org-apache-sling-jcr-resource/pull/18#issuecomment-959956597






-- 
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



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

Posted by GitBox <gi...@apache.org>.
kwin commented on a change in pull request #18:
URL: https://github.com/apache/sling-org-apache-sling-jcr-resource/pull/18#discussion_r742298613



##########
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) {

Review comment:
       Done in https://github.com/apache/sling-org-apache-sling-jcr-resource/pull/18/commits/d74a24df6297e7a78acd2127d19229a19752f5a4.




-- 
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



[GitHub] [sling-org-apache-sling-jcr-resource] sonarcloud[bot] commented on pull request #18: SLING-7975 support ordering of resources

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on pull request #18:
URL: https://github.com/apache/sling-org-apache-sling-jcr-resource/pull/18#issuecomment-959956597






-- 
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



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

Posted by GitBox <gi...@apache.org>.
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



[GitHub] [sling-org-apache-sling-jcr-resource] sonarcloud[bot] removed a comment on pull request #18: SLING-7975 support ordering of resources

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] removed a comment on pull request #18:
URL: https://github.com/apache/sling-org-apache-sling-jcr-resource/pull/18#issuecomment-959956597






-- 
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



[GitHub] [sling-org-apache-sling-jcr-resource] sonarcloud[bot] commented on pull request #18: SLING-7975 support ordering of resources

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on pull request #18:
URL: https://github.com/apache/sling-org-apache-sling-jcr-resource/pull/18#issuecomment-959956597


   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; ![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=CODE_SMELL) [1 Code Smell](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=CODE_SMELL)
   
   [![92.1%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/90-16px.png '92.1%')](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&metric=new_coverage&view=list) [92.1% Coverage](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&metric=new_coverage&view=list)  
   [![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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



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

Posted by GitBox <gi...@apache.org>.
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.

##########
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) {

Review comment:
       Done in https://github.com/apache/sling-org-apache-sling-jcr-resource/pull/18/commits/d74a24df6297e7a78acd2127d19229a19752f5a4.




-- 
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



[GitHub] [sling-org-apache-sling-jcr-resource] sonarcloud[bot] removed a comment on pull request #18: SLING-7975 support ordering of resources

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] removed a comment on pull request #18:
URL: https://github.com/apache/sling-org-apache-sling-jcr-resource/pull/18#issuecomment-959956597


   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; ![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=CODE_SMELL) [1 Code Smell](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=CODE_SMELL)
   
   [![92.1%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/90-16px.png '92.1%')](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&metric=new_coverage&view=list) [92.1% Coverage](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&metric=new_coverage&view=list)  
   [![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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



[GitHub] [sling-org-apache-sling-jcr-resource] sonarcloud[bot] removed a comment on pull request #18: SLING-7975 support ordering of resources

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] removed a comment on pull request #18:
URL: https://github.com/apache/sling-org-apache-sling-jcr-resource/pull/18#issuecomment-959956597


   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; ![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=CODE_SMELL) [1 Code Smell](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=CODE_SMELL)
   
   [![92.1%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/90-16px.png '92.1%')](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&metric=new_coverage&view=list) [92.1% Coverage](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&metric=new_coverage&view=list)  
   [![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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



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

Posted by GitBox <gi...@apache.org>.
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.

##########
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) {

Review comment:
       Done in https://github.com/apache/sling-org-apache-sling-jcr-resource/pull/18/commits/d74a24df6297e7a78acd2127d19229a19752f5a4.

##########
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.

##########
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) {

Review comment:
       Done in https://github.com/apache/sling-org-apache-sling-jcr-resource/pull/18/commits/d74a24df6297e7a78acd2127d19229a19752f5a4.




-- 
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



[GitHub] [sling-org-apache-sling-jcr-resource] sonarcloud[bot] commented on pull request #18: SLING-7975 support ordering of resources

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on pull request #18:
URL: https://github.com/apache/sling-org-apache-sling-jcr-resource/pull/18#issuecomment-959958080


   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; ![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=CODE_SMELL) [1 Code Smell](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&resolved=false&types=CODE_SMELL)
   
   [![92.1%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/90-16px.png '92.1%')](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&metric=new_coverage&view=list) [92.1% Coverage](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&metric=new_coverage&view=list)  
   [![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-jcr-resource&pullRequest=18&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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



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

Posted by GitBox <gi...@apache.org>.
rombert commented on a change in pull request #18:
URL: https://github.com/apache/sling-org-apache-sling-jcr-resource/pull/18#discussion_r740103514



##########
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:
       Does this loop assume that the node named `name` comes first in the children list? I am having a bit of a hard time following it.

##########
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) {

Review comment:
       This could be moved outside the try/catch block.




-- 
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