You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2021/05/14 19:23:41 UTC
[isis] branch master updated: ISIS-2661: use LayoutGroup-Id (not
name) and also case sensitive, when mapping actions to associations
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new ffc0d9f ISIS-2661: use LayoutGroup-Id (not name) and also case sensitive, when mapping actions to associations
ffc0d9f is described below
commit ffc0d9fb197615c39a84ba438f6c5753568f6167
Author: ahuber@apache.org <ah...@luna>
AuthorDate: Fri May 14 21:23:28 2021 +0200
ISIS-2661: use LayoutGroup-Id (not name) and also case sensitive, when
mapping actions to associations
---
.../core/metamodel/spec/feature/ObjectAction.java | 73 +++++++++++-----------
1 file changed, 37 insertions(+), 36 deletions(-)
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/feature/ObjectAction.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/feature/ObjectAction.java
index de1a389..7d33613 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/feature/ObjectAction.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/feature/ObjectAction.java
@@ -17,10 +17,12 @@
package org.apache.isis.core.metamodel.spec.feature;
+import java.util.HashSet;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
@@ -35,7 +37,6 @@ import org.apache.isis.applib.value.Clob;
import org.apache.isis.commons.collections.Can;
import org.apache.isis.commons.collections.CanVector;
import org.apache.isis.commons.internal.base._Strings;
-import org.apache.isis.commons.internal.collections._Sets;
import org.apache.isis.core.metamodel.consent.Consent;
import org.apache.isis.core.metamodel.consent.InteractionInitiatedBy;
import org.apache.isis.core.metamodel.consent.InteractionResultSet;
@@ -349,10 +350,12 @@ public interface ObjectAction extends ObjectMember {
val spec = adapter.getSpecification();
return spec.streamRuntimeActions(MixedIn.INCLUDED)
- .filter(ObjectAction.Predicates.isNotInAnyExistingLayoutGroup(spec))
- .filter(ObjectAction.Predicates.dynamicallyVisible(adapter,
- InteractionInitiatedBy.USER, Where.ANYWHERE))
- .filter(ObjectAction.Predicates.isNotWizard(spec));
+ .filter(Predicates
+ .isSharingAnyLayoutGroupOf(spec.streamAssociations(MixedIn.INCLUDED))
+ .negate())
+ .filter(Predicates
+ .dynamicallyVisible(adapter, InteractionInitiatedBy.USER, Where.ANYWHERE))
+ .filter(Predicates.isNotWizard(spec));
}
public static Stream<ObjectAction> findForAssociation(
@@ -362,8 +365,8 @@ public interface ObjectAction extends ObjectMember {
val spec = adapter.getSpecification();
return spec.streamRuntimeActions(MixedIn.INCLUDED)
- .filter(ObjectAction.Predicates.isSameLayoutGroupAs(association))
- .filter(ObjectAction.Predicates.isNotWizard(spec))
+ .filter(Predicates.isSameLayoutGroupAs(association))
+ .filter(Predicates.isNotWizard(spec))
.sorted(Comparators.byMemberOrderSequence(false));
}
@@ -406,9 +409,11 @@ public interface ObjectAction extends ObjectMember {
return (ObjectAction oa) -> oa.getType() == type;
}
- public static Predicate<ObjectAction> isSameLayoutGroupAs(ObjectAssociation association) {
- final String assocName = association.getName();
- final String assocId = association.getId();
+ public static Predicate<ObjectAction> isSameLayoutGroupAs(
+ final @NonNull ObjectAssociation association) {
+
+ final String assocIdLower = association.getId();
+
return (ObjectAction objectAction) -> {
val layoutGroupFacet = objectAction.getFacet(LayoutGroupFacet.class);
@@ -419,48 +424,44 @@ public interface ObjectAction extends ObjectMember {
if (_Strings.isNullOrEmpty(layoutGroupId)) {
return false;
}
- return layoutGroupId.equalsIgnoreCase(assocName)
- || layoutGroupId.equalsIgnoreCase(assocId);
+ return layoutGroupId.equals(assocIdLower);
};
}
- public static Predicate<ObjectAction> choicesFromAndHavingCollectionParameterFor(
- final OneToManyAssociation collection) {
-
- final ObjectSpecification collectionTypeOfSpec = collection.getSpecification();
-
- return new ChoicesFrom(collection)
- .and(new HasParameterMatching(
- new ObjectActionParameter.Predicates.CollectionParameter(collectionTypeOfSpec)
- ));
- }
-
- // -- HELPER
-
- private static Predicate<ObjectAction> isNotInAnyExistingLayoutGroup(final ObjectSpecification spec) {
+ private static Predicate<? super ObjectAction> isSharingAnyLayoutGroupOf(
+ final @NonNull Stream<ObjectAssociation> streamOfAssociations) {
- final Set<String> associationNamesAndIds = _Sets.newHashSet();
-
- spec.streamAssociations(MixedIn.INCLUDED)
- .forEach(ass->{
- associationNamesAndIds.add(_Strings.lower(ass.getName()));
- associationNamesAndIds.add(_Strings.lower(ass.getId()));
- });
+ final Set<String> associationIds = streamOfAssociations
+ .map(ObjectAssociation::getId)
+ .collect(Collectors.toCollection(HashSet::new));
return (ObjectAction objectAction) -> {
val layoutGroupFacet = objectAction.getFacet(LayoutGroupFacet.class);
if (layoutGroupFacet == null) {
- return true;
+ return false;
}
val layoutGroupId = layoutGroupFacet.getGroupId();
if (_Strings.isNullOrEmpty(layoutGroupId)) {
- return true;
+ return false;
}
- return !associationNamesAndIds.contains(layoutGroupId.toLowerCase());
+ return associationIds.contains(layoutGroupId);
};
}
+ public static Predicate<ObjectAction> choicesFromAndHavingCollectionParameterFor(
+ final @NonNull OneToManyAssociation collection) {
+
+ final ObjectSpecification collectionTypeOfSpec = collection.getSpecification();
+
+ return new ChoicesFrom(collection)
+ .and(new HasParameterMatching(
+ new ObjectActionParameter.Predicates.CollectionParameter(collectionTypeOfSpec)
+ ));
+ }
+
+ // -- HELPER
+
private static class ChoicesFrom implements Predicate<ObjectAction> {
private final @NonNull String memberId;
private final @NonNull String memberName;