Search in sources :

Example 6 with Config

use of co.cask.cdap.config.Config in project cdap by caskdata.

the class DashboardHttpHandler method list.

@Path("/")
@GET
public void list(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace) throws Exception {
    JsonArray jsonArray = new JsonArray();
    List<Config> configList = dashboardStore.list(namespace);
    for (Config config : configList) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty(ID, config.getId());
        jsonObject.add(CONFIG_PROPERTY, JSON_PARSER.parse(config.getProperties().get(CONFIG_PROPERTY)));
        jsonArray.add(jsonObject);
    }
    responder.sendJson(HttpResponseStatus.OK, jsonArray.toString());
}
Also used : JsonArray(com.google.gson.JsonArray) Config(co.cask.cdap.config.Config) JsonObject(com.google.gson.JsonObject) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 7 with Config

use of co.cask.cdap.config.Config in project cdap by caskdata.

the class DashboardHttpHandler method get.

@Path("/{dashboard-id}")
@GET
public void get(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @PathParam("dashboard-id") String id) throws Exception {
    try {
        Config dashConfig = dashboardStore.get(namespace, id);
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty(ID, id);
        // Dashboard Config is stored in ConfigStore as serialized JSON string with CONFIG_PROPERTY key.
        // When we send the data back, we send it as JSON object instead of sending the serialized string.
        jsonObject.add(CONFIG_PROPERTY, JSON_PARSER.parse(dashConfig.getProperties().get(CONFIG_PROPERTY)));
        responder.sendJson(HttpResponseStatus.OK, jsonObject.toString());
    } catch (ConfigNotFoundException e) {
        responder.sendString(HttpResponseStatus.NOT_FOUND, "Dashboard not found");
    }
}
Also used : Config(co.cask.cdap.config.Config) ConfigNotFoundException(co.cask.cdap.config.ConfigNotFoundException) JsonObject(com.google.gson.JsonObject) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

Config (co.cask.cdap.config.Config)7 Path (javax.ws.rs.Path)7 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)4 ConfigNotFoundException (co.cask.cdap.config.ConfigNotFoundException)4 PUT (javax.ws.rs.PUT)4 JsonObject (com.google.gson.JsonObject)3 GET (javax.ws.rs.GET)3 ImmutableMap (com.google.common.collect.ImmutableMap)1 JsonArray (com.google.gson.JsonArray)1 Map (java.util.Map)1