28
28
import software .amazon .awssdk .codegen .model .service .Member ;
29
29
import software .amazon .awssdk .codegen .model .service .ServiceModel ;
30
30
import software .amazon .awssdk .codegen .model .service .Shape ;
31
+ import software .amazon .awssdk .codegen .validation .ModelInvalidException ;
32
+ import software .amazon .awssdk .codegen .validation .ValidationEntry ;
33
+ import software .amazon .awssdk .codegen .validation .ValidationErrorId ;
34
+ import software .amazon .awssdk .codegen .validation .ValidationErrorSeverity ;
31
35
32
36
/**
33
37
* Processor for eventstreams with shared events. This Processor does two things: 1. Apply the duplicateAndRenameSharedEvents
@@ -60,28 +64,34 @@ public void preprocess(ServiceModel serviceModel) {
60
64
Member eventMemberToModify = eventStreamMembers .get (eventEntry .getKey ());
61
65
62
66
if (eventMemberToModify == null ) {
63
- throw new IllegalStateException (
67
+ throw ModelInvalidException .fromEntry (ValidationEntry .create (
68
+ ValidationErrorId .INVALID_CODEGEN_CUSTOMIZATION ,
69
+ ValidationErrorSeverity .DANGER ,
64
70
String .format ("Cannot find event member [%s] in the eventstream [%s] when processing "
65
71
+ "customization config duplicateAndRenameSharedEvents.%s" ,
66
- eventEntry .getKey (), eventStreamName , eventStreamName ));
72
+ eventEntry .getKey (), eventStreamName , eventStreamName ))) ;
67
73
}
68
74
69
75
String shapeToDuplicate = eventMemberToModify .getShape ();
70
76
Shape eventMemberShape = serviceModel .getShape (shapeToDuplicate );
71
77
72
78
if (eventMemberShape == null || !eventMemberShape .isEvent ()) {
73
- throw new IllegalStateException (
79
+ throw ModelInvalidException .fromEntry (ValidationEntry .create (
80
+ ValidationErrorId .INVALID_CODEGEN_CUSTOMIZATION ,
81
+ ValidationErrorSeverity .DANGER ,
74
82
String .format ("Error: [%s] must be an Event shape when processing "
75
83
+ "customization config duplicateAndRenameSharedEvents.%s" ,
76
- eventEntry .getKey (), eventStreamName ));
84
+ eventEntry .getKey (), eventStreamName ))) ;
77
85
}
78
86
79
87
String newShapeName = eventEntry .getValue ();
80
88
if (serviceModel .getShapes ().containsKey (newShapeName )) {
81
- throw new IllegalStateException (
89
+ throw ModelInvalidException .fromEntry (ValidationEntry .create (
90
+ ValidationErrorId .INVALID_CODEGEN_CUSTOMIZATION ,
91
+ ValidationErrorSeverity .DANGER ,
82
92
String .format ("Error: [%s] is already in the model when processing "
83
93
+ "customization config duplicateAndRenameSharedEvents.%s" ,
84
- newShapeName , eventStreamName ));
94
+ newShapeName , eventStreamName ))) ;
85
95
}
86
96
serviceModel .getShapes ().put (newShapeName , duplicateShape (eventMemberShape ));
87
97
eventMemberToModify .setShape (newShapeName );
@@ -105,14 +115,18 @@ private Shape duplicateShape(Shape shape) {
105
115
106
116
private static void validateIsEventStream (Shape shape , String name ) {
107
117
if (shape == null ) {
108
- throw new IllegalStateException (
118
+ throw ModelInvalidException .fromEntry (ValidationEntry .create (
119
+ ValidationErrorId .INVALID_CODEGEN_CUSTOMIZATION ,
120
+ ValidationErrorSeverity .DANGER ,
109
121
String .format ("Cannot find eventstream shape [%s] in the model when processing "
110
- + "customization config duplicateAndRenameSharedEvents.%s" , name , name ));
122
+ + "customization config duplicateAndRenameSharedEvents.%s" , name , name ))) ;
111
123
}
112
124
if (!shape .isEventstream ()) {
113
- throw new IllegalStateException (
125
+ throw ModelInvalidException .fromEntry (ValidationEntry .create (
126
+ ValidationErrorId .INVALID_CODEGEN_CUSTOMIZATION ,
127
+ ValidationErrorSeverity .DANGER ,
114
128
String .format ("Error: [%s] must be an EventStream when processing "
115
- + "customization config duplicateAndRenameSharedEvents.%s" , name , name ));
129
+ + "customization config duplicateAndRenameSharedEvents.%s" , name , name ))) ;
116
130
}
117
131
}
118
132
@@ -129,10 +143,13 @@ public void postprocess(IntermediateModel intermediateModel) {
129
143
if (memberShape != null && memberShape .isEvent ()) {
130
144
if (seenEvents .containsKey (memberShape .getShapeName ())
131
145
&& !seenEvents .get (memberShape .getShapeName ()).equals (shapeModel .getShapeName ())) {
132
- throw new IllegalStateException (
146
+ throw ModelInvalidException .fromEntry (ValidationEntry .create (
147
+ ValidationErrorId .SHARED_EVENTSTREAM_EVENT ,
148
+ ValidationErrorSeverity .DANGER ,
133
149
String .format ("Event shape `%s` is shared between multiple EventStreams. Apply the "
134
150
+ "duplicateAndRenameSharedEvents customization to resolve the issue." ,
135
- memberShape .getShapeName ()));
151
+ memberShape .getShapeName ())
152
+ ));
136
153
}
137
154
seenEvents .put (memberShape .getShapeName (), shapeModel .getShapeName ());
138
155
}
0 commit comments