mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
ALF-10429 / ALF-10413 Refactor the blog webscripts to follow the pattern of the other new service webscripts, avoiding the old JS style code
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@31184 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -18,12 +18,32 @@
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.blogs;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.blog.BlogServiceImpl;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.activities.ActivityService;
|
||||
import org.alfresco.service.cmr.blog.BlogPostInfo;
|
||||
import org.alfresco.service.cmr.blog.BlogService;
|
||||
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.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.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;
|
||||
|
||||
/**
|
||||
* @author Neil Mc Erlean
|
||||
@@ -37,6 +57,7 @@ public abstract class AbstractBlogWebScript extends DeclarativeWebScript
|
||||
protected static final String DATA = "data";
|
||||
protected static final String DRAFT = "draft";
|
||||
protected static final String EXTERNAL_BLOG_CONFIG = "externalBlogConfig";
|
||||
protected static final String POST = "post";
|
||||
protected static final String ITEM = "item";
|
||||
protected static final String NODE = "node";
|
||||
protected static final String PAGE = "page";
|
||||
@@ -44,11 +65,14 @@ public abstract class AbstractBlogWebScript extends DeclarativeWebScript
|
||||
protected static final String TAGS = "tags";
|
||||
protected static final String TITLE = "title";
|
||||
|
||||
private static Log logger = LogFactory.getLog(AbstractBlogWebScript.class);
|
||||
|
||||
// Injected services
|
||||
protected Repository repository;
|
||||
protected BlogService blogService;
|
||||
protected NodeService nodeService;
|
||||
protected SiteService siteService;
|
||||
protected ActivityService activityService;
|
||||
|
||||
//TODO Remove this after full refactor
|
||||
protected ServiceRegistry services;
|
||||
@@ -77,4 +101,190 @@ public abstract class AbstractBlogWebScript extends DeclarativeWebScript
|
||||
{
|
||||
this.siteService = siteService;
|
||||
}
|
||||
|
||||
public void setActivityService(ActivityService activityService)
|
||||
{
|
||||
this.activityService = activityService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an activity entry for the discussion item
|
||||
*
|
||||
* @param thing Either post or reply
|
||||
* @param event One of created, updated, deleted
|
||||
*/
|
||||
protected void addActivityEntry(String event, BlogPostInfo blog,
|
||||
SiteInfo site, WebScriptRequest req, JSONObject json)
|
||||
{
|
||||
// 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
|
||||
{
|
||||
String data = new JSONStringer()
|
||||
.object()
|
||||
.key(TITLE).value(title)
|
||||
.key(PAGE).value(page)
|
||||
.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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
||||
if (templateVars == null)
|
||||
{
|
||||
String error = "No parameters supplied";
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
|
||||
}
|
||||
|
||||
|
||||
// Parse the JSON, if supplied
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Did they request it by node reference or site?
|
||||
NodeRef nodeRef = null;
|
||||
SiteInfo site = null;
|
||||
BlogPostInfo blog = null;
|
||||
|
||||
if (templateVars.containsKey("site"))
|
||||
{
|
||||
// Site, and Optionally Blog Post
|
||||
String siteName = templateVars.get("site");
|
||||
site = siteService.getSite(siteName);
|
||||
if (site == null)
|
||||
{
|
||||
String error = "Could not find site: " + siteName;
|
||||
throw new WebScriptException(Status.STATUS_NOT_FOUND, error);
|
||||
}
|
||||
|
||||
// Did they give a blog post name too?
|
||||
if (templateVars.containsKey("path"))
|
||||
{
|
||||
String name = templateVars.get("path");
|
||||
blog = blogService.getBlogPost(siteName, name);
|
||||
|
||||
if (blog == null)
|
||||
{
|
||||
String error = "Could not find blog '" + name + "' for site '" +
|
||||
site.getShortName() + "'";
|
||||
throw new WebScriptException(Status.STATUS_NOT_FOUND, error);
|
||||
}
|
||||
nodeRef = blog.getNodeRef();
|
||||
}
|
||||
else
|
||||
{
|
||||
// The NodeRef is the container (if it exists)
|
||||
if (siteService.hasContainer(siteName, BlogServiceImpl.BLOG_COMPONENT))
|
||||
{
|
||||
nodeRef = siteService.getContainer(siteName, BlogServiceImpl.BLOG_COMPONENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (templateVars.containsKey("store_type") &&
|
||||
templateVars.containsKey("store_id") &&
|
||||
templateVars.containsKey("id"))
|
||||
{
|
||||
// NodeRef, should be a Blog Post
|
||||
StoreRef store = new StoreRef(
|
||||
templateVars.get("store_type"),
|
||||
templateVars.get("store_id"));
|
||||
|
||||
nodeRef = new NodeRef(store, templateVars.get("id"));
|
||||
if (! nodeService.exists(nodeRef))
|
||||
{
|
||||
String error = "Could not find node: " + nodeRef;
|
||||
throw new WebScriptException(Status.STATUS_NOT_FOUND, error);
|
||||
}
|
||||
|
||||
// Try to build the appropriate object for it
|
||||
blog = blogService.getForNodeRef(nodeRef);
|
||||
|
||||
// See if it's actually attached to a site
|
||||
if (blog != null)
|
||||
{
|
||||
NodeRef container = blog.getContainerNodeRef();
|
||||
if (container != null)
|
||||
{
|
||||
NodeRef maybeSite = nodeService.getPrimaryParent(container).getParentRef();
|
||||
if (maybeSite != null)
|
||||
{
|
||||
// Try to make it a site, will return Null if it isn't one
|
||||
site = siteService.getSite(maybeSite);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String error = "Unsupported template parameters found";
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
|
||||
}
|
||||
|
||||
// Have the real work done
|
||||
return executeImpl(site, nodeRef, blog, req, json, status, cache);
|
||||
}
|
||||
|
||||
protected abstract Map<String, Object> executeImpl(SiteInfo site,
|
||||
NodeRef nodeRef, BlogPostInfo blog, WebScriptRequest req,
|
||||
JSONObject json, Status status, Cache cache);
|
||||
}
|
||||
|
@@ -24,8 +24,7 @@ import java.util.Map;
|
||||
|
||||
import org.alfresco.model.BlogIntegrationModel;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
/**
|
||||
* This class is a port of a previous JavaScript library.
|
||||
@@ -57,15 +56,9 @@ public class BlogLibJs
|
||||
private static void putJSONEntryInMap(JSONObject json,
|
||||
Map<QName, Serializable> arr, String jsonKey, QName mapKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (json.has(jsonKey))
|
||||
{
|
||||
arr.put(mapKey, json.getString(jsonKey));
|
||||
}
|
||||
} catch (JSONException ignored)
|
||||
{
|
||||
// Intentionally empty
|
||||
}
|
||||
if (json.containsKey(jsonKey))
|
||||
{
|
||||
arr.put(mapKey, (Serializable)json.get(jsonKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -50,6 +50,8 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
|
||||
/**
|
||||
* Unit Test to test Blog Web Script API
|
||||
*
|
||||
* TODO Add unit tests for the Blog Integration part
|
||||
*
|
||||
* @author mruflin
|
||||
*/
|
||||
public class BlogServiceTest extends BaseWebScriptTest
|
||||
@@ -510,7 +512,7 @@ public class BlogServiceTest extends BaseWebScriptTest
|
||||
JSONObject metadata = result.getJSONObject("metadata");
|
||||
JSONObject perms = metadata.getJSONObject("blogPermissions");
|
||||
assertEquals(false, metadata.getBoolean("externalBlogConfig"));
|
||||
assertEquals(true, perms.getBoolean("delete"));
|
||||
assertEquals(false, perms.getBoolean("delete")); // No container yet
|
||||
assertEquals(true, perms.getBoolean("edit"));
|
||||
assertEquals(true, perms.getBoolean("create"));
|
||||
|
||||
@@ -530,6 +532,14 @@ public class BlogServiceTest extends BaseWebScriptTest
|
||||
assertEquals(2, result.getInt("itemCount"));
|
||||
assertEquals(2, result.getJSONArray("items").length());
|
||||
|
||||
// Check the core permissions
|
||||
metadata = result.getJSONObject("metadata");
|
||||
perms = metadata.getJSONObject("blogPermissions");
|
||||
assertEquals(false, metadata.getBoolean("externalBlogConfig"));
|
||||
assertEquals(true, perms.getBoolean("delete")); // On the container itself
|
||||
assertEquals(true, perms.getBoolean("edit"));
|
||||
assertEquals(true, perms.getBoolean("create"));
|
||||
|
||||
// Check each one in detail, they'll come back Published
|
||||
// then draft (newest first within that)
|
||||
blog = result.getJSONArray("items").getJSONObject(0);
|
||||
|
@@ -22,10 +22,13 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.web.scripts.blogs.AbstractBlogWebScript;
|
||||
import org.alfresco.repo.web.scripts.blogs.RequestUtilsLibJs;
|
||||
import org.alfresco.service.cmr.blog.BlogPostInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
@@ -37,14 +40,34 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
public class BlogGet extends AbstractBlogWebScript
|
||||
{
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
protected Map<String, Object> executeImpl(SiteInfo site, NodeRef containerNodeRef,
|
||||
BlogPostInfo blog, WebScriptRequest req, JSONObject json, Status status, Cache cache)
|
||||
{
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
|
||||
// get requested node
|
||||
NodeRef node = RequestUtilsLibJs.getRequestNode(req, services);
|
||||
model.put(ITEM, node);
|
||||
|
||||
return model;
|
||||
if (blog != null)
|
||||
{
|
||||
// They appear to have supplied a blog post itself...
|
||||
// Oh well, let's hope for the best!
|
||||
}
|
||||
|
||||
if (containerNodeRef == null && site != null)
|
||||
{
|
||||
// They want to know about a blog container on a
|
||||
// site where nothing has lazy-created the container
|
||||
// Give them info on the site for now, should be close enough!
|
||||
containerNodeRef = site.getNodeRef();
|
||||
}
|
||||
|
||||
if (containerNodeRef == null)
|
||||
{
|
||||
// Looks like they've asked for something that isn't there
|
||||
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Blog Not Found");
|
||||
}
|
||||
|
||||
// Build the response
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put(POST, blog);
|
||||
model.put(ITEM, blog.getNodeRef());
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
@@ -18,62 +18,59 @@
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.blogs.blog;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.BlogIntegrationModel;
|
||||
import org.alfresco.repo.blog.BlogServiceImpl;
|
||||
import org.alfresco.repo.web.scripts.blogs.AbstractBlogWebScript;
|
||||
import org.alfresco.repo.web.scripts.blogs.BlogLibJs;
|
||||
import org.alfresco.repo.web.scripts.blogs.RequestUtilsLibJs;
|
||||
import org.alfresco.service.cmr.blog.BlogPostInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
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 blog.get web script.
|
||||
* This class is the controller for the blog.put web script.
|
||||
*
|
||||
* TODO Push most of the logic from this into the BlogService
|
||||
*
|
||||
* @author Neil Mc Erlean (based on existing JavaScript webscript controllers)
|
||||
* @since 4.0
|
||||
*/
|
||||
public class BlogPut extends AbstractBlogWebScript
|
||||
{
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
protected Map<String, Object> executeImpl(SiteInfo site, NodeRef containerNodeRef,
|
||||
BlogPostInfo blog, WebScriptRequest req, JSONObject json, Status status, Cache cache)
|
||||
{
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
if (blog != null)
|
||||
{
|
||||
// They appear to have supplied a blog post itself...
|
||||
// Oh well, let's hope for the best!
|
||||
}
|
||||
|
||||
if (site != null && containerNodeRef == null)
|
||||
{
|
||||
// Force the lazy creation
|
||||
// This is a bit icky, but it'll have to do for now...
|
||||
containerNodeRef = siteService.createContainer(
|
||||
site.getShortName(), BlogServiceImpl.BLOG_COMPONENT, null, null);
|
||||
}
|
||||
|
||||
// get requested node
|
||||
NodeRef node = RequestUtilsLibJs.getRequestNode(req, services);
|
||||
|
||||
// parse the JSON
|
||||
JSONObject json = null;
|
||||
try
|
||||
{
|
||||
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
|
||||
}
|
||||
catch (JSONException jsonX)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Could not parse JSON", jsonX);
|
||||
}
|
||||
catch (IOException iox)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Could not parse JSON", iox);
|
||||
}
|
||||
|
||||
updateBlog(node, json);
|
||||
|
||||
model.put("item", node);
|
||||
|
||||
return model;
|
||||
// Do the work
|
||||
updateBlog(containerNodeRef, json);
|
||||
|
||||
// Record it as done
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("item", containerNodeRef);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -21,15 +21,14 @@ package org.alfresco.repo.web.scripts.blogs.post;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.web.scripts.blogs.AbstractBlogWebScript;
|
||||
import org.alfresco.repo.web.scripts.blogs.RequestUtilsLibJs;
|
||||
import org.alfresco.service.cmr.activities.ActivityService;
|
||||
import org.alfresco.service.cmr.blog.BlogPostInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONStringer;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
@@ -40,59 +39,30 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
*/
|
||||
public class BlogPostDelete extends AbstractBlogWebScript
|
||||
{
|
||||
private ActivityService activityService;
|
||||
|
||||
public void setActivityService(ActivityService activityService)
|
||||
{
|
||||
this.activityService = activityService;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
protected Map<String, Object> executeImpl(SiteInfo site, NodeRef nodeRef,
|
||||
BlogPostInfo blog, WebScriptRequest req, JSONObject json, Status status, Cache cache)
|
||||
{
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
if (blog == null)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Blog Post Not Found");
|
||||
}
|
||||
|
||||
// get requested node
|
||||
NodeRef node = RequestUtilsLibJs.getRequestNode(req, services);
|
||||
// TODO Get this from the BlogPostInfo Object
|
||||
final boolean isDraftBlogPost = blogService.isDraftBlogPost(blog.getNodeRef());
|
||||
|
||||
// Map<String, Object> item = BlogPostLibJs.getBlogPostData(node, services);
|
||||
|
||||
final String title = (String) nodeService.getProperty(node, ContentModel.PROP_TITLE);
|
||||
final String site = req.getServiceMatch().getTemplateVars().get("site");
|
||||
final String page = req.getParameter("page");
|
||||
final boolean isDraftBlogPost = blogService.isDraftBlogPost(node);
|
||||
|
||||
nodeService.deleteNode(node);
|
||||
|
||||
model.put("message", "Node " + node + " deleted");
|
||||
// Have it deleted
|
||||
blogService.deleteBlogPost(blog);
|
||||
|
||||
// If we're in a site, and it isn't a draft, add an activity
|
||||
if (site != null && !isDraftBlogPost)
|
||||
{
|
||||
sendActivityReport(title, site, page);
|
||||
addActivityEntry("deleted", blog, site, req, json);
|
||||
}
|
||||
|
||||
|
||||
// Report it as deleted
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("message", "Blog " + blog.getNodeRef() + " deleted");
|
||||
return model;
|
||||
}
|
||||
|
||||
private void sendActivityReport(final String title, final String site,
|
||||
final String page)
|
||||
{
|
||||
String data = null;
|
||||
try
|
||||
{
|
||||
data = new JSONStringer()
|
||||
.object()
|
||||
.key(TITLE).value(title)
|
||||
.key(PAGE).value(page)
|
||||
.endObject().toString();
|
||||
} catch (JSONException e)
|
||||
{
|
||||
// Intentionally empty
|
||||
}
|
||||
if (data != null)
|
||||
{
|
||||
activityService.postActivity("org.alfresco.blog.post-deleted", site, "blog", data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -23,10 +23,13 @@ import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.web.scripts.blogs.AbstractBlogWebScript;
|
||||
import org.alfresco.repo.web.scripts.blogs.BlogPostLibJs;
|
||||
import org.alfresco.repo.web.scripts.blogs.RequestUtilsLibJs;
|
||||
import org.alfresco.service.cmr.blog.BlogPostInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
@@ -37,16 +40,23 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
*/
|
||||
public class BlogPostGet extends AbstractBlogWebScript
|
||||
{
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
protected Map<String, Object> executeImpl(SiteInfo site, NodeRef nodeRef,
|
||||
BlogPostInfo blog, WebScriptRequest req, JSONObject json, Status status, Cache cache)
|
||||
{
|
||||
if (blog == null)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Blog Post Not Found");
|
||||
}
|
||||
|
||||
// Build the response
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
|
||||
// get requested node
|
||||
NodeRef node = RequestUtilsLibJs.getRequestNode(req, services);
|
||||
// TODO Fetch this from the BlogPostInfo object
|
||||
NodeRef node = blog.getNodeRef();
|
||||
Map<String, Object> item = BlogPostLibJs.getBlogPostData(node, services);
|
||||
model.put("item", item);
|
||||
model.put(ITEM, item);
|
||||
model.put(POST, blog);
|
||||
|
||||
model.put("externalBlogConfig", BlogPostLibJs.hasExternalBlogConfiguration(node, services));
|
||||
|
||||
|
@@ -29,13 +29,15 @@ import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.repo.web.scripts.blogs.AbstractBlogWebScript;
|
||||
import org.alfresco.repo.web.scripts.blogs.BlogPostLibJs;
|
||||
import org.alfresco.repo.web.scripts.blogs.RequestUtilsLibJs;
|
||||
import org.alfresco.service.cmr.blog.BlogPostInfo;
|
||||
import org.alfresco.service.cmr.blog.BlogService.RangedDateProperty;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.util.ScriptPagingDetails;
|
||||
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;
|
||||
@@ -49,13 +51,11 @@ public abstract class AbstractGetBlogWebScript extends AbstractBlogWebScript
|
||||
private static final Log log = LogFactory.getLog(AbstractGetBlogWebScript.class);
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
protected Map<String, Object> executeImpl(SiteInfo site, NodeRef nonSiteContainer,
|
||||
BlogPostInfo blog, WebScriptRequest req, JSONObject json, Status status, Cache cache)
|
||||
{
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
|
||||
// get requested node
|
||||
NodeRef node = RequestUtilsLibJs.getRequestNode(req, services);
|
||||
|
||||
// process additional parameters. <index, count>
|
||||
PagingRequest pagingReq = parsePagingParams(req);
|
||||
|
||||
@@ -85,9 +85,18 @@ public abstract class AbstractGetBlogWebScript extends AbstractBlogWebScript
|
||||
}
|
||||
}
|
||||
|
||||
// fetch and assign the data
|
||||
PagingResults<BlogPostInfo> blogPostList = getBlogPostList(node, fromDate, toDate,
|
||||
tag, pagingReq);
|
||||
// Fetch and assign the data
|
||||
PagingResults<BlogPostInfo> blogPostList =
|
||||
getBlogPostList(site, nonSiteContainer, fromDate, toDate, tag, pagingReq);
|
||||
|
||||
// We need the container for various bits
|
||||
NodeRef container = nonSiteContainer;
|
||||
if(container == null)
|
||||
{
|
||||
// Container mustn't exist yet
|
||||
// Fake it with the site for permissions checking reasons
|
||||
container = site.getNodeRef();
|
||||
}
|
||||
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
@@ -96,7 +105,7 @@ public abstract class AbstractGetBlogWebScript extends AbstractBlogWebScript
|
||||
log.debug(msg.toString());
|
||||
}
|
||||
|
||||
createFtlModel(req, model, node, pagingReq, blogPostList);
|
||||
createFtlModel(req, model, container, pagingReq, blogPostList);
|
||||
|
||||
return model;
|
||||
}
|
||||
@@ -135,28 +144,20 @@ public abstract class AbstractGetBlogWebScript extends AbstractBlogWebScript
|
||||
|
||||
private PagingRequest parsePagingParams(WebScriptRequest req)
|
||||
{
|
||||
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
||||
String startIndexStr = templateVars.get("startIndex");
|
||||
String pageSizeStr = templateVars.get("pageSize");
|
||||
|
||||
int startIndex = 0;
|
||||
int pageSize = 10;
|
||||
if (startIndexStr != null)
|
||||
{
|
||||
startIndex = Integer.parseInt(startIndexStr);
|
||||
}
|
||||
if (pageSizeStr != null)
|
||||
{
|
||||
pageSize = Integer.parseInt(pageSizeStr);
|
||||
}
|
||||
return new PagingRequest(startIndex, pageSize, null);
|
||||
return ScriptPagingDetails.buildPagingRequest(req, 1000);
|
||||
}
|
||||
|
||||
private Date parseDateParam(WebScriptRequest req, String paramName)
|
||||
{
|
||||
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
||||
String dateStr = templateVars.get(paramName);
|
||||
if(dateStr == null)
|
||||
{
|
||||
// Try on the parameters instead
|
||||
dateStr = req.getParameter(paramName);
|
||||
}
|
||||
|
||||
// Parse if available
|
||||
Date result = null;
|
||||
if (dateStr != null)
|
||||
{
|
||||
@@ -169,18 +170,28 @@ public abstract class AbstractGetBlogWebScript extends AbstractBlogWebScript
|
||||
/**
|
||||
* Fetches all posts of the given blog
|
||||
*/
|
||||
private PagingResults<BlogPostInfo> getBlogPostList(NodeRef node, Date fromDate, Date toDate, String tag, PagingRequest pagingReq)
|
||||
private PagingResults<BlogPostInfo> getBlogPostList(SiteInfo site, NodeRef nonSiteContainer,
|
||||
Date fromDate, Date toDate, String tag, PagingRequest pagingReq)
|
||||
{
|
||||
// Currently we only support CannedQuery-based gets without tags:
|
||||
if (tag == null || tag.trim().isEmpty())
|
||||
{
|
||||
return getBlogResultsImpl(node, fromDate, toDate, pagingReq);
|
||||
return getBlogResultsImpl(site, nonSiteContainer, fromDate, toDate, pagingReq);
|
||||
}
|
||||
else
|
||||
{
|
||||
return blogService.findBlogPosts(node, new RangedDateProperty(fromDate, toDate, ContentModel.PROP_CREATED), tag, pagingReq);
|
||||
RangedDateProperty dateRange = new RangedDateProperty(fromDate, toDate, ContentModel.PROP_CREATED);
|
||||
if(site != null)
|
||||
{
|
||||
return blogService.findBlogPosts(site.getShortName(), dateRange, tag, pagingReq);
|
||||
}
|
||||
else
|
||||
{
|
||||
return blogService.findBlogPosts(nonSiteContainer, dateRange, tag, pagingReq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract PagingResults<BlogPostInfo> getBlogResultsImpl(NodeRef node, Date fromDate, Date toDate, PagingRequest pagingReq);
|
||||
protected abstract PagingResults<BlogPostInfo> getBlogResultsImpl(
|
||||
SiteInfo site, NodeRef nonSiteContainer, Date fromDate, Date toDate, PagingRequest pagingReq);
|
||||
}
|
||||
|
@@ -20,10 +20,12 @@ package org.alfresco.repo.web.scripts.blogs.posts;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.alfresco.query.EmptyPagingResults;
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.service.cmr.blog.BlogPostInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
|
||||
/**
|
||||
* This class is the controller for the blog-posts.get web script.
|
||||
@@ -35,8 +37,16 @@ public class BlogPostsGet extends AbstractGetBlogWebScript
|
||||
{
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected PagingResults<BlogPostInfo> getBlogResultsImpl(NodeRef node, Date fromDate, Date toDate, PagingRequest pagingReq)
|
||||
protected PagingResults<BlogPostInfo> getBlogResultsImpl(
|
||||
SiteInfo site, NodeRef node, Date fromDate, Date toDate, PagingRequest pagingReq)
|
||||
{
|
||||
// As it uses deprecated methods, this bit can be a bit hacky...
|
||||
if (node == null)
|
||||
{
|
||||
// Site based request, but no container exists yet
|
||||
return new EmptyPagingResults<BlogPostInfo>();
|
||||
}
|
||||
|
||||
// This intentionally uses the deprecated method in the foundation service.
|
||||
// In fact the method is there specifically for this class.
|
||||
return blogService.getMyDraftsAndAllPublished(node, fromDate, toDate, pagingReq);
|
||||
|
@@ -25,6 +25,7 @@ import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.service.cmr.blog.BlogPostInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
|
||||
/**
|
||||
* This class is the controller for the blog-posts-mydrafts.get web script.
|
||||
@@ -36,8 +37,16 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
public class BlogPostsMyDraftsGet extends AbstractGetBlogWebScript
|
||||
{
|
||||
@Override
|
||||
protected PagingResults<BlogPostInfo> getBlogResultsImpl(NodeRef node, Date fromDate, Date toDate, PagingRequest pagingReq)
|
||||
protected PagingResults<BlogPostInfo> getBlogResultsImpl(SiteInfo site, NodeRef node, Date fromDate, Date toDate, PagingRequest pagingReq)
|
||||
{
|
||||
return blogService.getDrafts(node, AuthenticationUtil.getFullyAuthenticatedUser(), pagingReq);
|
||||
String user = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
if(site != null)
|
||||
{
|
||||
return blogService.getDrafts(site.getShortName(), user, pagingReq);
|
||||
}
|
||||
else
|
||||
{
|
||||
return blogService.getDrafts(node, user, pagingReq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@ import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.service.cmr.blog.BlogPostInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
|
||||
/**
|
||||
* This class is the controller for the blog-posts-mypublished.get web script.
|
||||
@@ -35,9 +36,17 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
public class BlogPostsMyPublishedGet extends AbstractGetBlogWebScript
|
||||
{
|
||||
@Override
|
||||
protected PagingResults<BlogPostInfo> getBlogResultsImpl(NodeRef node, Date fromDate, Date toDate, PagingRequest pagingReq)
|
||||
protected PagingResults<BlogPostInfo> getBlogResultsImpl(
|
||||
SiteInfo site, NodeRef node, Date fromDate, Date toDate, PagingRequest pagingReq)
|
||||
{
|
||||
String fullyAuthenticatedUser = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
return blogService.getPublished(node, fromDate, toDate, fullyAuthenticatedUser, pagingReq);
|
||||
if(site != null)
|
||||
{
|
||||
return blogService.getPublished(site.getShortName(), fromDate, toDate, fullyAuthenticatedUser, pagingReq);
|
||||
}
|
||||
else
|
||||
{
|
||||
return blogService.getPublished(node, fromDate, toDate, fullyAuthenticatedUser, pagingReq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.service.cmr.blog.BlogPostInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
|
||||
/**
|
||||
* This class is the controller for the blog-posts-publishedext.get web script.
|
||||
@@ -34,8 +35,16 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
public class BlogPostsNewGet extends AbstractGetBlogWebScript
|
||||
{
|
||||
@Override
|
||||
protected PagingResults<BlogPostInfo> getBlogResultsImpl(NodeRef node, Date fromDate, Date toDate, PagingRequest pagingReq)
|
||||
protected PagingResults<BlogPostInfo> getBlogResultsImpl(
|
||||
SiteInfo site, NodeRef node, Date fromDate, Date toDate, PagingRequest pagingReq)
|
||||
{
|
||||
return blogService.getPublished(node, fromDate, toDate, null, pagingReq);
|
||||
if(site != null)
|
||||
{
|
||||
return blogService.getPublished(site.getShortName(), fromDate, toDate, null, pagingReq);
|
||||
}
|
||||
else
|
||||
{
|
||||
return blogService.getPublished(node, fromDate, toDate, null, pagingReq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.service.cmr.blog.BlogPostInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
@@ -41,9 +42,17 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
public class BlogPostsPerMonthGet extends AbstractGetBlogWebScript
|
||||
{
|
||||
@Override
|
||||
protected PagingResults<BlogPostInfo> getBlogResultsImpl(NodeRef node, Date fromDate, Date toDate, PagingRequest pagingReq)
|
||||
protected PagingResults<BlogPostInfo> getBlogResultsImpl(
|
||||
SiteInfo site, NodeRef node, Date fromDate, Date toDate, PagingRequest pagingReq)
|
||||
{
|
||||
return blogService.getPublished(node, fromDate, toDate, null, pagingReq);
|
||||
if(site != null)
|
||||
{
|
||||
return blogService.getPublished(site.getShortName(), fromDate, toDate, null, pagingReq);
|
||||
}
|
||||
else
|
||||
{
|
||||
return blogService.getPublished(node, fromDate, toDate, null, pagingReq);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -18,30 +18,23 @@
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.blogs.posts;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.web.scripts.blogs.AbstractBlogWebScript;
|
||||
import org.alfresco.repo.web.scripts.blogs.BlogPostLibJs;
|
||||
import org.alfresco.repo.web.scripts.blogs.RequestUtilsLibJs;
|
||||
import org.alfresco.service.cmr.activities.ActivityService;
|
||||
import org.alfresco.service.cmr.blog.BlogPostInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.tagging.TaggingService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONStringer;
|
||||
import org.json.JSONTokener;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
@@ -55,34 +48,33 @@ public class BlogPostsPost extends AbstractBlogWebScript
|
||||
private static final Log log = LogFactory.getLog(BlogPostsPost.class);
|
||||
|
||||
// Injected services
|
||||
private ActivityService activityService;
|
||||
private TaggingService taggingService;
|
||||
|
||||
public void setActivityService(ActivityService activityService)
|
||||
{
|
||||
this.activityService = activityService;
|
||||
}
|
||||
|
||||
public void setTaggingService(TaggingService taggingService)
|
||||
{
|
||||
this.taggingService = taggingService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
protected Map<String, Object> executeImpl(SiteInfo site, NodeRef nodeRef,
|
||||
BlogPostInfo blog, WebScriptRequest req, JSONObject json, Status status, Cache cache)
|
||||
{
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
|
||||
JsonParams jsonPostParams = parsePostParams(req);
|
||||
// If they're doing Path Based rather than Site Based, ensure
|
||||
// that the Container is a Tag Scope
|
||||
if(site == null && nodeRef != null)
|
||||
{
|
||||
ensureTagScope(nodeRef);
|
||||
}
|
||||
|
||||
// Have the Blog Post created
|
||||
JsonParams jsonPostParams = parsePostParams(json);
|
||||
BlogPostInfo post = createBlogPost(jsonPostParams, site, nodeRef);
|
||||
|
||||
NodeRef node = RequestUtilsLibJs.getRequestNode(req, services);
|
||||
ensureTagScope(node);
|
||||
|
||||
NodeRef post = createBlogPost(jsonPostParams, node);
|
||||
|
||||
Map<String, Object> blogPostData = BlogPostLibJs.getBlogPostData(post, services);
|
||||
Map<String, Object> blogPostData = BlogPostLibJs.getBlogPostData(post.getNodeRef(), services);
|
||||
model.put(ITEM, blogPostData);
|
||||
model.put(EXTERNAL_BLOG_CONFIG, BlogPostLibJs.hasExternalBlogConfiguration(node, services));
|
||||
model.put(EXTERNAL_BLOG_CONFIG, BlogPostLibJs.hasExternalBlogConfiguration(nodeRef, services));
|
||||
|
||||
boolean isDraft = blogPostData.get(ITEM) != null &&
|
||||
((Boolean)blogPostData.get(ITEM)).booleanValue();
|
||||
@@ -91,92 +83,62 @@ public class BlogPostsPost extends AbstractBlogWebScript
|
||||
jsonPostParams.getPage() != null &&
|
||||
!isDraft)
|
||||
{
|
||||
final NodeRef nodeParam = (NodeRef)blogPostData.get(NODE);
|
||||
String postNodeName = (String)nodeService.getProperty(nodeParam, ContentModel.PROP_NAME);
|
||||
String postNodeTitle = (String)nodeService.getProperty(nodeParam, ContentModel.PROP_TITLE);
|
||||
String data = null;
|
||||
try
|
||||
{
|
||||
data = new JSONStringer()
|
||||
.object()
|
||||
.key(TITLE).value(postNodeTitle)
|
||||
.key(PAGE).value(jsonPostParams.getPage() + "?postId=" + postNodeName)
|
||||
.endObject().toString();
|
||||
} catch (JSONException e)
|
||||
{
|
||||
// Intentionally empty
|
||||
}
|
||||
if (data != null)
|
||||
{
|
||||
activityService.postActivity("org.alfresco.blog.post-created", jsonPostParams.getSite(), "blog", data);
|
||||
}
|
||||
addActivityEntry("created", post, site, req, json);
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
private JsonParams parsePostParams(WebScriptRequest req)
|
||||
private JsonParams parsePostParams(JSONObject json)
|
||||
{
|
||||
try
|
||||
{
|
||||
JSONObject json = new JSONObject(new JSONTokener(req.getContent().getContent()));
|
||||
|
||||
JsonParams result = new JsonParams();
|
||||
if (json.has(TITLE))
|
||||
{
|
||||
result.setTitle(json.getString(TITLE));
|
||||
}
|
||||
if (json.has(CONTENT))
|
||||
{
|
||||
result.setContent(json.getString(CONTENT));
|
||||
}
|
||||
if (json.has(DRAFT))
|
||||
{
|
||||
result.setIsDraft(json.getString(DRAFT));
|
||||
}
|
||||
// If there are no tags, this is a java.lang.String "".
|
||||
// If there are any tags, it's a JSONArray of strings. One or more.
|
||||
if (json.has(TAGS))
|
||||
{
|
||||
Object tagsObj = json.get(TAGS);
|
||||
List<String> tags = new ArrayList<String>();
|
||||
if (tagsObj instanceof JSONArray)
|
||||
{
|
||||
JSONArray tagsJsonArray = (JSONArray)tagsObj;
|
||||
for (int i = 0; i < tagsJsonArray.length(); i++)
|
||||
{
|
||||
tags.add(tagsJsonArray.getString(i));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tags.add(tagsObj.toString());
|
||||
}
|
||||
result.setTags(tags);
|
||||
}
|
||||
if (json.has(SITE))
|
||||
{
|
||||
result.setSite(json.getString(SITE));
|
||||
}
|
||||
if (json.has(PAGE))
|
||||
{
|
||||
result.setPage(json.getString(PAGE));
|
||||
}
|
||||
if (json.has(CONTAINER))
|
||||
{
|
||||
result.setContainer(json.getString(CONTAINER));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (IOException iox)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from req.", iox);
|
||||
}
|
||||
catch (JSONException je)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", je);
|
||||
}
|
||||
JsonParams result = new JsonParams();
|
||||
if (json.containsKey(TITLE))
|
||||
{
|
||||
result.setTitle((String)json.get(TITLE));
|
||||
}
|
||||
if (json.containsKey(CONTENT))
|
||||
{
|
||||
result.setContent((String)json.get(CONTENT));
|
||||
}
|
||||
if (json.containsKey(DRAFT))
|
||||
{
|
||||
result.setIsDraft((Boolean)json.get(DRAFT));
|
||||
}
|
||||
|
||||
// If there are no tags, this is a java.lang.String "".
|
||||
// If there are any tags, it's a JSONArray of strings. One or more.
|
||||
if (json.containsKey(TAGS))
|
||||
{
|
||||
Object tagsObj = json.get(TAGS);
|
||||
List<String> tags = new ArrayList<String>();
|
||||
if (tagsObj instanceof JSONArray)
|
||||
{
|
||||
JSONArray tagsJsonArray = (JSONArray)tagsObj;
|
||||
for (int i = 0; i < tagsJsonArray.size(); i++)
|
||||
{
|
||||
tags.add( (String)tagsJsonArray.get(i) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tags.add(tagsObj.toString());
|
||||
}
|
||||
result.setTags(tags);
|
||||
}
|
||||
if (json.containsKey(SITE))
|
||||
{
|
||||
result.setSite((String)json.get(SITE));
|
||||
}
|
||||
if (json.containsKey(PAGE))
|
||||
{
|
||||
result.setPage((String)json.get(PAGE));
|
||||
}
|
||||
if (json.containsKey(CONTAINER))
|
||||
{
|
||||
result.setContainer((String)json.get(CONTAINER));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,11 +164,11 @@ public class BlogPostsPost extends AbstractBlogWebScript
|
||||
/**
|
||||
* Creates a blog post
|
||||
*/
|
||||
private NodeRef createBlogPost(JsonParams jsonParams, NodeRef blogNode)
|
||||
private BlogPostInfo createBlogPost(JsonParams jsonParams, SiteInfo site, NodeRef blogNode)
|
||||
{
|
||||
String titleParam = jsonParams.getTitle() == null ? "" : jsonParams.getTitle();
|
||||
String contentParam = jsonParams.getContent() == null ? "" : jsonParams.getContent();
|
||||
boolean isDraftParam = jsonParams.getIsDraft() == null ? false : Boolean.parseBoolean(jsonParams.getIsDraft());
|
||||
boolean isDraftParam = jsonParams.getIsDraft();
|
||||
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
@@ -225,7 +187,17 @@ public class BlogPostsPost extends AbstractBlogWebScript
|
||||
tagsParam.addAll(jsonParams.getTags());
|
||||
}
|
||||
|
||||
BlogPostInfo newPostNode = blogService.createBlogPost(blogNode, titleParam, contentParam, isDraftParam);
|
||||
BlogPostInfo newPostNode;
|
||||
if(site != null)
|
||||
{
|
||||
newPostNode = blogService.createBlogPost(
|
||||
site.getShortName(), titleParam, contentParam, isDraftParam);
|
||||
}
|
||||
else
|
||||
{
|
||||
newPostNode = blogService.createBlogPost(
|
||||
blogNode, titleParam, contentParam, isDraftParam);
|
||||
}
|
||||
|
||||
// Ignore empty string tags
|
||||
List<String> nonEmptyTags = new ArrayList<String>();
|
||||
@@ -241,7 +213,7 @@ public class BlogPostsPost extends AbstractBlogWebScript
|
||||
taggingService.setTags(newPostNode.getNodeRef(), nonEmptyTags);
|
||||
}
|
||||
|
||||
return newPostNode.getNodeRef();
|
||||
return newPostNode;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -251,7 +223,7 @@ public class BlogPostsPost extends AbstractBlogWebScript
|
||||
{
|
||||
private String title;
|
||||
private String content;
|
||||
private String isDraft; //This is a String, not a boolean
|
||||
private boolean isDraft = false;
|
||||
private List<String> tags;
|
||||
private String site;
|
||||
private String container;
|
||||
@@ -273,11 +245,11 @@ public class BlogPostsPost extends AbstractBlogWebScript
|
||||
{
|
||||
this.content = content;
|
||||
}
|
||||
public String getIsDraft()
|
||||
public boolean getIsDraft()
|
||||
{
|
||||
return isDraft;
|
||||
}
|
||||
public void setIsDraft(String isDraft)
|
||||
public void setIsDraft(boolean isDraft)
|
||||
{
|
||||
this.isDraft = isDraft;
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.service.cmr.blog.BlogPostInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
|
||||
/**
|
||||
* This class is the controller for the blog-posts-publishedext.get web script.
|
||||
@@ -34,8 +35,16 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
public class BlogPostsPublishedExtGet extends AbstractGetBlogWebScript
|
||||
{
|
||||
@Override
|
||||
protected PagingResults<BlogPostInfo> getBlogResultsImpl(NodeRef node, Date fromDate, Date toDate, PagingRequest pagingReq)
|
||||
protected PagingResults<BlogPostInfo> getBlogResultsImpl(
|
||||
SiteInfo site, NodeRef node, Date fromDate, Date toDate, PagingRequest pagingReq)
|
||||
{
|
||||
return blogService.getPublishedExternally(node, pagingReq);
|
||||
if(site != null)
|
||||
{
|
||||
return blogService.getPublishedExternally(site.getShortName(), pagingReq);
|
||||
}
|
||||
else
|
||||
{
|
||||
return blogService.getPublishedExternally(node, pagingReq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user