Skip to content

Commit 51030d0

Browse files
Jalander Ramagiriafrittoli
authored andcommitted
changes to upgrade Java SDK with v0.3.0 spec
Signed-off-by: Jalander Ramagiri <[email protected]>
1 parent 2e914b3 commit 51030d0

File tree

177 files changed

+9642
-729
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+9642
-729
lines changed

generator/pom.xml

Lines changed: 111 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,22 @@
109109
<includeToString>false</includeToString>
110110
</configuration>
111111
</execution>
112+
<execution>
113+
<id>generate-artifact-signed-from-schema</id>
114+
<phase>generate-sources</phase>
115+
<goals>
116+
<goal>generate</goal>
117+
</goals>
118+
<configuration>
119+
<sourcePaths>
120+
<sourcePath>${parent.project.dir}/spec/schemas/artifactsigned.json</sourcePath>
121+
</sourcePaths>
122+
<outputDirectory>${sdk.project.dir}/src/main/java</outputDirectory>
123+
<targetPackage>dev.cdevents.models.artifact.signed</targetPackage>
124+
<includeHashcodeAndEquals>false</includeHashcodeAndEquals>
125+
<includeToString>false</includeToString>
126+
</configuration>
127+
</execution>
112128
<execution>
113129
<id>generate-branch-created-from-schema</id>
114130
<phase>generate-sources</phase>
@@ -317,6 +333,54 @@
317333
<includeToString>false</includeToString>
318334
</configuration>
319335
</execution>
336+
<execution>
337+
<id>generate-incident-detected-from-schema</id>
338+
<phase>generate-sources</phase>
339+
<goals>
340+
<goal>generate</goal>
341+
</goals>
342+
<configuration>
343+
<sourcePaths>
344+
<sourcePath>${parent.project.dir}/spec/schemas/incidentdetected.json</sourcePath>
345+
</sourcePaths>
346+
<outputDirectory>${sdk.project.dir}/src/main/java</outputDirectory>
347+
<targetPackage>dev.cdevents.models.incident.detected</targetPackage>
348+
<includeHashcodeAndEquals>false</includeHashcodeAndEquals>
349+
<includeToString>false</includeToString>
350+
</configuration>
351+
</execution>
352+
<execution>
353+
<id>generate-incident-reported-from-schema</id>
354+
<phase>generate-sources</phase>
355+
<goals>
356+
<goal>generate</goal>
357+
</goals>
358+
<configuration>
359+
<sourcePaths>
360+
<sourcePath>${parent.project.dir}/spec/schemas/incidentreported.json</sourcePath>
361+
</sourcePaths>
362+
<outputDirectory>${sdk.project.dir}/src/main/java</outputDirectory>
363+
<targetPackage>dev.cdevents.models.incident.reported</targetPackage>
364+
<includeHashcodeAndEquals>false</includeHashcodeAndEquals>
365+
<includeToString>false</includeToString>
366+
</configuration>
367+
</execution>
368+
<execution>
369+
<id>generate-incident-resolved-from-schema</id>
370+
<phase>generate-sources</phase>
371+
<goals>
372+
<goal>generate</goal>
373+
</goals>
374+
<configuration>
375+
<sourcePaths>
376+
<sourcePath>${parent.project.dir}/spec/schemas/incidentresolved.json</sourcePath>
377+
</sourcePaths>
378+
<outputDirectory>${sdk.project.dir}/src/main/java</outputDirectory>
379+
<targetPackage>dev.cdevents.models.incident.resolved</targetPackage>
380+
<includeHashcodeAndEquals>false</includeHashcodeAndEquals>
381+
<includeToString>false</includeToString>
382+
</configuration>
383+
</execution>
320384
<execution>
321385
<id>generate-pipelinerun-finished-from-schema</id>
322386
<phase>generate-sources</phase>
@@ -526,81 +590,113 @@
526590
</configuration>
527591
</execution>
528592
<execution>
529-
<id>generate-testcase-finished-from-schema</id>
593+
<id>generate-testcaserun-finished-from-schema</id>
594+
<phase>generate-sources</phase>
595+
<goals>
596+
<goal>generate</goal>
597+
</goals>
598+
<configuration>
599+
<sourcePaths>
600+
<sourcePath>${parent.project.dir}/spec/schemas/testcaserunfinished.json</sourcePath>
601+
</sourcePaths>
602+
<outputDirectory>${sdk.project.dir}/src/main/java</outputDirectory>
603+
<targetPackage>dev.cdevents.models.testcaserun.finished</targetPackage>
604+
<includeHashcodeAndEquals>false</includeHashcodeAndEquals>
605+
<includeToString>false</includeToString>
606+
</configuration>
607+
</execution>
608+
<execution>
609+
<id>generate-testcaserun-queued-from-schema</id>
610+
<phase>generate-sources</phase>
611+
<goals>
612+
<goal>generate</goal>
613+
</goals>
614+
<configuration>
615+
<sourcePaths>
616+
<sourcePath>${parent.project.dir}/spec/schemas/testcaserunqueued.json</sourcePath>
617+
</sourcePaths>
618+
<outputDirectory>${sdk.project.dir}/src/main/java</outputDirectory>
619+
<targetPackage>dev.cdevents.models.testcaserun.queued</targetPackage>
620+
<includeHashcodeAndEquals>false</includeHashcodeAndEquals>
621+
<includeToString>false</includeToString>
622+
</configuration>
623+
</execution>
624+
<execution>
625+
<id>generate-testcaserun-started-from-schema</id>
530626
<phase>generate-sources</phase>
531627
<goals>
532628
<goal>generate</goal>
533629
</goals>
534630
<configuration>
535631
<sourcePaths>
536-
<sourcePath>${parent.project.dir}/spec/schemas/testcasefinished.json</sourcePath>
632+
<sourcePath>${parent.project.dir}/spec/schemas/testcaserunstarted.json</sourcePath>
537633
</sourcePaths>
538634
<outputDirectory>${sdk.project.dir}/src/main/java</outputDirectory>
539-
<targetPackage>dev.cdevents.models.testcase.finished</targetPackage>
635+
<targetPackage>dev.cdevents.models.testcaserun.started</targetPackage>
540636
<includeHashcodeAndEquals>false</includeHashcodeAndEquals>
541637
<includeToString>false</includeToString>
542638
</configuration>
543639
</execution>
544640
<execution>
545-
<id>generate-testcase-queued-from-schema</id>
641+
<id>generate-testoutput-published-from-schema</id>
546642
<phase>generate-sources</phase>
547643
<goals>
548644
<goal>generate</goal>
549645
</goals>
550646
<configuration>
551647
<sourcePaths>
552-
<sourcePath>${parent.project.dir}/spec/schemas/testcasequeued.json</sourcePath>
648+
<sourcePath>${parent.project.dir}/spec/schemas/testoutputpublished.json</sourcePath>
553649
</sourcePaths>
554650
<outputDirectory>${sdk.project.dir}/src/main/java</outputDirectory>
555-
<targetPackage>dev.cdevents.models.testcase.queued</targetPackage>
651+
<targetPackage>dev.cdevents.models.testoutput.published</targetPackage>
556652
<includeHashcodeAndEquals>false</includeHashcodeAndEquals>
557653
<includeToString>false</includeToString>
558654
</configuration>
559655
</execution>
560656
<execution>
561-
<id>generate-testcase-started-from-schema</id>
657+
<id>generate-testsuiterun-finished-from-schema</id>
562658
<phase>generate-sources</phase>
563659
<goals>
564660
<goal>generate</goal>
565661
</goals>
566662
<configuration>
567663
<sourcePaths>
568-
<sourcePath>${parent.project.dir}/spec/schemas/testcasestarted.json</sourcePath>
664+
<sourcePath>${parent.project.dir}/spec/schemas/testsuiterunfinished.json</sourcePath>
569665
</sourcePaths>
570666
<outputDirectory>${sdk.project.dir}/src/main/java</outputDirectory>
571-
<targetPackage>dev.cdevents.models.testcase.started</targetPackage>
667+
<targetPackage>dev.cdevents.models.testsuiterun.finished</targetPackage>
572668
<includeHashcodeAndEquals>false</includeHashcodeAndEquals>
573669
<includeToString>false</includeToString>
574670
</configuration>
575671
</execution>
576672
<execution>
577-
<id>generate-testsuite-finished-from-schema</id>
673+
<id>generate-testsuiterun-queued-from-schema</id>
578674
<phase>generate-sources</phase>
579675
<goals>
580676
<goal>generate</goal>
581677
</goals>
582678
<configuration>
583679
<sourcePaths>
584-
<sourcePath>${parent.project.dir}/spec/schemas/testsuitefinished.json</sourcePath>
680+
<sourcePath>${parent.project.dir}/spec/schemas/testsuiterunqueued.json</sourcePath>
585681
</sourcePaths>
586682
<outputDirectory>${sdk.project.dir}/src/main/java</outputDirectory>
587-
<targetPackage>dev.cdevents.models.testsuite.finished</targetPackage>
683+
<targetPackage>dev.cdevents.models.testsuiterun.queued</targetPackage>
588684
<includeHashcodeAndEquals>false</includeHashcodeAndEquals>
589685
<includeToString>false</includeToString>
590686
</configuration>
591687
</execution>
592688
<execution>
593-
<id>generate-testsuite-started-from-schema</id>
689+
<id>generate-testsuiterun-started-from-schema</id>
594690
<phase>generate-sources</phase>
595691
<goals>
596692
<goal>generate</goal>
597693
</goals>
598694
<configuration>
599695
<sourcePaths>
600-
<sourcePath>${parent.project.dir}/spec/schemas/testsuitestarted.json</sourcePath>
696+
<sourcePath>${parent.project.dir}/spec/schemas/testsuiterunstarted.json</sourcePath>
601697
</sourcePaths>
602698
<outputDirectory>${sdk.project.dir}/src/main/java</outputDirectory>
603-
<targetPackage>dev.cdevents.models.testsuite.started</targetPackage>
699+
<targetPackage>dev.cdevents.models.testsuiterun.started</targetPackage>
604700
<includeHashcodeAndEquals>false</includeHashcodeAndEquals>
605701
<includeToString>false</includeToString>
606702
</configuration>

