This is an automated email from the ASF dual-hosted git repository. dklco pushed a commit to branch SLING-8913-multiple-instance-types in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git
commit 62ab9376e938e78817dd91139b40c1ef0651a91f Author: Dan Klco <[email protected]> AuthorDate: Fri Aug 28 22:05:54 2020 -0400 Adding support for publishing configs --- .../org/apache/sling/cms/PublishableResource.java | 4 ++++ .../sling/cms/publication/PublicationManager.java | 2 +- .../internal/models/PublishableResourceImpl.java | 6 +++++- .../ContentDistributionPublicationManager.java | 23 +++++++++++++++++----- .../resources/SLING-INF/nodetypes/nodetypes.cnd | 2 +- .../libs/sling-cms/content/config/bucket.json | 8 ++++++++ 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/api/src/main/java/org/apache/sling/cms/PublishableResource.java b/api/src/main/java/org/apache/sling/cms/PublishableResource.java index 068618d..e15ed54 100644 --- a/api/src/main/java/org/apache/sling/cms/PublishableResource.java +++ b/api/src/main/java/org/apache/sling/cms/PublishableResource.java @@ -22,6 +22,10 @@ import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ValueMap; import org.apache.sling.cms.publication.PublicationType; +/** + * A Model interface for adapting sling:File, sling:Page and sling:Config + * resources. + */ public interface PublishableResource { /** diff --git a/api/src/main/java/org/apache/sling/cms/publication/PublicationManager.java b/api/src/main/java/org/apache/sling/cms/publication/PublicationManager.java index 02057c6..bf9e316 100644 --- a/api/src/main/java/org/apache/sling/cms/publication/PublicationManager.java +++ b/api/src/main/java/org/apache/sling/cms/publication/PublicationManager.java @@ -43,7 +43,7 @@ public interface PublicationManager { * @param resource the resource to publish * @throws PublicationException an exception occurs publishing the resource */ - void unpublish(PublishableResource resource) throws PublicationException; + void unpublish(@NotNull PublishableResource resource) throws PublicationException; /** * The publication mode for the instance diff --git a/core/src/main/java/org/apache/sling/cms/core/internal/models/PublishableResourceImpl.java b/core/src/main/java/org/apache/sling/cms/core/internal/models/PublishableResourceImpl.java index 043646e..7386eeb 100644 --- a/core/src/main/java/org/apache/sling/cms/core/internal/models/PublishableResourceImpl.java +++ b/core/src/main/java/org/apache/sling/cms/core/internal/models/PublishableResourceImpl.java @@ -70,7 +70,11 @@ public class PublishableResourceImpl implements PublishableResource { this.resource = resource; this.created = resource.getValueMap().get(JcrConstants.JCR_CREATED, Calendar.class); this.createdBy = resource.getValueMap().get(NodeTypeConstants.JCR_CREATEDBY, String.class); - this.contentResource = resource.getChild(JcrConstants.JCR_CONTENT); + if (CMSConstants.NT_CONFIG.equals(resource.getValueMap().get(JcrConstants.JCR_PRIMARYTYPE, String.class))) { + this.contentResource = resource; + } else { + this.contentResource = resource.getChild(JcrConstants.JCR_CONTENT); + } if (this.contentResource != null) { ValueMap properties = contentResource.getValueMap(); this.lastModified = properties.get(JcrConstants.JCR_LASTMODIFIED, Calendar.class); diff --git a/core/src/main/java/org/apache/sling/cms/core/publication/ContentDistributionPublicationManager.java b/core/src/main/java/org/apache/sling/cms/core/publication/ContentDistributionPublicationManager.java index 2934232..98464da 100644 --- a/core/src/main/java/org/apache/sling/cms/core/publication/ContentDistributionPublicationManager.java +++ b/core/src/main/java/org/apache/sling/cms/core/publication/ContentDistributionPublicationManager.java @@ -31,6 +31,8 @@ import org.apache.sling.distribution.DistributionResponse; import org.apache.sling.distribution.Distributor; import org.apache.sling.distribution.SimpleDistributionRequest; import org.osgi.service.event.EventAdmin; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Implementation of the PublicationManager interface using Sling Content @@ -38,6 +40,8 @@ import org.osgi.service.event.EventAdmin; */ public class ContentDistributionPublicationManager extends StandalonePublicationManager { + private static final Logger log = LoggerFactory.getLogger(ContentDistributionPublicationManager.class); + private final Distributor distributor; private final String[] agents; @@ -45,18 +49,21 @@ public class ContentDistributionPublicationManager extends StandalonePublication super(eventAdmin); this.distributor = distributor; this.agents = agents; - + } @Override public void publish(PublishableResource resource) throws PublicationException { + log.info("Publishing: {}", resource.getPath()); DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, - new String[] { resource.getPath() }, Collections.singleton(resource.getContentResource().getPath())); + new String[] { resource.getPath(), resource.getContentResource().getPath() }, + Collections.singleton(resource.getContentResource().getPath())); List<DistributionResponse> failedResponses = this .distributeRequest(resource.getResource().getResourceResolver(), request); if (!failedResponses.isEmpty()) { throw new PublicationException("Failed to publish: " + collectFailures(failedResponses)); } else { + log.debug("Content Distribution successful, updating publication information"); super.publish(resource); } } @@ -67,14 +74,20 @@ public class ContentDistributionPublicationManager extends StandalonePublication } private List<DistributionResponse> distributeRequest(ResourceResolver resolver, DistributionRequest request) { - return Arrays.stream(agents).map(a -> distributor.distribute(a, resolver, request)) - .filter(res -> !res.isSuccessful()).collect(Collectors.toList()); + return Arrays.stream(agents).map(a -> { + log.info("Sending to agent: {}", a); + DistributionResponse response = distributor.distribute(a, resolver, request); + log.debug("Retrieved response [{}]: {}", response.getState(), response.getMessage()); + return response; + }).filter(res -> !res.isSuccessful()).collect(Collectors.toList()); } @Override public void unpublish(PublishableResource resource) throws PublicationException { + log.info("Unpublish: {}", resource.getPath()); DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.DELETE, - new String[] { resource.getPath() }, Collections.singleton(resource.getContentResource().getPath())); + new String[] { resource.getPath(), resource.getContentResource().getPath() }, + Collections.singleton(resource.getContentResource().getPath())); List<DistributionResponse> failedResponses = this .distributeRequest(resource.getResource().getResourceResolver(), request); if (!failedResponses.isEmpty()) { diff --git a/ui/src/main/resources/SLING-INF/nodetypes/nodetypes.cnd b/ui/src/main/resources/SLING-INF/nodetypes/nodetypes.cnd index 1d85577..43edb8f 100644 --- a/ui/src/main/resources/SLING-INF/nodetypes/nodetypes.cnd +++ b/ui/src/main/resources/SLING-INF/nodetypes/nodetypes.cnd @@ -36,7 +36,7 @@ - componentType (string) - jcr:title (string) -[sling:Config] > nt:hierarchyNode, mix:lastModified +[sling:Config] > nt:hierarchyNode, mix:lastModified, mix:publishable orderable - sling:resourceType (string) - jcr:title (string) diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/content/config/bucket.json b/ui/src/main/resources/jcr_root/libs/sling-cms/content/config/bucket.json index dbeda1f..c8d5461 100644 --- a/ui/src/main/resources/jcr_root/libs/sling-cms/content/config/bucket.json +++ b/ui/src/main/resources/jcr_root/libs/sling-cms/content/config/bucket.json @@ -37,6 +37,10 @@ "jcr:primaryType": "nt:unstructured", "title": "Title" }, + "published": { + "jcr:primaryType": "nt:unstructured", + "title": "Published" + }, "lastModified": { "jcr:primaryType": "nt:unstructured", "title": "Last Modified" @@ -63,6 +67,10 @@ "sling:resourceType": "sling-cms/components/cms/columns/text", "property": "jcr:title" }, + "publish": { + "jcr:primaryType": "nt:unstructured", + "sling:resourceType": "sling-cms/components/cms/columns/publish" + }, "lastModified": { "jcr:primaryType": "nt:unstructured", "sling:resourceType": "sling-cms/components/cms/columns/lastmodified",
