6868import java .util .List ;
6969
7070@ RestController
71- @ RequestMapping (path = "host/hub" )
71+ @ RequestMapping (path = "v2/ host/hub" )
7272@ SecurityRequirement (name = "api" )
7373public class HubController {
7474
@@ -83,28 +83,45 @@ public class HubController {
8383 @ Autowired
8484 HubMapper hubMapper ;
8585
86- @ RequestMapping (path = "" , method = RequestMethod .PUT , produces = "application/json" )
86+ @ RequestMapping (
87+ path = "" ,
88+ method = RequestMethod .PUT ,
89+ produces = "application/json"
90+ )
8791 @ Operation (summary = "Create new hub" )
8892 @ ApiResponses (value = {
89- @ ApiResponse (responseCode = "201" , description = "New hub created" ,
90- content = {@ Content (mediaType = "application/json" ,
91- schema = @ Schema (implementation = Hub .class ))}),
92- @ ApiResponse (responseCode = "409" , description = "ID,MD5 or fqhost already exists" ,
93- content = @ Content ),
94- @ ApiResponse (responseCode = "400" , description = "Internal server error, contact admin" , content = @ Content )})
93+ @ ApiResponse (
94+ responseCode = "201" ,
95+ description = "New hub created" ,
96+ content = {
97+ @ Content (
98+ mediaType = "application/json" ,
99+ schema = @ Schema (implementation = Hub .class )
100+ )
101+ }
102+ ),
103+ @ ApiResponse (
104+ responseCode = "409" ,
105+ description = "ID,MD5 or fqhost already exists" ,
106+ content = @ Content
107+ ),
108+ @ ApiResponse (
109+ responseCode = "400" ,
110+ description = "Internal server error, contact admin" ,
111+ content = @ Content
112+ )
113+ })
95114 public ResponseEntity <String > create (@ RequestBody Hub newHub ) {
96115 LOGGER .info ("About to insert <[{}]>" , newHub );
97116 try {
98- Hub h = hubMapper .create (
99- newHub .getFqHost (),
100- newHub .getMd5 (),
101- newHub .getIp ());
117+ Hub h = hubMapper .create (newHub .getFqHost (), newHub .getMd5 (), newHub .getIp ());
102118 LOGGER .debug ("Values returned <[{}]>" , h );
103119 JSONObject jsonObject = new JSONObject ();
104120 jsonObject .put ("id" , h .getId ());
105121 jsonObject .put ("message" , "New hub created" );
106122 return new ResponseEntity <>(jsonObject .toString (), HttpStatus .CREATED );
107- } catch (RuntimeException ex ) {
123+ }
124+ catch (RuntimeException ex ) {
108125 LOGGER .error (ex .getMessage ());
109126 JSONObject jsonErr = new JSONObject ();
110127 jsonErr .put ("id" , newHub .getId ());
@@ -123,21 +140,41 @@ public ResponseEntity<String> create(@RequestBody Hub newHub) {
123140 }
124141 }
125142
126- @ RequestMapping (path = "/{id}" , method = RequestMethod .GET , produces = "application/json" )
143+ @ RequestMapping (
144+ path = "/{id}" ,
145+ method = RequestMethod .GET ,
146+ produces = "application/json"
147+ )
127148 @ Operation (summary = "Fetch hub" )
128149 @ ApiResponses (value = {
129- @ ApiResponse (responseCode = "200" , description = "Hub retrieved" ,
130- content = {@ Content (mediaType = "application/json" ,
131- schema = @ Schema (implementation = Hub .class ))}),
132- @ ApiResponse (responseCode = "404" , description = "Hub does not exist with the given ID" ,
133- content = @ Content ),
134- @ ApiResponse (responseCode = "400" , description = "Internal server error, contact admin" , content = @ Content )})
135- public ResponseEntity <?> get (@ PathVariable ("id" ) int id , @ RequestParam (required = false ) Integer version ) {
150+ @ ApiResponse (
151+ responseCode = "200" ,
152+ description = "Hub retrieved" ,
153+ content = {
154+ @ Content (
155+ mediaType = "application/json" ,
156+ schema = @ Schema (implementation = Hub .class )
157+ )
158+ }
159+ ),
160+ @ ApiResponse (
161+ responseCode = "404" ,
162+ description = "Hub does not exist with the given ID" ,
163+ content = @ Content
164+ ),
165+ @ ApiResponse (
166+ responseCode = "400" ,
167+ description = "Internal server error, contact admin" ,
168+ content = @ Content
169+ )
170+ })
171+ public ResponseEntity <String > get (@ PathVariable ("id" ) int id , @ RequestParam (required = false ) Integer version ) {
136172 LOGGER .info ("About to fetch <[{}]>" , id );
137173 try {
138174 Hub h = hubMapper .get (id , version );
139- return new ResponseEntity <>(h , HttpStatus .OK );
140- } catch (RuntimeException ex ) {
175+ return new ResponseEntity <>(h .toString (), HttpStatus .OK );
176+ }
177+ catch (RuntimeException ex ) {
141178 LOGGER .error (ex .getMessage ());
142179 JSONObject jsonErr = new JSONObject ();
143180 jsonErr .put ("id" , id );
@@ -156,27 +193,64 @@ public ResponseEntity<?> get(@PathVariable("id") int id, @RequestParam(required
156193 }
157194 }
158195
159- @ RequestMapping (path = "" , method = RequestMethod .GET , produces = "application/json" )
160- @ Operation (summary = "Fetch all hubs" , description = "Will return empty list if there are no hubs to fetch" )
196+ @ RequestMapping (
197+ path = "" ,
198+ method = RequestMethod .GET ,
199+ produces = "application/json"
200+ )
201+ @ Operation (
202+ summary = "Fetch all hubs" ,
203+ description = "Will return empty list if there are no hubs to fetch"
204+ )
161205 @ ApiResponses (value = {
162- @ ApiResponse (responseCode = "200" , description = "Successfully retrieved" ,
163- content = {@ Content (mediaType = "application/json" ,
164- schema = @ Schema (implementation = Hub .class ))})})
206+ @ ApiResponse (
207+ responseCode = "200" ,
208+ description = "Successfully retrieved" ,
209+ content = {
210+ @ Content (
211+ mediaType = "application/json" ,
212+ schema = @ Schema (implementation = Hub .class )
213+ )
214+ }
215+ )
216+ })
165217 public List <Hub > getAll (@ RequestParam (required = false ) Integer version ) {
166218 return hubMapper .getAll (version );
167219 }
168220
169- @ RequestMapping (path = "/{id}" , method = RequestMethod .DELETE , produces = MediaType .APPLICATION_JSON_VALUE )
221+ @ RequestMapping (
222+ path = "/{id}" ,
223+ method = RequestMethod .DELETE ,
224+ produces = MediaType .APPLICATION_JSON_VALUE
225+ )
170226 @ Operation (summary = "Delete hub" )
171227 @ ApiResponses (value = {
172- @ ApiResponse (responseCode = "200" , description = "Hub deleted" ,
173- content = {@ Content (mediaType = "application/json" ,
174- schema = @ Schema (implementation = Hub .class ))}),
175- @ ApiResponse (responseCode = "404" , description = "Hub does not exist" ,
176- content = @ Content ),
177- @ ApiResponse (responseCode = "409" , description = "Hub is being used" ,
178- content = @ Content ),
179- @ ApiResponse (responseCode = "400" , description = "Internal server error, contact admin" , content = @ Content )})
228+ @ ApiResponse (
229+ responseCode = "200" ,
230+ description = "Hub deleted" ,
231+ content = {
232+ @ Content (
233+ mediaType = "application/json" ,
234+ schema = @ Schema (implementation = Hub .class )
235+ )
236+ }
237+ ),
238+ @ ApiResponse (
239+ responseCode = "404" ,
240+ description = "Hub does not exist" ,
241+ content = @ Content
242+ ),
243+ @ ApiResponse (
244+ responseCode = "409" ,
245+ description = "Hub is being used" ,
246+ content = @ Content
247+ ),
248+ @ ApiResponse (
249+ responseCode = "400" ,
250+ description = "Internal server error, contact admin" ,
251+ content = @ Content
252+ )
253+ })
180254 public ResponseEntity <String > delete (@ PathVariable ("id" ) int id ) {
181255 LOGGER .info ("Deleting Hub <[{}]>" , id );
182256 try {
@@ -185,7 +259,8 @@ public ResponseEntity<String> delete(@PathVariable("id") int id) {
185259 j .put ("id" , id );
186260 j .put ("message" , "Hub deleted" );
187261 return new ResponseEntity <>(j .toString (), HttpStatus .OK );
188- } catch (RuntimeException ex ) {
262+ }
263+ catch (RuntimeException ex ) {
189264 LOGGER .error (ex .getMessage ());
190265 JSONObject jsonErr = new JSONObject ();
191266 jsonErr .put ("id" , id );
@@ -198,8 +273,9 @@ public ResponseEntity<String> delete(@PathVariable("id") int id) {
198273 if (state .equals ("23000" )) {
199274 jsonErr .put ("message" , "Is in use" );
200275 return new ResponseEntity <>(jsonErr .toString (), HttpStatus .CONFLICT );
201- // 45000 = Custom error, row does not exist
202- } else if (state .equals ("45000" )) {
276+ // 45000 = Custom error, row does not exist
277+ }
278+ else if (state .equals ("45000" )) {
203279 jsonErr .put ("message" , "Record does not exist" );
204280 return new ResponseEntity <>(jsonErr .toString (), HttpStatus .NOT_FOUND );
205281 }
@@ -208,5 +284,3 @@ public ResponseEntity<String> delete(@PathVariable("id") int id) {
208284 }
209285 }
210286}
211-
212-
0 commit comments