Search in sources :

Example 1 with ConfigNotFoundException

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

the class DashboardHttpHandler method set.

@Path("/{dashboard-id}")
@PUT
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void set(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @PathParam("dashboard-id") String id) throws Exception {
    try {
        String data = request.getContent().toString(Charsets.UTF_8);
        if (!isValidJSON(data)) {
            responder.sendJson(HttpResponseStatus.BAD_REQUEST, "Invalid JSON in body");
            return;
        }
        Map<String, String> propMap = ImmutableMap.of(CONFIG_PROPERTY, data);
        dashboardStore.put(namespace, new Config(id, propMap));
        responder.sendStatus(HttpResponseStatus.OK);
    } 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) Path(javax.ws.rs.Path) AuditPolicy(co.cask.cdap.common.security.AuditPolicy) PUT(javax.ws.rs.PUT)

Example 2 with ConfigNotFoundException

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

the class DashboardHttpHandler method set.

@Path("/{dashboard-id}")
@PUT
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void set(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @PathParam("dashboard-id") String id) throws Exception {
    try {
        String data = request.content().toString(StandardCharsets.UTF_8);
        if (!isValidJSON(data)) {
            responder.sendJson(HttpResponseStatus.BAD_REQUEST, "Invalid JSON in body");
            return;
        }
        Map<String, String> propMap = ImmutableMap.of(CONFIG_PROPERTY, data);
        dashboardStore.put(namespace, new Config(id, propMap));
        responder.sendStatus(HttpResponseStatus.OK);
    } 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) Path(javax.ws.rs.Path) AuditPolicy(co.cask.cdap.common.security.AuditPolicy) PUT(javax.ws.rs.PUT)

Example 3 with ConfigNotFoundException

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

the class ConsoleSettingsHttpHandler method get.

@Path("/")
@GET
public void get(HttpRequest request, HttpResponder responder) throws Exception {
    String userId = Objects.firstNonNull(SecurityRequestContext.getUserId(), "");
    Config userConfig;
    try {
        userConfig = store.get(userId);
    } catch (ConfigNotFoundException e) {
        Map<String, String> propMap = ImmutableMap.of(CONFIG_PROPERTY, "{}");
        userConfig = new Config(userId, propMap);
    }
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty(ID, userConfig.getId());
    // We store the serialized JSON string of the properties in ConfigStore and we return a JsonObject back
    jsonObject.add(CONFIG_PROPERTY, JSON_PARSER.parse(userConfig.getProperties().get(CONFIG_PROPERTY)));
    responder.sendJson(HttpResponseStatus.OK, jsonObject.toString());
}
Also used : Config(co.cask.cdap.config.Config) ConfigNotFoundException(co.cask.cdap.config.ConfigNotFoundException) JsonObject(com.google.gson.JsonObject) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 4 with ConfigNotFoundException

use of co.cask.cdap.config.ConfigNotFoundException 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)4 ConfigNotFoundException (co.cask.cdap.config.ConfigNotFoundException)4 Path (javax.ws.rs.Path)4 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)2 JsonObject (com.google.gson.JsonObject)2 GET (javax.ws.rs.GET)2 PUT (javax.ws.rs.PUT)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1