ISIS-993: ensure that actions associated to properties/collections/fieldsets are added in the correct order when normalizing grid.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/e417a8ab Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/e417a8ab Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/e417a8ab Branch: refs/heads/master Commit: e417a8ab5984393394113066a7ad1ea8379bcab2 Parents: e014bf8 Author: Dan Haywood <d...@haywood-associates.co.uk> Authored: Mon Feb 29 11:10:50 2016 +0000 Committer: Dan Haywood <d...@haywood-associates.co.uk> Committed: Mon Feb 29 11:13:43 2016 +0000 ---------------------------------------------------------------------- .../bootstrap3/GridNormalizerServiceBS3.java | 31 ++++++++++++++++---- .../spec/feature/ObjectAssociation.java | 4 +++ .../metamodel/spec/feature/ObjectMember.java | 24 +++++++++++++++ .../specimpl/ObjectSpecificationAbstract.java | 3 +- 4 files changed, 55 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/isis/blob/e417a8ab/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/grid/bootstrap3/GridNormalizerServiceBS3.java ---------------------------------------------------------------------- diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/grid/bootstrap3/GridNormalizerServiceBS3.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/grid/bootstrap3/GridNormalizerServiceBS3.java index c57212a..0f7fa85 100644 --- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/grid/bootstrap3/GridNormalizerServiceBS3.java +++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/grid/bootstrap3/GridNormalizerServiceBS3.java @@ -62,6 +62,7 @@ import org.apache.isis.core.metamodel.spec.ObjectSpecification; import org.apache.isis.core.metamodel.spec.feature.Contributed; import org.apache.isis.core.metamodel.spec.feature.ObjectAction; import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation; +import org.apache.isis.core.metamodel.spec.feature.ObjectMember; import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation; import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation; @@ -423,7 +424,7 @@ public class GridNormalizerServiceBS3 extends GridNormalizerServiceAbstract<BS3G return oneToManyAssociationById.get(collectionId); } }) - .toSortedList(ObjectAssociation.Comparators.byMemberOrderSequence()) + .toSortedList(ObjectMember.Comparators.byMemberOrderSequence()) ); final ImmutableList<String> sortedMissingCollectionIds = FluentIterable.from(sortedCollections) @@ -447,7 +448,21 @@ public class GridNormalizerServiceBS3 extends GridNormalizerServiceAbstract<BS3G final List<String> associatedActionIds = Lists.newArrayList(); - FluentIterable.from(possiblyMissingActionIds) + List<ObjectAction> sortedPossiblyMissingActions = Lists.newArrayList( + FluentIterable.from(possiblyMissingActionIds) + .transform(new Function<String, ObjectAction>() { + @Nullable @Override public ObjectAction apply(@Nullable final String actionId) { + return objectActionById.get(actionId); + } + }) + .toSortedList(ObjectMember.Comparators.byMemberOrderSequence())); + + List<String> sortedPossiblyMissingActionIds = + FluentIterable.from(sortedPossiblyMissingActions) + .transform(ObjectMember.Functions.getId()) + .toList(); + + FluentIterable.from(sortedPossiblyMissingActionIds) .forEach( new Consumer<String>() { @Override @@ -523,7 +538,7 @@ public class GridNormalizerServiceBS3 extends GridNormalizerServiceAbstract<BS3G // ... the missing actions are those in the second tuple, excluding those associated (via @MemberOrder#name) // to a property or collection. - final List<String> missingActionIds = Lists.newArrayList(possiblyMissingActionIds); + final List<String> missingActionIds = Lists.newArrayList(sortedPossiblyMissingActionIds); missingActionIds.removeAll(associatedActionIds); for (String surplusActionId : surplusActionIds) { @@ -533,7 +548,7 @@ public class GridNormalizerServiceBS3 extends GridNormalizerServiceAbstract<BS3G if(!missingActionIds.isEmpty()) { final BS3Col bs3Col = colForUnreferencedActionsRef.get(); if(bs3Col != null) { - addActionsTo(bs3Col, missingActionIds); + addActionsTo(bs3Col, missingActionIds, actionLayoutDataById); } else { final FieldSet fieldSet = fieldSetForUnreferencedActionsRef.get(); if(fieldSet != null) { @@ -587,14 +602,18 @@ public class GridNormalizerServiceBS3 extends GridNormalizerServiceAbstract<BS3G protected void addActionsTo( final BS3Col bs3Col, - final List<String> actionIds) { + final List<String> actionIds, + final LinkedHashMap<String, ActionLayoutData> actionLayoutDataById) { for (String actionId : actionIds) { List<ActionLayoutData> actions = bs3Col.getActions(); if(actions == null) { actions = Lists.newArrayList(); bs3Col.setActions(actions); } - actions.add(new ActionLayoutData(actionId)); + final ActionLayoutData actionLayoutData = new ActionLayoutData(actionId); + actions.add(actionLayoutData); + actionLayoutDataById.put(actionId, actionLayoutData); + actionLayoutData.setOwner(bs3Col); } } http://git-wip-us.apache.org/repos/asf/isis/blob/e417a8ab/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/feature/ObjectAssociation.java ---------------------------------------------------------------------- diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/feature/ObjectAssociation.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/feature/ObjectAssociation.java index ae31903..922144b 100644 --- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/feature/ObjectAssociation.java +++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/feature/ObjectAssociation.java @@ -410,6 +410,10 @@ public interface ObjectAssociation extends ObjectMember, CurrentHolder { // ////////////////////////////////////////////////////// public static class Comparators { + /** + * Use {@link ObjectMember.Comparators#byMemberOrderSequence()} instead. + */ + @Deprecated public static Comparator<ObjectAssociation> byMemberOrderSequence() { return new Comparator<ObjectAssociation>() { private final DeweyOrderComparator deweyOrderComparator = new DeweyOrderComparator(); http://git-wip-us.apache.org/repos/asf/isis/blob/e417a8ab/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/feature/ObjectMember.java ---------------------------------------------------------------------- diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/feature/ObjectMember.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/feature/ObjectMember.java index 9d8fa15..147cc61 100644 --- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/feature/ObjectMember.java +++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/feature/ObjectMember.java @@ -19,6 +19,7 @@ package org.apache.isis.core.metamodel.spec.feature; +import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -33,6 +34,8 @@ import org.apache.isis.core.metamodel.adapter.ObjectAdapter; import org.apache.isis.core.metamodel.consent.Consent; import org.apache.isis.core.metamodel.consent.InteractionInitiatedBy; import org.apache.isis.core.metamodel.facets.all.hide.HiddenFacet; +import org.apache.isis.core.metamodel.facets.members.order.MemberOrderFacet; +import org.apache.isis.core.metamodel.util.DeweyOrderComparator; /** * Provides reflective access to an action or a field on a domain object. @@ -185,4 +188,25 @@ public interface ObjectMember extends ObjectFeature { } } + // ////////////////////////////////////////////////////// + // Comparators + // ////////////////////////////////////////////////////// + + public static class Comparators { + public static Comparator<ObjectMember> byMemberOrderSequence() { + return new Comparator<ObjectMember>() { + private final DeweyOrderComparator deweyOrderComparator = new DeweyOrderComparator(); + @Override + public int compare(final ObjectMember o1, final ObjectMember o2) { + final MemberOrderFacet o1Facet = o1.getFacet(MemberOrderFacet.class); + final MemberOrderFacet o2Facet = o2.getFacet(MemberOrderFacet.class); + return o1Facet == null? +1: + o2Facet == null? -1: + deweyOrderComparator.compare(o1Facet.sequence(), o2Facet.sequence()); + } + }; + } + + } + } http://git-wip-us.apache.org/repos/asf/isis/blob/e417a8ab/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectSpecificationAbstract.java ---------------------------------------------------------------------- diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectSpecificationAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectSpecificationAbstract.java index 708e700..68eaf9b 100644 --- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectSpecificationAbstract.java +++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectSpecificationAbstract.java @@ -95,6 +95,7 @@ import org.apache.isis.core.metamodel.spec.feature.Contributed; import org.apache.isis.core.metamodel.spec.feature.ObjectAction; import org.apache.isis.core.metamodel.spec.feature.ObjectActionParameter; import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation; +import org.apache.isis.core.metamodel.spec.feature.ObjectMember; import org.apache.isis.core.metamodel.spec.feature.ObjectMemberDependencies; import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation; import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation; @@ -712,7 +713,7 @@ public abstract class ObjectSpecificationAbstract extends FacetHolderImpl implem return Lists.newArrayList( FluentIterable.from(allAssociations) .filter(Filters.asPredicate(filter)) - .toSortedList(ObjectAssociation.Comparators.byMemberOrderSequence()) + .toSortedList(ObjectMember.Comparators.byMemberOrderSequence()) ); }