You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2020/09/08 19:29:59 UTC

[sling-org-apache-sling-app-cms] branch SLING-8913-multiple-instance-types updated (7fa6f9b -> 72c3197)

This is an automated email from the ASF dual-hosted git repository.

dklco pushed a change to branch SLING-8913-multiple-instance-types
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git.


    from 7fa6f9b  Adding UI for importers, exports and agents
     new 6ba973e  Updating icons to be less blurry
     new 72c3197  Adding missed files

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/sling/cms/ResourceTree.java    |  23 +++-
 .../IsPublishableResourceContainer.java            |  37 +++---
 .../cms/publication/IsPublishableResourceType.java |  28 ++---
 .../cms/core/publication/BulkPublicationJob.java   | 124 +++++++++++++++++++++
 transformer/src/test/resources/thumbnail.png       | Bin 20437 -> 21183 bytes
 ui/src/main/frontend/js/cms.form.js                |   3 +-
 .../components/publication/agent/agent.jsp         |  14 ++-
 .../libs/sling-cms/content/publication/bulk.json   |  48 ++++++++
 .../libs/sling-cms/content/publication/home.json   |   2 +-
 .../resources/jcr_root/libs/sling-cms/i18n.json    |   5 +
 .../sling-cms/thumbnails/bulk-publication.png      | Bin 0 -> 4080 bytes
 .../static/sling-cms/thumbnails/exporters.png      | Bin 0 -> 3838 bytes
 .../static/sling-cms/thumbnails/importers.png      | Bin 0 -> 3833 bytes
 .../static/sling-cms/thumbnails/publish-agent.png  | Bin 0 -> 3013 bytes
 14 files changed, 237 insertions(+), 47 deletions(-)
 copy core/src/main/java/org/apache/sling/cms/core/internal/models/PageManagerImpl.java => api/src/main/java/org/apache/sling/cms/publication/IsPublishableResourceContainer.java (53%)
 copy core/src/main/java/org/apache/sling/cms/core/internal/models/SiteManagerImpl.java => api/src/main/java/org/apache/sling/cms/publication/IsPublishableResourceType.java (59%)
 create mode 100644 core/src/main/java/org/apache/sling/cms/core/publication/BulkPublicationJob.java
 create mode 100644 ui/src/main/resources/jcr_root/libs/sling-cms/content/publication/bulk.json
 create mode 100644 ui/src/main/resources/jcr_root/static/sling-cms/thumbnails/bulk-publication.png
 create mode 100644 ui/src/main/resources/jcr_root/static/sling-cms/thumbnails/exporters.png
 create mode 100644 ui/src/main/resources/jcr_root/static/sling-cms/thumbnails/importers.png
 create mode 100644 ui/src/main/resources/jcr_root/static/sling-cms/thumbnails/publish-agent.png


[sling-org-apache-sling-app-cms] 02/02: Adding missed files

Posted by dk...@apache.org.
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 72c319753fb24b3d7247a5a60ca9f890fe6f4cf3
Author: Dan Klco <dk...@apache.org>
AuthorDate: Tue Sep 8 15:29:45 2020 -0400

    Adding missed files
---
 .../IsPublishableResourceContainer.java            |  40 +++++++
 .../cms/publication/IsPublishableResourceType.java |  36 ++++++
 .../cms/core/publication/BulkPublicationJob.java   | 124 +++++++++++++++++++++
 .../libs/sling-cms/content/publication/bulk.json   |  48 ++++++++
 4 files changed, 248 insertions(+)