generator/src/main/java/dev/cdevents/generator/CDEventsGenerator.java

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,28 +98,30 @@ private static SchemaData buildCDEventDataFromJsonSchema(File file) {
9898
try {
9999
JsonNode rootNode = objectMapper.readTree(file);
100100
JsonNode contextNode = rootNode.get("properties").get("context").get("properties");
101+
JsonNode subjectNode = rootNode.get("properties").get("subject").get("properties");
101102
String schemaURL = rootNode.get("$id").asText();
102103

104+
String subjectType = subjectNode.get("type").get("enum").get(0).asText();
103105
String eventType = contextNode.get("type").get("enum").get(0).asText();
104-
log.info("eventType: {}", eventType);
106+
log.info("eventType: {} subjectType: {}", eventType, subjectType);
105107
String[] type = eventType.split("\\.");
106108
String subject = type[SUBJECT_INDEX];
107109
String predicate = type[PREDICATE_INDEX];
108110
String capitalizedSubject = StringUtils.capitalize(subject);
109111
String capitalizedPredicate = StringUtils.capitalize(predicate);
110112
String version = type[VERSION_INDEX];
111113

114+
String upperCaseSubject = getUpperCaseSubjectType(subjectType);
112115
//set the Schema JsonNode required values to schemaData
113116
schemaData.setSchemaURL(schemaURL);
114117
schemaData.setSubject(subject);
115118
schemaData.setPredicate(predicate);
116119
schemaData.setCapitalizedSubject(capitalizedSubject);
117120
schemaData.setCapitalizedPredicate(capitalizedPredicate);
118121
schemaData.setSchemaFileName(file.getName());
119-
schemaData.setUpperCaseSubject(subject.toUpperCase());
122+
schemaData.setUpperCaseSubject(upperCaseSubject);
120123
schemaData.setVersion(version);
121124

122-
JsonNode subjectNode = rootNode.get("properties").get("subject").get("properties");
123125
JsonNode subjectContentNode = subjectNode.get("content").get("properties");
124126
updateSubjectContentProperties(schemaData, subjectContentNode);
125127
} catch (IOException e) {
@@ -129,6 +131,18 @@ private static SchemaData buildCDEventDataFromJsonSchema(File file) {
129131
return schemaData;
130132
}
131133

134+
private static String getUpperCaseSubjectType(String subjectType) {
135+
StringBuilder sb = new StringBuilder();
136+
subjectType.chars().forEachOrdered(c-> {
137+
char currentChar = (char) c;
138+
if (Character.isUpperCase(currentChar)) {
139+
sb.append('_');
140+
}
141+
sb.append(currentChar);
142+
});
143+
return sb.toString().toUpperCase();
144+
}
145+
132146
private static void updateSubjectContentProperties(SchemaData schemaData, JsonNode subjectContentNode) {
133147
Iterator<Map.Entry<String, JsonNode>> contentProps = subjectContentNode.fields();
134148
List<SchemaData.ContentField> contentFields = new ArrayList<>();
@@ -138,18 +152,36 @@ private static void updateSubjectContentProperties(SchemaData schemaData, JsonNo
138152
String contentField = contentMap.getKey();
139153
String capitalizedContentField = StringUtils.capitalize(contentField);
140154
JsonNode contentNode = contentMap.getValue();
155+
String dataType = "";
141156
if (!contentNode.get("type").asText().equals("object")) {
142-
contentFields.add(new SchemaData.ContentField(contentField, capitalizedContentField, "String"));
157+
if(contentNode.get("format") != null && contentNode.get("format").asText().equalsIgnoreCase("uri")) {
158+
dataType = "URI";
159+
} else if (contentNode.get("enum") != null) {
160+
dataType = "Content."+ capitalizedContentField;
161+
} else {
162+
dataType = "String";
163+
}
164+
contentFields.add(new SchemaData.ContentField(contentField, capitalizedContentField, dataType));
143165
} else {
144166
schemaData.setObjectName(contentField);
145167
schemaData.setCapitalizedObjectName(capitalizedContentField);
146168
JsonNode contentObjectNode = contentNode.get("properties");
147169
Iterator<String> contentObjectProps = contentObjectNode.fieldNames();
148170
while (contentObjectProps.hasNext()) {
171+
149172
String contentObjField = contentObjectProps.next();
150173
String capitalizedContentObjField = StringUtils.capitalize(contentObjField);
174+
JsonNode fieldNode = contentObjectNode.get(contentObjField);
175+
if(fieldNode.get("format") != null && fieldNode.get("format").asText().equalsIgnoreCase("uri")) {
176+
dataType = "URI";
177+
} else if (fieldNode.get("enum") != null) {
178+
dataType = capitalizedContentField + "." +capitalizedContentObjField;
179+
} else {
180+
dataType = "String";
181+
}
182+
151183
contentObjectFields.add(new SchemaData.ContentObjectField(contentObjField,
152-
capitalizedContentObjField, contentField, capitalizedContentField, "String"));
184+
capitalizedContentObjField, contentField, capitalizedContentField, dataType));
153185
}
154186
}
155187
}

generator/src/main/resources/template/event-template.mustache

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class {{capitalizedSubject}}{{capitalizedPredicate}}CDEvent extends {{cap
6464
{{#getCapitalizedObjectName}}
6565
getSubject().getContent().set{{capitalizedObjectName}}(new {{capitalizedObjectName}}());
6666
{{/getCapitalizedObjectName}}
67-
getSubject().setType(CDEventConstants.SubjectType.{{upperCaseSubject}}.getSubjectType());
67+
getSubject().setType(Subject.Type.{{upperCaseSubject}});
6868
}
6969

7070
/**
@@ -140,6 +140,7 @@ public class {{capitalizedSubject}}{{capitalizedPredicate}}CDEvent extends {{cap
140140
getSubject().setSource(subjectSource.toString());
141141
}
142142

143+
//getContentFields starts
143144

144145
{{#getContentFields}}
145146
/**
@@ -151,6 +152,8 @@ public class {{capitalizedSubject}}{{capitalizedPredicate}}CDEvent extends {{cap
151152

152153
{{/getContentFields}}
153154

155+
//getContentObjectFields starts
156+
154157
{{#getContentObjectFields}}
155158
/**
156159
* @param {{fieldName}}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ private CDEventConstants() {
1818
/**
1919
* CDEvents Version.
2020
*/
21-
public static final String CDEVENTS_SPEC_VERSION = "0.1.2";
21+
public static final String CDEVENTS_SPEC_VERSION = "0.3.0";
2222

2323
public enum SubjectType {
2424

sdk/src/main/java/dev/cdevents/events/ArtifactPackagedCDEvent.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void initCDEvent() {
6262
context.setVersion(CDEventConstants.CDEVENTS_SPEC_VERSION);
6363
getSubject().setContent(new Content());
6464
getSubject().getContent().setChange(new Change());
65-
getSubject().setType(CDEventConstants.SubjectType.ARTIFACT.getSubjectType());
65+
getSubject().setType(Subject.Type.ARTIFACT);
6666
}
6767

6868
/**
@@ -91,7 +91,7 @@ public String currentCDEventType() {
9191

9292
@Override
9393
public String schemaURL() {
94-
return "https://cdevents.dev/0.1.2/schema/artifact-packaged-event";
94+
return "https://cdevents.dev/0.3.0/schema/artifact-packaged-event";
9595
}
9696

9797

@@ -138,8 +138,11 @@ public void setSubjectSource(URI subjectSource) {
138138
getSubject().setSource(subjectSource.toString());
139139
}
140140

141+
//getContentFields starts
141142

142143

144+
//getContentObjectFields starts
145+
143146
/**
144147
* @param id
145148
*/

0 commit comments

Comments
 (0)