You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2016/05/01 10:16:54 UTC

[17/35] isis git commit: ISIS-1389: extending the new Interaction (in applib) to capture args and provide a callable to be executed.

ISIS-1389: extending the new Interaction (in applib) to capture args and provide a callable to be executed.


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/01a88a6b
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/01a88a6b
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/01a88a6b

Branch: refs/heads/ISIS-1291
Commit: 01a88a6b8233afbd4ceeda203ad58ab15e9dc8b3
Parents: 32ac64e
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Sat Apr 30 06:43:59 2016 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Sat Apr 30 06:43:59 2016 +0100

----------------------------------------------------------------------
 .../isis/applib/services/iactn/Interaction.java | 137 ++++++++++++++++---
 ...onInvocationFacetForDomainEventAbstract.java |  24 ++--
 .../PropertySetterFacetViaModifyMethod.java     |  21 ++-
 3 files changed, 146 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/01a88a6b/core/applib/src/main/java/org/apache/isis/applib/services/iactn/Interaction.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/iactn/Interaction.java b/core/applib/src/main/java/org/apache/isis/applib/services/iactn/Interaction.java
index 5121161..06a5347 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/iactn/Interaction.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/iactn/Interaction.java
@@ -24,7 +24,6 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
-import java.util.concurrent.Callable;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import com.google.common.collect.Lists;
@@ -89,14 +88,108 @@ public class Interaction implements HasTransactionId {
         return priorExecution;
     }
 
