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 2019/04/25 14:29:28 UTC

[isis] branch ISIS-2105 created (now cfa7f9a)

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

danhaywood pushed a change to branch ISIS-2105
in repository https://gitbox.apache.org/repos/asf/isis.git.


      at cfa7f9a  ISIS-2015: adds new mixin

This branch includes the following new commits:

     new cfa7f9a  ISIS-2015: adds new mixin

The 1 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.



[isis] 01/01: ISIS-2015: adds new mixin

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch ISIS-2105
in repository https://gitbox.apache.org/repos/asf/isis.git

commit cfa7f9a8d72e66369d6c9932431f5a5b3e0e8c7a
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Tue Apr 16 10:36:45 2019 +0100

    ISIS-2015: adds new mixin
---
 .../services/metamodel/MetaModelServicesMenu.java  |   4 +-
 .../metamodel/Object_downloadMetaModelXml.java     | 103 +++++++++++++++++++++
 .../services/homepage/HomePageViewModel.layout.xml |   1 +
 3 files changed, 106 insertions(+), 2 deletions(-)

diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/metamodel/MetaModelServicesMenu.java b/core/applib/src/main/java/org/apache/isis/applib/services/metamodel/MetaModelServicesMenu.java
index 1b80b0d..8a861c3 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/metamodel/MetaModelServicesMenu.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/metamodel/MetaModelServicesMenu.java
@@ -58,8 +58,8 @@ public class MetaModelServicesMenu {
     public static abstract class ActionDomainEvent extends IsisApplibModule.ActionDomainEvent<MetaModelServicesMenu> {
     }
 
-    private final MimeType mimeTypeTextCsv;
-    private final MimeType mimeTypeTextXml;
+    final MimeType mimeTypeTextCsv;
+    final MimeType mimeTypeTextXml;
 
     public MetaModelServicesMenu() {
         try {
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/metamodel/Object_downloadMetaModelXml.java b/core/applib/src/main/java/org/apache/isis/applib/services/metamodel/Object_downloadMetaModelXml.java
new file mode 100644
index 0000000..db1144f
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/metamodel/Object_downloadMetaModelXml.java
@@ -0,0 +1,103 @@
+/**
+ *  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.metamodel;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Objects;
+
+import javax.inject.Inject;
+
+import org.apache.isis.applib.annotation.Action;
+import org.apache.isis.applib.annotation.ActionLayout;
+import org.apache.isis.applib.annotation.Contributed;
+import org.apache.isis.applib.annotation.MemberOrder;
+import org.apache.isis.applib.annotation.Mixin;
+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.services.jaxb.JaxbService;
+import org.apache.isis.applib.services.layout.LayoutService;
+import org.apache.isis.applib.value.Clob;
+import org.apache.isis.schema.metamodel.v1.DomainClassDto;
+import org.apache.isis.schema.metamodel.v1.MetamodelDto;
+
+@Mixin(method="act")
+public class Object_downloadMetaModelXml {
+
+    private final Object object;
+
+    public Object_downloadMetaModelXml(final Object object) {
+        this.object = object;
+    }
+
+    public static class ActionDomainEvent extends org.apache.isis.applib.IsisApplibModule.ActionDomainEvent<Object_downloadMetaModelXml> {}
+
+    @Action(
+            domainEvent = ActionDomainEvent.class,
+            semantics = SemanticsOf.SAFE,
+            restrictTo = RestrictTo.PROTOTYPING
+    )
+    @ActionLayout(
+            contributed = Contributed.AS_ACTION,
+            cssClassFa = "fa-download",
+            position = ActionLayout.Position.PANEL_DROPDOWN
+    )
+    @MemberOrder(name = "datanucleusIdLong", sequence = "700.2")
+    public Object act(
+            @ParameterLayout(named = "File name")
+            final String fileName) {
+
+        MetaModelService6.Config config =
+                new MetaModelService6.Config()
+                        .withIgnoreNoop()
+                        .withIgnoreAbstractClasses()
+                        .withIgnoreInterfaces()
+                        .withIgnoreBuiltInValueTypes();
+        final String pkg = object.getClass().getPackage().getName();
+        config = config.withPackagePrefix(pkg);
+        final MetamodelDto metamodelDto = metaModelService.exportMetaModel(config);
+
+        final List<DomainClassDto> domainClassDtos = metamodelDto.getDomainClassDto();
+
+        final String className = object.getClass().getName();
+        for (Iterator<DomainClassDto> iterator = domainClassDtos.iterator(); iterator.hasNext(); ) {
+            final DomainClassDto classDto = iterator.next();
+            final String id = classDto.getId();
+            if(!Objects.equals(id, className)) {
+                iterator.remove();
+            }
+        }
+        final String asXml = jaxbService.toXml(metamodelDto);
+
+        return new Clob(
+                Util.withSuffix(fileName, "xml"),
+                metaModelServicesMenu.mimeTypeTextXml, asXml);
+    }
+
+    public String default0Act() {
+        return Util.withSuffix(object.getClass().getSimpleName(), "xml");
+    }
+
+
+    @javax.inject.Inject
+    MetaModelService6 metaModelService;
+    @Inject
+    JaxbService jaxbService;
+    @Inject
+    MetaModelServicesMenu metaModelServicesMenu;
+}
diff --git a/example/application/simpleapp/application/src/main/java/domainapp/application/services/homepage/HomePageViewModel.layout.xml b/example/application/simpleapp/application/src/main/java/domainapp/application/services/homepage/HomePageViewModel.layout.xml
index 6f6aa72..eb49936 100644
--- a/example/application/simpleapp/application/src/main/java/domainapp/application/services/homepage/HomePageViewModel.layout.xml
+++ b/example/application/simpleapp/application/src/main/java/domainapp/application/services/homepage/HomePageViewModel.layout.xml
@@ -27,6 +27,7 @@
                     <action id="clearHints" hidden="EVERYWHERE"/>
                     <action id="downloadLayoutXml" hidden="EVERYWHERE"/>
                     <action id="rebuildMetamodel" hidden="EVERYWHERE"/>
+                    <action id="downloadMetaModelXml" hidden="EVERYWHERE"/>
                     <action id="openRestApi" hidden="EVERYWHERE"/>
                 </bs3:col>
             </bs3:row>