You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2017/10/31 07:03:32 UTC

[isis] branch master updated: ISIS-1766: adds new method to LayoutService to download menubars.layout.xml. Also...

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

danhaywood 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 724dc03  ISIS-1766: adds new method to LayoutService to download menubars.layout.xml.  Also...
724dc03 is described below

commit 724dc03899497fd041c5d6ff5a88075861dcc6ff
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Tue Oct 31 07:01:23 2017 +0000

    ISIS-1766: adds new method to LayoutService to download menubars.layout.xml.  Also...
    
    Also adds a new hint-n-tip for RO viewer
---
 .../guides/ugvro/_ugvro_hints-and-tips.adoc        |  2 +
 ...vro_hints-and-tips_view-model-as-parameter.adoc | 70 ++++++++++++++++++++++
 .../applib/services/layout/LayoutService2.java     | 30 ++++++++++
 .../applib/services/layout/LayoutServiceMenu.java  | 33 +++++++++-
 .../services/layout/LayoutServiceDefault.java      | 36 ++++++++++-
 5 files changed, 167 insertions(+), 4 deletions(-)

diff --git a/adocs/documentation/src/main/asciidoc/guides/ugvro/_ugvro_hints-and-tips.adoc b/adocs/documentation/src/main/asciidoc/guides/ugvro/_ugvro_hints-and-tips.adoc
index 6f994f7..26fa065 100644
--- a/adocs/documentation/src/main/asciidoc/guides/ugvro/_ugvro_hints-and-tips.adoc
+++ b/adocs/documentation/src/main/asciidoc/guides/ugvro/_ugvro_hints-and-tips.adoc
@@ -33,7 +33,9 @@ include::_ugvro_hints-and-tips_using-chrome-devtools.adoc[leveloffset=+1,lines=3
 include::_ugvro_hints-and-tips_angular-tips.adoc[leveloffset=+1,lines=3..-1]
 include::_ugvro_hints-and-tips_pretty-printing.adoc[leveloffset=+1,lines=3..-1]
 include::_ugvro_hints-and-tips_restful-image-property.adoc[leveloffset=+1,lines=3..-1]
+include::_ugvro_hints-and-tips_view-model-as-parameter.adoc[leveloffset=+1,lines=3..-1]
 
 // end::inclusions[]
 
 
+https://lists.apache.org/thread.html/cbd18320bbf6e5c5e767283f9e675cf56e7f4692c109e1e79dbaa90a@%3Cusers.isis.apache.org%3E
\ No newline at end of file
diff --git a/adocs/documentation/src/main/asciidoc/guides/ugvro/_ugvro_hints-and-tips_view-model-as-parameter.adoc b/adocs/documentation/src/main/asciidoc/guides/ugvro/_ugvro_hints-and-tips_view-model-as-parameter.adoc
new file mode 100644
index 0000000..f938ca7
--- /dev/null
+++ b/adocs/documentation/src/main/asciidoc/guides/ugvro/_ugvro_hints-and-tips_view-model-as-parameter.adoc
@@ -0,0 +1,70 @@
+:_basedir: ../../
+:_imagesdir: images/
+[[_ugvro_hints-and-tips_view-model-as-parameter]]
+= View Model as Parameter
+:Notice: 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 ag [...]
+
+
+As discussed link:https://lists.apache.org/thread.html/cbd18320bbf6e5c5e767283f9e675cf56e7f4692c109e1e79dbaa90a@%3Cusers.isis.apache.org%3E[on the mailing list].
+
+== Query
+
+I must provide a REST service accepting more complex view model as input
+parameter.
+
+My view model parameter would look like
+
+[source,java]
+----
+@DomainObject(
+    nature = Nature.VIEW_MODEL,
+    objectType = "OfferTemplateFilter"
+)
+@XmlRootElement(name = "OfferTemplateFilter")
+@XmlAccessorType(XmlAccessType.FIELD)
+@Getter @Setter
+public class OfferTemplateFilter {
+    public List<String> selectedDeviceManufacturer = new ArrayList<>();
+    public List<String> selectedDeviceSizes = new ArrayList<>();
+}
+----
+
+My REST domain service would be someting like
+
+[source,java]
+----
+
+@DomainService(
+    nature = NatureOfService.VIEW_REST_ONLY,
+    objectType = "OfferRestService"
+)
+public class OfferRestService {
+
+    @Action(semantics = SemanticsOf.IDEMPOTENT)
+    public OfferTemplateSelectorForCustomer
+        offerSelectorForCustomer(
+            final String subscriberNumber,
+            final OfferTemplateFilter filter) {
+        return offerSelectorRepository.create(subscriberNumber, filter);
+    }
+    ...
+}
+----
+
+I'm wondering how this could be achieved without custom rest service.
+Ideally the service consumer would post a kind of JSON structure where my
+view model OfferTemplateFilter would be created?
+
+
+== Possible Answer...
+
+Rather than try to "upload" the `OfferTemplateFilter` view model as a parameter, instead treat it as a resource.
+
+That is:
+
+* have a new service to create an instance of the filter, and then
+* update this filter (adding/removing from its two collections).
+* When done, pass a reference to the filter to the original REST service, as a regular reference.
+
+Obviously the URL passed in the last step will be rather long and messy, but that's not a problem per-se.
+
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/layout/LayoutService2.java b/core/applib/src/main/java/org/apache/isis/applib/services/layout/LayoutService2.java
new file mode 100644
index 0000000..fde7b16
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/layout/LayoutService2.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.layout;
+
+import org.apache.isis.applib.annotation.Programmatic;
+import org.apache.isis.applib.services.menu.MenuBarsService;
+
+public interface LayoutService2 extends LayoutService {
+
+
+    /**
+     * Obtains the serialized XML form of the menu bars layout ({@link MenuBarsService}).
+     */
+    @Programmatic
+    String toMenuBarsXml();
+}
\ No newline at end of file
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/layout/LayoutServiceMenu.java b/core/applib/src/main/java/org/apache/isis/applib/services/layout/LayoutServiceMenu.java
index a038f25..30c9bb5 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/layout/LayoutServiceMenu.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/layout/LayoutServiceMenu.java
@@ -26,9 +26,11 @@ import org.apache.isis.applib.annotation.DomainService;
 import org.apache.isis.applib.annotation.DomainServiceLayout;
 import org.apache.isis.applib.annotation.MemberOrder;
 import org.apache.isis.applib.annotation.NatureOfService;
+import org.apache.isis.applib.annotation.ParameterLayout;
 import org.apache.isis.applib.annotation.RestrictTo;
 import org.apache.isis.applib.annotation.SemanticsOf;
 import org.apache.isis.applib.value.Blob;
+import org.apache.isis.applib.value.Clob;
 
 @DomainService(
         nature = NatureOfService.VIEW_MENU_ONLY,
@@ -64,7 +66,7 @@ public class LayoutServiceMenu {
     )
     @ActionLayout(
             cssClassFa = "fa-download",
-            named = "Download Layouts (XML)"
+            named = "Download Layouts (ZIP)"
     )
     @MemberOrder(sequence="500.400.1")
     public Blob downloadLayouts(final LayoutService.Style style) {
@@ -79,12 +81,39 @@ public class LayoutServiceMenu {
         return LayoutService.Style.NORMALIZED;
     }
 
+    public static class DownloadMenuBarsLayoutDomainEvent extends ActionDomainEvent {
+    }
+
+    @Action(
+            domainEvent = DownloadMenuBarsLayoutDomainEvent.class,
+            semantics = SemanticsOf.SAFE,
+            restrictTo = RestrictTo.PROTOTYPING
+    )
+    @ActionLayout(
+            cssClassFa = "fa-download",
+            named = "Download Menu Bars Layout (XML)"
+    )
+    @MemberOrder(sequence="500.400.2")
+    public Clob downloadMenuBarsLayout(
+            @ParameterLayout(named = "File name")
+            final String fileName) {
+
+        final String xml = layoutService.toMenuBarsXml();
+
+        return new Clob(Util.withSuffix(fileName,  ".xml"), "text/xml", xml);
+    }
+
+    public String default0DownloadMenuBarsLayout() {
+        return "menubars.layout.xml";
+    }
+
 
     // //////////////////////////////////////
 
 
     @javax.inject.Inject
-    LayoutService layoutService;
+    LayoutService2 layoutService;
+
 
 
 
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/layout/LayoutServiceDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/layout/LayoutServiceDefault.java
index ae67369..f8f0a9c 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/layout/LayoutServiceDefault.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/layout/LayoutServiceDefault.java
@@ -21,14 +21,17 @@ import java.io.File;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.util.Collection;
+import java.util.List;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 
 import javax.xml.bind.Marshaller;
 
+import com.google.common.base.Joiner;
 import com.google.common.base.Predicate;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -38,20 +41,26 @@ import org.apache.isis.applib.annotation.DomainService;
 import org.apache.isis.applib.annotation.NatureOfService;
 import org.apache.isis.applib.annotation.Programmatic;
 import org.apache.isis.applib.layout.component.Grid;
+import org.apache.isis.applib.layout.menus.MenuBars;
 import org.apache.isis.applib.services.grid.GridService;
 import org.apache.isis.applib.services.jaxb.JaxbService;
-import org.apache.isis.applib.services.layout.LayoutService;
+import org.apache.isis.applib.services.layout.LayoutService2;
+import org.apache.isis.applib.services.menu.MenuBarsService;
 import org.apache.isis.core.metamodel.facets.object.grid.GridFacet;
 import org.apache.isis.core.metamodel.facets.object.viewmodel.ViewModelFacet;
+import org.apache.isis.core.metamodel.services.grid.bootstrap3.GridSystemServiceBS3;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
 import org.apache.isis.objectstore.jdo.metamodel.facets.object.persistencecapable.JdoPersistenceCapableFacet;
 
+import static org.apache.isis.core.metamodel.services.grid.GridServiceDefault.COMMON_SCHEMA_LOCATION;
+import static org.apache.isis.core.metamodel.services.grid.GridServiceDefault.COMMON_TNS;
+
 @DomainService(
         nature = NatureOfService.DOMAIN,
         menuOrder = "" + Integer.MAX_VALUE
 )
-public class LayoutServiceDefault implements LayoutService {
+public class LayoutServiceDefault implements LayoutService2 {
 
     private static final Logger LOG = LoggerFactory.getLogger(LayoutServiceDefault.class);
 
@@ -137,6 +146,27 @@ public class LayoutServiceDefault implements LayoutService {
     }
 
 
+    @Programmatic
+    @Override
+    public String toMenuBarsXml() {
+        MenuBars menuBars = menuBarsService.menuBars();
+
+        // TODO: need something equivalent to GridSystemServiceBS3
+
+        final List<String> parts = Lists.newArrayList();
+        parts.add(COMMON_TNS);
+        parts.add(COMMON_SCHEMA_LOCATION);
+        parts.add(GridSystemServiceBS3.TNS);
+        parts.add(GridSystemServiceBS3.SCHEMA_LOCATION);
+
+        final String tnsAndSchemaLocation = Joiner.on(" ").join(parts);
+
+        return jaxbService.toXml(menuBars,
+                ImmutableMap.<String,Object>of(
+                        Marshaller.JAXB_SCHEMA_LOCATION,
+                        tnsAndSchemaLocation
+                ));
+    }
 
 
     @javax.inject.Inject
@@ -148,5 +178,7 @@ public class LayoutServiceDefault implements LayoutService {
     @javax.inject.Inject
     GridService gridService;
 
+    @javax.inject.Inject
+    MenuBarsService menuBarsService;
 
 }

-- 
To stop receiving notification emails like this one, please contact
['"commits@isis.apache.org" <co...@isis.apache.org>'].