+    public interface MemberCallable<T extends MemberArgs> {
+        Object call(T args);
+    }
+
+    public static abstract class MemberArgs {
+
+        public enum Type {
+            PROPERTY,
+            ACTION
+        }
+
+        private final Command command;
+        private final Object target;
+        private final Type type;
+
+        protected MemberArgs(
+                final Command command,
+                final Object target, final Type type) {
+            this.command = command;
+            this.target = target;
+            this.type = type;
+        }
+
+        public Command getCommand() {
+            return command;
+        }
+
+        public Object getTarget() {
+            return target;
+        }
+
+        public Type getType() {
+            return type;
+        }
+    }
+
+
+    public static class ActionArgs extends MemberArgs {
+        private final List<Object> args;
+
+        public ActionArgs(
+                final Command command,
+                final Object target,
+                final List<Object> args) {
+            super(command, target, Type.ACTION);
+            this.args = args;
+        }
+
+        public List<Object> getArgs() {
+            return args;
+        }
+    }
+
+    public static class PropertyArgs extends MemberArgs {
+        private final Object argValue;
+
+        public PropertyArgs(
+                final Command command,
+                final Object target,
+                final Object argValue) {
+            super(command, target, Type.PROPERTY);
+            this.argValue = argValue;
+        }
+
+        public Object getArgValue() {
+            return argValue;
+        }
+    }
+
     public <T> T execute(
-            final Callable<T> callable,
-            final String memberId,
-            final ClockService clockService,
-            final Command command) {
-        Timestamp startedAt = clockService.nowAsJavaSqlTimestamp();
-        Execution currentExecution = push(startedAt, memberId);
+            final MemberCallable memberCallable,
+            final ActionArgs actionArgs,
+            final ClockService clockService) {
+
+        final Timestamp startedAt = clockService.nowAsJavaSqlTimestamp();
+        final Execution execution = push(startedAt, actionArgs);
 
+        final Command command = actionArgs.getCommand();
+        return execute(memberCallable, actionArgs, clockService, command, startedAt, execution);
+
+    }
+
+    public <T> T execute(
+            final MemberCallable memberCallable,
+            final PropertyArgs propertyArgs,
+            final ClockService clockService) {
+
+        final Timestamp startedAt = clockService.nowAsJavaSqlTimestamp();
+        Execution execution = push(startedAt, propertyArgs);
+
+        final Command command = propertyArgs.getCommand();
+        return execute(memberCallable, propertyArgs, clockService, command, startedAt, execution);
+
+    }
+
+    private <T> T execute(
+            final MemberCallable memberCallable,
+            final MemberArgs memberArgs,
+            final ClockService clockService,
+            final Command command,
+            final Timestamp startedAt,
+            final Execution currentExecution) {
         // as a convenience, since in all cases we want the command to start when the first interaction executes,
         // we populate the command here.
         if(command.getStartedAt() == null) {
@@ -105,9 +198,9 @@ public class Interaction implements HasTransactionId {
 
         try {
             try {
-                T result = callable.call();
+                Object result = memberCallable.call(memberArgs);
                 currentExecution.setResult(result);
-                return result;
+                return (T)result;
             } catch (Exception e) {
 
                 // just because an exception has thrown, does not mean it is that significant; it could be that
@@ -131,20 +224,22 @@ public class Interaction implements HasTransactionId {
     public static class Execution {
 
         private final Timestamp startedAt;
-        private final String memberId;
+        private final MemberArgs memberArgs;
         private final Execution parent;
         private final List<Execution> children = Lists.newArrayList();
 
-        public Execution(final Timestamp startedAt, final String memberId) {
+        public Execution(
+                final MemberArgs memberArgs, final Timestamp startedAt) {
             this.startedAt = startedAt;
-            this.memberId = memberId;
+            this.memberArgs = memberArgs;
             this.parent = null;
         }
 
-        public Execution(final Execution parent, final Timestamp startedAt, final String memberId) {
+        public Execution(
+                final MemberArgs memberArgs, final Timestamp startedAt, final Execution parent) {
             this.startedAt = startedAt;
             this.parent = parent;
-            this.memberId = memberId;
+            this.memberArgs = memberArgs;
             parent.children.add(this);
         }
 
@@ -162,8 +257,8 @@ public class Interaction implements HasTransactionId {
             return Collections.unmodifiableList(children);
         }
 
-        public String getMemberId() {
-            return memberId;
+        public MemberArgs getMemberArgs() {
+            return memberArgs;
         }
 
         //region > event
@@ -294,17 +389,17 @@ public class Interaction implements HasTransactionId {
      * </p>
      */
     @Programmatic
-    Execution push(final Timestamp startedAt, final String memberId) {
+    Execution push(final Timestamp startedAt, final MemberArgs memberArgs) {
 
         final Execution newExecution;
         if(currentExecution == null) {
             // new top-level execution
-            newExecution = new Execution(startedAt, memberId);
+            newExecution = new Execution(memberArgs, startedAt);
             executionGraphs.add(newExecution);
 
         } else {
             // adds to graph of parent
-            newExecution = new Execution(currentExecution, startedAt, memberId);
+            newExecution = new Execution(memberArgs, startedAt, currentExecution);
         }
 
         // set
@@ -341,7 +436,7 @@ public class Interaction implements HasTransactionId {
 
     /**
      * Returns a (list of) graph(es) indicating the domain events in the order that they were
-     * {@link #push(Timestamp, String) pushed}.
+     * {@link #push(Timestamp, MemberArgs pushed}.
      *
      * <p>
      *     Each {@link Execution} represents a call stack of domain events (action invocations or property edits),
@@ -358,7 +453,7 @@ public class Interaction implements HasTransactionId {
     /**
      * <b>NOT API</b>: intended to be called only by the framework.
      *
-     * Clears the set of {@link AbstractDomainEvent}s that have been {@link #push(Timestamp, String) push}ed.
+     * Clears the set of {@link AbstractDomainEvent}s that have been {@link #push(Timestamp, MemberArgs push)}ed.
      */
     @Programmatic
     public void clear() {

http://git-wip-us.apache.org/repos/asf/isis/blob/01a88a6b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetForDomainEventAbstract.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetForDomainEventAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetForDomainEventAbstract.java
index 3968aea..d0be4ff 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetForDomainEventAbstract.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/actions/action/invocation/ActionInvocationFacetForDomainEventAbstract.java
@@ -21,6 +21,7 @@ package org.apache.isis.core.metamodel.facets.actions.action.invocation;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -298,7 +299,7 @@ public abstract class ActionInvocationFacetForDomainEventAbstract
     protected ObjectAdapter invokeThruCommand(
             final ObjectAction owningAction,
             final ObjectAdapter targetAdapter,
-            final ObjectAdapter[] arguments)
+            final ObjectAdapter[] argumentAdapters)
             throws IllegalAccessException, InvocationTargetException {
 
         final CommandContext commandContext = getCommandContext();
@@ -327,13 +328,18 @@ public abstract class ActionInvocationFacetForDomainEventAbstract
         } else {
 
             // otherwise, go ahead and execute action in the 'foreground'
-            interaction.execute(new Callable<Object>() {
 
+            final Object target = ObjectAdapter.Util.unwrap(targetAdapter);
+            final List<Object> arguments = ObjectAdapter.Util.unwrap(Arrays.asList(argumentAdapters));
+
+
+            final Interaction.ActionArgs actionArgs = new Interaction.ActionArgs(command, target, arguments);
+            final Interaction.MemberCallable callable = new Interaction.MemberCallable<Interaction.ActionArgs>() {
                 @Override
-                public Object call() {
+                public Object call(final Interaction.ActionArgs actionArgs) {
 
                     try {
-                        final Object resultPojo = invokeMethodElseFromCache(targetAdapter, arguments);
+                        final Object resultPojo = invokeMethodElseFromCache(targetAdapter, argumentAdapters);
 
                         if (LOG.isDebugEnabled()) {
                             LOG.debug(" action result " + resultPojo);
@@ -341,14 +347,16 @@ public abstract class ActionInvocationFacetForDomainEventAbstract
 
                         ObjectAdapter resultAdapter = cloneIfViewModelCloneable(resultPojo, targetAdapter);
 
-                        return resultAdapter != null? resultAdapter.getObject(): null;
+                        return resultAdapter != null ? resultAdapter.getObject() : null;
 
                     } catch (InvocationTargetException | IllegalAccessException e) {
                         throw new RuntimeException(e);
                     }
-
                 }
-            }, getIdentified().getIdentifier().toFullIdentityString(), getClockService(), command);
+            };
+
+
+            interaction.execute(callable, actionArgs, getClockService());
 
             final Interaction.Execution priorExecution = interaction.getPriorExecution();
 
@@ -361,7 +369,7 @@ public abstract class ActionInvocationFacetForDomainEventAbstract
             setCommandResultIfEntity(command, resultAdapter);
 
             // TODO: use InteractionContext instead
-            captureCurrentInvocationForPublishing(owningAction, targetAdapter, arguments, command, resultAdapter);
+            captureCurrentInvocationForPublishing(owningAction, targetAdapter, argumentAdapters, command, resultAdapter);
 
         }
         return resultAdapter;

http://git-wip-us.apache.org/repos/asf/isis/blob/01a88a6b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/properties/update/modify/PropertySetterFacetViaModifyMethod.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/properties/update/modify/PropertySetterFacetViaModifyMethod.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/properties/update/modify/PropertySetterFacetViaModifyMethod.java
index 1f1a5c3..d5b7ec9 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/properties/update/modify/PropertySetterFacetViaModifyMethod.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/properties/update/modify/PropertySetterFacetViaModifyMethod.java
@@ -22,7 +22,6 @@ package org.apache.isis.core.metamodel.facets.properties.update.modify;
 import java.lang.reflect.Method;
 import java.util.Collections;
 import java.util.List;
-import java.util.concurrent.Callable;
 
 import org.apache.isis.applib.services.clock.ClockService;
 import org.apache.isis.applib.services.command.Command;
@@ -84,12 +83,20 @@ public class PropertySetterFacetViaModifyMethod extends PropertySetterFacetAbstr
         command.setExecuteIn(org.apache.isis.applib.annotation.Command.ExecuteIn.FOREGROUND);
         command.setPersistence(org.apache.isis.applib.annotation.Command.Persistence.IF_HINTED);
 
-        interaction.execute(new Callable<Object>() {
-            @Override
-            public Object call() {
-                return ObjectAdapter.InvokeUtils.invoke(method, targetAdapter, valueAdapter);
-            }
-        }, getIdentified().getIdentifier().toFullIdentityString(), getClockService(), command);
+        final Object target = ObjectAdapter.Util.unwrap(targetAdapter);
+        final Object argValue = ObjectAdapter.Util.unwrap(valueAdapter);
+
+        final Interaction.PropertyArgs propertyArgs =
+                new Interaction.PropertyArgs(command, target, argValue);
+
+        final Interaction.MemberCallable<?> callable =
+                new Interaction.MemberCallable<Interaction.PropertyArgs>() {
+                    @Override public Object call(final Interaction.PropertyArgs propertyArgs) {
+                        return ObjectAdapter.InvokeUtils.invoke(method, targetAdapter, valueAdapter);
+                    }
+                };
+
+        interaction.execute(callable, propertyArgs, getClockService());
     }
 
     @Override