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/04/21 11:05:43 UTC

[07/12] isis git commit: ISIS-1291: small fixes while manually testing command module.

ISIS-1291: small fixes while manually testing command module.

specifically:
- fixing aim-2.0.xsd and cmd-1.0.xsd to have an @XmlRootElement
- simplifying cmd-1.0.xsd
- saving result and exception - after all - for commands executed in background
- fixing bug (missing @Inject) for BackgroundService


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

Branch: refs/heads/ISIS-1291
Commit: 69cd797c6a9b510c0a67f436ca0c8e22d8b1f10e
Parents: 0264ec6
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Wed Apr 20 18:12:45 2016 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Wed Apr 20 18:12:45 2016 +0100

----------------------------------------------------------------------
 .../services/background/BackgroundService.java  |  6 +-
 .../background/BackgroundCommandExecution.java  | 23 +++---
 .../background/BackgroundServiceDefault.java    | 44 ++++-------
 .../org/apache/isis/schema/aim/aim-2.0.xsd      | 62 +++++++--------
 .../org/apache/isis/schema/cmd/cmd-1.0.xsd      | 82 ++++++++++----------
 5 files changed, 104 insertions(+), 113 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/69cd797c/core/applib/src/main/java/org/apache/isis/applib/services/background/BackgroundService.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/background/BackgroundService.java b/core/applib/src/main/java/org/apache/isis/applib/services/background/BackgroundService.java
