Search in sources :

Example 1 with Config

use of co.cask.cdap.config.Config 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 Config

use of co.cask.cdap.config.Config 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 Config

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

the class ConsoleSettingsHttpHandler method set.

@Path("/")
@PUT
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void set(HttpRequest request, HttpResponder responder) throws Exception {
    String data = request.getContent().toString(Charsets.UTF_8);
    if (!isValidJSON(data)) {
        responder.sendJson(HttpResponseStatus.BAD_REQUEST, "Invalid JSON in body");
        return;
    }
    //Configuration Layout for UserSettings:
    //Config ID : userId
    //Config Properties : Map (Key = CONFIG_PROPERTY, Value = Serialized JSON string of properties)
    //User Settings configurations are stored under empty NAMESPACE.
    Map<String, String> propMap = ImmutableMap.of(CONFIG_PROPERTY, data);
    String userId = Objects.firstNonNull(SecurityRequestContext.getUserId(), "");
    Config userConfig = new Config(userId, propMap);
    store.put(userConfig);
    responder.sendStatus(HttpResponseStatus.OK);
}
Also used : Config(co.cask.cdap.config.Config) Path(javax.ws.rs.Path) AuditPolicy(co.cask.cdap.common.security.AuditPolicy) PUT(javax.ws.rs.PUT)

Example 4 with Config

use of co.cask.cdap.config.Config 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 5 with Config

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

the class ConsoleSettingsHttpHandler method set.

@Path("/")
@PUT
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void set(FullHttpRequest request, HttpResponder responder) throws Exception {
    String data = request.content().toString(StandardCharsets.UTF_8);
    if (!isValidJSON(data)) {
        responder.sendJson(HttpResponseStatus.BAD_REQUEST, "Invalid JSON in body");
        return;
    }
    // Configuration Layout for UserSettings:
    // Config ID : userId
    // Config Properties : Map (Key = CONFIG_PROPERTY, Value = Serialized JSON string of properties)
    // User Settings configurations are stored under empty NAMESPACE.
    Map<String, String> propMap = ImmutableMap.of(CONFIG_PROPERTY, data);
    String userId = Objects.firstNonNull(SecurityRequestContext.getUserId(), "");
    Config userConfig = new Config(userId, propMap);
    store.put(userConfig);
    responder.sendStatus(HttpResponseStatus.OK);
}
Also used : Config(co.cask.cdap.config.Config) Path(javax.ws.rs.Path) AuditPolicy(co.cask.cdap.common.security.AuditPolicy) PUT(javax.ws.rs.PUT)

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