This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-api.git
The following commit(s) were added to refs/heads/master by this push:
new 4fdc49c SLING-7975 API for reordering of resources (#36)
4fdc49c is described below
commit 4fdc49c61bd686c11877927810a68c8c7faa55c3
Author: Konrad Windszus <[email protected]>
AuthorDate: Thu Oct 28 11:32:27 2021 +0200
SLING-7975 API for reordering of resources (#36)
throw UOE instead of PersistenceException for CRUD operations by default
---
.../sling/api/resource/ResourceResolver.java | 18 +++++++++++++++
.../apache/sling/api/resource/package-info.java | 2 +-
.../sling/api/security/ResourceAccessSecurity.java | 10 +++++++++
.../apache/sling/api/security/package-info.java | 2 +-
.../api/wrappers/ResourceResolverWrapper.java | 8 +++++++
.../spi/resource/provider/ResourceProvider.java | 26 ++++++++++++++++++++--
.../sling/spi/resource/provider/package-info.java | 2 +-
7 files changed, 63 insertions(+), 5 deletions(-)
diff --git a/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
b/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
index 372ec13..b80d25a 100644
--- a/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
+++ b/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
@@ -692,6 +692,24 @@ public interface ResourceResolver extends Adaptable,
Closeable {
throws PersistenceException;
/**
+ * Orders the child resources returned by {@link #getChildren(Resource)}
and {@link #listChildren(Resource)} so that a given resource is listed before
the given sibling resource.
+ *
+ * The changes are transient and require a call to {@link #commit()} for
persisting.
+ *
+ * @param parent the parent resource containing the child resources to
order.
+ * @param name the name of the child resource in {@code parent} to order.
Must be an existing child name.
+ * @param followingSiblingName the name of the resource child in {@code
parent} which should come after the reordered resource. If {@code null} is
given the resource is ordered as last among all sibling resources.
+ * @return {@code true} in case the order of the child resources in {@code
parent} has been changed, {@code false} if the given resource were already in
the desired order.
+ * @throws UnsupportedOperationException in case the underlying resource
provider does not support ordering or the child resources of {@code parent} are
provided by different providers.
+ * @throws IllegalArgumentException if either {@code name} or {@code
followingSiblingName} are not existing child resource names of {@code parent}.
+ * @throws PersistenceException If the operation fails in the underlying
resource provider, e.g. in case the parent resource does not support orderable
children.
+ * @since 2.13.0 (Sling API Bundle 2.24.0)
+ * @see #listChildren(Resource)
+ * @see #getChildren(Resource)
+ */
+ boolean orderBefore(@NotNull Resource parent, @NotNull String name,
@Nullable String followingSiblingName) throws UnsupportedOperationException,
PersistenceException, IllegalArgumentException;
+
+ /**
* Revert all pending changes.
* @throws IllegalStateException if this resource resolver has already been
* {@link #close() closed}.
diff --git a/src/main/java/org/apache/sling/api/resource/package-info.java
b/src/main/java/org/apache/sling/api/resource/package-info.java
index 2c8f5ae..ac05b61 100644
--- a/src/main/java/org/apache/sling/api/resource/package-info.java
+++ b/src/main/java/org/apache/sling/api/resource/package-info.java
@@ -17,7 +17,7 @@
* under the License.
*/
-@Version("2.12.3")
+@Version("2.13.0")
package org.apache.sling.api.resource;
import org.osgi.annotation.versioning.Version;
diff --git
a/src/main/java/org/apache/sling/api/security/ResourceAccessSecurity.java
b/src/main/java/org/apache/sling/api/security/ResourceAccessSecurity.java
index b6f8222..5845f91 100644
--- a/src/main/java/org/apache/sling/api/security/ResourceAccessSecurity.java
+++ b/src/main/java/org/apache/sling/api/security/ResourceAccessSecurity.java
@@ -99,6 +99,16 @@ public interface ResourceAccessSecurity {
boolean canCreate(@NotNull String absPathName, @NotNull ResourceResolver
resourceResolver);
/**
+ * Check whether child resources can be ordered.
+ * @param resource The resource to test.
+ * @return true if child resources can be ordered below the supplied
resource
+ * @since 1.1.0 (Sling API Bundle 2.24.0)
+ */
+ default boolean canOrderChildren(@NotNull Resource resource) {
+ return false;
+ }
+
+ /**
* Check whether a resource can be updated at the path.
* @param resource The resource to test.
* @return true if supplied {@link Resource} can be updated
diff --git a/src/main/java/org/apache/sling/api/security/package-info.java
b/src/main/java/org/apache/sling/api/security/package-info.java
index c82551d..6ed80f7 100644
--- a/src/main/java/org/apache/sling/api/security/package-info.java
+++ b/src/main/java/org/apache/sling/api/security/package-info.java
@@ -17,7 +17,7 @@
* under the License.
*/
-@Version("1.0.4")
+@Version("1.1.0")
package org.apache.sling.api.security;
import org.osgi.annotation.versioning.Version;
diff --git
a/src/main/java/org/apache/sling/api/wrappers/ResourceResolverWrapper.java
b/src/main/java/org/apache/sling/api/wrappers/ResourceResolverWrapper.java
index 67c2fbf..500ec18 100644
--- a/src/main/java/org/apache/sling/api/wrappers/ResourceResolverWrapper.java
+++ b/src/main/java/org/apache/sling/api/wrappers/ResourceResolverWrapper.java
@@ -19,6 +19,8 @@ package org.apache.sling.api.wrappers;
import java.util.Iterator;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
import javax.servlet.http.HttpServletRequest;
import org.apache.sling.api.resource.LoginException;
@@ -281,6 +283,12 @@ public class ResourceResolverWrapper implements
ResourceResolver {
}
@Override
+ public boolean orderBefore(@NotNull Resource parent, @NotNull String name,
@Nullable String followingSiblingName)
+ throws UnsupportedOperationException, PersistenceException,
IllegalArgumentException {
+ return wrapped.orderBefore(parent, name, followingSiblingName);
+ }
+
+ @Override
public void revert() {
wrapped.revert();
}
diff --git
a/src/main/java/org/apache/sling/spi/resource/provider/ResourceProvider.java
b/src/main/java/org/apache/sling/spi/resource/provider/ResourceProvider.java
index 0ced2e6..cb9595c 100644
--- a/src/main/java/org/apache/sling/spi/resource/provider/ResourceProvider.java
+++ b/src/main/java/org/apache/sling/spi/resource/provider/ResourceProvider.java
@@ -506,7 +506,29 @@ public abstract class ResourceProvider<T> {
*/
public @NotNull Resource create(final @NotNull ResolveContext<T> ctx,
final String path, final Map<String, Object> properties)
throws PersistenceException {
- throw new PersistenceException("create is not supported.");
+ throw new UnsupportedOperationException("create is not supported.");
+ }
+
+ /**
+ * Orders the child resources returned by {@link
#listChildren(ResolveContext, Resource)} so that a given resource is listed
before the given sibling resource.
+ *
+ * The changes are transient until {@link #commit(ResolveContext)} is
called..
+ *
+ * @param ctx The {@link ResolveContext}.
+ * @param parent the parent resource containing the child resources to
order.
+ * @param name the name of the child resource in {@code parent} to order.
Must be an existing child name.
+ * @param followingSiblingName the name of the resource child in {@code
parent} which should come after the reordered resource. If {@code null} is
given the resource is ordered as last among all sibling resources.
+ * @return {@code true} in case the order of the child resources in {@code
parent} has been changed, {@code false} if the given resource were already in
the desired order.
+ * @throws UnsupportedOperationException in case the underlying resource
provider does not support ordering or the child resources of {@code parent} are
provided by different providers.
+ * @throws IllegalArgumentException if either {@code name} or {@code
followingSiblingName} are not existing child resource names of {@code parent}.
+ * @throws PersistenceException If the operation fails in the underlying
resource provider, e.g. in case the parent resource does not support orderable
children.
+ * @since 1.3.0 (Sling API Bundle 2.24.0)
+ * @see #listChildren(Resource)
+ * @see #getChildren(Resource)
+ */
+ public boolean orderBefore(final @NotNull ResolveContext<T> ctx, final
@NotNull Resource parent, final @NotNull String name, final @Nullable String
followingSiblingName)
+ throws PersistenceException {
+ throw new UnsupportedOperationException("orderBefore is not
supported.");
}
/**
@@ -524,7 +546,7 @@ public abstract class ResourceProvider<T> {
*/
public void delete(final @NotNull ResolveContext<T> ctx, final @NotNull
Resource resource)
throws PersistenceException {
- throw new PersistenceException("delete is not supported.");
+ throw new UnsupportedOperationException("delete is not supported.");
}
/**
diff --git
a/src/main/java/org/apache/sling/spi/resource/provider/package-info.java
b/src/main/java/org/apache/sling/spi/resource/provider/package-info.java
index 0ca533f..a225263 100644
--- a/src/main/java/org/apache/sling/spi/resource/provider/package-info.java
+++ b/src/main/java/org/apache/sling/spi/resource/provider/package-info.java
@@ -17,7 +17,7 @@
* under the License.
*/
-@Version("1.2.2")
+@Version("1.3.0")
package org.apache.sling.spi.resource.provider;
import org.osgi.annotation.versioning.Version;