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/14 12:11:31 UTC

[22/31] isis git commit: ISIS-1372: extending EventMetadata with a sequenceName, in preparation to CommandMementoService creating different sequences of events (published event, wrapped event, background commands).

ISIS-1372: extending EventMetadata with a sequenceName, in preparation to CommandMementoService creating different sequences of events (published event, wrapped event, background commands).

Also updated javadoc for Command, and created a constant "(edit)" which is the value of Command#getTargetAction() for property edits.


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

Branch: refs/heads/ISIS-1291
Commit: 0bd1660ae41f6000afd9fe74af4a7a131ef9eb40
Parents: bf26fc3
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Tue Apr 12 20:22:13 2016 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Tue Apr 12 20:57:20 2016 +0100

----------------------------------------------------------------------
 .../isis/applib/services/command/Command.java   | 20 ++++---
 .../applib/services/publish/EventMetadata.java  | 55 +++++++++++++++++---
 .../publish/EventMetadataTest_getId.java        | 38 ++++++++++++--
 .../PropertySetterFacetViaModifyMethod.java     |  4 +-
 4 files changed, 97 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/0bd1660a/core/applib/src/main/java/org/apache/isis/applib/services/command/Command.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/command/Command.java b/core/applib/src/main/java/org/apache/isis/applib/services/command/Command.java
