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:34 UTC
[25/31] isis git commit: ISIS-1291: introduce enum for sequenceName
(for newEventMetadata);
minor moving around of methods/extract methods refactoring of newEventMetadata
within IsisTransaction.
ISIS-1291: introduce enum for sequenceName (for newEventMetadata); minor moving around of methods/extract methods refactoring of newEventMetadata within IsisTransaction.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/8fb9dc4b
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/8fb9dc4b
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/8fb9dc4b
Branch: refs/heads/ISIS-1291
Commit: 8fb9dc4bda56f1573bba282646a5f31204865985
Parents: 2df011a
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Thu Apr 14 09:43:35 2016 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Thu Apr 14 09:45:10 2016 +0100
----------------------------------------------------------------------
.../applib/services/publish/EventMetadata.java | 37 ++++++---
.../publish/EventMetadataTest_getId.java | 4 +-
.../system/transaction/IsisTransaction.java | 86 ++++++++++----------
3 files changed, 71 insertions(+), 56 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/8fb9dc4b/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 bbadda4..47ab0ae 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
@@ -39,7 +39,7 @@ import org.apache.isis.applib.services.wrapper.WrapperFactory;
public class EventMetadata {
private final UUID transactionId;
- private final String sequenceName;
+ private final SequenceName sequenceName;
private final int sequence;
private final String user;
private final java.sql.Timestamp javaSqlTimestamp;
@@ -106,9 +106,30 @@ public class EventMetadata {
this(transactionId, null, sequence, eventType, user, javaSqlTimestamp, title, targetClass, targetAction, target, actionIdentifier, actionParameterNames, actionParameterTypes, actionReturnType);
}
+ public enum SequenceName {
+ /**
+ * "pt" - published event at the end of a transaction - could be multiple for objects
+ */
+ PUBLISHED_EVENT("pt"),
+ /**
+ * "pw" - published event as the result of an action invoked through the {@link WrapperFactory}
+ */
+ WRAPPED_ACTION("pw"),
+ /**
+ * "bc" - background command created through the {@link BackgroundService}
+ */
+ BACKGROUND_COMMAND("bc"),;
+
+ private final String abbr;
+ SequenceName(final String abbr) {
+ this.abbr = abbr;
+ }
+ public String abbr() { return abbr; }
+ }
+
public EventMetadata(
final UUID transactionId,
- final String sequenceName,
+ final SequenceName sequenceName,
final int sequence,
final EventType eventType,
final String user,
@@ -148,15 +169,7 @@ public class EventMetadata {
return transactionId;
}
- /**
- * The name of this sequence, for example:
- * <ul>
- * <li>"pt" - published event at the end of a transaction - could be multiple for objects,</li>
- * <li>"pw" - published event as the result of an action invoked through the {@link WrapperFactory}</li>
- * <li>"bc" - background command created through the {@link BackgroundService}</li>
- * </ul>
- */
- public String getSequenceName() {
+ public SequenceName getSequenceName() {
return sequenceName;
}
@@ -198,7 +211,7 @@ public class EventMetadata {
* If the {@link #getSequenceName()} is null, then just <tt>transactionId.sequence</tt>.
*/
public String getId() {
- return getTransactionId() + (getSequenceName() != null ? "." + getSequenceName(): "") + "." + getSequence();
+ return getTransactionId() + (getSequenceName() != null ? "." + getSequenceName().abbr(): "") + "." + getSequence();
}
/**
http://git-wip-us.apache.org/repos/asf/isis/blob/8fb9dc4b/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 69ee3c0..18c6906 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
@@ -65,14 +65,14 @@ public class EventMetadataTest_getId {
@Test
public void testWithSequence() {
UUID transactionId = UUID.fromString("1bd8e5d4-2d67-4395-b5e8-d74acd766766");
- final String sequenceName = "pt";
+ final EventMetadata.SequenceName sequenceName = EventMetadata.SequenceName.PUBLISHED_EVENT;
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.getSequenceName(), is(EventMetadata.SequenceName.PUBLISHED_EVENT));
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/8fb9dc4b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java
index 0d42a92..625b822 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java
@@ -553,7 +553,6 @@ public class IsisTransaction implements TransactionScopedComponent {
if(publishedActionFacet == null) {
return;
}
- final PublishedAction.PayloadFactory payloadFactory = publishedActionFacet.value();
final ObjectAdapter targetAdapter = currentInvocation.getTarget();
@@ -585,12 +584,14 @@ public class IsisTransaction implements TransactionScopedComponent {
parameterTypes = null;
returnType = null;
}
-
- final EventMetadata metadata = newEventMetadata(
- EventType.ACTION_INVOCATION, currentUser, timestamp, title,
- actionTargetClass, actionTargetAction, actionTarget, actionMemberIdentifier,
- // commandTargetClass, commandTargetAction, commandTarget, commandMemberIdentifier,
+
+ final Command command1 = this.command;
+ final EventMetadata metadata = newEventMetadata(command1, EventType.ACTION_INVOCATION, currentUser, timestamp, title,
+ actionTargetClass, actionTargetAction, actionTarget,
+ actionMemberIdentifier,
parameterNames, parameterTypes, returnType);
+
+ final PublishedAction.PayloadFactory payloadFactory = publishedActionFacet.value();
publishingService.publishAction(payloadFactory, metadata, currentInvocation, objectStringifier());
} finally {
// ensures that cannot publish this action more than once
@@ -634,33 +635,6 @@ public class IsisTransaction implements TransactionScopedComponent {
return enlistedAdapters;
}
- private EventMetadata newEventMetadata(
- final String currentUser,
- final Timestamp timestamp,
- final ChangeKind changeKind,
- final String enlistedAdapterClass,
- final Bookmark enlistedTarget) {
- final String oidStr = enlistedTarget.toString();
- final String title = oidStr;
-
- final EventType eventTypeFor = eventTypeFor(changeKind);
-
- return newEventMetadata(eventTypeFor, currentUser, timestamp, title, enlistedAdapterClass, null, enlistedTarget, null, null, null, null);
- }
-
- private static EventType eventTypeFor(ChangeKind changeKind) {
- if(changeKind == ChangeKind.UPDATE) {
- return EventType.OBJECT_UPDATED;
- }
- if(changeKind == ChangeKind.CREATE) {
- return EventType.OBJECT_CREATED;
- }
- if(changeKind == ChangeKind.DELETE) {
- return EventType.OBJECT_DELETED;
- }
- throw new IllegalArgumentException("unknown ChangeKind '" + changeKind + "'");
- }
-
protected ObjectStringifier objectStringifier() {
if(objectStringifier == null) {
// lazily created; is threadsafe so no need to guard against race conditions
@@ -690,6 +664,36 @@ public class IsisTransaction implements TransactionScopedComponent {
}
private EventMetadata newEventMetadata(
+ final String currentUser,
+ final Timestamp timestamp,
+ final ChangeKind changeKind,
+ final String enlistedAdapterClass,
+ final Bookmark enlistedTarget) {
+ final String oidStr = enlistedTarget.toString();
+ final String title = oidStr;
+
+ final EventType eventTypeFor = eventTypeFor(changeKind);
+
+ final Command command = this.command;
+ return newEventMetadata(command, eventTypeFor, currentUser, timestamp, title, enlistedAdapterClass, null, enlistedTarget,
+ null, null, null, null);
+ }
+
+ private static EventType eventTypeFor(ChangeKind changeKind) {
+ if(changeKind == ChangeKind.UPDATE) {
+ return EventType.OBJECT_UPDATED;
+ }
+ if(changeKind == ChangeKind.CREATE) {
+ return EventType.OBJECT_CREATED;
+ }
+ if(changeKind == ChangeKind.DELETE) {
+ return EventType.OBJECT_DELETED;
+ }
+ throw new IllegalArgumentException("unknown ChangeKind '" + changeKind + "'");
+ }
+
+ private EventMetadata newEventMetadata(
+ final Command command,
final EventType eventType,
final String currentUser,
final Timestamp timestampEpoch,
@@ -701,17 +705,15 @@ public class IsisTransaction implements TransactionScopedComponent {
final List<String> parameterNames,
final List<Class<?>> parameterTypes,
final Class<?> returnType) {
- int nextEventSequence = nextEventSequence();
- return new EventMetadata(
- getTransactionId(), nextEventSequence, eventType, currentUser, timestampEpoch, title,
- targetClass, targetAction, target, memberIdentifier, parameterNames, parameterTypes, returnType);
- }
-
- private int nextEventSequence() {
if(command == null) {
throw new IllegalStateException("CommandContext service is required to support Publishing.");
- }
- return command.next("publishedEvent");
+ }
+ final EventMetadata.SequenceName sequenceName = EventMetadata.SequenceName.PUBLISHED_EVENT;
+ final int nextEventSequence = command.next(sequenceName.abbr());
+ final UUID transactionId = command.getTransactionId();
+ return new EventMetadata(
+ transactionId, sequenceName, nextEventSequence, eventType, currentUser, timestampEpoch, title,
+ targetClass, targetAction, target, memberIdentifier, parameterNames, parameterTypes, returnType);
}
public void auditChangedProperty(