danhaywood commented on code in PR #1887:
URL: https://github.com/apache/causeway/pull/1887#discussion_r1333919544


##########
core/metamodel/src/main/java/org/apache/causeway/core/metamodel/spec/feature/ObjectAssociation.java:
##########
@@ -157,6 +165,43 @@ public static final Predicate<ObjectAssociation> 
staticallyVisible(final Where w
             };
         }
 
+        static Where whereContextFor(final Identifier memberIdentifier) {
+            return memberIdentifier.getType().isAction()
+                    ? STANDALONE_TABLES
+                    : PARENTED_TABLES;
+        }
+
+        /**
+         * Returns true if no {@link HiddenFacet} is found that vetoes 
visibility.
+         * <p>
+         * However, if its a 1-to-Many, whereHidden={@link Where.ALL_TABLES} 
is used as default
+         * when no {@link HiddenFacet} is found.
+         * @apiNote an alternative would be to prime the meta-model with 
fallback facets,
+         *      however the current approach is more heap friendly
+         */
+        public static Predicate<ObjectAssociation> 
visibleAccordingToHiddenFacet(
+                final Identifier memberIdentifier) {
+            val whereContext = whereContextFor(memberIdentifier);
+            return (final ObjectAssociation assoc) -> 
assoc.lookupFacet(HiddenFacet.class)
+                    .map(WhereValueFacet.class::cast)
+                    .map(WhereValueFacet::where)
+                    // in case its a 1-to-Many, whereHidden=ALL_TABLES is the 
default when not specified otherwise
+                    
.or(()->assoc.getSpecialization().right().map(__->Where.ALL_TABLES))
+                    .stream()
+                    .noneMatch(whereHidden -> 
whereHidden.includes(whereContext));
+        }
+
+        public static Predicate<ObjectAssociation> referencesParent(
+                final @Nullable ObjectSpecification parentSpec) {
+            if(parentSpec == null) {
+                return _Predicates.alwaysFalse();
+            }
+            return (final ObjectAssociation assoc) -> {
+                    if(assoc.isCollection()) return false; // never true for 
collections
+                    return 
Facets.hiddenWhereMatches(Where.REFERENCES_PARENT::equals).test(assoc)
+                            && parentSpec.isOfType(assoc.getElementType());

Review Comment:
   Thanks, my comment above was incorrect, there is no such method as 
`assoc.getReturnType()` , the `assoc.getElementType()` is the one.
   
   I think the check to return `false` for Collections is still right, 
actually.  The purpose of `REFERENCES_PARENT` is for use cases such as `Order` 
---> `OrderItem`, where the `OrderItem` refers back to its parent `Order` ; 
that's redundant information to show in the collection of items if we're 
viewing the parent `Order`.
   
   Suppose though that `OrderItem` itself had a collection of `Order`s; bit of 
an odd model, but perhaps something like pointing to previous `Order`s where 
the product being bought was also purchased.  Anyway, it wouldn't make sense to 
hide this collection of `OrderItem`, even though its elementType would be 
`Order`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to