index 14820a5..f1640b5 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/command/Command.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/command/Command.java
@@ -56,6 +56,12 @@ import org.apache.isis.applib.services.wrapper.WrapperFactory;
  */
 public interface Command extends HasTransactionId {
 
+    /**
+     * The value for {@link #getTargetAction()} if this command represents an edit of an object's property
+     * (rather than an action).
+     */
+    String TARGET_ACTION_FOR_EDIT = "(edit)";
+
     // //////////////////////////////////////
     // user (property)
     // //////////////////////////////////////
@@ -116,13 +122,8 @@ public interface Command extends HasTransactionId {
     // //////////////////////////////////////
 
     /**
-     * Holds a string representation of the invoked action, equivalent to
+     * Holds a string representation of the invoked action, or the edited property, equivalent to
      * {@link Identifier#toClassAndNameIdentityString()}.
-     * 
-     * <p>
-     * This property is called 'memberIdentifier' rather than 'actionIdentifier' for
-     * consistency with other services (such as auditing and publishing) that may act on
-     * properties rather than simply just actions.
      */
     public abstract String getMemberIdentifier();
 
@@ -130,7 +131,8 @@ public interface Command extends HasTransactionId {
      * <b>NOT API</b>: intended to be called only by the framework.
      * 
      * <p>
-     * Implementation notes: set when the action is invoked (in the <tt>ActionInvocationFacet</tt>).
+     * Implementation notes: set when the action is invoked (in <tt>ActionInvocationFacet</tt>) or in
+     * property edited (in <tt>PropertySetterFacet</tt>).
      */
     public abstract void setMemberIdentifier(String actionIdentifier);
     
@@ -157,6 +159,10 @@ public interface Command extends HasTransactionId {
     
     /**
      * The human-friendly name of the action invoked on the target object.
+     *
+     * <p>
+     *     If the command represents an edit of a property, then holds the value &quot;{@value TARGET_ACTION_FOR_EDIT}&quot;.
+     * </p>
      */
     public abstract String getTargetAction();
     

http://git-wip-us.apache.org/repos/asf/isis/blob/0bd1660a/core/applib/src/main/java/org/apache/isis/applib/services/publish/EventMetadata.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/publish/EventMetadata.java b/core/applib/src/main/java/org/apache/isis/applib/services/publish/EventMetadata.java
index 5523e4e..bbadda4 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/publish/EventMetadata.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/publish/EventMetadata.java
@@ -24,7 +24,9 @@ import java.util.List;
 import java.util.UUID;
 
 import org.apache.isis.applib.Identifier;
+import org.apache.isis.applib.services.background.BackgroundService;
 import org.apache.isis.applib.services.bookmark.Bookmark;
+import org.apache.isis.applib.services.wrapper.WrapperFactory;
 
 /**
  * Standard metadata about an event to be published.
@@ -37,6 +39,7 @@ import org.apache.isis.applib.services.bookmark.Bookmark;
 public class EventMetadata {
     
     private final UUID transactionId;
+    private final String sequenceName;
     private final int sequence;
     private final String user;
     private final java.sql.Timestamp javaSqlTimestamp;
@@ -81,7 +84,11 @@ public class EventMetadata {
             final String actionIdentifier) {
         this(transactionId, sequence, eventType, user, javaSqlTimestamp, title, targetClass, targetAction, target, actionIdentifier, null, null, null );
     }
-    
+
+    /**
+     * @deprecated - no longer called by the framework.
+     */
+    @Deprecated
     public EventMetadata(
             final UUID transactionId,
             final int sequence,
@@ -96,7 +103,26 @@ public class EventMetadata {
             final List<String> actionParameterNames,
             final List<Class<?>> actionParameterTypes,
             final Class<?> actionReturnType) {
+        this(transactionId, null, sequence, eventType, user, javaSqlTimestamp, title, targetClass, targetAction, target, actionIdentifier, actionParameterNames, actionParameterTypes, actionReturnType);
+    }
+
+    public EventMetadata(
+            final UUID transactionId,
+            final String sequenceName,
+            final int sequence,
+            final EventType eventType,
+            final String user,
+            final Timestamp javaSqlTimestamp,
+            final String title,
+            final String targetClass,
+            final String targetAction,
+            final Bookmark target,
+            final String actionIdentifier,
+            final List<String> actionParameterNames,
+            final List<Class<?>> actionParameterTypes,
+            final Class<?> actionReturnType) {
         this.transactionId = transactionId;
+        this.sequenceName = sequenceName;
         this.sequence = sequence;
         this.user = user;
         this.javaSqlTimestamp = javaSqlTimestamp;
@@ -116,17 +142,29 @@ public class EventMetadata {
      * originated.
      * 
      * <p>
-     * Note that there could be several events all with the same transaction Id.
+     * Note that there could be several events all with the same transaction Id, distinguished by {@link #getSequenceName()} and {@link #getSequence()}.
      */
     public UUID getTransactionId() {
         return transactionId;
     }
-    
+
     /**
-     * The zero-based sequence number of this event within the transaction.
+     * The name of this sequence, for example:
+     * <ul>
+     *     <li>&quot;pt&quot; - published event at the end of a transaction - could be multiple for objects,</li>
+     *     <li>&quot;pw&quot; - published event as the result of an action invoked through the {@link WrapperFactory}</li>
+     *     <li>&quot;bc&quot; - background command created through the {@link BackgroundService}</li>
+     * </ul>
+     */
+    public String getSequenceName() {
+        return sequenceName;
+    }
+
+    /**
+     * The zero-based sequence number within the sequence name.
      * 
      * <p>
-     * The combination of {@link #getTransactionId() transaction Id} and {@link #getSequence() sequence}
+     * The combination of {@link #getTransactionId() transaction Id}, {@link #getSequenceName()} sequence name} and {@link #getSequence() sequence}
      * is guaranteed to be unique.
      */
     public int getSequence() {
@@ -155,11 +193,12 @@ public class EventMetadata {
     }
     
     /**
-     * Returns a string that concatenates the {@link #getTransactionId()} and the
-     * {@link #getSequence()} with a period (<tt>.</tt>).
+     * Returns a string in form <tt>transactionId.sequenceName.sequence</tt>.
+     *
+     * If the {@link #getSequenceName()} is null, then just <tt>transactionId.sequence</tt>.
      */
     public String getId() {
-        return getTransactionId() + "." + getSequence();
+        return getTransactionId() + (getSequenceName() != null ? "." + getSequenceName(): "") + "." + getSequence();
     }
     
     /**

http://git-wip-us.apache.org/repos/asf/isis/blob/0bd1660a/core/applib/src/test/java/org/apache/isis/applib/services/publish/EventMetadataTest_getId.java
----------------------------------------------------------------------
diff --git a/core/applib/src/test/java/org/apache/isis/applib/services/publish/EventMetadataTest_getId.java b/core/applib/src/test/java/org/apache/isis/applib/services/publish/EventMetadataTest_getId.java
index 7ac3312..69ee3c0 100644
--- a/core/applib/src/test/java/org/apache/isis/applib/services/publish/EventMetadataTest_getId.java
+++ b/core/applib/src/test/java/org/apache/isis/applib/services/publish/EventMetadataTest_getId.java
@@ -19,13 +19,14 @@
 
 package org.apache.isis.applib.services.publish;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
 import java.util.UUID;
 
 import org.junit.Test;
 
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
 public class EventMetadataTest_getId {
 
     @Test
@@ -46,4 +47,35 @@ public class EventMetadataTest_getId {
         assertThat(eventMetadata.getEventType(), is(EventType.ACTION_INVOCATION));
     }
 
+    @Test
+    public void testWithoutSequence() {
+        UUID transactionId = UUID.fromString("1bd8e5d4-2d67-4395-b5e8-d74acd766766");
+        int sequence = 2;
+
+        EventMetadata eventMetadata = new EventMetadata(transactionId, null, sequence, EventType.ACTION_INVOCATION,
+                null, null, null, null, null, null, null, null, null, null);
+
+        assertThat(eventMetadata.getTransactionId(), is(UUID.fromString("1bd8e5d4-2d67-4395-b5e8-d74acd766766")));
+        assertThat(eventMetadata.getSequenceName(), is(nullValue()));
+        assertThat(eventMetadata.getSequence(), is(2));
+
+        assertThat(eventMetadata.getId(), is("1bd8e5d4-2d67-4395-b5e8-d74acd766766.2"));
+    }
+
+    @Test
+    public void testWithSequence() {
+        UUID transactionId = UUID.fromString("1bd8e5d4-2d67-4395-b5e8-d74acd766766");
+        final String sequenceName = "pt";
+        int sequence = 2;
+
+        EventMetadata eventMetadata = new EventMetadata(transactionId, sequenceName, sequence, EventType.ACTION_INVOCATION,
+                null, null, null, null, null, null, null, null, null, null);
+
+        assertThat(eventMetadata.getTransactionId(), is(UUID.fromString("1bd8e5d4-2d67-4395-b5e8-d74acd766766")));
+        assertThat(eventMetadata.getSequenceName(), is("pt"));
+        assertThat(eventMetadata.getSequence(), is(2));
+
+        assertThat(eventMetadata.getId(), is("1bd8e5d4-2d67-4395-b5e8-d74acd766766.pt.2"));
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/0bd1660a/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 96caa8c..2230d38 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
@@ -74,8 +74,8 @@ public class PropertySetterFacetViaModifyMethod extends PropertySetterFacetAbstr
 
             command.setTarget(CommandUtil.bookmarkFor(targetAdapter));
             command.setTargetClass(CommandUtil.targetClassNameFor(targetAdapter));
-            command.setTargetAction("(edit)");
-            command.setMemberIdentifier("(edit)");
+            command.setTargetAction(Command.TARGET_ACTION_FOR_EDIT);
+            command.setMemberIdentifier(Command.TARGET_ACTION_FOR_EDIT);
 
             command.setExecuteIn(org.apache.isis.applib.annotation.Command.ExecuteIn.FOREGROUND);
             command.setPersistence(org.apache.isis.applib.annotation.Command.Persistence.IF_HINTED);