index 7e7f388..18d2356 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/background/BackgroundService.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/background/BackgroundService.java
@@ -47,10 +47,10 @@ public interface BackgroundService {
 
     /**
      * Not API: for framework use only.
-     * @param domainObject
-     * @param args
-     * @return
+     *
+     * @deprecated - no longer called by the framework (moved to <tt>CommandMementoService</tt>, an internal SPI service).
      */
+    @Deprecated
     @Programmatic
     ActionInvocationMemento asActionInvocationMemento(Method m, Object domainObject, Object[] args);
 

http://git-wip-us.apache.org/repos/asf/isis/blob/69cd797c/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundCommandExecution.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundCommandExecution.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundCommandExecution.java
index 79c2ab8..82ec4ab 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundCommandExecution.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundCommandExecution.java
@@ -100,12 +100,12 @@ public abstract class BackgroundCommandExecution extends AbstractIsisSessionTemp
 
                 commandContext.setCommand(command);
                 final String memento = command.getMemento();
-                final boolean legacy = memento.startsWith("<memento");
 
                 try {
                     command.setStartedAt(Clock.getTimeAsJavaSqlTimestamp());
                     command.setExecutor(Executor.BACKGROUND);
 
+                    final boolean legacy = memento.startsWith("<memento");
                     if(legacy) {
 
                         final ActionInvocationMemento aim = new ActionInvocationMemento(mementoService, memento);
@@ -150,21 +150,24 @@ public abstract class BackgroundCommandExecution extends AbstractIsisSessionTemp
                                     findObjectAction(mixinFqClassName, targetAdapter, actionId);
 
                             final ObjectAdapter[] argAdapters = argAdaptersFor(dto);
-                            objectAction.execute(
+                            final ObjectAdapter resultAdapter = objectAction.execute(
                                     targetAdapter, argAdapters, InteractionInitiatedBy.FRAMEWORK);
 
-                            // no longer capture the result, because there may be many
-                            // (should be done by auditing/profiling instead).
+                            // this doesn't really make sense if >1 action
+                            // in any case, the capturing of the action interaction should be the
+                            // responsibiity of auditing/profiling
+                            if(resultAdapter != null) {
+                                Bookmark resultBookmark = CommandUtil.bookmarkFor(resultAdapter);
+                                command.setResult(resultBookmark);
+                            }
                         }
                     }
 
                 } catch (Exception e) {
-                    if(legacy) {
-                        command.setException(Throwables.getStackTraceAsString(e));
-                    } else {
-                        // no longer capture any exceptions, could be bulk action.
-                        // (should be done by auditing/profiling instead).
-                    }
+                    // this doesn't really make sense if >1 action
+                    // in any case, the capturing of the action interaction should be the
+                    // responsibiity of auditing/profiling
+                    command.setException(Throwables.getStackTraceAsString(e));
                 } finally {
                     // decided to keep this, even though really this
                     // should be the responsibility of auditing/profiling

http://git-wip-us.apache.org/repos/asf/isis/blob/69cd797c/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundServiceDefault.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundServiceDefault.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundServiceDefault.java
index 0c2badc..845d7ff 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundServiceDefault.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundServiceDefault.java
@@ -18,6 +18,10 @@ package org.apache.isis.core.runtime.services.background;
 
 import java.lang.reflect.Method;
 import java.util.Collections;
+import java.util.Map;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
 
 import org.apache.isis.applib.annotation.DomainService;
 import org.apache.isis.applib.annotation.NatureOfService;
@@ -29,20 +33,18 @@ import org.apache.isis.applib.services.background.BackgroundService;
 import org.apache.isis.applib.services.bookmark.BookmarkService;
 import org.apache.isis.applib.services.command.Command;
 import org.apache.isis.applib.services.command.CommandContext;
-import org.apache.isis.core.metamodel.services.command.CommandMementoService;
-import org.apache.isis.core.commons.ensure.Ensure;
 import org.apache.isis.core.commons.exceptions.IsisException;
 import org.apache.isis.core.commons.lang.ArrayExtensions;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
 import org.apache.isis.core.metamodel.facets.actions.action.invocation.CommandUtil;
+import org.apache.isis.core.metamodel.services.command.CommandMementoService;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
 import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
 import org.apache.isis.core.metamodel.spec.feature.ObjectMember;
 import org.apache.isis.core.metamodel.specloader.classsubstitutor.JavassistEnhanced;
 import org.apache.isis.core.metamodel.specloader.specimpl.dflt.ObjectSpecificationDefault;
-import org.apache.isis.core.runtime.services.memento.MementoServiceDefault;
 import org.apache.isis.core.runtime.system.context.IsisContext;
 import org.apache.isis.schema.cmd.v1.CommandMementoDto;
 
@@ -50,9 +52,6 @@ import javassist.util.proxy.MethodFilter;
 import javassist.util.proxy.MethodHandler;
 import javassist.util.proxy.ProxyFactory;
 import javassist.util.proxy.ProxyObject;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.CoreMatchers.nullValue;
 
 /**
  * Depends on an implementation of {@link org.apache.isis.applib.services.background.BackgroundCommandService} to
@@ -63,16 +62,18 @@ import static org.hamcrest.CoreMatchers.nullValue;
 )
 public class BackgroundServiceDefault implements BackgroundService {
 
-    private final MementoServiceDefault mementoService;
-    
-    public BackgroundServiceDefault() {
-        this(new MementoServiceDefault());
+
+
+    @Programmatic
+    @PostConstruct
+    public void init(Map<String,String> props) {
     }
-    
-    BackgroundServiceDefault(MementoServiceDefault mementoService) {
-        this.mementoService = mementoService.withNoEncoding();
+
+    @Programmatic
+    @PreDestroy
+    public void shutdown() {
+
     }
-    
 
     // //////////////////////////////////////
 
@@ -101,10 +102,6 @@ public class BackgroundServiceDefault implements BackgroundService {
     @Programmatic
     @Override
     public <T> T execute(final T domainObject) {
-
-        // only perform check if actually used.
-        ensureDependenciesInjected();
-
         final Class<? extends Object> cls = domainObject.getClass();
         final MethodHandler methodHandler = newMethodHandler(domainObject);
         return newProxy(cls, methodHandler);
@@ -226,16 +223,9 @@ public class BackgroundServiceDefault implements BackgroundService {
     @javax.inject.Inject
     private BookmarkService bookmarkService;
 
+    @javax.inject.Inject
     private CommandContext commandContext;
 
-    /**
-     * Checked lazily in {@link #execute(Object)}.
-     */
-    private void ensureDependenciesInjected() {
-        Ensure.ensureThatState(this.bookmarkService, is(not(nullValue())), "BookmarkService domain service must be configured");
-        Ensure.ensureThatState(this.backgroundCommandService, is(not(nullValue())), "BackgroundCommandService domain service must be configured");
-        Ensure.ensureThatState(this.commandContext, is(not(nullValue())), "CommandContext domain service must be configured");
-    }
 
     // //////////////////////////////////////
 
@@ -247,6 +237,4 @@ public class BackgroundServiceDefault implements BackgroundService {
         return IsisContext.getPersistenceSession();
     }
 
-
-
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/69cd797c/core/schema/src/main/resources/org/apache/isis/schema/aim/aim-2.0.xsd
----------------------------------------------------------------------
diff --git a/core/schema/src/main/resources/org/apache/isis/schema/aim/aim-2.0.xsd b/core/schema/src/main/resources/org/apache/isis/schema/aim/aim-2.0.xsd
index ce1bfed..811dff1 100644
--- a/core/schema/src/main/resources/org/apache/isis/schema/aim/aim-2.0.xsd
+++ b/core/schema/src/main/resources/org/apache/isis/schema/aim/aim-2.0.xsd
@@ -28,42 +28,42 @@
     <xs:import namespace="http://isis.apache.org/schema/common" schemaLocation="../common/common-1.0.xsd"/>
     <xs:import namespace="http://isis.apache.org/schema/cmd" schemaLocation="../cmd/cmd-1.0.xsd"/>
 
-    <xs:element name="actionInvocationMementoDto" type="actionInvocationMementoDto">
+    <xs:element name="actionInvocationMementoDto">
         <xs:annotation>
             <xs:documentation>Represents v2.0 of this schema.  Changes since v1.0 are the addition of the 'majorVersion' and 'minorVersion', the 'mixinFqClassName' element, the 'threw' element, the 'timestampComplete' element and the 'subActions' element.  The 'timestamp' element has been replaced by 'timestampStart'.  The 'returned' element has been redefined.  The 'metadata' and 'payload' containers have been removed.  The supporting 'paramDto' types have been moved to common (so can be shared with cmd.xsd).
             </xs:documentation>
         </xs:annotation>
-    </xs:element>
+        <xs:complexType>
+            <xs:sequence>
+                <xs:element name="majorVersion" type="xs:string" minOccurs="0" maxOccurs="1" default="2">
+                    <xs:annotation>
+                        <xs:documentation>The major version of the schema that an XML instance was created using.
+                        </xs:documentation>
+                    </xs:annotation>
+                </xs:element>
+                <xs:element name="minorVersion" type="xs:string" minOccurs="0" maxOccurs="1" default="0">
+                    <xs:annotation>
+                        <xs:documentation>The minor version of the schema that an XML instance was created using.
+                        </xs:documentation>
+                    </xs:annotation>
+                </xs:element>
+                <xs:element name="transactionId" type="xs:string">
+                    <xs:annotation>
+                        <xs:documentation>Transaction id within which this action was invoked; can be used to locate the corresponding Command object (which may have been persisted).  However, there could be many such actions (eg by virtue of WrapperFactory); the 'sequence' is used to provide a unique id for each action invocation.
+                        </xs:documentation>
+                    </xs:annotation>
+                </xs:element>
+                <xs:element name="invocation" type="actionInvocationDto"/>
+                <xs:element name="subInvocations" type="actionInvocationDto" minOccurs="0" maxOccurs="unbounded">
+                    <xs:annotation>
+                        <xs:documentation>Capture invocations of any other actions invoked from this action, using the WrapperFactory service.  These therefore define a graph/call-stack of actions.  Note that the subactions will redundantly also specify their majorVersion and minorVersion (the alternative would have required restructuring in such a way as to break backward compatibility).
+                        </xs:documentation>
+                    </xs:annotation>
+                </xs:element>
+            </xs:sequence>
+        </xs:complexType>
 
-    <xs:complexType name="actionInvocationMementoDto">
-        <xs:sequence>
-            <xs:element name="majorVersion" type="xs:string" minOccurs="0" maxOccurs="1" default="2">
-                <xs:annotation>
-                    <xs:documentation>The major version of the schema that an XML instance was created using.
-                    </xs:documentation>
-                </xs:annotation>
-            </xs:element>
-            <xs:element name="minorVersion" type="xs:string" minOccurs="0" maxOccurs="1" default="0">
-                <xs:annotation>
-                    <xs:documentation>The minor version of the schema that an XML instance was created using.
-                    </xs:documentation>
-                </xs:annotation>
-            </xs:element>
-            <xs:element name="transactionId" type="xs:string">
-                <xs:annotation>
-                    <xs:documentation>Transaction id within which this action was invoked; can be used to locate the corresponding Command object (which may have been persisted).  However, there could be many such actions (eg by virtue of WrapperFactory); the 'sequence' is used to provide a unique id for each action invocation.
-                    </xs:documentation>
-                </xs:annotation>
-            </xs:element>
-            <xs:element name="invocation" type="actionInvocationDto"/>
-            <xs:element name="subInvocations" type="actionInvocationDto" minOccurs="0" maxOccurs="unbounded">
-                <xs:annotation>
-                    <xs:documentation>Capture invocations of any other actions invoked from this action, using the WrapperFactory service.  These therefore define a graph/call-stack of actions.  Note that the subactions will redundantly also specify their majorVersion and minorVersion (the alternative would have required restructuring in such a way as to break backward compatibility).
-                    </xs:documentation>
-                </xs:annotation>
-            </xs:element>
-        </xs:sequence>
-    </xs:complexType>
+    </xs:element>
 
     <xs:complexType name="actionInvocationDto">
         <xs:sequence>

http://git-wip-us.apache.org/repos/asf/isis/blob/69cd797c/core/schema/src/main/resources/org/apache/isis/schema/cmd/cmd-1.0.xsd
----------------------------------------------------------------------
diff --git a/core/schema/src/main/resources/org/apache/isis/schema/cmd/cmd-1.0.xsd b/core/schema/src/main/resources/org/apache/isis/schema/cmd/cmd-1.0.xsd
index 75b9479..85ed6f1 100644
--- a/core/schema/src/main/resources/org/apache/isis/schema/cmd/cmd-1.0.xsd
+++ b/core/schema/src/main/resources/org/apache/isis/schema/cmd/cmd-1.0.xsd
@@ -25,52 +25,52 @@
 
     <xs:import namespace="http://isis.apache.org/schema/common" schemaLocation="../common/common-1.0.xsd"/>
 
-    <xs:element name="commandMementoDto" type="commandMementoDto">
+    <xs:element name="commandMementoDto">
         <xs:annotation>
             <xs:documentation>Represents v1.0 of this schema.
             </xs:documentation>
         </xs:annotation>
-    </xs:element>
+        <xs:complexType>
+            <xs:sequence>
+                <xs:element name="majorVersion" type="xs:string" minOccurs="1" maxOccurs="1" default="1">
+                    <xs:annotation>
+                        <xs:documentation>The major version of the schema that an XML instance was created using.
+                        </xs:documentation>
+                    </xs:annotation>
+                </xs:element>
+                <xs:element name="minorVersion" type="xs:string" minOccurs="1" maxOccurs="1" default="1">
+                    <xs:annotation>
+                        <xs:documentation>Introduced in v1.1. The minor version of the schema that an XML instance was created using.
+                        </xs:documentation>
+                    </xs:annotation>
+                </xs:element>
+                <xs:element name="transactionId" type="xs:string">
+                    <xs:annotation>
+                        <xs:documentation>Transaction id for this command, a unique identifier.
+                        </xs:documentation>
+                    </xs:annotation>
+                </xs:element>
+                <xs:element name="targets" type="common:oidDto" minOccurs="1" maxOccurs="unbounded">
+                    <xs:annotation>
+                        <xs:documentation>For regular actions, represents the entity/entities or view model(s) upon which the action is to be invoked.  For mixin actions, is the object(s) being mixed-into (the constructor arg to the mixin).  For contributed actions, is the domain service (the contributee object will be one of the action arguments within the payload).  Note that this means that bulk contributed actions cannot be reified as a memento (for this use case, implement as a mixin action instead).  Mixin actions can be determined by the presence of the 'mixinFqClassName' element.
+                        </xs:documentation>
+                    </xs:annotation>
+                </xs:element>
+                <xs:element name="action" type="actionDto">
+                    <xs:annotation>
+                        <xs:documentation>The action and arguments to be invoked on the target object(s).</xs:documentation>
+                    </xs:annotation>
+                </xs:element>
+                <xs:element name="user" type="xs:string">
+                    <xs:annotation>
+                        <xs:documentation>The name of the user that initiated/created this command.
+                        </xs:documentation>
+                    </xs:annotation>
+                </xs:element>
+            </xs:sequence>
+        </xs:complexType>
 
-    <xs:complexType name="commandMementoDto">
-        <xs:sequence>
-            <xs:element name="majorVersion" type="xs:string" minOccurs="1" maxOccurs="1" default="1">
-                <xs:annotation>
-                    <xs:documentation>The major version of the schema that an XML instance was created using.
-                    </xs:documentation>
-                </xs:annotation>
-            </xs:element>
-            <xs:element name="minorVersion" type="xs:string" minOccurs="1" maxOccurs="1" default="1">
-                <xs:annotation>
-                    <xs:documentation>Introduced in v1.1. The minor version of the schema that an XML instance was created using.
-                    </xs:documentation>
-                </xs:annotation>
-            </xs:element>
-            <xs:element name="transactionId" type="xs:string">
-                <xs:annotation>
-                    <xs:documentation>Transaction id for this command, a unique identifier.
-                    </xs:documentation>
-                </xs:annotation>
-            </xs:element>
-            <xs:element name="targets" type="common:oidDto" minOccurs="1" maxOccurs="unbounded">
-                <xs:annotation>
-                    <xs:documentation>For regular actions, represents the entity/entities or view model(s) upon which the action is to be invoked.  For mixin actions, is the object(s) being mixed-into (the constructor arg to the mixin).  For contributed actions, is the domain service (the contributee object will be one of the action arguments within the payload).  Note that this means that bulk contributed actions cannot be reified as a memento (for this use case, implement as a mixin action instead).  Mixin actions can be determined by the presence of the 'mixinFqClassName' element.
-                    </xs:documentation>
-                </xs:annotation>
-            </xs:element>
-            <xs:element name="action" type="actionDto">
-                <xs:annotation>
-                    <xs:documentation>The action and arguments to be invoked on the target object(s).</xs:documentation>
-                </xs:annotation>
-            </xs:element>
-            <xs:element name="user" type="xs:string">
-                <xs:annotation>
-                    <xs:documentation>The name of the user that initiated/created this command.
-                    </xs:documentation>
-                </xs:annotation>
-            </xs:element>
-        </xs:sequence>
-    </xs:complexType>
+    </xs:element>
 
     <xs:complexType name="actionDto">
         <xs:annotation>