diff --git a/api/src/main/java/org/apache/sling/cms/publication/IsPublishableResourceContainer.java b/api/src/main/java/org/apache/sling/cms/publication/IsPublishableResourceContainer.java
new file mode 100644
index 0000000..a2a1436
--- /dev/null
+++ b/api/src/main/java/org/apache/sling/cms/publication/IsPublishableResourceContainer.java
@@ -0,0 +1,40 @@
+/*
+ * 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.cms.publication;
+
+import java.util.Optional;
+import java.util.function.Predicate;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.cms.CMSConstants;
+import org.apache.sling.jcr.resource.api.JcrResourceConstants;
+
+/**
+ * A predicate for evaluating if a resource can contain publishable resources or
+ * be a publishable resource itself
+ */
+public class IsPublishableResourceContainer implements Predicate<Resource> {
+
+    @Override
+    public boolean test(Resource r) {
+        return Optional.ofNullable(r).map(Resource::getResourceType)
+                .map(rt -> JcrResourceConstants.NT_SLING_FOLDER.equals(rt)
+                        || JcrResourceConstants.NT_SLING_ORDERED_FOLDER.equals(rt) || CMSConstants.NT_FILE.equals(rt)
+                        || CMSConstants.NT_SITE.equals(rt) || CMSConstants.NT_PAGE.equals(rt))
+                .orElse(false);
+    }
+}
\ No newline at end of file
diff --git a/api/src/main/java/org/apache/sling/cms/publication/IsPublishableResourceType.java b/api/src/main/java/org/apache/sling/cms/publication/IsPublishableResourceType.java
new file mode 100644
index 0000000..0cc1ecb
--- /dev/null
+++ b/api/src/main/java/org/apache/sling/cms/publication/IsPublishableResourceType.java
@@ -0,0 +1,36 @@
+/*
+ * 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.cms.publication;
+
+import java.util.Optional;
+import java.util.function.Predicate;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.cms.CMSConstants;
+import org.apache.sling.cms.ResourceTree;
+
+/**
+ * A predicate for evaluating if a resource is a publishable resource type.
+ */
+public class IsPublishableResourceType implements Predicate<ResourceTree> {
+
+    @Override
+    public boolean test(ResourceTree rt) {
+        return Optional.ofNullable(rt).map(ResourceTree::getResource).map(Resource::getResourceType)
+                .map(type -> CMSConstants.NT_FILE.equals(type) || CMSConstants.NT_PAGE.equals(type)).orElse(false);
+    }
+}
\ No newline at end of file
diff --git a/core/src/main/java/org/apache/sling/cms/core/publication/BulkPublicationJob.java b/core/src/main/java/org/apache/sling/cms/core/publication/BulkPublicationJob.java
new file mode 100644
index 0000000..6239692
--- /dev/null
+++ b/core/src/main/java/org/apache/sling/cms/core/publication/BulkPublicationJob.java
@@ -0,0 +1,124 @@
+/*
+ * 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.cms.core.publication;
+
+import java.util.Collections;
+import java.util.stream.Stream;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.apache.sling.cms.ConfigurableJobExecutor;
+import org.apache.sling.cms.PublishableResource;
+import org.apache.sling.cms.ResourceTree;
+import org.apache.sling.cms.publication.IsPublishableResourceContainer;
+import org.apache.sling.cms.publication.IsPublishableResourceType;
+import org.apache.sling.cms.publication.PublicationException;
+import org.apache.sling.cms.publication.PublicationManager;
+import org.apache.sling.cms.publication.PublicationManagerFactory;
+import org.apache.sling.cms.publication.PublicationType;
+import org.apache.sling.event.jobs.Job;
+import org.apache.sling.event.jobs.consumer.JobConsumer;
+import org.apache.sling.event.jobs.consumer.JobExecutionContext;
+import org.apache.sling.event.jobs.consumer.JobExecutionResult;
+import org.apache.sling.event.jobs.consumer.JobExecutor;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A Sling Post Operation to unpublish content
+ */
+@Component(service = { JobExecutor.class, ConfigurableJobExecutor.class }, property = {
+        JobConsumer.PROPERTY_TOPICS + "=" + BulkPublicationJob.TOPIC })
+public class BulkPublicationJob extends ConfigurableJobExecutor {
+
+    private static final Logger log = LoggerFactory.getLogger(BulkPublicationJob.class);
+
+    public static final String TOPIC = "cmsjob/org/apache/sling/cms/publication/Bulk";
+
+    @Reference
+    private PublicationManagerFactory publicationManagerFactory;
+
+    @Reference
+    private ResourceResolverFactory factory;
+
+    @Override
+    public JobExecutionResult doProcess(Job job, JobExecutionContext context, ResourceResolver resolver) {
+        String[] paths = job.getProperty("paths", String[].class);
+        PublicationType type = PublicationType.valueOf(job.getProperty("type", String.class));
+        boolean deep = job.getProperty("deep", false);
+
+        PublicationManager publicationManager = publicationManagerFactory.getPublicationManager();
+
+        context.initProgress(paths.length, paths.length * 5000L);
+
+        log.info("Starting bulk publication: paths={}, type={}, deep={}", paths, type, deep);
+
+        for (String path : paths) {
+            Stream<PublishableResource> toPublish = null;
+            Resource resource = resolver.getResource(path);
+            if (deep) {
+                toPublish = ResourceTree
+                        .stream(resource, new IsPublishableResourceContainer(), new IsPublishableResourceType())
+                        .map(rt -> rt.getResource().adaptTo(PublishableResource.class));
+            } else {
+                toPublish = Collections.singletonList(resource.adaptTo(PublishableResource.class)).stream();
+            }
+            toPublish.forEach(pr -> {
+                try {
+                    if (type == PublicationType.ADD) {
+                        publicationManager.publish(pr);
+                    } else {
+                        publicationManager.unpublish(pr);
+                    }
+                    context.log("{0} complete for {1}", type, pr.getPath());
+                } catch (PublicationException e) {
+                    context.log("{0} failed for {1}", type, pr.getPath());
+                    log.warn("Failed to publish {}", pr, e);
+                }
+            });
+
+            context.log("Publication complete for path: {0}", path);
+            context.incrementProgressCount(1);
+        }
+
+        context.log("Publication complete!");
+        return context.result().succeeded();
+    }
+
+    @Override
+    public String getConfigurationPath() {
+        return "/mnt/overlay/sling-cms/content/publication/bulk";
+    }
+
+    @Override
+    public ResourceResolverFactory getResolverFactory() {
+        return factory;
+    }
+
+    @Override
+    public String getTitleKey() {
+        return "slingcms.bulkpublication.title";
+    }
+
+    @Override
+    public String getTopic() {
+        return TOPIC;
+    }
+}
\ No newline at end of file
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/content/publication/bulk.json b/ui/src/main/resources/jcr_root/libs/sling-cms/content/publication/bulk.json
new file mode 100644
index 0000000..c32debf
--- /dev/null
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/content/publication/bulk.json
@@ -0,0 +1,48 @@
+{
+    "jcr:primaryType": "nt:unstructured",
+    "sling:resourceType": "sling-cms/components/general/container",
+    "paths": {
+        "jcr:primaryType": "nt:unstructured",
+        "sling:resourceType": "sling-cms/components/editor/fields/repeating",
+        "label": "Paths",
+        "name": "paths"
+    },
+    "type": {
+        "jcr:primaryType": "nt:unstructured",
+        "sling:resourceType": "sling-cms/components/editor/fields/select",
+        "label": "Type",
+        "name": "type",
+        "options": {
+            "ADD": {
+                "label": "Publish",
+                "value": "ADD"
+            },
+            "regex": {
+                "label": "Unpublish",
+                "value": "DELETE"
+            }
+        }
+    },
+    "deep": {
+        "jcr:primaryType": "nt:unstructured",
+        "sling:resourceType": "sling-cms/components/editor/fields/select",
+        "label": "Is Deep",
+        "name": "deep",
+        "options": {
+            "ADD": {
+                "label": "Yes",
+                "value": "true"
+            },
+            "regex": {
+                "label": "No",
+                "value": "false"
+            }
+        }
+    },
+    "topic": {
+        "jcr:primaryType": "nt:unstructured",
+        "sling:resourceType": "sling-cms/components/editor/fields/hidden",
+        "name": "job.topics",
+        "value": "cmsjob/org/apache/sling/cms/publication/Bulk"
+    }
+}
\ No newline at end of file


