You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2021/11/08 16:04:22 UTC

[isis] branch master updated: ISIS-2883: add new prototyping menu-item for site-map export

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

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new d0cb7e1  ISIS-2883: add new prototyping menu-item for site-map export
d0cb7e1 is described below

commit d0cb7e1015ca9a4b9fb21027071c15def67721bc
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Nov 8 17:04:09 2021 +0100

    ISIS-2883: add new prototyping menu-item for site-map export
    
    - yet just a stub
---
 .../org/apache/isis/applib/IsisModuleApplib.java   |  2 +
 .../applib/services/sitemap/SitemapService.java    | 30 +++++++
 .../services/sitemap/SitemapServiceMenu.java       | 89 ++++++++++++++++++++
 .../IsisModuleCoreRuntimeServices.java             |  2 +
 .../sitemap/SitemapServiceDefault.java             | 98 ++++++++++++++++++++++
 .../src/main/java/demoapp/dom/menubars.layout.xml  |  4 +
 6 files changed, 225 insertions(+)

diff --git a/api/applib/src/main/java/org/apache/isis/applib/IsisModuleApplib.java b/api/applib/src/main/java/org/apache/isis/applib/IsisModuleApplib.java
index ca69a72..cbb0dd7 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/IsisModuleApplib.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/IsisModuleApplib.java
@@ -53,6 +53,7 @@ import org.apache.isis.applib.services.publishing.log.EntityPropertyChangeLogger
 import org.apache.isis.applib.services.publishing.log.ExecutionLogger;
 import org.apache.isis.applib.services.queryresultscache.QueryResultsCache;
 import org.apache.isis.applib.services.session.SessionLoggingServiceLogging;
+import org.apache.isis.applib.services.sitemap.SitemapServiceMenu;
 import org.apache.isis.applib.services.sudo.SudoService;
 import org.apache.isis.applib.services.user.ImpersonateMenu;
 import org.apache.isis.applib.services.user.ImpersonateStopMenu;
@@ -101,6 +102,7 @@ import org.apache.isis.schema.IsisModuleSchema;
         ClockService.class,
         ConfigurationMenu.class,
         LayoutServiceMenu.class,
+        SitemapServiceMenu.class,
         ImpersonateMenu.class,
         ImpersonateStopMenu.class,
         MetaModelServiceMenu.class,
diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/sitemap/SitemapService.java b/api/applib/src/main/java/org/apache/isis/applib/services/sitemap/SitemapService.java
new file mode 100644
index 0000000..a8ac56a
--- /dev/null
+++ b/api/applib/src/main/java/org/apache/isis/applib/services/sitemap/SitemapService.java
@@ -0,0 +1,30 @@
+/*
+ *  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.isis.applib.services.sitemap;
+
+/**
+ * Provides a site-map based on the menu bar layout.
+ *
+ * @since 2.x {@index}
+ */
+public interface SitemapService {
+
+    String toSitemapAdoc(String title);
+
+}
diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/sitemap/SitemapServiceMenu.java b/api/applib/src/main/java/org/apache/isis/applib/services/sitemap/SitemapServiceMenu.java
new file mode 100644
index 0000000..a7ddc92
--- /dev/null
+++ b/api/applib/src/main/java/org/apache/isis/applib/services/sitemap/SitemapServiceMenu.java
@@ -0,0 +1,89 @@
+/*
+ *  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.isis.applib.services.sitemap;
+
+import javax.inject.Named;
+
+import org.apache.isis.applib.IsisModuleApplib;
+import org.apache.isis.applib.annotation.Action;
+import org.apache.isis.applib.annotation.ActionLayout;
+import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.annotation.DomainServiceLayout;
+import org.apache.isis.applib.annotation.MemberSupport;
+import org.apache.isis.applib.annotation.Optionality;
+import org.apache.isis.applib.annotation.Parameter;
+import org.apache.isis.applib.annotation.PriorityPrecedence;
+import org.apache.isis.applib.annotation.RestrictTo;
+import org.apache.isis.applib.annotation.SemanticsOf;
+import org.apache.isis.applib.value.Clob;
+import org.apache.isis.commons.internal.base._Strings;
+
+/**
+ * Simply provides a UI to allow a site-map (obtained from {@link SitemapService}
+ * to be downloaded within the UI.
+ *
+ * @since 2.x {@index}
+ */
+@Named(SitemapServiceMenu.LOGICAL_TYPE_NAME)
+@DomainService(logicalTypeName = SitemapServiceMenu.LOGICAL_TYPE_NAME)
+@DomainServiceLayout(
+        named = "Prototyping",
+        menuBar = DomainServiceLayout.MenuBar.SECONDARY
+)
+@javax.annotation.Priority(PriorityPrecedence.EARLY)
+public class SitemapServiceMenu {
+
+    public static final String LOGICAL_TYPE_NAME = IsisModuleApplib.NAMESPACE + ".SitemapServiceMenu";
+
+    public static abstract class ActionDomainEvent<T> extends IsisModuleApplib.ActionDomainEvent<T> {}
+
+    private final SitemapService sitemapService;
+
+    public SitemapServiceMenu(final SitemapService sitemapService) {
+        this.sitemapService = sitemapService;
+    }
+
+    @Action(
+            domainEvent = downloadSitemap.ActionEvent.class,
+            semantics = SemanticsOf.NON_IDEMPOTENT, //disable client-side caching
+            restrictTo = RestrictTo.PROTOTYPING
+            )
+    @ActionLayout(
+            cssClassFa = "fa-download",
+            named = "Download Site-Map Template (Adoc)",
+            sequence="500.450.1")
+    public class downloadSitemap{
+
+        public class ActionEvent extends ActionDomainEvent<downloadSitemap> {}
+
+        @MemberSupport public Clob act(
+                @Parameter(optionality = Optionality.MANDATORY) final String title,
+                @Parameter(optionality = Optionality.MANDATORY) final String fileName) {
+
+            final String adoc = sitemapService.toSitemapAdoc(title);
+
+            return new Clob(_Strings.asFileNameWithExtension(fileName,  ".adoc"), "text/plain", adoc);
+        }
+
+        @MemberSupport public String default0Act() { return "Site-Map"; }
+        @MemberSupport public String default1Act() { return "sitemap.adoc"; }
+
+    }
+
+}
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/IsisModuleCoreRuntimeServices.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/IsisModuleCoreRuntimeServices.java
index fa1d8db..c42ecc7 100644
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/IsisModuleCoreRuntimeServices.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/IsisModuleCoreRuntimeServices.java
@@ -56,6 +56,7 @@ import org.apache.isis.core.runtimeservices.repository.RepositoryServiceDefault;
 import org.apache.isis.core.runtimeservices.routing.RoutingServiceDefault;
 import org.apache.isis.core.runtimeservices.scratchpad.ScratchpadDefault;
 import org.apache.isis.core.runtimeservices.session.InteractionServiceDefault;
+import org.apache.isis.core.runtimeservices.sitemap.SitemapServiceDefault;
 import org.apache.isis.core.runtimeservices.transaction.TransactionServiceSpring;
 import org.apache.isis.core.runtimeservices.urlencoding.UrlEncodingServiceWithCompression;
 import org.apache.isis.core.runtimeservices.user.ImpersonateMenuAdvisorDefault;
@@ -98,6 +99,7 @@ import org.apache.isis.core.runtimeservices.xmlsnapshot.XmlSnapshotServiceDefaul
         MessageServiceDefault.class,
         ObjectIconServiceDefault.class,
         ScratchpadDefault.class,
