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

commit 7bf1199d587a2a10049c06c9676e70ba9aded890
Author: danhaywood <d...@haywood-associates.co.uk>
AuthorDate: Tue Dec 3 14:43:32 2019 +0000

    ISIS-2204: fixes algorithm, was allowing create(...) returning an entity as 
being visible while list(): List<Entity> was not.
---
 .../metamodel/services/swagger/internal/Util.java  | 42 +++++++++++++---------
 1 file changed, 25 insertions(+), 17 deletions(-)

diff --git 
a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/Util.java
 
b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/Util.java
index 4f1c460..1f77574 100644
--- 
a/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/Util.java
+++ 
b/core/metamodel/src/main/java/org/apache/isis/metamodel/services/swagger/internal/Util.java
@@ -42,25 +42,29 @@ public final class Util {
     private Util(){}
 
     static boolean isVisibleForPublic(final ObjectAction objectAction) {
+
         final ObjectSpecification specification = objectAction.getReturnType();
-        boolean visible = isVisibleForPublic(specification);
-        if(!visible) {
-            final TypeOfFacet typeOfFacet = 
objectAction.getFacet(TypeOfFacet.class);
-            if(typeOfFacet != null) {
-                ObjectSpecification elementSpec = typeOfFacet.valueSpec();
-                if(!isVisibleForPublic(elementSpec)) {
-                    return false;
-                }
-            }
-        }
-        List<ObjectSpecification> parameterTypes = 
objectAction.getParameterTypes();
-        for (ObjectSpecification parameterType : parameterTypes) {
-            boolean paramVisible = isVisibleForPublic(parameterType);
-            if(!paramVisible) {
-                return false;
-            }
+        return ( isVisibleForPublic(specification) || 
isTypeOfVisibleForPublic(objectAction) )
+                && isVisibleForPublic(objectAction.getParameterTypes());
+    }
+
+    private static boolean isTypeOfVisibleForPublic(ObjectAction objectAction) 
{
+        final TypeOfFacet typeOfFacet = 
objectAction.getFacet(TypeOfFacet.class);
+        if (typeOfFacet == null) {
+            return false;
         }
-        return true;
+        return isVisibleForPublic(typeOfFacet.valueSpec());
+    }
+
+    private static boolean isVisibleForPublic(List<ObjectSpecification> 
parameterTypes) {
+
+        final boolean atLeastOneParamNotVisible =
+                parameterTypes.stream()
+                    .map(Util::isNotVisibleForPublic)
+                    .findAny()
+                    .isPresent();
+
+        return !atLeastOneParamNotVisible;
     }
 
     static boolean isVisibleForPublic(final ObjectAssociation 
objectAssociation) {
@@ -68,6 +72,10 @@ public final class Util {
         return isVisibleForPublic(specification);
     }
 
+    static boolean isNotVisibleForPublic(final ObjectSpecification 
specification) {
+        return ! isVisibleForPublic(specification);
+    }
+
     static boolean isVisibleForPublic(final ObjectSpecification specification) 
{
         if (specification == null) {
             return true;

Reply via email to