andi-huber commented on code in PR #3426:
URL: https://github.com/apache/causeway/pull/3426#discussion_r2874102869
##########
core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facetapi/FacetRanking.java:
##########
@@ -130,24 +131,45 @@ public void addAll(final @NonNull FacetRanking
facetRanking) {
* based on whether there was any added that has given facetType.
* @param facetType - for convenience, so the caller does not need to cast
the result
*/
- public <F extends Facet> Optional<F> getWinner(final @NonNull Class<F>
facetType) {
+ public <F extends Facet> Optional<F> getWinner(
+ final @NonNull Class<F> facetType,
+ final @Nullable String qualifier) {
var eventFacet = getEventFacet(facetType);
- if(eventFacet.isPresent()) {
+ if(eventFacet.isPresent())
return eventFacet;
- }
- return getWinnerNonEvent(facetType);
+ return getWinnerNonEvent(facetType, qualifier);
}
/**
* Optionally returns the winning facet, considering the top rank,
* based on whether there was any added that has given facetType.
* @param facetType - for convenience, so the caller does not need to cast
the result
*/
- public <F extends Facet> Optional<F> getWinnerNonEvent(final @NonNull
Class<F> facetType) {
+ public <F extends Facet> Optional<F> getWinnerNonEvent(
+ final @NonNull Class<F> facetType,
+ final @Nullable String qualifier) {
var topRank = getTopRank(facetType);
- // TODO find winner if there are more than one
- // (also report conflicting semantics) - only historically the last
one wins
- return topRank.getLast();
+ // all matching QualifiedFacet(s) take precedence
+ // all non-matching QualifiedFacet(s) must be ignored
+ // historically (initial design) the last one wins
+
+ F bestSoFar = null;
+
+ for(var facet : topRank) {
+ if(facet instanceof QualifiedFacet qFacet) {
+ if(Objects.equals(qualifier, qFacet.qualifier()))
+ return Optional.of(facet);
+ else {
+ continue;
+ }
+ }
+ bestSoFar = facet;
+ }
+
+ //FIXME if bestSoFar == null, then we have to go to the next lower
rank;
+ //FIXME the getTopRank(facetType) logic is broken, because it depends
now on context
Review Comment:
Technical challenge: finding the top rank now depends on context
(`qualifier`); (`getTopRank(..)`)
--
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]