Skip to content

Full Continuous Deployment CDEvents to render as CloudEvent and schema validation #50

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

Merged
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
5 changes: 5 additions & 0 deletions src/main/java/dev/cdevents/constants/CDEventConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public enum SubjectType {
*/
ENVIRONMENT("environment"),

/**
* Subject Type Service.
*/
SERVICE("service"),

/**
* Subject type branch.
*/
Expand Down
179 changes: 179 additions & 0 deletions src/main/java/dev/cdevents/events/EnvironmentDeletedCDEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
package dev.cdevents.events;

import com.fasterxml.jackson.annotation.JsonProperty;
import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.models.CDEvent;
import dev.cdevents.models.EnvironmentDeletedSubject;

import java.net.URI;

public class EnvironmentDeletedCDEvent extends CDEvent {

private static final String CDEVENT_VERSION = "0.1.0";
@JsonProperty(required = true)
private EnvironmentDeletedSubject subject;

/**
* Constructor to init CDEvent and set the Subject for {@link EnvironmentDeletedCDEvent}.
*/
public EnvironmentDeletedCDEvent() {
initCDEvent(currentCDEventType());
setSubject(new EnvironmentDeletedSubject(CDEventConstants.SubjectType.ENVIRONMENT));
}

/**
* @return subject
*/
public EnvironmentDeletedSubject getSubject() {
return subject;
}

/**
* @param subject
*/
public void setSubject(EnvironmentDeletedSubject subject) {
this.subject = subject;
}

/**
* @return the current CDEvent type
*/
@Override
public String currentCDEventType() {
return CDEventConstants.CDEventTypes.EnvironmentDeletedEvent.getEventType().concat(CDEVENT_VERSION);
}

/**
* @return the environment-Deleted-event schema URL
*/
@Override
public String schemaURL() {
return String.format("https://cdevents.dev/%s/schema/environment-deleted-event", CDEventConstants.CDEVENTS_SPEC_VERSION);
}

/**
* @return the environment-Deleted-event schema Json
*/
@Override
public String eventSchema() {
return "{\n" +
" \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n" +
" \"$id\": \"https://cdevents.dev/0.1.2/schema/environment-deleted-event\",\n" +
" \"properties\": {\n" +
" \"context\": {\n" +
" \"properties\": {\n" +
" \"version\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"id\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"source\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"type\": {\n" +
" \"type\": \"string\",\n" +
" \"enum\": [\n" +
" \"dev.cdevents.environment.deleted.0.1.0\"\n" +
" ],\n" +
" \"default\": \"dev.cdevents.environment.deleted.0.1.0\"\n" +
" },\n" +
" \"timestamp\": {\n" +
" \"type\": \"string\",\n" +
" \"format\": \"date-time\"\n" +
" }\n" +
" },\n" +
" \"additionalProperties\": false,\n" +
" \"type\": \"object\",\n" +
" \"required\": [\n" +
" \"version\",\n" +
" \"id\",\n" +
" \"source\",\n" +
" \"type\",\n" +
" \"timestamp\"\n" +
" ]\n" +
" },\n" +
" \"subject\": {\n" +
" \"properties\": {\n" +
" \"id\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"source\": {\n" +
" \"type\": \"string\"\n" +
" },\n" +
" \"type\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"content\": {\n" +
" \"properties\": {\n" +
" \"name\": {\n" +
" \"type\": \"string\"\n" +
" }\n" +
" },\n" +
" \"additionalProperties\": false,\n" +
" \"type\": \"object\"\n" +
" }\n" +
" },\n" +
" \"additionalProperties\": false,\n" +
" \"type\": \"object\",\n" +
" \"required\": [\n" +
" \"id\",\n" +
" \"type\",\n" +
" \"content\"\n" +
" ]\n" +
" },\n" +
" \"customData\": {\n" +
" \"oneOf\": [\n" +
" {\n" +
" \"type\": \"object\"\n" +
" },\n" +
" {\n" +
" \"type\": \"string\",\n" +
" \"contentEncoding\": \"base64\"\n" +
" }\n" +
" ]\n" +
" },\n" +
" \"customDataContentType\": {\n" +
" \"type\": \"string\"\n" +
" }\n" +
" },\n" +
" \"additionalProperties\": false,\n" +
" \"type\": \"object\",\n" +
" \"required\": [\n" +
" \"context\",\n" +
" \"subject\"\n" +
" ]\n" +
"}";
}

/**
* @param subjectId
* sets the subject Id
*/
public void setSubjectId(String subjectId) {
getSubject().setId(subjectId);
}

/**
* @param subjectSource
* sets the subject source
*/
public void setSubjectSource(URI subjectSource) {
getSubject().setSource(subjectSource);
}

/**
* @param subjectName
* sets the subject name
*/
public void setSubjectName(String subjectName) {
getSubject().getContent().setName(subjectName);
}


}
190 changes: 190 additions & 0 deletions src/main/java/dev/cdevents/events/EnvironmentModifiedCDEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
package dev.cdevents.events;

import com.fasterxml.jackson.annotation.JsonProperty;
import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.models.CDEvent;
import dev.cdevents.models.EnvironmentModifiedSubject;

import java.net.URI;

public class EnvironmentModifiedCDEvent extends CDEvent {

private static final String CDEVENT_VERSION = "0.1.0";
@JsonProperty(required = true)
private EnvironmentModifiedSubject subject;

/**
* Constructor to init CDEvent and set the Subject for {@link EnvironmentModifiedCDEvent}.
*/
public EnvironmentModifiedCDEvent() {
initCDEvent(currentCDEventType());
setSubject(new EnvironmentModifiedSubject(CDEventConstants.SubjectType.ENVIRONMENT));
}

/**
* @return subject
*/
public EnvironmentModifiedSubject getSubject() {
return subject;
}

/**
* @param subject
*/
public void setSubject(EnvironmentModifiedSubject subject) {
this.subject = subject;
}

/**
* @return the current CDEvent type
*/
@Override
public String currentCDEventType() {
return CDEventConstants.CDEventTypes.EnvironmentModifiedEvent.getEventType().concat(CDEVENT_VERSION);
}

/**
* @return the environment-Modified-event schema URL
*/
@Override
public String schemaURL() {
return String.format("https://cdevents.dev/%s/schema/environment-modified-event", CDEventConstants.CDEVENTS_SPEC_VERSION);
}

/**
* @return the environment-Modified-event schema Json
*/
@Override
public String eventSchema() {
return "{\n" +
" \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n" +
" \"$id\": \"https://cdevents.dev/0.1.2/schema/environment-modified-event\",\n" +
" \"properties\": {\n" +
" \"context\": {\n" +
" \"properties\": {\n" +
" \"version\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"id\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"source\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"type\": {\n" +
" \"type\": \"string\",\n" +
" \"enum\": [\n" +
" \"dev.cdevents.environment.modified.0.1.0\"\n" +
" ],\n" +
" \"default\": \"dev.cdevents.environment.modified.0.1.0\"\n" +
" },\n" +
" \"timestamp\": {\n" +
" \"type\": \"string\",\n" +
" \"format\": \"date-time\"\n" +
" }\n" +
" },\n" +
" \"additionalProperties\": false,\n" +
" \"type\": \"object\",\n" +
" \"required\": [\n" +
" \"version\",\n" +
" \"id\",\n" +
" \"source\",\n" +
" \"type\",\n" +
" \"timestamp\"\n" +
" ]\n" +
" },\n" +
" \"subject\": {\n" +
" \"properties\": {\n" +
" \"id\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"source\": {\n" +
" \"type\": \"string\"\n" +
" },\n" +
" \"type\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"content\": {\n" +
" \"properties\": {\n" +
" \"name\": {\n" +
" \"type\": \"string\"\n" +
" },\n" +
" \"url\": {\n" +
" \"type\": \"string\"\n" +
" }\n" +
" },\n" +
" \"additionalProperties\": false,\n" +
" \"type\": \"object\"\n" +
" }\n" +
" },\n" +
" \"additionalProperties\": false,\n" +
" \"type\": \"object\",\n" +
" \"required\": [\n" +
" \"id\",\n" +
" \"type\",\n" +
" \"content\"\n" +
" ]\n" +
" },\n" +
" \"customData\": {\n" +
" \"oneOf\": [\n" +
" {\n" +
" \"type\": \"object\"\n" +
" },\n" +
" {\n" +
" \"type\": \"string\",\n" +
" \"contentEncoding\": \"base64\"\n" +
" }\n" +
" ]\n" +
" },\n" +
" \"customDataContentType\": {\n" +
" \"type\": \"string\"\n" +
" }\n" +
" },\n" +
" \"additionalProperties\": false,\n" +
" \"type\": \"object\",\n" +
" \"required\": [\n" +
" \"context\",\n" +
" \"subject\"\n" +
" ]\n" +
"}";
}

/**
* @param subjectId
* sets the subject Id
*/
public void setSubjectId(String subjectId) {
getSubject().setId(subjectId);
}

/**
* @param subjectSource
* sets the subject source
*/
public void setSubjectSource(URI subjectSource) {
getSubject().setSource(subjectSource);
}

/**
* @param subjectName
* sets the subject name
*/
public void setSubjectName(String subjectName) {
getSubject().getContent().setName(subjectName);
}

/**
* @param subjectUrl
* sets the subject URL
*/
public void setSubjectUrl(String subjectUrl) {
getSubject().getContent().setUrl(subjectUrl);
}


}
Loading