1616
1717package io .swagger .petstore .controller ;
1818
19- import com .bugsnag .Bugsnag ;
2019import io .swagger .oas .inflector .models .RequestContext ;
2120import io .swagger .oas .inflector .models .ResponseContext ;
2221import io .swagger .petstore .data .PetData ;
2322import io .swagger .petstore .model .Category ;
2423import io .swagger .petstore .model .Pet ;
2524import io .swagger .petstore .model .Tag ;
25+ import io .swagger .petstore .notification .Notifier ;
26+ import io .swagger .petstore .notification .NullNotifier ;
2627import io .swagger .petstore .utils .Util ;
2728
2829import javax .ws .rs .core .MediaType ;
3435public class PetController {
3536
3637 private static PetData petData = new PetData ();
37- private static Bugsnag bugsnag ;
38+ private Notifier notifier = new NullNotifier () ;
3839
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+ }
4547 }
4648 }
4749
4850 public ResponseContext findPetsByStatus (final RequestContext request , final String status ) {
4951 if (status == null ) {
50- bugsnag .notify (new RuntimeException ("No status provided" ));
52+ notifier .notify (new RuntimeException ("No status provided" ));
5153 return new ResponseContext ()
5254 .status (Response .Status .BAD_REQUEST )
5355 .entity ("No status provided. Try again?" );
@@ -56,19 +58,19 @@ public ResponseContext findPetsByStatus(final RequestContext request, final Stri
5658 final List <Pet > petByStatus = petData .findPetByStatus (status );
5759
5860 if (petByStatus == null ) {
59- bugsnag .notify (new RuntimeException ("Pets not found" ));
61+ notifier .notify (new RuntimeException ("Pets not found" ));
6062 return new ResponseContext ().status (Response .Status .NOT_FOUND ).entity ("Pets not found" );
6163 }
6264
63- bugsnag .notify (new RuntimeException ("Pets not found" ));
65+ notifier .notify (new RuntimeException ("Pets not found" ));
6466 return new ResponseContext ()
6567 .contentType (Util .getMediaType (request ))
6668 .entity (petByStatus );
6769 }
6870
6971 public ResponseContext getPetById (final RequestContext request , final Long petId ) {
7072 if (petId == null ) {
71- bugsnag .notify (new RuntimeException ("No petId provided" ));
73+ notifier .notify (new RuntimeException ("No petId provided" ));
7274 return new ResponseContext ()
7375 .status (Response .Status .BAD_REQUEST )
7476 .entity ("No petId provided. Try again?" );
@@ -82,20 +84,20 @@ public ResponseContext getPetById(final RequestContext request, final Long petId
8284 .entity (pet );
8385 }
8486
85- bugsnag .notify (new RuntimeException ("Pets not found" ));
87+ notifier .notify (new RuntimeException ("Pets not found" ));
8688 return new ResponseContext ().status (Response .Status .NOT_FOUND ).entity ("Pet not found" );
8789 }
8890
8991 public ResponseContext updatePetWithForm (final RequestContext request , final Long petId , final String name , final String status ) {
9092 if (petId == null ) {
91- bugsnag .notify (new RuntimeException ("No petId provided" ));
93+ notifier .notify (new RuntimeException ("No petId provided" ));
9294 return new ResponseContext ()
9395 .status (Response .Status .BAD_REQUEST )
9496 .entity ("No Pet provided. Try again?" );
9597 }
9698
9799 if (name == null ) {
98- bugsnag .notify (new RuntimeException ("No name provided" ));
100+ notifier .notify (new RuntimeException ("No name provided" ));
99101 return new ResponseContext ()
100102 .status (Response .Status .BAD_REQUEST )
101103 .entity ("No Name provided. Try again?" );
@@ -105,7 +107,7 @@ public ResponseContext updatePetWithForm(final RequestContext request, final Lon
105107 final Pet existingPet = petData .getPetById (petId );
106108
107109 if (existingPet == null ) {
108- bugsnag .notify (new RuntimeException ("No pet provided" ));
110+ notifier .notify (new RuntimeException ("No pet provided" ));
109111 return new ResponseContext ().status (Response .Status .NOT_FOUND ).entity ("Pet not found" );
110112 }
111113
@@ -121,7 +123,7 @@ public ResponseContext updatePetWithForm(final RequestContext request, final Lon
121123
122124 public ResponseContext deletePet (final RequestContext request , final String apiKey , final Long petId ) {
123125 if (petId == null ) {
124- bugsnag .notify (new RuntimeException ("No petId provided" ));
126+ notifier .notify (new RuntimeException ("No petId provided" ));
125127 return new ResponseContext ()
126128 .status (Response .Status .BAD_REQUEST )
127129 .entity ("No petId provided. Try again?" );
@@ -138,28 +140,28 @@ public ResponseContext deletePet(final RequestContext request, final String apiK
138140 .contentType (outputType )
139141 .entity ("Pet deleted" );
140142 } else {
141- bugsnag .notify (new RuntimeException ("Pet couldn't be deleted" ));
143+ notifier .notify (new RuntimeException ("Pet couldn't be deleted" ));
142144 return new ResponseContext ().status (Response .Status .NOT_MODIFIED ).entity ("Pet couldn't be deleted." );
143145 }
144146
145147 }
146148
147149 public ResponseContext uploadFile (final RequestContext request , final Long petId , final String apiKey , final File file ) {
148150 if (petId == null ) {
149- bugsnag .notify (new RuntimeException ("No petId provided" ));
151+ notifier .notify (new RuntimeException ("No petId provided" ));
150152 return new ResponseContext ()
151153 .status (Response .Status .BAD_REQUEST )
152154 .entity ("No petId provided. Try again?" );
153155 }
154156
155157 if (file == null ) {
156- bugsnag .notify (new RuntimeException ("No file provided" ));
158+ notifier .notify (new RuntimeException ("No file provided" ));
157159 return new ResponseContext ().status (Response .Status .BAD_REQUEST ).entity ("No file uploaded" );
158160 }
159161
160162 final Pet existingPet = petData .getPetById (petId );
161163 if (existingPet == null ) {
162- bugsnag .notify (new RuntimeException ("No pet provided" ));
164+ notifier .notify (new RuntimeException ("No pet provided" ));
163165 return new ResponseContext ().status (Response .Status .NOT_FOUND ).entity ("Pet not found" );
164166 }
165167
@@ -174,14 +176,14 @@ public ResponseContext uploadFile(final RequestContext request, final Long petId
174176 .contentType (Util .getMediaType (request ))
175177 .entity (pet );
176178 } else {
177- bugsnag .notify (new RuntimeException ("Pet couldn't be updated" ));
179+ notifier .notify (new RuntimeException ("Pet couldn't be updated" ));
178180 return new ResponseContext ().status (Response .Status .NOT_MODIFIED ).entity ("Pet couldn't be updated." );
179181 }
180182 }
181183
182184 public ResponseContext addPet (final RequestContext request , final Pet pet ) {
183185 if (pet == null ) {
184- bugsnag .notify (new RuntimeException ("No pet provided" ));
186+ notifier .notify (new RuntimeException ("No pet provided" ));
185187 return new ResponseContext ()
186188 .status (Response .Status .BAD_REQUEST )
187189 .entity ("No Pet provided. Try again?" );
@@ -202,15 +204,15 @@ public ResponseContext addPet(final RequestContext request, final Long id, final
202204
203205 public ResponseContext updatePet (final RequestContext request , final Pet pet ) {
204206 if (pet == null ) {
205- bugsnag .notify (new RuntimeException ("No pet provided" ));
207+ notifier .notify (new RuntimeException ("No pet provided" ));
206208 return new ResponseContext ()
207209 .status (Response .Status .BAD_REQUEST )
208210 .entity ("No Pet provided. Try again?" );
209211 }
210212
211213 final Pet existingPet = petData .getPetById (pet .getId ());
212214 if (existingPet == null ) {
213- bugsnag .notify (new RuntimeException ("No pet provided" ));
215+ notifier .notify (new RuntimeException ("No pet provided" ));
214216 return new ResponseContext ().status (Response .Status .NOT_FOUND ).entity ("Pet not found" );
215217 }
216218
@@ -230,7 +232,7 @@ public ResponseContext updatePet(final RequestContext request, final Long id, fi
230232
231233 public ResponseContext findPetsByTags (final RequestContext request , final List <String > tags ) {
232234 if (tags == null || tags .size () == 0 ) {
233- bugsnag .notify (new RuntimeException ("No tags provided" ));
235+ notifier .notify (new RuntimeException ("No tags provided" ));
234236 return new ResponseContext ()
235237 .status (Response .Status .BAD_REQUEST )
236238 .entity ("No tags provided. Try again?" );
0 commit comments