Committed by
Gerrit Code Review
CORD Subscriber GUI -- Updated GUI REST layer to provide dashboard, bundle and users namespaces.
Change-Id: I9777324a93a6ab9bc641eb13b69198a9506d8fea
Showing
2 changed files
with
35 additions
and
11 deletions
| ... | @@ -18,6 +18,9 @@ package org.onosproject.cord.gui; | ... | @@ -18,6 +18,9 @@ package org.onosproject.cord.gui; |
| 18 | 18 | ||
| 19 | import javax.ws.rs.GET; | 19 | import javax.ws.rs.GET; |
| 20 | import javax.ws.rs.Path; | 20 | import javax.ws.rs.Path; |
| 21 | +import javax.ws.rs.PathParam; | ||
| 22 | +import javax.ws.rs.Produces; | ||
| 23 | +import javax.ws.rs.core.MediaType; | ||
| 21 | import javax.ws.rs.core.Response; | 24 | import javax.ws.rs.core.Response; |
| 22 | 25 | ||
| 23 | /** | 26 | /** |
| ... | @@ -26,15 +29,34 @@ import javax.ws.rs.core.Response; | ... | @@ -26,15 +29,34 @@ import javax.ws.rs.core.Response; |
| 26 | @Path("") | 29 | @Path("") |
| 27 | public class CordWebResource { | 30 | public class CordWebResource { |
| 28 | 31 | ||
| 32 | + private Response fakeData(String which, String suffix) { | ||
| 33 | + String path = "local/" + which + "-" + suffix + ".json"; | ||
| 34 | + String content = FakeUtils.slurp(path); | ||
| 35 | + if (content == null) { | ||
| 36 | + return Response.status(Response.Status.NOT_FOUND).build(); | ||
| 37 | + } | ||
| 38 | + return Response.ok(content).build(); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + @GET | ||
| 42 | + @Produces(MediaType.APPLICATION_JSON) | ||
| 43 | + @Path("dashboard/{suffix}") | ||
| 44 | + public Response dashboard(@PathParam("suffix") String suffix) { | ||
| 45 | + return fakeData("dashboard", suffix); | ||
| 46 | + } | ||
| 47 | + | ||
| 29 | @GET | 48 | @GET |
| 30 | - @Path("hello") | 49 | + @Produces(MediaType.APPLICATION_JSON) |
| 31 | - public Response hello() { | 50 | + @Path("bundle/{suffix}") |
| 32 | - return Response.ok("Hello World").build(); | 51 | + public Response bundle(@PathParam("suffix") String suffix) { |
| 52 | + return fakeData("bundle", suffix); | ||
| 33 | } | 53 | } |
| 34 | 54 | ||
| 35 | @GET | 55 | @GET |
| 36 | - @Path("fake") | 56 | + @Produces(MediaType.APPLICATION_JSON) |
| 37 | - public Response fake() { | 57 | + @Path("users/{suffix}") |
| 38 | - return Response.ok(FakeUtils.slurp("sample.json")).build(); | 58 | + public Response users(@PathParam("suffix") String suffix) { |
| 59 | + return fakeData("users", suffix); | ||
| 39 | } | 60 | } |
| 61 | + | ||
| 40 | } | 62 | } | ... | ... |
| ... | @@ -37,12 +37,14 @@ public class FakeUtils { | ... | @@ -37,12 +37,14 @@ public class FakeUtils { |
| 37 | * @return contents of file as a string | 37 | * @return contents of file as a string |
| 38 | */ | 38 | */ |
| 39 | public static String slurp(String path) { | 39 | public static String slurp(String path) { |
| 40 | - String result = ""; | 40 | + String result = null; |
| 41 | InputStream is = CL.getResourceAsStream(ROOT_PATH + path); | 41 | InputStream is = CL.getResourceAsStream(ROOT_PATH + path); |
| 42 | - try { | 42 | + if (is != null) { |
| 43 | - result = IOUtils.toString(is, UTF_8); | 43 | + try { |
| 44 | - } catch (IOException e) { | 44 | + result = IOUtils.toString(is, UTF_8); |
| 45 | - e.printStackTrace(); | 45 | + } catch (IOException e) { |
| 46 | + e.printStackTrace(); | ||
| 47 | + } | ||
| 46 | } | 48 | } |
| 47 | return result; | 49 | return result; |
| 48 | } | 50 | } | ... | ... |
-
Please register or login to post a comment