use of org.json.JSONWriter in project alfresco-remote-api by Alfresco.
the class AbstractBlogWebScript method addActivityEntry.
/**
* Generates an activity entry for the discussion item
*
* @param event One of created, updated, deleted
* @param blog Either post or reply
* @param site site
* @param req request
* @param json json
* @param nodeRef NodeRef
*/
protected void addActivityEntry(String event, BlogPostInfo blog, SiteInfo site, WebScriptRequest req, JSONObject json, NodeRef nodeRef) {
// We can only add activities against a site
if (site == null) {
logger.info("Unable to add activity entry for blog " + event + " as no site given");
return;
}
// What page is this for?
String page = req.getParameter("page");
if (page == null && json != null) {
if (json.containsKey("page")) {
page = (String) json.get("page");
}
}
if (page == null) {
// Default
page = "blog-postview";
}
if (page.indexOf('?') == -1) {
page += "?postId=" + blog.getSystemName();
}
// Get the title
String title = blog.getTitle();
try {
JSONWriter jsonWriter = new JSONStringer().object().key(TITLE).value(title).key(PAGE).value(page);
if (nodeRef != null) {
// ALF-10182: the nodeRef needs to be included in the activity
// post to ensure read permissions are respected.
jsonWriter.key(PostLookup.JSON_NODEREF).value(nodeRef.toString());
}
String data = jsonWriter.endObject().toString();
activityService.postActivity("org.alfresco.blog.post-" + event, site.getShortName(), "blog", data);
} catch (Exception e) {
// Warn, but carry on
logger.warn("Error adding blog post " + event + " to activities feed", e);
}
}
Aggregations