use of co.cask.cdap.notifications.feeds.NotificationFeedException in project cdap by caskdata.
the class NotificationFeedHttpHandler method createFeed.
@PUT
@Path("/feeds/categories/{feed-category}/names/{feed-name}")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void createFeed(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("feed-category") String category, @PathParam("feed-name") String name) {
try {
NotificationFeedInfo feedInfo;
try {
Map<String, String> body = parseBody(request, MAP_TYPE);
String description = body == null ? null : body.get("description");
feedInfo = new NotificationFeedInfo(namespaceId, category, name, description);
} catch (IllegalArgumentException e) {
responder.sendString(HttpResponseStatus.BAD_REQUEST, String.format("Could not create Notification Feed. %s", e.getMessage()));
return;
}
if (feedManager.createFeed(feedInfo)) {
responder.sendString(HttpResponseStatus.OK, "Notification Feed created successfully");
} else {
LOG.trace("Notification Feed already exists.");
responder.sendString(HttpResponseStatus.OK, "Notification Feed already exists.");
}
} catch (NotificationFeedException e) {
LOG.error("Could not create notification feed.", e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage());
} catch (JsonSyntaxException e) {
responder.sendString(HttpResponseStatus.BAD_REQUEST, "Invalid json object provided in request body.");
} catch (IOException e) {
LOG.error("Failed to read Notification feed request body.", e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage());
} catch (Throwable t) {
LOG.debug("Error in creating notification feed.", t);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, t.getMessage());
}
}
use of co.cask.cdap.notifications.feeds.NotificationFeedException in project cdap by caskdata.
the class NotificationFeedHttpHandler method listFeeds.
@GET
@Path("/feeds")
public void listFeeds(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) {
try {
List<NotificationFeedInfo> feeds = feedManager.listFeeds(new NamespaceId(namespaceId));
responder.sendJson(HttpResponseStatus.OK, feeds);
} catch (NotificationFeedException e) {
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, String.format("Could not check subscribe permission for Notification Feed. %s", e.getMessage()));
} catch (Throwable t) {
LOG.debug("Error in listing notification feeds.", t);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, t.getMessage());
}
}
Aggregations