Skip to content

Commit 94e20c1

Browse files
authored
Full Continuous Deployment CDEvents to render as CloudEvent and schema validation (#50)
* Adding first continuous deployment event * Added the rest of the Continuous Deployment Events
1 parent 906ff00 commit 94e20c1

16 files changed

+2278
-5
lines changed

src/main/java/dev/cdevents/constants/CDEventConstants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public enum SubjectType {
3232
*/
3333
ENVIRONMENT("environment"),
3434

35+
/**
36+
* Subject Type Service.
37+
*/
38+
SERVICE("service"),
39+
3540
/**
3641
* Subject type branch.
3742
*/
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
package dev.cdevents.events;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import dev.cdevents.constants.CDEventConstants;
5+
import dev.cdevents.models.CDEvent;
6+
import dev.cdevents.models.EnvironmentDeletedSubject;
7+
8+
import java.net.URI;
9+
10+
public class EnvironmentDeletedCDEvent extends CDEvent {
11+
12+
private static final String CDEVENT_VERSION = "0.1.0";
13+
@JsonProperty(required = true)
14+
private EnvironmentDeletedSubject subject;
15+
16+
/**
17+
* Constructor to init CDEvent and set the Subject for {@link EnvironmentDeletedCDEvent}.
18+
*/
19+
public EnvironmentDeletedCDEvent() {
20+
initCDEvent(currentCDEventType());
21+
setSubject(new EnvironmentDeletedSubject(CDEventConstants.SubjectType.ENVIRONMENT));
22+
}
23+
24+
/**
25+
* @return subject
26+
*/
27+
public EnvironmentDeletedSubject getSubject() {
28+
return subject;
29+
}
30+
31+
/**
32+
* @param subject
33+
*/
34+
public void setSubject(EnvironmentDeletedSubject subject) {
35+
this.subject = subject;
36+
}
37+
38+
/**
39+
* @return the current CDEvent type
40+
*/
41+
@Override
42+
public String currentCDEventType() {
43+
return CDEventConstants.CDEventTypes.EnvironmentDeletedEvent.getEventType().concat(CDEVENT_VERSION);
44+
}
45+
46+
/**
47+
* @return the environment-Deleted-event schema URL
48+
*/
49+
@Override
50+
public String schemaURL() {
51+
return String.format("https://cdevents.dev/%s/schema/environment-deleted-event", CDEventConstants.CDEVENTS_SPEC_VERSION);
52+
}
53+
54+
/**
55+
* @return the environment-Deleted-event schema Json
56+
*/
57+
@Override
58+
public String eventSchema() {
59+
return "{\n" +
60+
" \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n" +
61+
" \"$id\": \"https://cdevents.dev/0.1.2/schema/environment-deleted-event\",\n" +
62+
" \"properties\": {\n" +
63+
" \"context\": {\n" +
64+
" \"properties\": {\n" +
65+
" \"version\": {\n" +
66+
" \"type\": \"string\",\n" +
67+
" \"minLength\": 1\n" +
68+
" },\n" +
69+
" \"id\": {\n" +
70+
" \"type\": \"string\",\n" +
71+
" \"minLength\": 1\n" +
72+
" },\n" +
73+
" \"source\": {\n" +
74+
" \"type\": \"string\",\n" +
75+
" \"minLength\": 1\n" +
76+
" },\n" +
77+
" \"type\": {\n" +
78+
" \"type\": \"string\",\n" +
79+
" \"enum\": [\n" +
80+
" \"dev.cdevents.environment.deleted.0.1.0\"\n" +
81+
" ],\n" +
82+
" \"default\": \"dev.cdevents.environment.deleted.0.1.0\"\n" +
83+
" },\n" +
84+
" \"timestamp\": {\n" +
85+
" \"type\": \"string\",\n" +
86+
" \"format\": \"date-time\"\n" +
87+
" }\n" +
88+
" },\n" +
89+
" \"additionalProperties\": false,\n" +
90+
" \"type\": \"object\",\n" +
91+
" \"required\": [\n" +
92+
" \"version\",\n" +
93+
" \"id\",\n" +
94+
" \"source\",\n" +
95+
" \"type\",\n" +
96+
" \"timestamp\"\n" +
97+
" ]\n" +
98+
" },\n" +
99+
" \"subject\": {\n" +
100+
" \"properties\": {\n" +
101+
" \"id\": {\n" +
102+
" \"type\": \"string\",\n" +
103+
" \"minLength\": 1\n" +
104+
" },\n" +
105+
" \"source\": {\n" +
106+
" \"type\": \"string\"\n" +
107+
" },\n" +
108+
" \"type\": {\n" +
109+
" \"type\": \"string\",\n" +
110+
" \"minLength\": 1\n" +
111+
" },\n" +
112+
" \"content\": {\n" +
113+
" \"properties\": {\n" +
114+
" \"name\": {\n" +
115+
" \"type\": \"string\"\n" +
116+
" }\n" +
117+
" },\n" +
118+
" \"additionalProperties\": false,\n" +
119+
" \"type\": \"object\"\n" +
120+
" }\n" +
121+
" },\n" +
122+
" \"additionalProperties\": false,\n" +
123+
" \"type\": \"object\",\n" +
124+
" \"required\": [\n" +
125+
" \"id\",\n" +
126+
" \"type\",\n" +
127+
" \"content\"\n" +
128+
" ]\n" +
129+
" },\n" +
130+
" \"customData\": {\n" +
131+
" \"oneOf\": [\n" +
132+
" {\n" +
133+
" \"type\": \"object\"\n" +
134+
" },\n" +
135+
" {\n" +
136+
" \"type\": \"string\",\n" +
137+
" \"contentEncoding\": \"base64\"\n" +
138+
" }\n" +
139+
" ]\n" +
140+
" },\n" +
141+
" \"customDataContentType\": {\n" +
142+
" \"type\": \"string\"\n" +
143+
" }\n" +
144+
" },\n" +
145+
" \"additionalProperties\": false,\n" +
146+
" \"type\": \"object\",\n" +
147+
" \"required\": [\n" +
148+
" \"context\",\n" +
149+
" \"subject\"\n" +
150+
" ]\n" +
151+
"}";
152+
}
153+
154+
/**
155+
* @param subjectId
156+
* sets the subject Id
157+
*/
158+
public void setSubjectId(String subjectId) {
159+
getSubject().setId(subjectId);
160+
}
161+
162+
/**
163+
* @param subjectSource
164+
* sets the subject source
165+
*/
166+
public void setSubjectSource(URI subjectSource) {
167+
getSubject().setSource(subjectSource);
168+
}
169+
170+
/**
171+
* @param subjectName
172+
* sets the subject name
173+
*/
174+
public void setSubjectName(String subjectName) {
175+
getSubject().getContent().setName(subjectName);
176+
}
177+
178+
179+
}
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
package dev.cdevents.events;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import dev.cdevents.constants.CDEventConstants;
5+
import dev.cdevents.models.CDEvent;
6+
import dev.cdevents.models.EnvironmentModifiedSubject;
7+
8+
import java.net.URI;
9+
10+
public class EnvironmentModifiedCDEvent extends CDEvent {
11+
12+
private static final String CDEVENT_VERSION = "0.1.0";
13+
@JsonProperty(required = true)
14+
private EnvironmentModifiedSubject subject;
15+
16+
/**
17+
* Constructor to init CDEvent and set the Subject for {@link EnvironmentModifiedCDEvent}.
18+
*/
19+
public EnvironmentModifiedCDEvent() {
20+
initCDEvent(currentCDEventType());
21+
setSubject(new EnvironmentModifiedSubject(CDEventConstants.SubjectType.ENVIRONMENT));
22+
}
23+
24+
/**
25+
* @return subject
26+
*/
27+
public EnvironmentModifiedSubject getSubject() {
28+
return subject;
29+
}
30+
31+
/**
32+
* @param subject
33+
*/
34+
public void setSubject(EnvironmentModifiedSubject subject) {
35+
this.subject = subject;
36+
}
37+
38+
/**
39+
* @return the current CDEvent type
40+
*/
41+
@Override
42+
public String currentCDEventType() {
43+
return CDEventConstants.CDEventTypes.EnvironmentModifiedEvent.getEventType().concat(CDEVENT_VERSION);
44+
}
45+
46+
/**
47+
* @return the environment-Modified-event schema URL
48+
*/
49+
@Override
50+
public String schemaURL() {
51+
return String.format("https://cdevents.dev/%s/schema/environment-modified-event", CDEventConstants.CDEVENTS_SPEC_VERSION);
52+
}
53+
54+
/**
55+
* @return the environment-Modified-event schema Json
56+
*/
57+
@Override
58+
public String eventSchema() {
59+
return "{\n" +
60+
" \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n" +
61+
" \"$id\": \"https://cdevents.dev/0.1.2/schema/environment-modified-event\",\n" +
62+
" \"properties\": {\n" +
63+
" \"context\": {\n" +
64+
" \"properties\": {\n" +
65+
" \"version\": {\n" +
66+
" \"type\": \"string\",\n" +
67+
" \"minLength\": 1\n" +
68+
" },\n" +
69+
" \"id\": {\n" +
70+
" \"type\": \"string\",\n" +
71+
" \"minLength\": 1\n" +
72+
" },\n" +
73+
" \"source\": {\n" +
74+
" \"type\": \"string\",\n" +
75+
" \"minLength\": 1\n" +
76+
" },\n" +
77+
" \"type\": {\n" +
78+
" \"type\": \"string\",\n" +
79+
" \"enum\": [\n" +
80+
" \"dev.cdevents.environment.modified.0.1.0\"\n" +
81+
" ],\n" +
82+
" \"default\": \"dev.cdevents.environment.modified.0.1.0\"\n" +
83+
" },\n" +
84+
" \"timestamp\": {\n" +
85+
" \"type\": \"string\",\n" +
86+
" \"format\": \"date-time\"\n" +
87+
" }\n" +
88+
" },\n" +
89+
" \"additionalProperties\": false,\n" +
90+
" \"type\": \"object\",\n" +
91+
" \"required\": [\n" +
92+
" \"version\",\n" +
93+
" \"id\",\n" +
94+
" \"source\",\n" +
95+
" \"type\",\n" +
96+
" \"timestamp\"\n" +
97+
" ]\n" +
98+
" },\n" +
99+
" \"subject\": {\n" +
100+
" \"properties\": {\n" +
101+
" \"id\": {\n" +
102+
" \"type\": \"string\",\n" +
103+
" \"minLength\": 1\n" +
104+
" },\n" +
105+
" \"source\": {\n" +
106+
" \"type\": \"string\"\n" +
107+
" },\n" +
108+
" \"type\": {\n" +
109+
" \"type\": \"string\",\n" +
110+
" \"minLength\": 1\n" +
111+
" },\n" +
112+
" \"content\": {\n" +
113+
" \"properties\": {\n" +
114+
" \"name\": {\n" +
115+
" \"type\": \"string\"\n" +
116+
" },\n" +
117+
" \"url\": {\n" +
118+
" \"type\": \"string\"\n" +
119+
" }\n" +
120+
" },\n" +
121+
" \"additionalProperties\": false,\n" +
122+
" \"type\": \"object\"\n" +
123+
" }\n" +
124+
" },\n" +
125+
" \"additionalProperties\": false,\n" +
126+
" \"type\": \"object\",\n" +
127+
" \"required\": [\n" +
128+
" \"id\",\n" +
129+
" \"type\",\n" +
130+
" \"content\"\n" +
131+
" ]\n" +
132+
" },\n" +
133+
" \"customData\": {\n" +
134+
" \"oneOf\": [\n" +
135+
" {\n" +
136+
" \"type\": \"object\"\n" +
137+
" },\n" +
138+
" {\n" +
139+
" \"type\": \"string\",\n" +
140+
" \"contentEncoding\": \"base64\"\n" +
141+
" }\n" +
142+
" ]\n" +
143+
" },\n" +
144+
" \"customDataContentType\": {\n" +
145+
" \"type\": \"string\"\n" +
146+
" }\n" +
147+
" },\n" +
148+
" \"additionalProperties\": false,\n" +
149+
" \"type\": \"object\",\n" +
150+
" \"required\": [\n" +
151+
" \"context\",\n" +
152+
" \"subject\"\n" +
153+
" ]\n" +
154+
"}";
155+
}
156+
157+
/**
158+
* @param subjectId
159+
* sets the subject Id
160+
*/
161+
public void setSubjectId(String subjectId) {
162+
getSubject().setId(subjectId);
163+
}
164+
165+
/**
166+
* @param subjectSource
167+
* sets the subject source
168+
*/
169+
public void setSubjectSource(URI subjectSource) {
170+
getSubject().setSource(subjectSource);
171+
}
172+
173+
/**
174+
* @param subjectName
175+
* sets the subject name
176+
*/
177+
public void setSubjectName(String subjectName) {
178+
getSubject().getContent().setName(subjectName);
179+
}
180+
181+
/**
182+
* @param subjectUrl
183+
* sets the subject URL
184+
*/
185+
public void setSubjectUrl(String subjectUrl) {
186+
getSubject().getContent().setUrl(subjectUrl);
187+
}
188+
189+
190+
}

0 commit comments

Comments
 (0)