From 92a37a6a5905d7c5ac76926897f5897c323667e6 Mon Sep 17 00:00:00 2001 From: danhaywood Date: Tue, 1 Oct 2019 12:26:27 +0100 Subject: [PATCH] #115 - adds OutboxEvent and PublishedEventAbstract (as common superclass with PublshedEvent) --- .../publishmq/dom/jdo/events/OutboxEvent.java | 17 + .../dom/jdo/events/PublishedEvent.java | 292 +----------------- .../jdo/events/PublishedEventAbstract.java | 220 +++++++++++++ 3 files changed, 240 insertions(+), 289 deletions(-) create mode 100644 modules/spi/publishmq/impl/jdo/src/main/java/org/isisaddons/module/publishmq/dom/jdo/events/OutboxEvent.java create mode 100644 modules/spi/publishmq/impl/jdo/src/main/java/org/isisaddons/module/publishmq/dom/jdo/events/PublishedEventAbstract.java diff --git a/modules/spi/publishmq/impl/jdo/src/main/java/org/isisaddons/module/publishmq/dom/jdo/events/OutboxEvent.java b/modules/spi/publishmq/impl/jdo/src/main/java/org/isisaddons/module/publishmq/dom/jdo/events/OutboxEvent.java new file mode 100644 index 000000000..14c6ed912 --- /dev/null +++ b/modules/spi/publishmq/impl/jdo/src/main/java/org/isisaddons/module/publishmq/dom/jdo/events/OutboxEvent.java @@ -0,0 +1,17 @@ +package org.isisaddons.module.publishmq.dom.jdo.events; + +import org.apache.isis.applib.annotation.DomainObject; +import org.apache.isis.applib.annotation.DomainObjectLayout; +import org.apache.isis.applib.annotation.Editing; + +@javax.jdo.annotations.PersistenceCapable( + schema = "isispublishmq", + table="OutboxEvent") +@DomainObject( + editing = Editing.DISABLED, + objectType = "isispublishmq.OutboxEvent" +) +@DomainObjectLayout(named = "Outbox Event") +public class OutboxEvent extends PublishedEventAbstract { + +} diff --git a/modules/spi/publishmq/impl/jdo/src/main/java/org/isisaddons/module/publishmq/dom/jdo/events/PublishedEvent.java b/modules/spi/publishmq/impl/jdo/src/main/java/org/isisaddons/module/publishmq/dom/jdo/events/PublishedEvent.java index 9a7d68c93..1fc53e8c0 100644 --- a/modules/spi/publishmq/impl/jdo/src/main/java/org/isisaddons/module/publishmq/dom/jdo/events/PublishedEvent.java +++ b/modules/spi/publishmq/impl/jdo/src/main/java/org/isisaddons/module/publishmq/dom/jdo/events/PublishedEvent.java @@ -1,38 +1,12 @@ package org.isisaddons.module.publishmq.dom.jdo.events; -import java.text.SimpleDateFormat; -import java.util.UUID; - -import javax.jdo.annotations.IdentityType; - -import org.apache.isis.applib.Identifier; import org.apache.isis.applib.annotation.DomainObject; import org.apache.isis.applib.annotation.DomainObjectLayout; import org.apache.isis.applib.annotation.Editing; -import org.apache.isis.applib.annotation.Programmatic; -import org.apache.isis.applib.annotation.Property; -import org.apache.isis.applib.annotation.PropertyLayout; -import org.apache.isis.applib.annotation.Where; -import org.apache.isis.applib.services.HasTransactionId; -import org.apache.isis.applib.services.HasUsername; -import org.apache.isis.applib.services.RepresentsInteractionMemberExecution; -import org.apache.isis.applib.services.publish.EventType; -import org.apache.isis.applib.util.ObjectContracts; -import org.apache.isis.applib.util.TitleBuffer; -import org.apache.isis.objectstore.jdo.applib.service.DomainChangeJdoAbstract; -import org.apache.isis.objectstore.jdo.applib.service.JdoColumnLength; -import org.apache.isis.objectstore.jdo.applib.service.Util; - -import org.isisaddons.module.publishmq.PublishMqModule; - -import lombok.Getter; -import lombok.Setter; @javax.jdo.annotations.PersistenceCapable( - identityType=IdentityType.APPLICATION, schema = "isispublishmq", - table="PublishedEvent", - objectIdClass=PublishedEventPK.class) + table="PublishedEvent") @javax.jdo.annotations.Queries( { @javax.jdo.annotations.Query( name="findByTransactionId", language="JDOQL", @@ -117,268 +91,8 @@ editing = Editing.DISABLED, objectType = "isispublishmq.PublishedEvent" ) -@DomainObjectLayout( - named = "Published Event" -) -public class PublishedEvent extends DomainChangeJdoAbstract implements HasTransactionId, - RepresentsInteractionMemberExecution, HasUsername { - - //region > domain events - public static abstract class PropertyDomainEvent - extends PublishMqModule.PropertyDomainEvent { - } - - public static abstract class CollectionDomainEvent - extends PublishMqModule.CollectionDomainEvent { - } - - public static abstract class ActionDomainEvent - extends PublishMqModule.ActionDomainEvent { - } - //endregion - - //region > constructor, identification - - public PublishedEvent() { - super(ChangeType.PUBLISHED_INTERACTION); - } - //endregion - - //region > title - public String title() { - - // nb: not thread-safe - // formats defined in https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html - final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - - final TitleBuffer buf = new TitleBuffer(); - buf.append(format.format(getTimestamp())); - buf.append(" ").append(getMemberIdentifier()); - return buf.toString(); - } - //endregion - - //region > title (hidden property, unused) - public static class TitleDomainEvent extends PropertyDomainEvent { } - - @javax.jdo.annotations.Column(allowsNull="false", length=255, position = 9) - @Property(hidden = Where.EVERYWHERE) - @Getter @Setter - private String title; - //endregion - - //region > user (property), getUsername() - public static class UserDomainEvent extends PropertyDomainEvent { } - - @javax.jdo.annotations.Column(allowsNull="false", length=50, position = 10) - @Property( - domainEvent = UserDomainEvent.class - ) - @Getter @Setter - private String user; - - @Override - @Programmatic - public String getUsername() { - return getUser(); - } - //endregion - - //region > timestamp (property) - - public static class TimestampDomainEvent extends PropertyDomainEvent { } - - @javax.jdo.annotations.Persistent - @javax.jdo.annotations.Column(allowsNull="false", position = 8) - @Property( - domainEvent = TimestampDomainEvent.class - ) - @Getter @Setter - private java.sql.Timestamp timestamp; - //endregion - - //region > transactionId (property) - - public static class TransactionIdDomainEvent extends PropertyDomainEvent { - } - - /** - * The unique identifier (a GUID) of the transaction in which this published event was persisted. - * - *

