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 2019/09/21 09:00:52 UTC

[isis] branch v2 updated (59b018b -> d5c76d9)

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

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


 discard 59b018b  ISIS-2158: NatureOfService: resurrect former enum options
     new d5c76d9  ISIS-2158: NatureOfService: resurrect former enum options

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (59b018b)
            \
             N -- N -- N   refs/heads/v2 (d5c76d9)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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.


Summary of changes:
 .../isis/applib/annotation/NatureOfService.java       | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)


[isis] 01/01: ISIS-2158: NatureOfService: resurrect former enum options

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

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

commit d5c76d9cdbcf390803ecdd46b1f615aae96dfd49
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sat Sep 21 10:59:46 2019 +0200

    ISIS-2158: NatureOfService: resurrect former enum options
    
    - in order to ease domain code migration (from 1.x to 2.x)
    - also providing more precise specifications with associated java-doc
---
 .../isis/applib/annotation/NatureOfService.java    | 98 ++++++++++++++++------
 .../actions/layout/ActionLayoutFacetFactory.java   |  2 +-
 .../services/swagger/internal/Generation.java      | 27 +++---
 .../menubars/bootstrap3/MenuBarsServiceBS3.java    |  3 +-
 .../resources/DomainServiceResourceServerside.java | 10 +--
 .../isis/testdomain/jdo/InventoryResource.java     |  2 +-
 6 files changed, 95 insertions(+), 47 deletions(-)