[sling-org-apache-sling-app-cms] 01/02: Updating icons to be less blurry

Posted by dk...@apache.org.
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 6ba973e8843dac3b91b2b1fa529ad96c256fd073
Author: Dan Klco <dk...@apache.org>
AuthorDate: Tue Sep 8 15:28:49 2020 -0400

    Updating icons to be less blurry
---
 .../java/org/apache/sling/cms/ResourceTree.java    |  23 +++++++++++++++------
 transformer/src/test/resources/thumbnail.png       | Bin 20437 -> 21183 bytes
 ui/src/main/frontend/js/cms.form.js                |   3 ++-
 .../components/publication/agent/agent.jsp         |  14 ++++++++++++-
 .../libs/sling-cms/content/publication/home.json   |   2 +-
 .../resources/jcr_root/libs/sling-cms/i18n.json    |   5 +++++
 .../sling-cms/thumbnails/bulk-publication.png      | Bin 0 -> 4080 bytes
 .../static/sling-cms/thumbnails/exporters.png      | Bin 0 -> 3838 bytes
 .../static/sling-cms/thumbnails/importers.png      | Bin 0 -> 3833 bytes
 .../static/sling-cms/thumbnails/publish-agent.png  | Bin 0 -> 3013 bytes
 10 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/api/src/main/java/org/apache/sling/cms/ResourceTree.java b/api/src/main/java/org/apache/sling/cms/ResourceTree.java
