16
16
17
17
package io .swagger .petstore .controller ;
18
18
19
- import com .bugsnag .Bugsnag ;
20
19
import io .swagger .oas .inflector .models .RequestContext ;
21
20
import io .swagger .oas .inflector .models .ResponseContext ;
22
21
import io .swagger .petstore .data .PetData ;
23
22
import io .swagger .petstore .model .Category ;
24
23
import io .swagger .petstore .model .Pet ;
25
24
import io .swagger .petstore .model .Tag ;
25
+ import io .swagger .petstore .notification .Notifier ;
26
+ import io .swagger .petstore .notification .NullNotifier ;
26
27
import io .swagger .petstore .utils .Util ;
27
28
28
29
import javax .ws .rs .core .MediaType ;
34
35
public class PetController {
35
36
36
37
private static PetData petData = new PetData ();
37
- private static Bugsnag bugsnag ;
38
+ private Notifier notifier = new NullNotifier () ;
38
39
39
- static {
40
- String bugsnagApiKey = System .getenv ("BUGSNAG_API_KEY" );
41
- if (bugsnagApiKey != null ) {
42
- bugsnag = new Bugsnag (bugsnagApiKey );
43
- } else {
44
- throw new IllegalStateException ("BUGSNAG_API_KEY environment variable is not set" );
40
+ public PetController () {
41
+ if (System .getenv ("notifierClass" ) != null ) {
42
+ try {
43
+ notifier = (Notifier ) this .getClass ().forName (System .getenv ("notifierClass" )).newInstance ();
44
+ } catch (Exception e ) {
45
+ //
46
+ }
45
47
}
46
48
}
47
49
48
50
public ResponseContext findPetsByStatus (final RequestContext request , final String status ) {
49
51
if (status == null ) {
50
- bugsnag .notify (new RuntimeException ("No status provided" ));
52
+ notifier .notify (new RuntimeException ("No status provided" ));
51
53
return new ResponseContext ()
52
54
.status (Response .Status .BAD_REQUEST )
53
55
.entity ("No status provided. Try again?" );
@@ -56,19 +58,19 @@ public ResponseContext findPetsByStatus(final RequestContext request, final Stri
56
58
final List <Pet > petByStatus = petData .findPetByStatus (status );
57
59
58
60
if (petByStatus == null ) {
59
- bugsnag .notify (new RuntimeException ("Pets not found" ));
61
+ notifier .notify (new RuntimeException ("Pets not found" ));
60
62
return new ResponseContext ().status (Response .Status .NOT_FOUND ).entity ("Pets not found" );
61
63
}
62
64
63
- bugsnag .notify (new RuntimeException ("Pets not found" ));
65
+ notifier .notify (new RuntimeException ("Pets not found" ));
64
66
return new ResponseContext ()
65
67
.contentType (Util .getMediaType (request ))
66
68
.entity (petByStatus );
67
69
}
68
70
69
71
public ResponseContext getPetById (final RequestContext request , final Long petId ) {
70
72
if (petId == null ) {
71
- bugsnag .notify (new RuntimeException ("No petId provided" ));
73
+ notifier .notify (new RuntimeException ("No petId provided" ));
72
74
return new ResponseContext ()
73
75
.status (Response .Status .BAD_REQUEST )
74
76
.entity ("No petId provided. Try again?" );
@@ -82,20 +84,20 @@ public ResponseContext getPetById(final RequestContext request, final Long petId
82
84
.entity (pet );
83
85
}
84
86
85
- bugsnag .notify (new RuntimeException ("Pets not found" ));
87
+ notifier .notify (new RuntimeException ("Pets not found" ));
86
88
return new ResponseContext ().status (Response .Status .NOT_FOUND ).entity ("Pet not found" );
87
89
}
88
90
89
91
public ResponseContext updatePetWithForm (final RequestContext request , final Long petId , final String name , final String status ) {
90
92
if (petId == null ) {
91
- bugsnag .notify (new RuntimeException ("No petId provided" ));
93
+ notifier .notify (new RuntimeException ("No petId provided" ));
92
94
return new ResponseContext ()
93
95
.status (Response .Status .BAD_REQUEST )
94
96
.entity ("No Pet provided. Try again?" );
95
97
}
96
98
97
99
if (name == null ) {
98
- bugsnag .notify (new RuntimeException ("No name provided" ));
100
+ notifier .notify (new RuntimeException ("No name provided" ));
99
101
return new ResponseContext ()
100
102
.status (Response .Status .BAD_REQUEST )
101
103
.entity ("No Name provided. Try again?" );
@@ -105,7 +107,7 @@ public ResponseContext updatePetWithForm(final RequestContext request, final Lon
105
107
final Pet existingPet = petData .getPetById (petId );
106
108
107
109
if (existingPet == null ) {
108
- bugsnag .notify (new RuntimeException ("No pet provided" ));
110
+ notifier .notify (new RuntimeException ("No pet provided" ));
109
111
return new ResponseContext ().status (Response .Status .NOT_FOUND ).entity ("Pet not found" );
110
112
}
111
113
@@ -121,7 +123,7 @@ public ResponseContext updatePetWithForm(final RequestContext request, final Lon
121
123
122
124
public ResponseContext deletePet (final RequestContext request , final String apiKey , final Long petId ) {
123
125
if (petId == null ) {
124
- bugsnag .notify (new RuntimeException ("No petId provided" ));
126
+ notifier .notify (new RuntimeException ("No petId provided" ));
125
127
return new ResponseContext ()
126
128
.status (Response .Status .BAD_REQUEST )
127
129
.entity ("No petId provided. Try again?" );
@@ -138,28 +140,28 @@ public ResponseContext deletePet(final RequestContext request, final String apiK
138
140
.contentType (outputType )
139
141
.entity ("Pet deleted" );
140
142
} else {
141
- bugsnag .notify (new RuntimeException ("Pet couldn't be deleted" ));
143
+ notifier .notify (new RuntimeException ("Pet couldn't be deleted" ));
142
144
return new ResponseContext ().status (Response .Status .NOT_MODIFIED ).entity ("Pet couldn't be deleted." );
143
145
}
144
146
145
147
}
146
148
147
149
public ResponseContext uploadFile (final RequestContext request , final Long petId , final String apiKey , final File file ) {
148
150
if (petId == null ) {
149
- bugsnag .notify (new RuntimeException ("No petId provided" ));
151
+ notifier .notify (new RuntimeException ("No petId provided" ));
150
152
return new ResponseContext ()
151
153
.status (Response .Status .BAD_REQUEST )
152
154
.entity ("No petId provided. Try again?" );
153
155
}
154
156
155
157
if (file == null ) {
156
- bugsnag .notify (new RuntimeException ("No file provided" ));
158
+ notifier .notify (new RuntimeException ("No file provided" ));
157
159
return new ResponseContext ().status (Response .Status .BAD_REQUEST ).entity ("No file uploaded" );
158
160
}
159
161
160
162
final Pet existingPet = petData .getPetById (petId );
161
163
if (existingPet == null ) {
162
- bugsnag .notify (new RuntimeException ("No pet provided" ));
164
+ notifier .notify (new RuntimeException ("No pet provided" ));
163
165
return new ResponseContext ().status (Response .Status .NOT_FOUND ).entity ("Pet not found" );
164
166
}
165
167
@@ -174,14 +176,14 @@ public ResponseContext uploadFile(final RequestContext request, final Long petId
174
176
.contentType (Util .getMediaType (request ))
175
177
.entity (pet );
176
178
} else {
177
- bugsnag .notify (new RuntimeException ("Pet couldn't be updated" ));
179
+ notifier .notify (new RuntimeException ("Pet couldn't be updated" ));
178
180
return new ResponseContext ().status (Response .Status .NOT_MODIFIED ).entity ("Pet couldn't be updated." );
179
181
}
180
182
}
181
183
182
184
public ResponseContext addPet (final RequestContext request , final Pet pet ) {
183
185
if (pet == null ) {
184
- bugsnag .notify (new RuntimeException ("No pet provided" ));
186
+ notifier .notify (new RuntimeException ("No pet provided" ));
185
187
return new ResponseContext ()
186
188
.status (Response .Status .BAD_REQUEST )
187
189
.entity ("No Pet provided. Try again?" );
@@ -202,15 +204,15 @@ public ResponseContext addPet(final RequestContext request, final Long id, final
202
204
203
205
public ResponseContext updatePet (final RequestContext request , final Pet pet ) {
204
206
if (pet == null ) {
205
- bugsnag .notify (new RuntimeException ("No pet provided" ));
207
+ notifier .notify (new RuntimeException ("No pet provided" ));
206
208
return new ResponseContext ()
207
209
.status (Response .Status .BAD_REQUEST )
208
210
.entity ("No Pet provided. Try again?" );
209
211
}
210
212
211
213
final Pet existingPet = petData .getPetById (pet .getId ());
212
214
if (existingPet == null ) {
213
- bugsnag .notify (new RuntimeException ("No pet provided" ));
215
+ notifier .notify (new RuntimeException ("No pet provided" ));
214
216
return new ResponseContext ().status (Response .Status .NOT_FOUND ).entity ("Pet not found" );
215
217
}
216
218
@@ -230,7 +232,7 @@ public ResponseContext updatePet(final RequestContext request, final Long id, fi
230
232
231
233
public ResponseContext findPetsByTags (final RequestContext request , final List <String > tags ) {
232
234
if (tags == null || tags .size () == 0 ) {
233
- bugsnag .notify (new RuntimeException ("No tags provided" ));
235
+ notifier .notify (new RuntimeException ("No tags provided" ));
234
236
return new ResponseContext ()
235
237
.status (Response .Status .BAD_REQUEST )
236
238
.entity ("No tags provided. Try again?" );
0 commit comments