mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged 5.2.N (5.2.1) to HEAD (5.2)
125783 rmunteanu: Merged 5.1.N (5.1.2) to 5.2.N (5.2.1) 125605 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2) 125498 slanglois: MNT-16155 Update source headers - remove svn:eol-style property on Java and JSP source files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127809 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,324 +1,324 @@
|
||||
package org.alfresco.repo.web.scripts.comments;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.policy.BehaviourFilter;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.activities.ActivityService;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONStringer;
|
||||
import org.json.JSONWriter;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
* This class is the abstract controller for the comments web scripts (delete
|
||||
* and post)
|
||||
*
|
||||
* @author Ramona Popa
|
||||
* @since 4.2.6
|
||||
*/
|
||||
public abstract class AbstractCommentsWebScript extends DeclarativeWebScript
|
||||
{
|
||||
|
||||
protected final static String COMMENTS_TOPIC_NAME = "Comments";
|
||||
|
||||
private static Log logger = LogFactory.getLog(CommentsPost.class);
|
||||
|
||||
protected final static String JSON_KEY_SITE = "site";
|
||||
protected final static String JSON_KEY_SITE_ID = "siteid";
|
||||
protected final static String JSON_KEY_ITEM_TITLE = "itemTitle";
|
||||
protected final static String JSON_KEY_PAGE = "page";
|
||||
protected final static String JSON_KEY_TITLE = "title";
|
||||
protected final static String JSON_KEY_PAGE_PARAMS = "pageParams";
|
||||
protected final static String JSON_KEY_NODEREF = "nodeRef";
|
||||
protected final static String JSON_KEY_CONTENT = "content";
|
||||
|
||||
protected final static String COMMENT_CREATED_ACTIVITY = "org.alfresco.comments.comment-created";
|
||||
protected final static String COMMENT_DELETED_ACTIVITY = "org.alfresco.comments.comment-deleted";
|
||||
|
||||
protected ServiceRegistry serviceRegistry;
|
||||
protected NodeService nodeService;
|
||||
protected ContentService contentService;
|
||||
protected PersonService personService;
|
||||
protected SiteService siteService;
|
||||
protected PermissionService permissionService;
|
||||
protected ActivityService activityService;
|
||||
|
||||
protected BehaviourFilter behaviourFilter;
|
||||
|
||||
protected static final String PARAM_MESSAGE = "message";
|
||||
protected static final String PARAM_NODE = "node";
|
||||
protected static final String PARAM_ITEM = "item";
|
||||
|
||||
public void setServiceRegistry(ServiceRegistry serviceRegistry)
|
||||
{
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.nodeService = serviceRegistry.getNodeService();
|
||||
this.siteService = serviceRegistry.getSiteService();
|
||||
this.contentService = serviceRegistry.getContentService();
|
||||
this.personService = serviceRegistry.getPersonService();
|
||||
this.permissionService = serviceRegistry.getPermissionService();
|
||||
}
|
||||
|
||||
public void setBehaviourFilter(BehaviourFilter behaviourFilter)
|
||||
{
|
||||
this.behaviourFilter = behaviourFilter;
|
||||
}
|
||||
|
||||
public void setActivityService(ActivityService activityService)
|
||||
{
|
||||
this.activityService = activityService;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the nodeRef from web script request
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
protected NodeRef parseRequestForNodeRef(WebScriptRequest req)
|
||||
{
|
||||
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
||||
String storeType = templateVars.get("store_type");
|
||||
String storeId = templateVars.get("store_id");
|
||||
String nodeId = templateVars.get("id");
|
||||
|
||||
// create the NodeRef and ensure it is valid
|
||||
StoreRef storeRef = new StoreRef(storeType, storeId);
|
||||
return new NodeRef(storeRef, nodeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the value from JSON for given key if exists
|
||||
* @param json
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
protected String getOrNull(JSONObject json, String key)
|
||||
{
|
||||
if (json != null && json.containsKey(key))
|
||||
{
|
||||
return (String) json.get(key);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse JSON from request
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
protected JSONObject parseJSON(WebScriptRequest req)
|
||||
{
|
||||
JSONObject json = null;
|
||||
String contentType = req.getContentType();
|
||||
if (contentType != null && contentType.indexOf(';') != -1)
|
||||
{
|
||||
contentType = contentType.substring(0, contentType.indexOf(';'));
|
||||
}
|
||||
if (MimetypeMap.MIMETYPE_JSON.equals(contentType))
|
||||
{
|
||||
JSONParser parser = new JSONParser();
|
||||
try
|
||||
{
|
||||
json = (JSONObject) parser.parse(req.getContent().getContent());
|
||||
}
|
||||
catch (IOException io)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + io.getMessage());
|
||||
}
|
||||
catch (ParseException pe)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + pe.getMessage());
|
||||
}
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse JSON for a given input string
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
protected JSONObject parseJSONFromString(String input)
|
||||
{
|
||||
JSONObject json = null;
|
||||
|
||||
JSONParser parser = new JSONParser();
|
||||
try
|
||||
{
|
||||
if (input != null)
|
||||
{
|
||||
json = (JSONObject) parser.parse(input);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
catch (ParseException pe)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Invalid JSON: " + pe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post an activity entry for the comment added or deleted
|
||||
*
|
||||
* @param json
|
||||
* - is not sent null with this activity type - only for delete
|
||||
* @param req
|
||||
* @param nodeRef
|
||||
* @param activityType
|
||||
*/
|
||||
protected void postActivity(JSONObject json, WebScriptRequest req, NodeRef nodeRef, String activityType)
|
||||
{
|
||||
String jsonActivityData = "";
|
||||
String siteId = "";
|
||||
String page = "";
|
||||
String title = "";
|
||||
|
||||
if (nodeRef == null)
|
||||
{
|
||||
// in case we don't have an parent nodeRef provided we do not need
|
||||
// to post activity for parent node
|
||||
return;
|
||||
}
|
||||
|
||||
String strNodeRef = nodeRef.toString();
|
||||
|
||||
SiteInfo siteInfo = getSiteInfo(req, COMMENT_CREATED_ACTIVITY.equals(activityType));
|
||||
|
||||
// post an activity item, but only if we've got a site
|
||||
if (siteInfo != null)
|
||||
{
|
||||
siteId = siteInfo.getShortName();
|
||||
if (siteId == null || siteId.length() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// json is not sent null with this activity type - only for delete
|
||||
if (COMMENT_CREATED_ACTIVITY.equals(activityType))
|
||||
{
|
||||
try
|
||||
{
|
||||
org.json.JSONObject params = new org.json.JSONObject(getOrNull(json, JSON_KEY_PAGE_PARAMS));
|
||||
String strParams = "";
|
||||
|
||||
Iterator<?> itr = params.keys();
|
||||
while (itr.hasNext())
|
||||
{
|
||||
String strParam = itr.next().toString();
|
||||
strParams += strParam + "=" + params.getString(strParam) + "&";
|
||||
}
|
||||
page = getOrNull(json, JSON_KEY_PAGE) + "?" + (strParams != "" ? strParams.substring(0, strParams.length() - 1) : "");
|
||||
title = getOrNull(json, JSON_KEY_ITEM_TITLE);
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.warn("Error parsing JSON", e);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// COMMENT_DELETED_ACTIVITY
|
||||
title = req.getParameter(JSON_KEY_ITEM_TITLE);
|
||||
page = req.getParameter(JSON_KEY_PAGE) + "?" + JSON_KEY_NODEREF + "=" + strNodeRef;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
JSONWriter jsonWriter = new JSONStringer().object();
|
||||
jsonWriter.key(JSON_KEY_TITLE).value(title);
|
||||
jsonWriter.key(JSON_KEY_PAGE).value(page);
|
||||
jsonWriter.key(JSON_KEY_NODEREF).value(strNodeRef);
|
||||
|
||||
jsonActivityData = jsonWriter.endObject().toString();
|
||||
activityService.postActivity(activityType, siteId, COMMENTS_TOPIC_NAME, jsonActivityData);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.warn("Error adding comment to activities feed", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* returns SiteInfo needed for post activity
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
protected SiteInfo getSiteInfo(WebScriptRequest req, boolean searchForSiteInJSON)
|
||||
{
|
||||
String siteName = req.getParameter(JSON_KEY_SITE);
|
||||
|
||||
if (siteName == null && searchForSiteInJSON )
|
||||
{
|
||||
JSONObject json = parseJSON(req);
|
||||
if (json != null){
|
||||
if (json.containsKey(JSON_KEY_SITE))
|
||||
{
|
||||
siteName = (String) json.get(JSON_KEY_SITE);
|
||||
}
|
||||
else if (json.containsKey(JSON_KEY_SITE_ID))
|
||||
{
|
||||
siteName = (String) json.get(JSON_KEY_SITE_ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (siteName != null)
|
||||
{
|
||||
SiteInfo site = siteService.getSite(siteName);
|
||||
return site;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides DeclarativeWebScript with parse request for nodeRef
|
||||
*/
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
// get requested node
|
||||
NodeRef nodeRef = parseRequestForNodeRef(req);
|
||||
|
||||
// Have the real work done
|
||||
return executeImpl(nodeRef, req, status, cache);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param nodeRef
|
||||
* @param req
|
||||
* @param status
|
||||
* @param cache
|
||||
* @return
|
||||
*/
|
||||
protected abstract Map<String, Object> executeImpl(NodeRef nodeRef, WebScriptRequest req, Status status, Cache cache);
|
||||
|
||||
}
|
||||
package org.alfresco.repo.web.scripts.comments;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.policy.BehaviourFilter;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.activities.ActivityService;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONStringer;
|
||||
import org.json.JSONWriter;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
* This class is the abstract controller for the comments web scripts (delete
|
||||
* and post)
|
||||
*
|
||||
* @author Ramona Popa
|
||||
* @since 4.2.6
|
||||
*/
|
||||
public abstract class AbstractCommentsWebScript extends DeclarativeWebScript
|
||||
{
|
||||
|
||||
protected final static String COMMENTS_TOPIC_NAME = "Comments";
|
||||
|
||||
private static Log logger = LogFactory.getLog(CommentsPost.class);
|
||||
|
||||
protected final static String JSON_KEY_SITE = "site";
|
||||
protected final static String JSON_KEY_SITE_ID = "siteid";
|
||||
protected final static String JSON_KEY_ITEM_TITLE = "itemTitle";
|
||||
protected final static String JSON_KEY_PAGE = "page";
|
||||
protected final static String JSON_KEY_TITLE = "title";
|
||||
protected final static String JSON_KEY_PAGE_PARAMS = "pageParams";
|
||||
protected final static String JSON_KEY_NODEREF = "nodeRef";
|
||||
protected final static String JSON_KEY_CONTENT = "content";
|
||||
|
||||
protected final static String COMMENT_CREATED_ACTIVITY = "org.alfresco.comments.comment-created";
|
||||
protected final static String COMMENT_DELETED_ACTIVITY = "org.alfresco.comments.comment-deleted";
|
||||
|
||||
protected ServiceRegistry serviceRegistry;
|
||||
protected NodeService nodeService;
|
||||
protected ContentService contentService;
|
||||
protected PersonService personService;
|
||||
protected SiteService siteService;
|
||||
protected PermissionService permissionService;
|
||||
protected ActivityService activityService;
|
||||
|
||||
protected BehaviourFilter behaviourFilter;
|
||||
|
||||
protected static final String PARAM_MESSAGE = "message";
|
||||
protected static final String PARAM_NODE = "node";
|
||||
protected static final String PARAM_ITEM = "item";
|
||||
|
||||
public void setServiceRegistry(ServiceRegistry serviceRegistry)
|
||||
{
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.nodeService = serviceRegistry.getNodeService();
|
||||
this.siteService = serviceRegistry.getSiteService();
|
||||
this.contentService = serviceRegistry.getContentService();
|
||||
this.personService = serviceRegistry.getPersonService();
|
||||
this.permissionService = serviceRegistry.getPermissionService();
|
||||
}
|
||||
|
||||
public void setBehaviourFilter(BehaviourFilter behaviourFilter)
|
||||
{
|
||||
this.behaviourFilter = behaviourFilter;
|
||||
}
|
||||
|
||||
public void setActivityService(ActivityService activityService)
|
||||
{
|
||||
this.activityService = activityService;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the nodeRef from web script request
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
protected NodeRef parseRequestForNodeRef(WebScriptRequest req)
|
||||
{
|
||||
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
||||
String storeType = templateVars.get("store_type");
|
||||
String storeId = templateVars.get("store_id");
|
||||
String nodeId = templateVars.get("id");
|
||||
|
||||
// create the NodeRef and ensure it is valid
|
||||
StoreRef storeRef = new StoreRef(storeType, storeId);
|
||||
return new NodeRef(storeRef, nodeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the value from JSON for given key if exists
|
||||
* @param json
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
protected String getOrNull(JSONObject json, String key)
|
||||
{
|
||||
if (json != null && json.containsKey(key))
|
||||
{
|
||||
return (String) json.get(key);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse JSON from request
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
protected JSONObject parseJSON(WebScriptRequest req)
|
||||
{
|
||||
JSONObject json = null;
|
||||
String contentType = req.getContentType();
|
||||
if (contentType != null && contentType.indexOf(';') != -1)
|
||||
{
|
||||
contentType = contentType.substring(0, contentType.indexOf(';'));
|
||||
}
|
||||
if (MimetypeMap.MIMETYPE_JSON.equals(contentType))
|
||||
{
|
||||
JSONParser parser = new JSONParser();
|
||||
try
|
||||
{
|
||||
json = (JSONObject) parser.parse(req.getContent().getContent());
|
||||
}
|
||||
catch (IOException io)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + io.getMessage());
|
||||
}
|
||||
catch (ParseException pe)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + pe.getMessage());
|
||||
}
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse JSON for a given input string
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
protected JSONObject parseJSONFromString(String input)
|
||||
{
|
||||
JSONObject json = null;
|
||||
|
||||
JSONParser parser = new JSONParser();
|
||||
try
|
||||
{
|
||||
if (input != null)
|
||||
{
|
||||
json = (JSONObject) parser.parse(input);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
catch (ParseException pe)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Invalid JSON: " + pe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post an activity entry for the comment added or deleted
|
||||
*
|
||||
* @param json
|
||||
* - is not sent null with this activity type - only for delete
|
||||
* @param req
|
||||
* @param nodeRef
|
||||
* @param activityType
|
||||
*/
|
||||
protected void postActivity(JSONObject json, WebScriptRequest req, NodeRef nodeRef, String activityType)
|
||||
{
|
||||
String jsonActivityData = "";
|
||||
String siteId = "";
|
||||
String page = "";
|
||||
String title = "";
|
||||
|
||||
if (nodeRef == null)
|
||||
{
|
||||
// in case we don't have an parent nodeRef provided we do not need
|
||||
// to post activity for parent node
|
||||
return;
|
||||
}
|
||||
|
||||
String strNodeRef = nodeRef.toString();
|
||||
|
||||
SiteInfo siteInfo = getSiteInfo(req, COMMENT_CREATED_ACTIVITY.equals(activityType));
|
||||
|
||||
// post an activity item, but only if we've got a site
|
||||
if (siteInfo != null)
|
||||
{
|
||||
siteId = siteInfo.getShortName();
|
||||
if (siteId == null || siteId.length() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// json is not sent null with this activity type - only for delete
|
||||
if (COMMENT_CREATED_ACTIVITY.equals(activityType))
|
||||
{
|
||||
try
|
||||
{
|
||||
org.json.JSONObject params = new org.json.JSONObject(getOrNull(json, JSON_KEY_PAGE_PARAMS));
|
||||
String strParams = "";
|
||||
|
||||
Iterator<?> itr = params.keys();
|
||||
while (itr.hasNext())
|
||||
{
|
||||
String strParam = itr.next().toString();
|
||||
strParams += strParam + "=" + params.getString(strParam) + "&";
|
||||
}
|
||||
page = getOrNull(json, JSON_KEY_PAGE) + "?" + (strParams != "" ? strParams.substring(0, strParams.length() - 1) : "");
|
||||
title = getOrNull(json, JSON_KEY_ITEM_TITLE);
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.warn("Error parsing JSON", e);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// COMMENT_DELETED_ACTIVITY
|
||||
title = req.getParameter(JSON_KEY_ITEM_TITLE);
|
||||
page = req.getParameter(JSON_KEY_PAGE) + "?" + JSON_KEY_NODEREF + "=" + strNodeRef;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
JSONWriter jsonWriter = new JSONStringer().object();
|
||||
jsonWriter.key(JSON_KEY_TITLE).value(title);
|
||||
jsonWriter.key(JSON_KEY_PAGE).value(page);
|
||||
jsonWriter.key(JSON_KEY_NODEREF).value(strNodeRef);
|
||||
|
||||
jsonActivityData = jsonWriter.endObject().toString();
|
||||
activityService.postActivity(activityType, siteId, COMMENTS_TOPIC_NAME, jsonActivityData);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.warn("Error adding comment to activities feed", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* returns SiteInfo needed for post activity
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
protected SiteInfo getSiteInfo(WebScriptRequest req, boolean searchForSiteInJSON)
|
||||
{
|
||||
String siteName = req.getParameter(JSON_KEY_SITE);
|
||||
|
||||
if (siteName == null && searchForSiteInJSON )
|
||||
{
|
||||
JSONObject json = parseJSON(req);
|
||||
if (json != null){
|
||||
if (json.containsKey(JSON_KEY_SITE))
|
||||
{
|
||||
siteName = (String) json.get(JSON_KEY_SITE);
|
||||
}
|
||||
else if (json.containsKey(JSON_KEY_SITE_ID))
|
||||
{
|
||||
siteName = (String) json.get(JSON_KEY_SITE_ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (siteName != null)
|
||||
{
|
||||
SiteInfo site = siteService.getSite(siteName);
|
||||
return site;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides DeclarativeWebScript with parse request for nodeRef
|
||||
*/
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
// get requested node
|
||||
NodeRef nodeRef = parseRequestForNodeRef(req);
|
||||
|
||||
// Have the real work done
|
||||
return executeImpl(nodeRef, req, status, cache);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param nodeRef
|
||||
* @param req
|
||||
* @param status
|
||||
* @param cache
|
||||
* @return
|
||||
*/
|
||||
protected abstract Map<String, Object> executeImpl(NodeRef nodeRef, WebScriptRequest req, Status status, Cache cache);
|
||||
|
||||
}
|
||||
|
@@ -1,113 +1,113 @@
|
||||
package org.alfresco.repo.web.scripts.comments;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.model.ForumModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
* This class is the controller for the comment.delete web script.
|
||||
*
|
||||
* @author Ramona Popa
|
||||
* @since 4.2.6
|
||||
*/
|
||||
|
||||
public class CommentDelete extends AbstractCommentsWebScript
|
||||
{
|
||||
|
||||
private static Log logger = LogFactory.getLog(CommentDelete.class);
|
||||
|
||||
/**
|
||||
* Overrides AbstractCommentsWebScript to delete comment
|
||||
*/
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(NodeRef nodeRef, WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
String pageParams = req.getParameter(JSON_KEY_PAGE_PARAMS);
|
||||
|
||||
JSONObject jsonPageParams = parseJSONFromString(pageParams);
|
||||
|
||||
String parentNodeRefStr = getOrNull(jsonPageParams, JSON_KEY_NODEREF);
|
||||
NodeRef parentNodeRef = null;
|
||||
if (parentNodeRefStr != null)
|
||||
{
|
||||
parentNodeRef = new NodeRef((String) getOrNull(jsonPageParams, JSON_KEY_NODEREF));
|
||||
}
|
||||
|
||||
if (parentNodeRef != null)
|
||||
{
|
||||
this.behaviourFilter.disableBehaviour(parentNodeRef, ContentModel.ASPECT_AUDITABLE);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// delete node
|
||||
deleteComment(nodeRef);
|
||||
|
||||
if (nodeService.exists(nodeRef))
|
||||
{
|
||||
// comment was not removed
|
||||
status.setCode(Status.STATUS_INTERNAL_SERVER_ERROR, "Unable to delete node: " + nodeRef);
|
||||
return null;
|
||||
}
|
||||
|
||||
// generate response model for a comment node
|
||||
Map<String, Object> model = generateModel(nodeRef);
|
||||
|
||||
// post an activity item - it is ok to send json as null since the
|
||||
// infos that we need are as parameters on request
|
||||
postActivity(null, req, parentNodeRef, COMMENT_DELETED_ACTIVITY);
|
||||
|
||||
status.setCode(Status.STATUS_OK);
|
||||
return model;
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (parentNodeRef != null)
|
||||
{
|
||||
this.behaviourFilter.enableBehaviour(parentNodeRef, ContentModel.ASPECT_AUDITABLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* deletes comment node
|
||||
*
|
||||
* @param commentNodeRef
|
||||
*/
|
||||
private void deleteComment(NodeRef commentNodeRef)
|
||||
{
|
||||
QName nodeType = nodeService.getType(commentNodeRef);
|
||||
if (!nodeType.equals(ForumModel.TYPE_POST))
|
||||
{
|
||||
throw new IllegalArgumentException("Node to delete is not a comment node.");
|
||||
}
|
||||
|
||||
nodeService.deleteNode(commentNodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* generates model for delete comment script
|
||||
*
|
||||
* @param commentNodeRef
|
||||
* @return
|
||||
*/
|
||||
private Map<String, Object> generateModel(NodeRef commentNodeRef)
|
||||
{
|
||||
Map<String, Object> model = new HashMap<String, Object>(2, 1.0f);
|
||||
|
||||
model.put(PARAM_MESSAGE, "Node " + commentNodeRef + " deleted");
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
package org.alfresco.repo.web.scripts.comments;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.model.ForumModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
* This class is the controller for the comment.delete web script.
|
||||
*
|
||||
* @author Ramona Popa
|
||||
* @since 4.2.6
|
||||
*/
|
||||
|
||||
public class CommentDelete extends AbstractCommentsWebScript
|
||||
{
|
||||
|
||||
private static Log logger = LogFactory.getLog(CommentDelete.class);
|
||||
|
||||
/**
|
||||
* Overrides AbstractCommentsWebScript to delete comment
|
||||
*/
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(NodeRef nodeRef, WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
String pageParams = req.getParameter(JSON_KEY_PAGE_PARAMS);
|
||||
|
||||
JSONObject jsonPageParams = parseJSONFromString(pageParams);
|
||||
|
||||
String parentNodeRefStr = getOrNull(jsonPageParams, JSON_KEY_NODEREF);
|
||||
NodeRef parentNodeRef = null;
|
||||
if (parentNodeRefStr != null)
|
||||
{
|
||||
parentNodeRef = new NodeRef((String) getOrNull(jsonPageParams, JSON_KEY_NODEREF));
|
||||
}
|
||||
|
||||
if (parentNodeRef != null)
|
||||
{
|
||||
this.behaviourFilter.disableBehaviour(parentNodeRef, ContentModel.ASPECT_AUDITABLE);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// delete node
|
||||
deleteComment(nodeRef);
|
||||
|
||||
if (nodeService.exists(nodeRef))
|
||||
{
|
||||
// comment was not removed
|
||||
status.setCode(Status.STATUS_INTERNAL_SERVER_ERROR, "Unable to delete node: " + nodeRef);
|
||||
return null;
|
||||
}
|
||||
|
||||
// generate response model for a comment node
|
||||
Map<String, Object> model = generateModel(nodeRef);
|
||||
|
||||
// post an activity item - it is ok to send json as null since the
|
||||
// infos that we need are as parameters on request
|
||||
postActivity(null, req, parentNodeRef, COMMENT_DELETED_ACTIVITY);
|
||||
|
||||
status.setCode(Status.STATUS_OK);
|
||||
return model;
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (parentNodeRef != null)
|
||||
{
|
||||
this.behaviourFilter.enableBehaviour(parentNodeRef, ContentModel.ASPECT_AUDITABLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* deletes comment node
|
||||
*
|
||||
* @param commentNodeRef
|
||||
*/
|
||||
private void deleteComment(NodeRef commentNodeRef)
|
||||
{
|
||||
QName nodeType = nodeService.getType(commentNodeRef);
|
||||
if (!nodeType.equals(ForumModel.TYPE_POST))
|
||||
{
|
||||
throw new IllegalArgumentException("Node to delete is not a comment node.");
|
||||
}
|
||||
|
||||
nodeService.deleteNode(commentNodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* generates model for delete comment script
|
||||
*
|
||||
* @param commentNodeRef
|
||||
* @return
|
||||
*/
|
||||
private Map<String, Object> generateModel(NodeRef commentNodeRef)
|
||||
{
|
||||
Map<String, Object> model = new HashMap<String, Object>(2, 1.0f);
|
||||
|
||||
model.put(PARAM_MESSAGE, "Node " + commentNodeRef + " deleted");
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user