danhaywood commented on code in PR #1887:
URL: https://github.com/apache/causeway/pull/1887#discussion_r1333673675
##########
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:
As you noticed, I did just refactor the code, but yes, there's a ticket I
raised recently regarding the fact that REFERENCES_PARENT doesn't seem to be
honoured.
Actually I think the correct formulation may be
assoc.getReturnType().isOfType(parentSpec), because the assoc in question is of
the elements of the collection, and we want to exclude those that point back to
(have a return type of) the parent owning the collection.
--
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]