index 3096b33..445d8f5 100644
--- a/api/src/main/java/org/apache/sling/cms/ResourceTree.java
+++ b/api/src/main/java/org/apache/sling/cms/ResourceTree.java
@@ -16,6 +16,7 @@
  */
 package org.apache.sling.cms;
 
+import java.util.function.Predicate;
 import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
 
@@ -33,6 +34,11 @@ public class ResourceTree {
         return new ResourceTree(resource).streamTree(filterType);
     }
 
+    public static Stream<ResourceTree> stream(Resource resource, Predicate<Resource> filterTraversal,
+            Predicate<ResourceTree> filterInclude) {
+        return new ResourceTree(resource).streamTree(filterTraversal, filterInclude);
+    }
+
     private ResourceTree(Resource root) {
         this.root = root;
     }
@@ -42,14 +48,19 @@ public class ResourceTree {
     }
 
     private Stream<ResourceTree> streamTree() {
-        return Stream.concat(Stream.of(this), StreamSupport.stream(root.getChildren().spliterator(), false)
-                .map(ResourceTree::new).flatMap(ResourceTree::streamTree));
+        return streamTree(r -> true, rt -> true);
     }
 
     private Stream<ResourceTree> streamTree(String filterType) {
-        return Stream.concat(Stream.of(this),
-                StreamSupport.stream(root.getChildren().spliterator(), false)
-                        .filter(c -> filterType.equals(c.getResourceType())).map(ResourceTree::new)
-                        .flatMap(rt -> rt.streamTree(filterType)));
+        return streamTree((r -> filterType.equals(r.getResourceType())), rt -> true);
+    }
+
+    private Stream<ResourceTree> streamTree(Predicate<Resource> filterTraversal,
+            Predicate<ResourceTree> filterInclude) {
+        return Stream
+                .concat(Stream.of(this),
+                        StreamSupport.stream(root.getChildren().spliterator(), false).filter(filterTraversal)
+                                .map(ResourceTree::new).flatMap(rt -> rt.streamTree(filterTraversal, filterInclude)))
+                .filter(filterInclude);
     }
 }
\ No newline at end of file
diff --git a/transformer/src/test/resources/thumbnail.png b/transformer/src/test/resources/thumbnail.png
index f38c3a4..62cf067 100644
Binary files a/transformer/src/test/resources/thumbnail.png and b/transformer/src/test/resources/thumbnail.png differ
diff --git a/ui/src/main/frontend/js/cms.form.js b/ui/src/main/frontend/js/cms.form.js
index 7eb1dec..97b0ca1 100644
--- a/ui/src/main/frontend/js/cms.form.js
+++ b/ui/src/main/frontend/js/cms.form.js
@@ -54,7 +54,8 @@ rava.bind('.Form-Ajax', {
           }
           form.appendChild(dateContainer);
         }