+        SitemapServiceDefault.class,
         TransactionServiceSpring.class,
         UrlEncodingServiceWithCompression.class,
         WrapperFactoryDefault.class,
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/sitemap/SitemapServiceDefault.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/sitemap/SitemapServiceDefault.java
new file mode 100644
index 0000000..96fed28
--- /dev/null
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/sitemap/SitemapServiceDefault.java
@@ -0,0 +1,98 @@
+/*
+ *  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.isis.core.runtimeservices.sitemap;
+
+import javax.annotation.Priority;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Service;
+
+import org.apache.isis.applib.annotation.PriorityPrecedence;
+import org.apache.isis.applib.layout.grid.Grid;
+import org.apache.isis.applib.services.grid.GridService;
+import org.apache.isis.applib.services.layout.Style;
+import org.apache.isis.applib.services.menu.MenuBarsService;
+import org.apache.isis.applib.services.sitemap.SitemapService;
+import org.apache.isis.core.metamodel.facets.object.grid.GridFacet;
+import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
+
+import lombok.RequiredArgsConstructor;
+import lombok.val;
+
+@Service
+@Named("isis.runtimeservices.SitemapServiceDefault")
+@Priority(PriorityPrecedence.MIDPOINT)
+@Qualifier("Default")
+@RequiredArgsConstructor(onConstructor_ = {@Inject})
+//@Log4j2
+public class SitemapServiceDefault implements SitemapService {
+
+    private final SpecificationLoader specificationLoader;
+    private final GridService gridService;
+    private final MenuBarsService menuBarsService;
+
+    @Override
+    public String toSitemapAdoc(final String title) {
+
+        val adoc = new StringBuilder();
+        adoc.append(String.format("= %s\n\n", title));
+
+        val menuBars = menuBarsService.menuBars(MenuBarsService.Type.DEFAULT);
+        menuBars.visit(actionLayout->{
+            //TODO structor by sections
+            adoc.append(String.format("== %s\n\n", actionLayout.getId()));
+        });
+
+        return adoc.toString();
+    }
+
+    // -- HELPER
+
+    private Grid toGrid(final Class<?> domainClass, final Style style) {
+
+        if (style == Style.CURRENT) {
+
+            return specificationLoader.specForType(domainClass)
+                    .flatMap(spec->spec.lookupFacet(GridFacet.class))
+                    .map(gridFacet->gridFacet.getGrid(null))
+                    .orElse(null);
+        }
+
+        // don't use the grid from the facet, because it will be modified subsequently.
+        Grid grid = gridService.load(domainClass);
+        if(grid == null) {
+            grid = gridService.defaultGridFor(domainClass);
+        }
+        gridService.normalize(grid);
+        if (style == Style.NORMALIZED) {
+            return grid;
+        }
+        if (style == Style.COMPLETE) {
+            return gridService.complete(grid);
+        }
+        if (style == Style.MINIMAL) {
+            return gridService.minimal(grid);
+        }
+        throw new IllegalArgumentException("unsupported style");
+    }
+
+
+}
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/menubars.layout.xml b/examples/demo/domain/src/main/java/demoapp/dom/menubars.layout.xml
index 762e32d..0d74077 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/menubars.layout.xml
+++ b/examples/demo/domain/src/main/java/demoapp/dom/menubars.layout.xml
@@ -286,6 +286,10 @@ For latest we use: https://raw.githubusercontent.com/apache/isis/master/antora/s
                 <mb3:serviceAction objectType="isis.applib.LayoutServiceMenu" id="downloadMenuBarsLayout"/>
             </mb3:section>
             <mb3:section>
+                <mb3:named>Site-Map</mb3:named>
+                <mb3:serviceAction objectType="isis.applib.SitemapServiceMenu" id="downloadSitemap"/>
+            </mb3:section>
+            <mb3:section>
                 <mb3:named>Meta Model and Features</mb3:named>
                 <mb3:serviceAction objectType="isis.applib.MetaModelServiceMenu" id="downloadMetaModelXml"/>
                 <mb3:serviceAction objectType="isis.applib.MetaModelServiceMenu" id="downloadMetaModelCsv"/>