From 57d4094fc684e06b5ba7cccf606fe2edea4f05a6 Mon Sep 17 00:00:00 2001 From: chiki Date: Thu, 30 Apr 2020 11:42:33 +0530 Subject: [PATCH 1/8] SLING-9389: Changes to add a distribution event property for distribution queue item creation time stamp --- .../distribution/event/DistributionEventProperties.java | 5 +++++ .../org/apache/sling/distribution/event/package-info.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java b/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java index a70f9b2..7d39c52 100644 --- a/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java +++ b/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java @@ -47,4 +47,9 @@ public interface DistributionEventProperties { * property containing the type of the distribution paths */ String DISTRIBUTION_PATHS= "distribution.paths"; + + /** + * property containing the time when an item was enqueued for distribution + */ + String DISTRIBUTION_ENQUEUE_TIMESTAMP = "distribution.enqueue.timestamp"; } diff --git a/src/main/java/org/apache/sling/distribution/event/package-info.java b/src/main/java/org/apache/sling/distribution/event/package-info.java index 41d9d59..39da672 100644 --- a/src/main/java/org/apache/sling/distribution/event/package-info.java +++ b/src/main/java/org/apache/sling/distribution/event/package-info.java @@ -17,7 +17,7 @@ * under the License. */ -@Version("0.2.0") +@Version("0.3.0") package org.apache.sling.distribution.event; import aQute.bnd.annotation.Version; From 2c4ea6e4ae49e9d58c19a310b625773968c7d080 Mon Sep 17 00:00:00 2001 From: chiki Date: Thu, 30 Apr 2020 12:53:02 +0530 Subject: [PATCH 2/8] SLING-9389: Corrected the documentation --- .../sling/distribution/event/DistributionEventProperties.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java b/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java index 7d39c52..72132f8 100644 --- a/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java +++ b/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java @@ -49,7 +49,7 @@ public interface DistributionEventProperties { String DISTRIBUTION_PATHS= "distribution.paths"; /** - * property containing the time when an item was enqueued for distribution + * property containing the time when an item was created and enqueued for distribution */ String DISTRIBUTION_ENQUEUE_TIMESTAMP = "distribution.enqueue.timestamp"; } From 0428ae62eb3c9a7e320eba3e5b2ad8b6b536c23e Mon Sep 17 00:00:00 2001 From: tmaret Date: Wed, 13 May 2020 10:38:09 +0200 Subject: [PATCH 3/8] SLING-9442 - Complete the semantic definition of distribution events --- .../distribution/event/DistributionEventTopics.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/apache/sling/distribution/event/DistributionEventTopics.java b/src/main/java/org/apache/sling/distribution/event/DistributionEventTopics.java index 572e25c..4d1a1f3 100644 --- a/src/main/java/org/apache/sling/distribution/event/DistributionEventTopics.java +++ b/src/main/java/org/apache/sling/distribution/event/DistributionEventTopics.java @@ -29,27 +29,28 @@ public interface DistributionEventTopics { String EVENT_BASE = "org/apache/sling/distribution"; /** - * event for package created + * Event raised after the successful creation of a content package. */ String AGENT_PACKAGE_CREATED = EVENT_BASE + "/agent/package/created"; /** - * event for package queued + * Event raised after successfully storing a content package to the distribution queues. */ String AGENT_PACKAGE_QUEUED = EVENT_BASE + "/agent/package/queued"; /** - * event for package distributed + * Event raised after successfully distributing a content package from a distribution queue. */ String AGENT_PACKAGE_DISTRIBUTED = EVENT_BASE + "/agent/package/distributed"; /** - * event for package dropped + * Event raised when a content package could not be distributed + * and was removed from a distribution queue. */ String AGENT_PACKAGE_DROPPED = EVENT_BASE + "/agent/package/dropped"; /** - * event for package imported + * Event raised after successfully importing a content package. */ String IMPORTER_PACKAGE_IMPORTED = EVENT_BASE + "/importer/package/imported"; } From d460e27564809f70f52158c1eb78272ee19cda27 Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Wed, 13 May 2020 15:21:53 +0200 Subject: [PATCH 4/8] SLING-9447 - Add packageId property (#5) --- .../distribution/event/DistributionEventProperties.java | 5 +++++ .../org/apache/sling/distribution/event/package-info.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java b/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java index a70f9b2..45b0553 100644 --- a/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java +++ b/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java @@ -47,4 +47,9 @@ public interface DistributionEventProperties { * property containing the type of the distribution paths */ String DISTRIBUTION_PATHS= "distribution.paths"; + + /** + * Package id + */ + String DISTRIBUTION_PACKAGE_ID = "distribution.package.id"; } diff --git a/src/main/java/org/apache/sling/distribution/event/package-info.java b/src/main/java/org/apache/sling/distribution/event/package-info.java index 41d9d59..39da672 100644 --- a/src/main/java/org/apache/sling/distribution/event/package-info.java +++ b/src/main/java/org/apache/sling/distribution/event/package-info.java @@ -17,7 +17,7 @@ * under the License. */ -@Version("0.2.0") +@Version("0.3.0") package org.apache.sling.distribution.event; import aQute.bnd.annotation.Version; From 4c4bf621224cfdd008b715fb83c9ba418e99f19e Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Wed, 13 May 2020 16:29:22 +0200 Subject: [PATCH 5/8] SLING-9448 - Update to sling bundle parent (#6) --- pom.xml | 42 +++++++------------ .../distribution/DistributionRequest.java | 12 +++--- .../DistributionRequestState.java | 2 +- .../distribution/DistributionRequestType.java | 6 +-- .../distribution/DistributionResponse.java | 8 ++-- .../sling/distribution/Distributor.java | 11 ++--- .../SimpleDistributionRequest.java | 21 +++++----- .../event/DistributionEventProperties.java | 3 +- .../event/DistributionEventTopics.java | 2 +- .../distribution/event/package-info.java | 4 +- .../sling/distribution/package-info.java | 6 +-- .../DistributionTransportSecret.java | 5 ++- .../DistributionTransportSecretProvider.java | 6 +-- .../distribution/transport/package-info.java | 4 +- 14 files changed, 60 insertions(+), 72 deletions(-) diff --git a/pom.xml b/pom.xml index 8736f98..ed6997b 100644 --- a/pom.xml +++ b/pom.xml @@ -24,8 +24,8 @@ org.apache.sling - sling - 26 + sling-bundle-parent + 38 @@ -34,7 +34,6 @@ org.apache.sling.distribution.api 0.4.1-SNAPSHOT - bundle Apache Sling Distribution API @@ -54,22 +53,8 @@ - org.apache.felix - maven-scr-plugin - - - org.apache.sling - maven-sling-plugin - - - org.apache.felix - maven-bundle-plugin - true - - - org.apache.sling.distribution.api - - + biz.aQute.bnd + bnd-maven-plugin org.apache.maven.plugins @@ -93,27 +78,32 @@ javax.jcr jcr - 2.0 javax.servlet servlet-api + 2.4 org.osgi - org.osgi.core + osgi.core + provided org.osgi - org.osgi.compendium + osgi.cmpn + provided - org.jetbrains - annotations - 16.0.2 + org.osgi + org.osgi.annotation.versioning provided - + + com.google.code.findbugs + jsr305 + 2.0.0 + diff --git a/src/main/java/org/apache/sling/distribution/DistributionRequest.java b/src/main/java/org/apache/sling/distribution/DistributionRequest.java index 6545130..5421080 100644 --- a/src/main/java/org/apache/sling/distribution/DistributionRequest.java +++ b/src/main/java/org/apache/sling/distribution/DistributionRequest.java @@ -18,9 +18,9 @@ */ package org.apache.sling.distribution; -import aQute.bnd.annotation.ProviderType; +import javax.annotation.Nonnull; -import org.jetbrains.annotations.NotNull; +import org.osgi.annotation.versioning.ProviderType; /** * A {@link org.apache.sling.distribution.DistributionRequest} represents the need from the caller to have @@ -35,7 +35,7 @@ public interface DistributionRequest { * * @return the type of the request as a {@link DistributionRequestType} */ - @NotNull + @Nonnull DistributionRequestType getRequestType(); /** @@ -43,7 +43,7 @@ public interface DistributionRequest { * * @return an array of paths */ - @NotNull + @Nonnull public String[] getPaths(); /** @@ -52,7 +52,7 @@ public interface DistributionRequest { * @param path the path to be checked * @return true if the paths are deep */ - public boolean isDeep(@NotNull String path); + public boolean isDeep(String path); @@ -65,6 +65,6 @@ public interface DistributionRequest { * @param path the path to get applicable filters for * @return an array of filters */ - @NotNull + @Nonnull public String[] getFilters(String path); } diff --git a/src/main/java/org/apache/sling/distribution/DistributionRequestState.java b/src/main/java/org/apache/sling/distribution/DistributionRequestState.java index 4dcf6d6..2e3045e 100644 --- a/src/main/java/org/apache/sling/distribution/DistributionRequestState.java +++ b/src/main/java/org/apache/sling/distribution/DistributionRequestState.java @@ -18,7 +18,7 @@ */ package org.apache.sling.distribution; -import aQute.bnd.annotation.ProviderType; +import org.osgi.annotation.versioning.ProviderType; /** *

diff --git a/src/main/java/org/apache/sling/distribution/DistributionRequestType.java b/src/main/java/org/apache/sling/distribution/DistributionRequestType.java index c534983..d183a57 100644 --- a/src/main/java/org/apache/sling/distribution/DistributionRequestType.java +++ b/src/main/java/org/apache/sling/distribution/DistributionRequestType.java @@ -18,9 +18,9 @@ */ package org.apache.sling.distribution; -import aQute.bnd.annotation.ProviderType; +import javax.annotation.Nullable; -import org.jetbrains.annotations.Nullable; +import org.osgi.annotation.versioning.ProviderType; /** *

@@ -66,7 +66,7 @@ public enum DistributionRequestType { * @return the type or {@code null} */ @Nullable - public static DistributionRequestType fromName(String n) { + public static DistributionRequestType fromName(@Nullable String n) { if (n == null) { return null; } diff --git a/src/main/java/org/apache/sling/distribution/DistributionResponse.java b/src/main/java/org/apache/sling/distribution/DistributionResponse.java index 12f778c..55c936f 100644 --- a/src/main/java/org/apache/sling/distribution/DistributionResponse.java +++ b/src/main/java/org/apache/sling/distribution/DistributionResponse.java @@ -18,10 +18,10 @@ */ package org.apache.sling.distribution; -import aQute.bnd.annotation.ProviderType; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import org.osgi.annotation.versioning.ProviderType; /** * A {@link org.apache.sling.distribution.DistributionResponse} represents the outcome of a @@ -47,7 +47,7 @@ public interface DistributionResponse { * * @return the state of the associated request */ - @NotNull + @Nonnull DistributionRequestState getState(); /** diff --git a/src/main/java/org/apache/sling/distribution/Distributor.java b/src/main/java/org/apache/sling/distribution/Distributor.java index 8895401..cdaab0e 100644 --- a/src/main/java/org/apache/sling/distribution/Distributor.java +++ b/src/main/java/org/apache/sling/distribution/Distributor.java @@ -19,9 +19,10 @@ package org.apache.sling.distribution; -import aQute.bnd.annotation.ProviderType; +import javax.annotation.Nonnull; + import org.apache.sling.api.resource.ResourceResolver; -import org.jetbrains.annotations.NotNull; +import org.osgi.annotation.versioning.ProviderType; /** *

@@ -49,9 +50,9 @@ public interface Distributor { * @param resourceResolver the resource resolver used for authorizing the request, * @return a {@link org.apache.sling.distribution.DistributionResponse} */ - @NotNull - DistributionResponse distribute(@NotNull String agentName, @NotNull ResourceResolver resourceResolver, - @NotNull DistributionRequest distributionRequest); + @Nonnull + DistributionResponse distribute(String agentName, ResourceResolver resourceResolver, + DistributionRequest distributionRequest); } diff --git a/src/main/java/org/apache/sling/distribution/SimpleDistributionRequest.java b/src/main/java/org/apache/sling/distribution/SimpleDistributionRequest.java index a1645fe..123d27a 100644 --- a/src/main/java/org/apache/sling/distribution/SimpleDistributionRequest.java +++ b/src/main/java/org/apache/sling/distribution/SimpleDistributionRequest.java @@ -18,14 +18,15 @@ */ package org.apache.sling.distribution; -import aQute.bnd.annotation.ProviderType; - import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; -import org.jetbrains.annotations.NotNull; + +import javax.annotation.Nonnull; + +import org.osgi.annotation.versioning.ProviderType; /** * A {@link SimpleDistributionRequest} is a {@link DistributionRequest} where all paths are either "deep" or "shallow". @@ -45,7 +46,7 @@ public final class SimpleDistributionRequest implements DistributionRequest { * @param isDeep is true if all paths are "deep" and is false if all paths are "shallow" * @param paths the array of paths to be distributed */ - public SimpleDistributionRequest(@NotNull DistributionRequestType requestType, boolean isDeep, @NotNull String... paths) { + public SimpleDistributionRequest(DistributionRequestType requestType, boolean isDeep, String... paths) { this(requestType, paths, isDeep? new HashSet(Arrays.asList(paths)) : new HashSet()); } @@ -54,7 +55,7 @@ public SimpleDistributionRequest(@NotNull DistributionRequestType requestType, b * @param requestType the request type * @param paths the array of paths to be distributed */ - public SimpleDistributionRequest(@NotNull DistributionRequestType requestType, @NotNull String... paths) { + public SimpleDistributionRequest(DistributionRequestType requestType, String... paths) { this(requestType, false, paths); } @@ -65,7 +66,7 @@ public SimpleDistributionRequest(@NotNull DistributionRequestType requestType, @ * @param paths the array of paths to be distributed * @param deepPaths the set of paths that are to be distributed in depth (with all their children) */ - public SimpleDistributionRequest(@NotNull DistributionRequestType requestType, @NotNull String[] paths, @NotNull Set deepPaths) { + public SimpleDistributionRequest(DistributionRequestType requestType, String[] paths, Set deepPaths) { this(requestType, paths, deepPaths, new HashMap()); } @@ -77,7 +78,7 @@ public SimpleDistributionRequest(@NotNull DistributionRequestType requestType, @ * @param deepPaths the set of paths that are to be distributed in depth (with all their children) * @param pathFilters the filters applicable for each path */ - public SimpleDistributionRequest(@NotNull DistributionRequestType requestType, @NotNull String[] paths, @NotNull Set deepPaths, @NotNull Map pathFilters) { + public SimpleDistributionRequest(DistributionRequestType requestType, String[] paths, Set deepPaths, Map pathFilters) { this.requestType = requestType; this.paths = paths; this.deepPaths = deepPaths; @@ -89,7 +90,7 @@ public SimpleDistributionRequest(@NotNull DistributionRequestType requestType, @ * * @return the type of the request as a {@link DistributionRequestType} */ - @NotNull + @Nonnull public DistributionRequestType getRequestType() { return requestType; } @@ -108,11 +109,11 @@ public String[] getPaths() { * Returns whether the a path is covering the entire subtree (deep) or just the specified nodes (shallow) * @return true if the path is deep */ - public boolean isDeep(@NotNull String path) { + public boolean isDeep(String path) { return deepPaths.contains(path); } - @NotNull + @Nonnull public String[] getFilters(String path) { String[] filters = pathFilters.get(path); return filters != null ? filters : new String[0]; diff --git a/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java b/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java index 45b0553..dd5da1e 100644 --- a/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java +++ b/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java @@ -18,8 +18,7 @@ */ package org.apache.sling.distribution.event; - -import aQute.bnd.annotation.ProviderType; +import org.osgi.annotation.versioning.ProviderType; /** * an interface containing of the possible properties of events related to distribution diff --git a/src/main/java/org/apache/sling/distribution/event/DistributionEventTopics.java b/src/main/java/org/apache/sling/distribution/event/DistributionEventTopics.java index 4d1a1f3..7323cf8 100644 --- a/src/main/java/org/apache/sling/distribution/event/DistributionEventTopics.java +++ b/src/main/java/org/apache/sling/distribution/event/DistributionEventTopics.java @@ -18,7 +18,7 @@ */ package org.apache.sling.distribution.event; -import aQute.bnd.annotation.ProviderType; +import org.osgi.annotation.versioning.ProviderType; /** * an interface containing of the possible topics of events related to distribution diff --git a/src/main/java/org/apache/sling/distribution/event/package-info.java b/src/main/java/org/apache/sling/distribution/event/package-info.java index 39da672..fd0e012 100644 --- a/src/main/java/org/apache/sling/distribution/event/package-info.java +++ b/src/main/java/org/apache/sling/distribution/event/package-info.java @@ -17,8 +17,6 @@ * under the License. */ -@Version("0.3.0") +@org.osgi.annotation.versioning.Version("0.3.0") package org.apache.sling.distribution.event; -import aQute.bnd.annotation.Version; - diff --git a/src/main/java/org/apache/sling/distribution/package-info.java b/src/main/java/org/apache/sling/distribution/package-info.java index 5c2c564..ab781c9 100644 --- a/src/main/java/org/apache/sling/distribution/package-info.java +++ b/src/main/java/org/apache/sling/distribution/package-info.java @@ -17,8 +17,6 @@ * under the License. */ -@Version("0.3.1") +@javax.annotation.ParametersAreNonnullByDefault +@org.osgi.annotation.versioning.Version("0.3.1") package org.apache.sling.distribution; - -import aQute.bnd.annotation.Version; - diff --git a/src/main/java/org/apache/sling/distribution/transport/DistributionTransportSecret.java b/src/main/java/org/apache/sling/distribution/transport/DistributionTransportSecret.java index 815142a..55004e9 100644 --- a/src/main/java/org/apache/sling/distribution/transport/DistributionTransportSecret.java +++ b/src/main/java/org/apache/sling/distribution/transport/DistributionTransportSecret.java @@ -19,9 +19,10 @@ package org.apache.sling.distribution.transport; import java.util.Map; -import aQute.bnd.annotation.ConsumerType; -import org.jetbrains.annotations.Nullable; +import javax.annotation.Nullable; + +import org.osgi.annotation.versioning.ConsumerType; /** *

diff --git a/src/main/java/org/apache/sling/distribution/transport/DistributionTransportSecretProvider.java b/src/main/java/org/apache/sling/distribution/transport/DistributionTransportSecretProvider.java index eaac9c9..3a0c933 100644 --- a/src/main/java/org/apache/sling/distribution/transport/DistributionTransportSecretProvider.java +++ b/src/main/java/org/apache/sling/distribution/transport/DistributionTransportSecretProvider.java @@ -18,11 +18,11 @@ */ package org.apache.sling.distribution.transport; -import aQute.bnd.annotation.ConsumerType; - import java.net.URI; -import org.jetbrains.annotations.Nullable; +import javax.annotation.Nullable; + +import org.osgi.annotation.versioning.ConsumerType; /** *

diff --git a/src/main/java/org/apache/sling/distribution/transport/package-info.java b/src/main/java/org/apache/sling/distribution/transport/package-info.java index 822acfc..32a676f 100644 --- a/src/main/java/org/apache/sling/distribution/transport/package-info.java +++ b/src/main/java/org/apache/sling/distribution/transport/package-info.java @@ -17,8 +17,8 @@ * under the License. */ -@Version("0.1.1") +@javax.annotation.ParametersAreNonnullByDefault +@org.osgi.annotation.versioning.Version("0.1.1") package org.apache.sling.distribution.transport; -import aQute.bnd.annotation.Version; From 8e6dfce8e39870ceec8874467eb850044815e1fb Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Wed, 13 May 2020 16:56:28 +0200 Subject: [PATCH 6/8] SLING-9445 - DistributionEvent (#4) --- pom.xml | 6 ++ .../distribution/event/DistributionEvent.java | 91 +++++++++++++++++++ .../event/DistributionEventTest.java | 69 ++++++++++++++ 3 files changed, 166 insertions(+) create mode 100644 src/main/java/org/apache/sling/distribution/event/DistributionEvent.java create mode 100644 src/test/java/org/apache/sling/distribution/event/DistributionEventTest.java diff --git a/pom.xml b/pom.xml index ed6997b..6af374c 100644 --- a/pom.xml +++ b/pom.xml @@ -104,6 +104,12 @@ jsr305 2.0.0 + + + junit + junit + test + diff --git a/src/main/java/org/apache/sling/distribution/event/DistributionEvent.java b/src/main/java/org/apache/sling/distribution/event/DistributionEvent.java new file mode 100644 index 0000000..7512065 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/event/DistributionEvent.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.event; + +import static org.apache.sling.distribution.event.DistributionEventProperties.DISTRIBUTION_COMPONENT_KIND; +import static org.apache.sling.distribution.event.DistributionEventProperties.DISTRIBUTION_COMPONENT_NAME; +import static org.apache.sling.distribution.event.DistributionEventProperties.DISTRIBUTION_PACKAGE_ID; +import static org.apache.sling.distribution.event.DistributionEventProperties.DISTRIBUTION_PATHS; +import static org.apache.sling.distribution.event.DistributionEventProperties.DISTRIBUTION_TYPE; + +import java.util.Dictionary; +import java.util.Hashtable; + +import org.osgi.service.event.Event; + +public class DistributionEvent { + + private final String packageId; + private final String componentName; + private final String componentKind; + private final String distType; + private final String[] distPaths; + + public DistributionEvent( + String packageId, + String componentName, + String componentKind, + String distType, + String[] distPaths) { + this.packageId = packageId; + this.componentName = componentName; + this.componentKind = componentKind; + this.distType = distType; + this.distPaths = distPaths; + } + + public String getPackageId() { + return packageId; + } + + public String getComponentName() { + return componentName; + } + + public String getComponentKind() { + return componentKind; + } + + public String getDistType() { + return distType; + } + + public String[] getDistPaths() { + return distPaths; + } + + public Event toEvent(String topic) { + Dictionary props = new Hashtable(); + props.put(DISTRIBUTION_PACKAGE_ID, packageId); + props.put(DISTRIBUTION_COMPONENT_NAME, componentName); + props.put(DISTRIBUTION_COMPONENT_KIND, componentKind); + props.put(DISTRIBUTION_TYPE, distType); + props.put(DISTRIBUTION_PATHS, distPaths); + return new Event(topic, props); + } + + public static DistributionEvent fromEvent(Event event) { + return new DistributionEvent( + event.getProperty(DISTRIBUTION_PACKAGE_ID).toString(), + event.getProperty(DISTRIBUTION_COMPONENT_NAME).toString(), + event.getProperty(DISTRIBUTION_COMPONENT_KIND).toString(), + event.getProperty(DISTRIBUTION_TYPE).toString(), + (String[])event.getProperty(DISTRIBUTION_PATHS)); + } +} diff --git a/src/test/java/org/apache/sling/distribution/event/DistributionEventTest.java b/src/test/java/org/apache/sling/distribution/event/DistributionEventTest.java new file mode 100644 index 0000000..ce9a006 --- /dev/null +++ b/src/test/java/org/apache/sling/distribution/event/DistributionEventTest.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.event; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; + +import org.hamcrest.CoreMatchers; +import org.junit.Before; +import org.junit.Test; +import org.osgi.service.event.Event; + +public class DistributionEventTest { + + private static final String PATH1 = "/test"; + private static final String DIST_TYPE = "ADD"; + private static final String NAME = "myagent"; + private static final String KIND = "agent"; + private static final String PKG_ID = "pkg-1"; + private DistributionEvent event; + + @Before + public void before() { + event = new DistributionEvent(PKG_ID, NAME, KIND, DIST_TYPE, new String[] {PATH1}); + } + + @Test + public void testToEvent() { + Event osgiEvent = event.toEvent(DistributionEventTopics.AGENT_PACKAGE_CREATED); + assertThat(osgiEvent.getTopic(), equalTo(DistributionEventTopics.AGENT_PACKAGE_CREATED)); + assertThat((String)osgiEvent.getProperty(DistributionEventProperties.DISTRIBUTION_PACKAGE_ID), equalTo(PKG_ID)); + assertThat((String)osgiEvent.getProperty(DistributionEventProperties.DISTRIBUTION_COMPONENT_KIND), equalTo(KIND)); + assertThat((String)osgiEvent.getProperty(DistributionEventProperties.DISTRIBUTION_COMPONENT_NAME), equalTo(NAME)); + assertThat((String)osgiEvent.getProperty(DistributionEventProperties.DISTRIBUTION_TYPE), equalTo(DIST_TYPE)); + String[] paths = (String[])(osgiEvent.getProperty(DistributionEventProperties.DISTRIBUTION_PATHS)); + assertThat(Arrays.asList(paths), CoreMatchers.hasItems(PATH1)); + } + + @Test + public void testFromEvent() { + Event osgiEvent = event.toEvent(DistributionEventTopics.AGENT_PACKAGE_CREATED); + DistributionEvent event2 = DistributionEvent.fromEvent(osgiEvent); + assertThat(event2.getPackageId(), equalTo(PKG_ID)); + assertThat(event2.getComponentKind(), equalTo(KIND)); + assertThat(event2.getComponentName(), equalTo(NAME)); + assertThat(event2.getDistType(), equalTo(DIST_TYPE)); + String[] paths = event2.getDistPaths(); + assertThat(Arrays.asList(paths), CoreMatchers.hasItems(PATH1)); + } + +} From 90d76aac34847e440a2d3e26cad2c9ebe422a401 Mon Sep 17 00:00:00 2001 From: chiki Date: Thu, 30 Apr 2020 11:42:33 +0530 Subject: [PATCH 7/8] SLING-9389: Changes to add a distribution event property for distribution queue item creation time stamp --- .../distribution/event/DistributionEventProperties.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java b/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java index dd5da1e..9cada27 100644 --- a/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java +++ b/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java @@ -51,4 +51,9 @@ public interface DistributionEventProperties { * Package id */ String DISTRIBUTION_PACKAGE_ID = "distribution.package.id"; + + /** + * property containing the time when an item was enqueued for distribution + */ + String DISTRIBUTION_ENQUEUE_TIMESTAMP = "distribution.enqueue.timestamp"; } From cf822607e25ca2df61a46b61bbaf06b1666325e1 Mon Sep 17 00:00:00 2001 From: chiki Date: Thu, 30 Apr 2020 12:53:02 +0530 Subject: [PATCH 8/8] SLING-9389: Corrected the documentation --- .../sling/distribution/event/DistributionEventProperties.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java b/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java index 9cada27..6034133 100644 --- a/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java +++ b/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java @@ -53,7 +53,7 @@ public interface DistributionEventProperties { String DISTRIBUTION_PACKAGE_ID = "distribution.package.id"; /** - * property containing the time when an item was enqueued for distribution + * property containing the time when an item was created and enqueued for distribution */ String DISTRIBUTION_ENQUEUE_TIMESTAMP = "distribution.enqueue.timestamp"; }