- * The combination of ({@link #getTransactionId() transactionId}, {@link #getSequence() sequence}) makes up the - * primary key. - */ - @javax.jdo.annotations.PrimaryKey - @javax.jdo.annotations.Column(allowsNull="false",length=JdoColumnLength.TRANSACTION_ID, position = 0) - @Property( - domainEvent = TransactionIdDomainEvent.class - ) - @PropertyLayout( - typicalLength = JdoColumnLength.TRANSACTION_ID - ) - @Getter @Setter - private UUID transactionId; - - //endregion - - //region > sequence (property) - - public static class SequenceDomainEvent extends PropertyDomainEvent { - } - - /** - * The 0-based additional identifier of a published event within the given {@link #getTransactionId() transaction}. - * - *

- * The combination of ({@link #getTransactionId() transactionId}, {@link #getSequence() sequence}) makes up the - * primary key. - */ - @javax.jdo.annotations.PrimaryKey - @javax.jdo.annotations.Column(position = 1) - @Property( - domainEvent = SequenceDomainEvent.class - ) - @Getter @Setter - private int sequence; - - //endregion - - //region > eventType (property) - - public static class EventTypeDomainEvent extends PropertyDomainEvent { - } - - @javax.jdo.annotations.Column(allowsNull="false", length=JdoColumnLength.PublishedEvent.EVENT_TYPE, position = 2) - @Property( - domainEvent = EventTypeDomainEvent.class - ) - @Getter @Setter - private PublishedEventType eventType; - //endregion - - //region > targetClass (property) - - public static class TargetClassDomainEvent extends PropertyDomainEvent { } - - @javax.jdo.annotations.Column(allowsNull="true", length=JdoColumnLength.TARGET_CLASS, position = 6) - @Property( - domainEvent = TargetClassDomainEvent.class - ) - @PropertyLayout( - named = "Class", - typicalLength = 30 - ) - @Getter - private String targetClass; - - public void setTargetClass(final String targetClass) { - this.targetClass = Util.abbreviated(targetClass, JdoColumnLength.TARGET_CLASS); - } - //endregion - - //region > targetAction (property) - - public static class TargetActionDomainEvent extends PropertyDomainEvent { - } - - /** - * Only populated for {@link EventType#ACTION_INVOCATION} - */ - @javax.jdo.annotations.Column(allowsNull="true", length=JdoColumnLength.TARGET_ACTION, position = 5) - @Property( - domainEvent = TargetActionDomainEvent.class - ) - @PropertyLayout( - named = "Action", - typicalLength = 30 - ) - @Getter - private String targetAction; - - public void setTargetAction(final String targetAction) { - this.targetAction = Util.abbreviated(targetAction, JdoColumnLength.TARGET_ACTION); - } - //endregion - - //region > targetStrDomain (property) - - public static class TargetStrDomainEvent extends PropertyDomainEvent { - } - - @javax.jdo.annotations.Column(allowsNull="true", length=JdoColumnLength.BOOKMARK, name="target", position = 7) - @Property( - domainEvent = TargetStrDomainEvent.class - ) - @PropertyLayout( - named = "Object" - ) - @Getter @Setter - private String targetStr; - - //endregion - - //region > memberIdentifier (property) - - public static class MemberIdentifierDomainEvent extends PropertyDomainEvent { - } - - /** - * Holds a string representation of the invoked action, equivalent to - * {@link Identifier#toClassAndNameIdentityString()}. - * - *

- * Only populated for {@link EventType#ACTION_INVOCATION}, - * returns null otherwise. - * - *

- * 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. - */ - @javax.jdo.annotations.Column(allowsNull="true", length=JdoColumnLength.MEMBER_IDENTIFIER, position = 3) - @Property( - domainEvent = MemberIdentifierDomainEvent.class - ) - @PropertyLayout( - hidden = Where.ALL_TABLES, - typicalLength = 60 - ) - @Getter - private String memberIdentifier; - - - public void setMemberIdentifier(final String actionIdentifier) { - this.memberIdentifier = Util.abbreviated(actionIdentifier, JdoColumnLength.MEMBER_IDENTIFIER); - } - - //endregion - - //region > serializedForm (property) - - public static class SerializedFormDomainEvent extends PropertyDomainEvent { - } - - @javax.jdo.annotations.Column(allowsNull="true", jdbcType="CLOB", sqlType="LONGVARCHAR", position = 4) - @Property( - domainEvent = SerializedFormDomainEvent.class - ) - @Getter @Setter - @PropertyLayout( - hidden = Where.ALL_TABLES, - multiLine = 14 - ) - private String serializedForm; - - //endregion - - //region > toString - - @Override - public String toString() { - return ObjectContracts.toString(this, "timestamp","user","eventType","memberIdentifier"); - } - //endregion +@DomainObjectLayout(named = "Published Event") +public class PublishedEvent extends PublishedEventAbstract { } diff --git a/modules/spi/publishmq/impl/jdo/src/main/java/org/isisaddons/module/publishmq/dom/jdo/events/PublishedEventAbstract.java b/modules/spi/publishmq/impl/jdo/src/main/java/org/isisaddons/module/publishmq/dom/jdo/events/PublishedEventAbstract.java new file mode 100644 index 000000000..4ffb8a622 --- /dev/null +++ b/modules/spi/publishmq/impl/jdo/src/main/java/org/isisaddons/module/publishmq/dom/jdo/events/PublishedEventAbstract.java @@ -0,0 +1,220 @@ +package org.isisaddons.module.publishmq.dom.jdo.events; + +import java.text.SimpleDateFormat; +import java.util.UUID; + +import javax.jdo.annotations.IdentityType; +import javax.jdo.annotations.Inheritance; +import javax.jdo.annotations.InheritanceStrategy; + +import org.apache.isis.applib.Identifier; +import org.apache.isis.applib.annotation.Programmatic; +import org.apache.isis.applib.annotation.Property; +import org.apache.isis.applib.annotation.PropertyLayout; +import org.apache.isis.applib.annotation.Where; +import org.apache.isis.applib.services.HasTransactionId; +import org.apache.isis.applib.services.HasUsername; +import org.apache.isis.applib.services.RepresentsInteractionMemberExecution; +import org.apache.isis.applib.services.publish.EventType; +import org.apache.isis.applib.util.TitleBuffer; +import org.apache.isis.objectstore.jdo.applib.service.DomainChangeJdoAbstract; +import org.apache.isis.objectstore.jdo.applib.service.JdoColumnLength; +import org.apache.isis.objectstore.jdo.applib.service.Util; +import org.isisaddons.module.publishmq.PublishMqModule; + +import lombok.Getter; +import lombok.Setter; + + +@javax.jdo.annotations.PersistenceCapable( + identityType=IdentityType.APPLICATION, + schema = "isispublishmq", + table="PublishedEventAbstract", + objectIdClass=PublishedEventPK.class) +@Inheritance(strategy = InheritanceStrategy.COMPLETE_TABLE) +public abstract class PublishedEventAbstract extends DomainChangeJdoAbstract implements HasTransactionId, + RepresentsInteractionMemberExecution, HasUsername { + + public static abstract class PropertyDomainEvent + extends PublishMqModule.PropertyDomainEvent { } + public static abstract class CollectionDomainEvent + extends PublishMqModule.CollectionDomainEvent { } + public static abstract class ActionDomainEvent + extends PublishMqModule.ActionDomainEvent { } + + public PublishedEventAbstract() { + super(ChangeType.PUBLISHED_INTERACTION); + } + + public String title() { + // nb: not thread-safe + // formats defined in https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html + final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + + final TitleBuffer buf = new TitleBuffer(); + buf.append(format.format(getTimestamp())); + buf.append(" ").append(getMemberIdentifier()); + return buf.toString(); + } + + + + @javax.jdo.annotations.Column(allowsNull="false", length=255, position = 9) + @Property(hidden = Where.EVERYWHERE) + @Getter @Setter + private String title; + + + + public static class UserDomainEvent extends PropertyDomainEvent { } + @javax.jdo.annotations.Column(allowsNull="false", length=50, position = 10) + @Property(domainEvent = UserDomainEvent.class) + @Getter @Setter + private String user; + + @Override + @Programmatic + public String getUsername() { + return getUser(); + } + + + + public static class TimestampDomainEvent extends PropertyDomainEvent { } + @javax.jdo.annotations.Persistent + @javax.jdo.annotations.Column(allowsNull="false", position = 8) + @Property(domainEvent = TimestampDomainEvent.class) + @Getter @Setter + private java.sql.Timestamp timestamp; + + + public static class TransactionIdDomainEvent extends PropertyDomainEvent { } + + /** + * The unique identifier (a GUID) of the transaction in which this published event was persisted. + * + *

+ * The combination of ({@link #getTransactionId() transactionId}, {@link #getSequence() sequence}) makes up the + * primary key. + *

+ */ + @javax.jdo.annotations.PrimaryKey + @javax.jdo.annotations.Column(allowsNull="false",length=JdoColumnLength.TRANSACTION_ID, position = 0) + @Property(domainEvent = TransactionIdDomainEvent.class) + @PropertyLayout(typicalLength = JdoColumnLength.TRANSACTION_ID) + @Getter @Setter + private UUID transactionId; + + + + public static class SequenceDomainEvent extends PropertyDomainEvent { } + /** + * The 0-based additional identifier of a published event within the given {@link #getTransactionId() transaction}. + * + *

+ * The combination of ({@link #getTransactionId() transactionId}, {@link #getSequence() sequence}) makes up the + * primary key. + *

+ */ + @javax.jdo.annotations.PrimaryKey + @javax.jdo.annotations.Column(position = 1) + @Property(domainEvent = SequenceDomainEvent.class) + @Getter @Setter + private int sequence; + + + + public static class EventTypeDomainEvent extends PropertyDomainEvent { } + @javax.jdo.annotations.Column(allowsNull="false", length=JdoColumnLength.PublishedEvent.EVENT_TYPE, position = 2) + @Property(domainEvent = EventTypeDomainEvent.class) + @Getter @Setter + private PublishedEventType eventType; + + + + public static class TargetClassDomainEvent extends PropertyDomainEvent { } + @javax.jdo.annotations.Column(allowsNull="true", length=JdoColumnLength.TARGET_CLASS, position = 6) + @Property(domainEvent = TargetClassDomainEvent.class) + @PropertyLayout(named = "Class", typicalLength = 30) + @Getter + private String targetClass; + + public void setTargetClass(final String targetClass) { + this.targetClass = Util.abbreviated(targetClass, JdoColumnLength.TARGET_CLASS); + } + + + + public static class TargetActionDomainEvent extends PropertyDomainEvent { } + /** + * Only populated for {@link EventType#ACTION_INVOCATION} + */ + @javax.jdo.annotations.Column(allowsNull="true", length=JdoColumnLength.TARGET_ACTION, position = 5) + @Property(domainEvent = TargetActionDomainEvent.class) + @PropertyLayout(named = "Action", typicalLength = 30) + @Getter + private String targetAction; + + public void setTargetAction(final String targetAction) { + this.targetAction = Util.abbreviated(targetAction, JdoColumnLength.TARGET_ACTION); + } + + + + public static class TargetStrDomainEvent extends PropertyDomainEvent { } + @javax.jdo.annotations.Column(allowsNull="true", length=JdoColumnLength.BOOKMARK, name="target", position = 7) + @Property(domainEvent = TargetStrDomainEvent.class) + @PropertyLayout(named = "Object") + @Getter @Setter + private String targetStr; + + + + public static class MemberIdentifierDomainEvent extends PropertyDomainEvent { } + /** + * Holds a string representation of the invoked action, equivalent to + * {@link Identifier#toClassAndNameIdentityString()}. + * + *

+ * Only populated for {@link EventType#ACTION_INVOCATION}, + * returns null otherwise. + * + *

+ * 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. + */ + @javax.jdo.annotations.Column(allowsNull="true", length=JdoColumnLength.MEMBER_IDENTIFIER, position = 3) + @Property(domainEvent = MemberIdentifierDomainEvent.class) + @PropertyLayout( + hidden = Where.ALL_TABLES, + typicalLength = 60 + ) + @Getter + private String memberIdentifier; + + public void setMemberIdentifier(final String actionIdentifier) { + this.memberIdentifier = Util.abbreviated(actionIdentifier, JdoColumnLength.MEMBER_IDENTIFIER); + } + + + + public static class SerializedFormDomainEvent extends PropertyDomainEvent { } + @javax.jdo.annotations.Column(allowsNull="true", jdbcType="CLOB", sqlType="LONGVARCHAR", position = 4) + @Property(domainEvent = SerializedFormDomainEvent.class) + @PropertyLayout(hidden = Where.ALL_TABLES, multiLine = 14) + @Getter @Setter + private String serializedForm; + + + + @Override public String toString() { + return "PublishedEventAbstract{" + + "timestamp='" + timestamp + '\'' + + ", user=" + user + + ", eventType=" + eventType + + ", memberIdentifier='" + memberIdentifier + '\'' + + '}'; + } + +}