diff --git a/core/applib/src/main/java/org/apache/isis/applib/annotation/NatureOfService.java b/core/applib/src/main/java/org/apache/isis/applib/annotation/NatureOfService.java
index 5d9794a..5ec926e 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/annotation/NatureOfService.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/annotation/NatureOfService.java
@@ -21,56 +21,104 @@ package org.apache.isis.applib.annotation;
 /**
  * The different sorts of domain services recognized by Isis, as specified in {@link DomainService#nature()}
  * 
- * <p>
- * Deprecation Notes (1.x):
- * <ul>
- * <li>instead of {@code VIEW_MENU_ONLY} use {@code VIEW}</li> 
- * <li>instead of {@code VIEW_CONTRIBUTIONS_ONLY} use Mixins</li>
- * </ul>
- * 
+ * @apiNote
+ * [EXPERIMENTAL]
+ * Any service might also act as a stateless <em>Viewmodel</em>, eg. when used as return type of 
+ * an <em>Action</em>. 
+ * It's not well defined, what a viewer will render in such cases.
  */
 public enum NatureOfService {
 
     /**
-     * The service's actions appear in the viewer, for example in the menu bar.
+     * The service's actions appear in the REST API and in 'viewers', eg. in the menu bar.
+     * 
+     * @apiNote
+     * Contributing actions to the 'viewer' implies, that these must also be exposed to the REST API,
+     * simply because alternative viewers might be solely based on the provided REST end-points.  
      */
     VIEW,
 
     /**
-     * The services actions should only be visible in the REST API exposed by the Restful Objects viewer.
+     * The service's actions should only be visible in the REST API exposed by the Restful Objects viewer.
      */
-    VIEW_REST_ONLY,
-
+    REST,
+    
     /**
-     * The service's actions do not appear on menus and are not contributed.
+     * A <em>programmatic</em> service.
+     * <p>
+     * The service's actions do not appear on any viewer and are not visible in the REST API. In other words 
+     * these are not contributed to the domain-model. However, the service is injectable into domain objects.  
+     * </p>
      */
     DOMAIN,
+    
+    // -- DEPRECATIONS
+    
+    /**
+     * @deprecated was renamed, use {@link #REST} instead
+     * @apiNote since 2.0 used as synonym for {@link #REST} 
+     */
+    @Deprecated
+    VIEW_REST_ONLY,
+    
+    /**
+     * @deprecated was removed, use {@link #VIEW} instead
+     * @apiNote since 2.0 used as synonym for {@link #VIEW}
+     */
+    @Deprecated
+    VIEW_MENU_ONLY,
+    
+    /**
+     * @deprecated was removed, contributing actions are simply ignored
+     * <p>
+     * Instead, for each {@code Action} write a mixin class. 
+     * see {@link Mixin}
+     * @apiNote since 2.0 used as synonym for {@link #DOMAIN}
+     */
+    @Deprecated
+    VIEW_CONTRIBUTIONS_ONLY,
 
     ;
 
     // -- BASIC PREDICATES
 
-    public boolean isViewRestOnly() {
-        return this == VIEW_REST_ONLY;
-    }
-
+    /**
+     * @see {@link NatureOfService#VIEW}
+     */
     public boolean isView() {
-        return this == VIEW;
+        return this == VIEW || this == VIEW_MENU_ONLY;
     }
-
+    
+    /**
+     * Whether a service contributes its actions exclusively to the REST API.
+     * @see {@link NatureOfService#REST}
+     */
+    public boolean isRestOnly() {
+        return this == REST || this == VIEW_REST_ONLY;
+    }
+    
+    /**
+     * @see {@link NatureOfService#DOMAIN}
+     */
     public boolean isDomain() {
-        return this == DOMAIN;
+        return this == DOMAIN || this == VIEW_CONTRIBUTIONS_ONLY;
     }
 
-    // -- ADVANCED PREDICATES
+    // -- SEMANTIC PREDICATES
+
+    /**
+     * Whether a service contributes its actions (not necessarily exclusive) to the REST API.
+     */
+    public boolean isRestAlso() {
+        return isRestOnly() || isView();
+    }
 
     /**
-     * @implNote introduced as a refactoring step, should be removed if no longer required
+     * Whether a service contributes no actions at all.
      */
-    public boolean isContributingToViewer() {
-        return
-                //this != NatureOfService.VIEW_MENU_ONLY &&
-                this != NatureOfService.DOMAIN;
+    public boolean isProgrammatic() {
+        return isDomain();
     }
 
+
 }
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/actions/layout/ActionLayoutFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/actions/layout/ActionLayoutFacetFactory.java
index 869adaa..278b068 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/actions/layout/ActionLayoutFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/actions/layout/ActionLayoutFacetFactory.java
@@ -129,7 +129,7 @@ public class ActionLayoutFacetFactory extends FacetFactoryAbstract implements Co
     private static boolean isContributingService(final ObjectSpecification spec) {
         final DomainServiceFacet domainServiceFacet = spec.getFacet(DomainServiceFacet.class);
         return domainServiceFacet != null && !domainServiceFacet.isNoop() && 
-                domainServiceFacet.getNatureOfService().isContributingToViewer();
+                !domainServiceFacet.getNatureOfService().isProgrammatic();
     }
 
     private static boolean isMixinObject(final ObjectSpecification spec) {
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/Generation.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/Generation.java
index 1cf56d1..fcb4e35 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/Generation.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/Generation.java
@@ -58,6 +58,7 @@ import io.swagger.models.properties.ObjectProperty;
 import io.swagger.models.properties.Property;
 import io.swagger.models.properties.RefProperty;
 import io.swagger.models.properties.StringProperty;
+import lombok.val;
 
 class Generation {
 
@@ -127,29 +128,31 @@ class Generation {
     void appendServicePathsAndDefinitions() {
         // (previously we took a protective copy to avoid a concurrent modification exception,
         // but this is now done by SpecificationLoader itself)
-        for (final ObjectSpecification objectSpec : specificationLoader.currentSpecifications()) {
+        for (val spec : specificationLoader.currentSpecifications()) {
 
-            final DomainServiceFacet domainServiceFacet = objectSpec.getFacet(DomainServiceFacet.class);
+            val domainServiceFacet = spec.getFacet(DomainServiceFacet.class);
             if (domainServiceFacet == null) {
                 continue;
             }
-            if (visibility.isPublic() &&
-                    domainServiceFacet.getNatureOfService() != NatureOfService.VIEW_REST_ONLY) {
-                continue;
+            val natureOfService = domainServiceFacet.getNatureOfService();
+            
+            if (natureOfService.isProgrammatic()) {
+                continue; // ignore programmatic services
             }
-            if (    domainServiceFacet.getNatureOfService() != NatureOfService.VIEW &&
-                    domainServiceFacet.getNatureOfService() != NatureOfService.VIEW_REST_ONLY) {
-                continue;
+            
+            if (visibility.isPublic() && !natureOfService.isRestAlso()) {
+                continue; // ignore services that don't publicly contribute to rest
             }
 
-            final List<ObjectAction> serviceActions = Util.actionsOf(objectSpec, visibility, classExcluder);
+            val serviceActions = Util.actionsOf(spec, visibility, classExcluder);
             if(serviceActions.isEmpty()) {
                 continue;
             }
-            appendServicePath(objectSpec);
+            
+            appendServicePath(spec);
 
-            for (final ObjectAction serviceAction : serviceActions) {
-                appendServiceActionInvokePath(objectSpec, serviceAction);
+            for (val serviceAction : serviceActions) {
+                appendServiceActionInvokePath(spec, serviceAction);
             }
         }
     }
diff --git a/core/runtime-services/src/main/java/org/apache/isis/runtime/services/menubars/bootstrap3/MenuBarsServiceBS3.java b/core/runtime-services/src/main/java/org/apache/isis/runtime/services/menubars/bootstrap3/MenuBarsServiceBS3.java
index c881a12..0065192 100644
--- a/core/runtime-services/src/main/java/org/apache/isis/runtime/services/menubars/bootstrap3/MenuBarsServiceBS3.java
+++ b/core/runtime-services/src/main/java/org/apache/isis/runtime/services/menubars/bootstrap3/MenuBarsServiceBS3.java
@@ -344,8 +344,7 @@ public class MenuBarsServiceBS3 implements MenuBarsService {
         final DomainServiceFacet domainServiceFacet = serviceSpec.getFacet(DomainServiceFacet.class);
         if (domainServiceFacet != null) {
             final NatureOfService natureOfService = domainServiceFacet.getNatureOfService();
-            if (natureOfService == NatureOfService.VIEW_REST_ONLY ||
-                    natureOfService == NatureOfService.DOMAIN) {
+            if (!natureOfService.isView()) {
                 return Stream.empty();
             }
         }
diff --git a/core/viewer-restfulobjects/server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainServiceResourceServerside.java b/core/viewer-restfulobjects/server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainServiceResourceServerside.java
index b41eb66..9c3633b 100644
--- a/core/viewer-restfulobjects/server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainServiceResourceServerside.java
+++ b/core/viewer-restfulobjects/server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainServiceResourceServerside.java
@@ -33,7 +33,6 @@ import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
-import org.apache.isis.applib.annotation.NatureOfService;
 import org.apache.isis.applib.annotation.Where;
 import org.apache.isis.applib.services.command.Command;
 import org.apache.isis.commons.internal.url.UrlDecoderUtil;
@@ -58,16 +57,15 @@ import lombok.val;
 @Path("/services")
 public class DomainServiceResourceServerside extends ResourceAbstract implements DomainServiceResource {
 
-    private final static Predicate<ObjectAdapter> NATURE_OF_MENU = (final ObjectAdapter input) -> {
+    private final static Predicate<ObjectAdapter> NATURE_REST_ALSO = (final ObjectAdapter input) -> {
         final ObjectSpecification specification = input.getSpecification();
         final DomainServiceFacet facet = specification.getFacet(DomainServiceFacet.class);
         if (facet == null) {
             // not expected, because we know these are domain services.
             return false;
         }
-        final NatureOfService natureOfService = facet.getNatureOfService();
-        return  natureOfService == NatureOfService.VIEW ||
-                natureOfService == NatureOfService.VIEW_REST_ONLY;
+        val natureOfService = facet.getNatureOfService();
+        return natureOfService.isRestAlso();
     };
 
     @Override
@@ -80,7 +78,7 @@ public class DomainServiceResourceServerside extends ResourceAbstract implements
         val metaModelContext = MetaModelContext.current();
 
         final Stream<ObjectAdapter> serviceAdapters = metaModelContext.streamServiceAdapters()
-                .filter(NATURE_OF_MENU);
+                .filter(NATURE_REST_ALSO);
 
         final DomainServicesListReprRenderer renderer = new DomainServicesListReprRenderer(getResourceContext(), null, JsonRepresentation.newMap());
         renderer.usingLinkToBuilder(new DomainServiceLinkTo())
diff --git a/examples/smoketests/src/main/java/org/apache/isis/testdomain/jdo/InventoryResource.java b/examples/smoketests/src/main/java/org/apache/isis/testdomain/jdo/InventoryResource.java
index 8e519e9..9d2ee72 100644
--- a/examples/smoketests/src/main/java/org/apache/isis/testdomain/jdo/InventoryResource.java
+++ b/examples/smoketests/src/main/java/org/apache/isis/testdomain/jdo/InventoryResource.java
@@ -35,7 +35,7 @@ import org.apache.isis.commons.internal.base._NullSafe;
 import lombok.val;
 
 @DomainService(
-        nature = NatureOfService.VIEW_REST_ONLY,
+        nature = NatureOfService.REST,
         objectType = "testdomain.InventoryResource")
 public class InventoryResource {