Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add artifact created event based on the outbox pattern #5274

Merged
merged 14 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions app/src/main/java/io/apicurio/registry/events/ArtifactCreated.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.apicurio.registry.events;

import io.apicurio.registry.storage.dto.ArtifactMetaDataDto;
import io.apicurio.registry.storage.dto.OutboxEvent;
import org.json.JSONObject;

import java.util.UUID;

import static io.apicurio.registry.storage.StorageEventType.ARTIFACT_CREATED;

public class ArtifactCreated extends OutboxEvent {
private final JSONObject eventPayload;

private ArtifactCreated(String id, String aggregateId, JSONObject eventPayload) {
super(id, aggregateId);
this.eventPayload = eventPayload;
}

public static ArtifactCreated of(ArtifactMetaDataDto artifactMetaDataDto) {
String id = UUID.randomUUID().toString();
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", id).put("groupId", artifactMetaDataDto.getGroupId())
.put("artifactId", artifactMetaDataDto.getArtifactId())
.put("name", artifactMetaDataDto.getName())
.put("description", artifactMetaDataDto.getDescription())
.put("eventType", ARTIFACT_CREATED.name());

return new ArtifactCreated(id,
artifactMetaDataDto.getGroupId() + "-" + artifactMetaDataDto.getArtifactId(), jsonObject);
}

@Override
public String getType() {
return ARTIFACT_CREATED.name();
}

@Override
public JSONObject getPayload() {
return eventPayload;
}
}
37 changes: 37 additions & 0 deletions app/src/main/java/io/apicurio/registry/events/ArtifactDeleted.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.apicurio.registry.events;

import io.apicurio.registry.storage.dto.OutboxEvent;
import org.json.JSONObject;

import java.util.UUID;

import static io.apicurio.registry.storage.StorageEventType.ARTIFACT_DELETED;

public class ArtifactDeleted extends OutboxEvent {

private final JSONObject eventPayload;

private ArtifactDeleted(String id, String aggregateId, JSONObject eventPayload) {
super(id, aggregateId);
this.eventPayload = eventPayload;
}

public static ArtifactDeleted of(String groupId, String artifactId) {
String id = UUID.randomUUID().toString();
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", id).put("groupId", groupId).put("artifactId", artifactId).put("eventType",
ARTIFACT_DELETED.name());

return new ArtifactDeleted(id, groupId + "-" + artifactId, jsonObject);
}

@Override
public String getType() {
return ARTIFACT_DELETED.name();
}

