Simon Hunt
Committed by Gerrit Code Review

CORD Subscriber GUI -- Updated GUI REST layer to provide dashboard, bundle and users namespaces.

Change-Id: I9777324a93a6ab9bc641eb13b69198a9506d8fea
......@@ -18,6 +18,9 @@ package org.onosproject.cord.gui;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
/**
......@@ -26,15 +29,34 @@ import javax.ws.rs.core.Response;
@Path("")
public class CordWebResource {
private Response fakeData(String which, String suffix) {
String path = "local/" + which + "-" + suffix + ".json";
String content = FakeUtils.slurp(path);
if (content == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
return Response.ok(content).build();
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("dashboard/{suffix}")
public Response dashboard(@PathParam("suffix") String suffix) {
return fakeData("dashboard", suffix);
}
@GET
@Path("hello")
public Response hello() {
return Response.ok("Hello World").build();
@Produces(MediaType.APPLICATION_JSON)
@Path("bundle/{suffix}")
public Response bundle(@PathParam("suffix") String suffix) {
return fakeData("bundle", suffix);
}
@GET
@Path("fake")
public Response fake() {
return Response.ok(FakeUtils.slurp("sample.json")).build();
@Produces(MediaType.APPLICATION_JSON)
@Path("users/{suffix}")
public Response users(@PathParam("suffix") String suffix) {
return fakeData("users", suffix);
}
}
......
......@@ -37,12 +37,14 @@ public class FakeUtils {
* @return contents of file as a string
*/
public static String slurp(String path) {
String result = "";
String result = null;
InputStream is = CL.getResourceAsStream(ROOT_PATH + path);
try {
result = IOUtils.toString(is, UTF_8);
} catch (IOException e) {
e.printStackTrace();
if (is != null) {
try {
result = IOUtils.toString(is, UTF_8);
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}
......