Skip to content

Commit

Permalink
feat(Events): Fire event on state change (#5410)
Browse files Browse the repository at this point in the history
* Fix a problem where getVersionMetaData API operation was not properly returning the modifiedOn

* Fire an event when a version state changes

* spotless:apply
  • Loading branch information
EricWittmann authored Oct 25, 2024
1 parent 26880c0 commit 1656c7b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
});
}
Expand Down

0 comments on commit 1656c7b

Please sign in to comment.