@Override
public JSONObject getPayload() {
return eventPayload;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.apicurio.registry.events;

import io.apicurio.registry.storage.dto.EditableArtifactMetaDataDto;
import io.apicurio.registry.storage.dto.OutboxEvent;
import org.json.JSONObject;

import java.util.UUID;

import static io.apicurio.registry.storage.StorageEventType.ARTIFACT_METADATA_UPDATED;

public class ArtifactMetadataUpdated extends OutboxEvent {

private final JSONObject eventPayload;

private ArtifactMetadataUpdated(String id, String aggregateId, JSONObject eventPayload) {
super(id, aggregateId);
this.eventPayload = eventPayload;
}

public static ArtifactMetadataUpdated of(String groupId, String artifactId,
EditableArtifactMetaDataDto artifactMetaDataDto) {
String id = UUID.randomUUID().toString();
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", id).put("groupId", groupId).put("artifactId", artifactId)
.put("name", artifactMetaDataDto.getName()).put("owner", artifactMetaDataDto.getOwner())
.put("description", artifactMetaDataDto.getDescription())
.put("eventType", ARTIFACT_METADATA_UPDATED.name());

return new ArtifactMetadataUpdated(id, groupId + "-" + artifactId, jsonObject);
}

@Override
public String getType() {
return ARTIFACT_METADATA_UPDATED.name();
}

@Override
public JSONObject getPayload() {
return eventPayload;
}
}
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.storage.dto.RuleConfigurationDto;
import io.apicurio.registry.types.RuleType;
import org.json.JSONObject;

import java.util.UUID;

import static io.apicurio.registry.storage.StorageEventType.ARTIFACT_RULE_CONFIGURED;

public class ArtifactRuleConfigured extends OutboxEvent {
private final JSONObject eventPayload;

private ArtifactRuleConfigured(String id, String aggregateId, JSONObject eventPayload) {
super(id, aggregateId);
this.eventPayload = eventPayload;
}

public static ArtifactRuleConfigured of(String groupId, String artifactId, RuleType ruleType,
RuleConfigurationDto rule) {
String id = UUID.randomUUID().toString();
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", id).put("groupId", groupId).put("artifactId", artifactId)
.put("ruleType", ruleType.value()).put("rule", rule.getConfiguration())
.put("eventType", ARTIFACT_RULE_CONFIGURED.name());

return new ArtifactRuleConfigured(id, groupId + "-" + artifactId, jsonObject);
}

@Override
public String getType() {
return ARTIFACT_RULE_CONFIGURED.name();
}

@Override
public JSONObject getPayload() {
return eventPayload;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.apicurio.registry.events;

import io.apicurio.registry.storage.dto.ArtifactVersionMetaDataDto;
import io.apicurio.registry.storage.dto.OutboxEvent;
import org.json.JSONObject;

import java.util.UUID;

import static io.apicurio.registry.storage.StorageEventType.ARTIFACT_VERSION_CREATED;

public class ArtifactVersionCreated extends OutboxEvent {
private final JSONObject eventPayload;

private ArtifactVersionCreated(String id, String aggregateId, JSONObject eventPayload) {
super(id, aggregateId);
this.eventPayload = eventPayload;
}

public static ArtifactVersionCreated of(ArtifactVersionMetaDataDto versionMetaDataDto) {
String id = UUID.randomUUID().toString();
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", id).put("groupId", versionMetaDataDto.getGroupId())
.put("artifactId", versionMetaDataDto.getArtifactId())
.put("version", versionMetaDataDto.getVersion()).put("name", versionMetaDataDto.getName())
.put("description", versionMetaDataDto.getDescription())
.put("eventType", ARTIFACT_VERSION_CREATED.name());

return new ArtifactVersionCreated(id, versionMetaDataDto.getGroupId() + "-"
+ versionMetaDataDto.getArtifactId() + "-" + versionMetaDataDto.getVersion(), jsonObject);
}

@Override
public String getType() {
return ARTIFACT_VERSION_CREATED.name();
}

@Override
public JSONObject getPayload() {
return eventPayload;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.apicurio.registry.events;

import io.apicurio.registry.storage.dto.OutboxEvent;
import org.json.JSONObject;

import java.util.UUID;

import static io.apicurio.registry.storage.StorageEventType.ARTIFACT_VERSION_DELETED;

public class ArtifactVersionDeleted extends OutboxEvent {

private final JSONObject eventPayload;

private ArtifactVersionDeleted(String id, String aggregateId, JSONObject eventPayload) {
super(id, aggregateId);
this.eventPayload = eventPayload;
}

public static ArtifactVersionDeleted of(String groupId, String artifactId, String version) {
String id = UUID.randomUUID().toString();
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", id).put("groupId", groupId).put("artifactId", artifactId).put("version", version)
.put("eventType", ARTIFACT_VERSION_DELETED.name());

return new ArtifactVersionDeleted(id, groupId + "-" + artifactId + "-" + version, jsonObject);
}

@Override
public String getType() {
return ARTIFACT_VERSION_DELETED.name();
}

@Override
public JSONObject getPayload() {
return eventPayload;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.apicurio.registry.events;

import io.apicurio.registry.storage.dto.EditableVersionMetaDataDto;
import io.apicurio.registry.storage.dto.OutboxEvent;
import org.json.JSONObject;

import java.util.UUID;

import static io.apicurio.registry.storage.StorageEventType.ARTIFACT_VERSION_METADATA_UPDATED;

public class ArtifactVersionMetadataUpdated extends OutboxEvent {

private final JSONObject eventPayload;

private ArtifactVersionMetadataUpdated(String id, String aggregateId, JSONObject eventPayload) {
super(id, aggregateId);
this.eventPayload = eventPayload;
}

public static ArtifactVersionMetadataUpdated of(String groupId, String artifactId, String version,
EditableVersionMetaDataDto editableVersionMetaDataDto) {
String id = UUID.randomUUID().toString();
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", id).put("groupId", groupId).put("artifactId", artifactId).put("version", version)
.put("name", editableVersionMetaDataDto.getName())
.put("description", editableVersionMetaDataDto.getDescription())
.put("eventType", ARTIFACT_VERSION_METADATA_UPDATED.name());

return new ArtifactVersionMetadataUpdated(id, groupId + "-" + artifactId + "-" + version, jsonObject);
}

@Override
public String getType() {
return ARTIFACT_VERSION_METADATA_UPDATED.name();
}

@Override
public JSONObject getPayload() {
return eventPayload;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.apicurio.registry.events;

import io.apicurio.registry.storage.dto.OutboxEvent;
import io.apicurio.registry.storage.dto.RuleConfigurationDto;
import io.apicurio.registry.types.RuleType;
import org.json.JSONObject;

import java.util.UUID;

import static io.apicurio.registry.storage.StorageEventType.GLOBAL_RULE_CONFIGURED;

public class GlobalRuleConfigured extends OutboxEvent {
private final JSONObject eventPayload;

private GlobalRuleConfigured(String id, String aggregateId, JSONObject eventPayload) {
super(id, aggregateId);
this.eventPayload = eventPayload;
}

public static GlobalRuleConfigured of(RuleType ruleType, RuleConfigurationDto rule) {
String id = UUID.randomUUID().toString();
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", id).put("ruleType", ruleType.value()).put("rule", rule.getConfiguration())
.put("eventType", GLOBAL_RULE_CONFIGURED.name());

return new GlobalRuleConfigured(id, ruleType.value(), jsonObject);
}

@Override
public String getType() {
return GLOBAL_RULE_CONFIGURED.name();
}

@Override
public JSONObject getPayload() {
return eventPayload;
}
}
37 changes: 37 additions & 0 deletions app/src/main/java/io/apicurio/registry/events/GroupCreated.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.apicurio.registry.events;

import io.apicurio.registry.storage.dto.GroupMetaDataDto;
import io.apicurio.registry.storage.dto.OutboxEvent;
import org.json.JSONObject;

import java.util.UUID;

import static io.apicurio.registry.storage.StorageEventType.GROUP_CREATED;

public class GroupCreated extends OutboxEvent {
private final JSONObject eventPayload;

private GroupCreated(String id, String aggregateId, JSONObject eventPayload) {
super(id, aggregateId);
this.eventPayload = eventPayload;
}

public static GroupCreated of(GroupMetaDataDto groupMetaDataDto) {
String id = UUID.randomUUID().toString();
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", id).put("groupId", groupMetaDataDto.getGroupId()).put("eventType",
GROUP_CREATED.name());

return new GroupCreated(id, groupMetaDataDto.getGroupId(), jsonObject);
}

@Override
public String getType() {
return GROUP_CREATED.name();
}

@Override
public JSONObject getPayload() {
return eventPayload;
}
}
Loading
Loading