This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch maint-1.16.1
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 655dd28110f9e7dfbbc86767d8c97bea5f31660e
Author: Dan Haywood <d...@haywood-associates.co.uk>
AuthorDate: Mon Feb 12 17:36:38 2018 +0000

    ISIS-1585: fixes for mixins, and not honouring associateWith
    
    The logic to set up choices for action parameters was not (!) in fact 
filtering on the associated with collections, resulting in ChoicesFacet being 
installed where it shouldna been.
    And, for choices installed on a mixin action, need to disambiguate the 
target.
    
    Also:
    - metamodel validation error resulting in non-@Programmatic public methods 
in SpecificationLoader (now made @Programmatic).
---
 ...llectionParameterDefaultsAndChoicesPostProcessor.java |  8 +++++++-
 ...ctionParameterChoicesFacetFromParentedCollection.java | 16 +++++++++++++++-
 .../core/metamodel/specloader/SpecificationLoader.java   |  2 ++
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git 
a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/postprocessors/param/ActionCollectionParameterDefaultsAndChoicesPostProcessor.java
 
b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/postprocessors/param/ActionCollectionParameterDefaultsAndChoicesPostProcessor.java
index a3d1c20..75e177c 100644
--- 
a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/postprocessors/param/ActionCollectionParameterDefaultsAndChoicesPostProcessor.java
+++ 
b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/postprocessors/param/ActionCollectionParameterDefaultsAndChoicesPostProcessor.java
@@ -71,6 +71,8 @@ public class 
ActionCollectionParameterDefaultsAndChoicesPostProcessor implements
         // for each collection, ...
         for (final OneToManyAssociation otma : oneToManyAssociations) {
 
+            final String collectionId = otma.getId();
+
             // ... see if any of its actions has a collection parameter of the 
same type
             //
             // eg Order#getItems() and Order#removeItems(List<OrderItem>)
@@ -80,7 +82,11 @@ public class 
ActionCollectionParameterDefaultsAndChoicesPostProcessor implements
             final ObjectActionParameter.Predicates.CollectionParameter 
whetherCollectionParamOfType =
                     new 
ObjectActionParameter.Predicates.CollectionParameter(specification);
 
-            for (final ObjectAction action : objectActions) {
+            final ImmutableList<ObjectAction> actions = 
FluentIterable.from(objectActions)
+                    
.filter(ObjectAction.Predicates.associatedWith(collectionId))
+                    .toList();
+
+            for (final ObjectAction action : actions) {
 
                 final List<ObjectActionParameter> parameters = 
action.getParameters();
 
diff --git 
a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/postprocessors/param/ActionParameterChoicesFacetFromParentedCollection.java
 
b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/postprocessors/param/ActionParameterChoicesFacetFromParentedCollection.java
index 3515f67..b89be1e 100644
--- 
a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/postprocessors/param/ActionParameterChoicesFacetFromParentedCollection.java
+++ 
b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/postprocessors/param/ActionParameterChoicesFacetFromParentedCollection.java
@@ -28,6 +28,7 @@ import 
org.apache.isis.core.metamodel.consent.InteractionInitiatedBy;
 import org.apache.isis.core.metamodel.deployment.DeploymentCategory;
 import org.apache.isis.core.metamodel.facetapi.FacetHolder;
 import 
org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
+import org.apache.isis.core.metamodel.facets.object.mixin.MixinFacet;
 import 
org.apache.isis.core.metamodel.facets.param.choices.ActionParameterChoicesFacetAbstract;
 import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
 import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
@@ -52,9 +53,22 @@ public class 
ActionParameterChoicesFacetFromParentedCollection extends ActionPar
             final ObjectAdapter target,
             final List<ObjectAdapter> arguments,
             final InteractionInitiatedBy interactionInitiatedBy) {
-        final ObjectAdapter objectAdapter = otma.get(target, 
interactionInitiatedBy);
+        final ObjectAdapter parentAdapter = determineParentAdapter(target);
+        final ObjectAdapter objectAdapter = otma.get(parentAdapter, 
interactionInitiatedBy);
         final List<ObjectAdapter> objectAdapters = 
CollectionFacet.Utils.convertToAdapterList(objectAdapter);
         return ObjectAdapter.Util.unwrap(objectAdapters.toArray(new 
ObjectAdapter[0]));
     }
 
+    /**
+     * in the case of a mixin action, the target passed to the facet is 
actually the mixin itself, not the mixee.
+     */
+    private ObjectAdapter determineParentAdapter(final ObjectAdapter target) {
+        final MixinFacet mixinFacet = 
target.getSpecification().getFacet(MixinFacet.class);
+        ObjectAdapter mixedInTarget = null;
+        if(mixinFacet != null) {
+            mixedInTarget = mixinFacet.mixedIn(target, 
MixinFacet.Policy.FAIL_FAST);
+        }
+        return mixedInTarget != null ? mixedInTarget : target;
+    }
+
 }
diff --git 
a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/SpecificationLoader.java
 
b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/SpecificationLoader.java
index df881cb..ca81150 100644
--- 
a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/SpecificationLoader.java
+++ 
b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/SpecificationLoader.java
@@ -463,6 +463,7 @@ public class SpecificationLoader implements 
ApplicationScopedComponent {
         
specSpi.setIntrospectionState(ObjectSpecificationAbstract.IntrospectionState.INTROSPECTED);
     }
 
+    @Programmatic
     public void postProcess() {
 
         final Collection<ObjectSpecification> specs = allSpecifications();
@@ -472,6 +473,7 @@ public class SpecificationLoader implements 
ApplicationScopedComponent {
 
     }
 
+    @Programmatic
     public void postProcess(final ObjectSpecification spec) {
         postProcessor.postProcess(spec);
     }

-- 
To stop receiving notification emails like this one, please contact
danhayw...@apache.org.

Reply via email to