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");
}
}
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");
}
}
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);
}
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());
}
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);
}
Aggregations