diff --git a/app/src/main/java/io/apicurio/registry/events/ArtifactVersionStateChanged.java b/app/src/main/java/io/apicurio/registry/events/ArtifactVersionStateChanged.java new file mode 100644 index 0000000000..00706b75d6 --- /dev/null +++ b/app/src/main/java/io/apicurio/registry/events/ArtifactVersionStateChanged.java @@ -0,0 +1,40 @@ +package io.apicurio.registry.events; + +import io.apicurio.registry.storage.dto.OutboxEvent; +import io.apicurio.registry.types.VersionState; +import org.json.JSONObject; + +import java.util.UUID; + +import static io.apicurio.registry.storage.StorageEventType.ARTIFACT_VERSION_STATE_CHANGED; + +public class ArtifactVersionStateChanged extends OutboxEvent { + + private final JSONObject eventPayload; + + private ArtifactVersionStateChanged(String id, String aggregateId, JSONObject eventPayload) { + super(id, aggregateId); + this.eventPayload = eventPayload; + } + + public static ArtifactVersionStateChanged of(String groupId, String artifactId, String version, + VersionState oldState, VersionState newState) { + String id = UUID.randomUUID().toString(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", id).put("groupId", groupId).put("artifactId", artifactId).put("version", version) + .put("oldState", oldState.name()).put("newDate", newState.name()) + .put("eventType", ARTIFACT_VERSION_STATE_CHANGED.name()); + + return new ArtifactVersionStateChanged(id, groupId + "-" + artifactId + "-" + version, jsonObject); + } + + @Override + public String getType() { + return ARTIFACT_VERSION_STATE_CHANGED.name(); + } + + @Override + public JSONObject getPayload() { + return eventPayload; + } +} \ No newline at end of file diff --git a/app/src/main/java/io/apicurio/registry/storage/StorageEventType.java b/app/src/main/java/io/apicurio/registry/storage/StorageEventType.java index 7e58c09315..8c75a1b6db 100644 --- a/app/src/main/java/io/apicurio/registry/storage/StorageEventType.java +++ b/app/src/main/java/io/apicurio/registry/storage/StorageEventType.java @@ -5,5 +5,5 @@ public enum StorageEventType { /** * The READY event type MUST be fired only once. */ - READY, ARTIFACT_CREATED, ARTIFACT_DELETED, ARTIFACT_METADATA_UPDATED, GROUP_CREATED, GROUP_DELETED, GROUP_METADATA_UPDATED, ARTIFACT_VERSION_CREATED, ARTIFACT_VERSION_METADATA_UPDATED, ARTIFACT_VERSION_DELETED, GLOBAL_RULE_CONFIGURED, GROUP_RULE_CONFIGURED, ARTIFACT_RULE_CONFIGURED + READY, ARTIFACT_CREATED, ARTIFACT_DELETED, ARTIFACT_METADATA_UPDATED, GROUP_CREATED, GROUP_DELETED, GROUP_METADATA_UPDATED, ARTIFACT_VERSION_CREATED, ARTIFACT_VERSION_METADATA_UPDATED, ARTIFACT_VERSION_DELETED, GLOBAL_RULE_CONFIGURED, GROUP_RULE_CONFIGURED, ARTIFACT_RULE_CONFIGURED, ARTIFACT_VERSION_STATE_CHANGED } diff --git a/app/src/main/java/io/apicurio/registry/storage/impl/sql/AbstractSqlRegistryStorage.java b/app/src/main/java/io/apicurio/registry/storage/impl/sql/AbstractSqlRegistryStorage.java index 75cd930e13..ac5fa44b8f 100644 --- a/app/src/main/java/io/apicurio/registry/storage/impl/sql/AbstractSqlRegistryStorage.java +++ b/app/src/main/java/io/apicurio/registry/storage/impl/sql/AbstractSqlRegistryStorage.java @@ -13,6 +13,7 @@ import io.apicurio.registry.events.ArtifactVersionCreated; import io.apicurio.registry.events.ArtifactVersionDeleted; import io.apicurio.registry.events.ArtifactVersionMetadataUpdated; +import io.apicurio.registry.events.ArtifactVersionStateChanged; import io.apicurio.registry.events.GlobalRuleConfigured; import io.apicurio.registry.events.GroupCreated; import io.apicurio.registry.events.GroupDeleted; @@ -2064,6 +2065,9 @@ public void updateArtifactVersionState(String groupId, String artifactId, String removeVersionFromBranchRaw(handle, gav, BranchId.DRAFTS); } + outboxEvent.fire(SqlOutboxEvent.of( + ArtifactVersionStateChanged.of(groupId, artifactId, version, currentState, newState))); + return null; }); }