andi-huber commented on code in PR #1887:
URL: https://github.com/apache/causeway/pull/1887#discussion_r1333604259
##########
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:
Perhaps this needs to be flipped to make more sense:
`assoc.getElementType().isOfType(parentSpec)`
In other words, the match is successful, if the parent type is assignable
from the property type. (Not the other way around.)
(I know not a change this PR introduced, as this is just copy pasted code.)
--
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]