-        const response = await fetch(form.action, {
+        const action = form.getAttribute('action');
+        const response = await fetch(action, {
           method: 'POST',
           body: formData,
           cache: 'no-cache',
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/publication/agent/agent.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/publication/agent/agent.jsp
index a1b581d..dcbf8d3 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/components/publication/agent/agent.jsp
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/publication/agent/agent.jsp
@@ -64,7 +64,19 @@
                             <sling:include resource="${configRsrc}" />
                         </c:forEach>
                     </dl>
-                    <a class="button" href="/system/console/configMgr/${agentCfg['service.pid']}">Edit</a>
+                    <div class="level">
+                        <div class="level-left">
+                            <div class="level-item">
+                                <a class="button" href="/system/console/configMgr/${agentCfg['service.pid']}">Edit</a>
+                            </div>
+                            <div class="level-item">
+                                <form method="post" action="/libs/sling/distribution/services/agents/${agent.name}" class="mb-0" target="_blank">
+                                    <input type="hidden" name="action" value="TEST" />
+                                    <button class="button" type="submit">Test</button>
+                                </form>
+                            </div>
+                        </div>
+                    </div>
                 </div>
             </article>
         </div>
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/content/publication/home.json b/ui/src/main/resources/jcr_root/libs/sling-cms/content/publication/home.json
index d628749..65e922e 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/content/publication/home.json
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/content/publication/home.json
@@ -30,7 +30,7 @@
                     "jcr:primaryType": "nt:unstructured",
                     "sling:resourceType": "sling-cms/components/cms/tilecard",
                     "image": "/static/sling-cms/thumbnails/bulk-publication.png.transform/sling-cms-thumbnail.png",
-                    "link": "/cms/publication/bulk-publication.html",
+                    "link": "/cms/jobs/list.html",
                     "title": "Bulk Publication"
                 },
                 "exporters": {
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/i18n.json b/ui/src/main/resources/jcr_root/libs/sling-cms/i18n.json
index 5441116..03af135 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/i18n.json
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/i18n.json
@@ -95,6 +95,11 @@
             "sling:message": "Job Properties",
             "sling:key": "slingcms.jobs.properties"
         },
+        "slingcms-bulkpublication-title": {
+            "jcr:primaryType": "sling:MessageEntry",
+            "sling:message": "Bulk Publication",
+            "sling:key": "slingcms.bulkpublication.title"
+        },
         "slingcms-publicationstatus": {
             "jcr:primaryType": "sling:MessageEntry",
             "sling:message": "Publication Status",
diff --git a/ui/src/main/resources/jcr_root/static/sling-cms/thumbnails/bulk-publication.png b/ui/src/main/resources/jcr_root/static/sling-cms/thumbnails/bulk-publication.png
new file mode 100644
index 0000000..b4e5c5c
Binary files /dev/null and b/ui/src/main/resources/jcr_root/static/sling-cms/thumbnails/bulk-publication.png differ
diff --git a/ui/src/main/resources/jcr_root/static/sling-cms/thumbnails/exporters.png b/ui/src/main/resources/jcr_root/static/sling-cms/thumbnails/exporters.png
new file mode 100644
index 0000000..4723a15
Binary files /dev/null and b/ui/src/main/resources/jcr_root/static/sling-cms/thumbnails/exporters.png differ
diff --git a/ui/src/main/resources/jcr_root/static/sling-cms/thumbnails/importers.png b/ui/src/main/resources/jcr_root/static/sling-cms/thumbnails/importers.png
new file mode 100644
index 0000000..8c63b29
Binary files /dev/null and b/ui/src/main/resources/jcr_root/static/sling-cms/thumbnails/importers.png differ
diff --git a/ui/src/main/resources/jcr_root/static/sling-cms/thumbnails/publish-agent.png b/ui/src/main/resources/jcr_root/static/sling-cms/thumbnails/publish-agent.png
new file mode 100644
index 0000000..705007e
Binary files /dev/null and b/ui/src/main/resources/jcr_root/static/sling-cms/thumbnails/publish-agent.png differ