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