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
31 additions
and
7 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 | + | ||
29 | @GET | 41 | @GET |
30 | - @Path("hello") | 42 | + @Produces(MediaType.APPLICATION_JSON) |
31 | - public Response hello() { | 43 | + @Path("dashboard/{suffix}") |
32 | - return Response.ok("Hello World").build(); | 44 | + public Response dashboard(@PathParam("suffix") String suffix) { |
45 | + return fakeData("dashboard", suffix); | ||
33 | } | 46 | } |
34 | 47 | ||
35 | @GET | 48 | @GET |
36 | - @Path("fake") | 49 | + @Produces(MediaType.APPLICATION_JSON) |
37 | - public Response fake() { | 50 | + @Path("bundle/{suffix}") |
38 | - return Response.ok(FakeUtils.slurp("sample.json")).build(); | 51 | + public Response bundle(@PathParam("suffix") String suffix) { |
52 | + return fakeData("bundle", suffix); | ||
39 | } | 53 | } |
54 | + | ||
55 | + @GET | ||
56 | + @Produces(MediaType.APPLICATION_JSON) | ||
57 | + @Path("users/{suffix}") | ||
58 | + public Response users(@PathParam("suffix") String suffix) { | ||
59 | + return fakeData("users", suffix); | ||
60 | + } | ||
61 | + | ||
40 | } | 62 | } | ... | ... |
... | @@ -37,13 +37,15 @@ public class FakeUtils { | ... | @@ -37,13 +37,15 @@ 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 | + if (is != null) { | ||
42 | try { | 43 | try { |
43 | result = IOUtils.toString(is, UTF_8); | 44 | result = IOUtils.toString(is, UTF_8); |
44 | } catch (IOException e) { | 45 | } catch (IOException e) { |
45 | e.printStackTrace(); | 46 | e.printStackTrace(); |
46 | } | 47 | } |
48 | + } | ||
47 | return result; | 49 | return result; |
48 | } | 50 | } |
49 | } | 51 | } | ... | ... |
-
Please register or login to post a comment