This is an automated email from the ASF dual-hosted git repository.
diru pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
The following commit(s) were added to refs/heads/master by this push:
new fb1a7bc add a sitemap purged event
fb1a7bc is described below
commit fb1a7bc1c843a02b3959686860384d44753f4de3
Author: Dirk Rudolph <[email protected]>
AuthorDate: Mon Jun 7 16:05:52 2021 +0200
add a sitemap purged event
---
sitemap/README.md | 15 +++++++++------
.../apache/sling/sitemap/generator/SitemapGenerator.java | 6 +++++-
.../org/apache/sling/sitemap/impl/SitemapStorage.java | 14 +++++++++++++-
3 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/sitemap/README.md b/sitemap/README.md
index 2b48881..a7fb288 100644
--- a/sitemap/README.md
+++ b/sitemap/README.md
@@ -14,19 +14,22 @@ background to even sites that collect 3rd party data to
include dynamically rend
## Open Topics
-* Housekeeping of SitemapStorage (used for background generation), esp. when
sitemap roots change
-* More general approach for creating absolute urls.
* Implement Google specific sitemap extensions (image/video/news)
## Getting Started
To get started, at least one `SitemapGenerator` must be implemented. The
abstract `ResourcceTreeSitemapGenator` may be a
-good starting point for any generator walking down the resource tree.
+good starting point for any generator walking down the resource tree. Next the
`SitemapServlet` must be registered for
+the appropriate resource type(s) that match the content. Last but not least,
either configure the `SitemapService`
+implementation to serve your sitemaps on-demand, or configure a
`SitemapScheduler` to generate them in the background.
-Next the `SitemapServlet` must be registered for the appropriate resource
type(s) that match the content.
+The default implementation requires two service user mappings to be
configured. They are only relevant for background
+generation of sitemaps. On-demand generated sitemaps use the request session.
-Last but not least, either configure the `SitemapService` implementation to
serve your sitemaps on-demand, or configure
-a `SitemapScheduler` to generate them in the background.
+| Service User Mapping | Usage | Recommended Settings |
+| ------------ | ----- | -------------------- |
+| org.apache.sling.sitemap:sitemap-reader | Read access on the content to be
contained in the generated sitemaps. Sessions with that service user will be
passed to the `SitemapGenerators`. | `jcr:read on /content` |
+| org.apache.sling.sitemap:sitemap-writer | Write access for background
generation. Used by the sitemap storage abstraction when storing intermediate
states and finished sitemaps in the storage path. It is also used for the
cleanup task of the storage an so requires read access to the same paths the
`sitempa-reader` has read access to. | `jcr:all on /var/sitemaps`<br/>`jcr:read
on /content`|
## Implementation Details
diff --git
a/sitemap/src/main/java/org/apache/sling/sitemap/generator/SitemapGenerator.java
b/sitemap/src/main/java/org/apache/sling/sitemap/generator/SitemapGenerator.java
index f6e099c..51e84f3 100644
---
a/sitemap/src/main/java/org/apache/sling/sitemap/generator/SitemapGenerator.java
+++
b/sitemap/src/main/java/org/apache/sling/sitemap/generator/SitemapGenerator.java
@@ -48,7 +48,11 @@ public interface SitemapGenerator {
/**
* The background generation will send events with that topic right after
a generated sitemap was persisted.
*/
- String EVENT_TOPIC_SITEMAP_UPDATED =
"org/apache/sling/sitemap/build/FINISHED";
+ String EVENT_TOPIC_SITEMAP_UPDATED = "org/apache/sling/sitemap/UPDATED";
+ /**
+ * The background cleanup will send events with that topic right after an
obsolete sitemap file was purged.
+ */
+ String EVENT_TOPIC_SITEMAP_PURGED = "org/apache/sling/sitemap/PURGED";
/**
* The event property storing the generated sitemap's root path.
*/
diff --git
a/sitemap/src/main/java/org/apache/sling/sitemap/impl/SitemapStorage.java
b/sitemap/src/main/java/org/apache/sling/sitemap/impl/SitemapStorage.java
index e6f41ea..2b283e3 100644
--- a/sitemap/src/main/java/org/apache/sling/sitemap/impl/SitemapStorage.java
+++ b/sitemap/src/main/java/org/apache/sling/sitemap/impl/SitemapStorage.java
@@ -25,11 +25,15 @@ import org.apache.sling.api.resource.*;
import org.apache.sling.api.wrappers.ValueMapDecorator;
import org.apache.sling.commons.scheduler.Scheduler;
import org.apache.sling.serviceusermapping.ServiceUserMapped;
+import org.apache.sling.sitemap.generator.SitemapGenerator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.service.event.EventProperties;
import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.Designate;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
@@ -92,6 +96,8 @@ public class SitemapStorage implements Runnable {
private ServiceUserMapped serviceUserMapped;
@Reference
private SitemapGeneratorManager generatorManager;
+ @Reference
+ private EventAdmin eventAdmin;
private String rootPath = "/var/sitemaps";
private int maxStateAge = Integer.MAX_VALUE;
@@ -116,6 +122,12 @@ public class SitemapStorage implements Runnable {
}
}
for (Resource resource : toDelete) {
+ Map<String, Object> properties = new HashMap<>();
+
properties.put(SitemapGenerator.EVENT_PROPERTY_SITEMAP_STORAGE_PATH,
resource.getPath());
+ eventAdmin.postEvent(new Event(
+ SitemapGenerator.EVENT_TOPIC_SITEMAP_PURGED,
+ new EventProperties(properties)
+ ));
resolver.delete(resource);
}
resolver.commit();
@@ -184,7 +196,7 @@ public class SitemapStorage implements Runnable {
}
public String writeSitemap(@NotNull Resource sitemapRoot, @NotNull String
name, @NotNull InputStream data, int size,
- int entries) throws IOException {
+ int entries) throws IOException {
String sitemapFilePath = getSitemapFilePath(sitemapRoot, name);
String statePath = sitemapFilePath + STATE_EXTENSION;
sitemapFilePath = sitemapFilePath + XML_EXTENSION;