This is an automated email from the ASF dual-hosted git repository. cschneider pushed a commit to branch SLING-9445 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-api.git
commit bf8b5e565580ba05247defcf279f5a063cf015ce Author: Christian Schneider <[email protected]> AuthorDate: Wed May 13 14:44:31 2020 +0200 SLING-9445 - DistributionEvent --- .../distribution/event/DistributionEvent.java | 91 ++++++++++++++++++++++ .../event/DistributionEventProperties.java | 5 ++ .../sling/distribution/event/package-info.java | 2 +- 3 files changed, 97 insertions(+), 1 deletion(-) 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..b3e7118 --- /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_PATHS; +import static org.apache.sling.distribution.event.DistributionEventProperties.DISTRIBUTION_TYPE; +import static org.apache.sling.distribution.event.DistributionEventProperties.PACKAGE_ID; + +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 getDistributionType() { + return distType; + } + + public String[] getDistributionPaths() { + return distPaths; + } + + public Event toEvent(String topic) { + Dictionary<String, Object> props = new Hashtable<String, Object>(); + props.put(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(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/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java b/src/main/java/org/apache/sling/distribution/event/DistributionEventProperties.java index a70f9b2..f19337d 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 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;
