mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
REPO-3236: Remove blogs (#177)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Branch specific configuration file for localisation scripts
|
||||
|
||||
MESSAGE_SEARCH_PATH="src/main/resources/alfresco/messages/admin-console*.properties src/main/resources/alfresco/messages/custommodel-restapi-messages*.properties src/main/resources/alfresco/messages/rest-framework-messages*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/admin/admin-communitysummary.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/admin/consoles/admin-repoconsole.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/admin/consoles/admin-tenantconsole.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/admin/consoles/admin-workflowconsole.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/admin/support-tools/admin-nodebrowser.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/audit/entry*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/blogs/post/blog-post.delete*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/links/links-delete.post*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/links/links.post*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/links/links.put*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/person/user-csv-upload.post*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/event.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/event.post*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/event.put*.properties"
|
||||
MESSAGE_SEARCH_PATH="src/main/resources/alfresco/messages/admin-console*.properties src/main/resources/alfresco/messages/custommodel-restapi-messages*.properties src/main/resources/alfresco/messages/rest-framework-messages*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/admin/admin-communitysummary.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/admin/consoles/admin-repoconsole.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/admin/consoles/admin-tenantconsole.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/admin/consoles/admin-workflowconsole.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/admin/support-tools/admin-nodebrowser.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/audit/entry*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/links/links-delete.post*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/links/links.post*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/links/links.put*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/person/user-csv-upload.post*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/event.get*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/event.post*.properties src/main/resources/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/event.put*.properties"
|
||||
|
||||
EXCLUDED_FILES="src/main/resources/alfresco/templates/webscripts/org/alfresco/repository/audit/control.properties"
|
||||
|
||||
|
2
pom.xml
2
pom.xml
@@ -35,7 +35,7 @@
|
||||
<dir.root>${project.build.directory}/alf_data</dir.root>
|
||||
<img.exe>convert</img.exe>
|
||||
|
||||
<dependency.alfresco-repository.version>7.55</dependency.alfresco-repository.version>
|
||||
<dependency.alfresco-repository.version>7.56</dependency.alfresco-repository.version>
|
||||
<dependency.alfresco-core.version>7.9</dependency.alfresco-core.version>
|
||||
<dependency.alfresco-data-model.version>8.29</dependency.alfresco-data-model.version>
|
||||
<dependency.alfresco-pdf-renderer.version>1.1</dependency.alfresco-pdf-renderer.version>
|
||||
|
@@ -1,311 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.blogs;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.activities.post.lookup.PostLookup;
|
||||
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.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;
|
||||
|
||||
/**
|
||||
* @author Neil Mc Erlean
|
||||
* @since 4.0
|
||||
*/
|
||||
public abstract class AbstractBlogWebScript extends DeclarativeWebScript
|
||||
{
|
||||
// Various common parameter strings in the blog webscripts.
|
||||
protected static final String CONTAINER = "container";
|
||||
protected static final String CONTENT = "content";
|
||||
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";
|
||||
protected static final String SITE = "site";
|
||||
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;
|
||||
|
||||
public void setServiceRegistry(ServiceRegistry services)
|
||||
{
|
||||
this.services = services;
|
||||
}
|
||||
|
||||
public void setRepository(Repository repository)
|
||||
{
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
public void setBlogService(BlogService blogService)
|
||||
{
|
||||
this.blogService = blogService;
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
public void setSiteService(SiteService siteService)
|
||||
{
|
||||
this.siteService = siteService;
|
||||
}
|
||||
|
||||
public void setActivityService(ActivityService activityService)
|
||||
{
|
||||
this.activityService = activityService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.blogs;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.BlogIntegrationModel;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
/**
|
||||
* This class is a port of a previous JavaScript library.
|
||||
*
|
||||
* @author Neil Mc Erlean (based on previous JavaScript)
|
||||
* @since 4.0
|
||||
* @deprecated This class should not be extended or reused as it may be refactored.
|
||||
*/
|
||||
public class BlogLibJs
|
||||
{
|
||||
/**
|
||||
* Fetches the blog properties from the json object and adds them to an array
|
||||
* using the correct property names as indexes.
|
||||
*/
|
||||
public static Map<QName, Serializable> getBlogPropertiesArray(JSONObject json)
|
||||
{
|
||||
Map<QName, Serializable> arr = new HashMap<QName, Serializable>();
|
||||
|
||||
putJSONEntryInMap(json, arr, "blogType", BlogIntegrationModel.PROP_BLOG_IMPLEMENTATION);
|
||||
putJSONEntryInMap(json, arr, "blogId", BlogIntegrationModel.PROP_ID);
|
||||
putJSONEntryInMap(json, arr, "blogName", BlogIntegrationModel.PROP_NAME);
|
||||
putJSONEntryInMap(json, arr, "blogDescription", BlogIntegrationModel.PROP_DESCRIPTION);
|
||||
putJSONEntryInMap(json, arr, "blogUrl", BlogIntegrationModel.PROP_URL);
|
||||
putJSONEntryInMap(json, arr, "username", BlogIntegrationModel.PROP_USER_NAME);
|
||||
putJSONEntryInMap(json, arr, "password", BlogIntegrationModel.PROP_PASSWORD);
|
||||
return arr;
|
||||
}
|
||||
|
||||
private static void putJSONEntryInMap(JSONObject json,
|
||||
Map<QName, Serializable> arr, String jsonKey, QName mapKey)
|
||||
{
|
||||
if (json.containsKey(jsonKey))
|
||||
{
|
||||
arr.put(mapKey, (Serializable)json.get(jsonKey));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,132 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.blogs;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.BlogIntegrationModel;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* This class is a port of a previous JavaScript library.
|
||||
*
|
||||
* @author Neil Mc Erlean (based on previous JavaScript)
|
||||
* @since 4.0
|
||||
*/
|
||||
public class BlogPostLibJs
|
||||
{
|
||||
//FIXME It will be refactored when the other services are ported from JavaScript to Java.
|
||||
|
||||
/**
|
||||
* Checks whether a blog configuration is available
|
||||
* This should at some point also check whether the configuration is enabled.
|
||||
*
|
||||
* @param node the node that should be checked. Will check all parents if
|
||||
* the node itself doesn't contain a configuration.
|
||||
* @return {boolean} whether a configuration could be found.
|
||||
*/
|
||||
public static boolean hasExternalBlogConfiguration(NodeRef node, ServiceRegistry services)
|
||||
{
|
||||
if (node == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (services.getNodeService().hasAspect(node, BlogIntegrationModel.ASPECT_BLOG_DETAILS))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return hasExternalBlogConfiguration(services.getNodeService().getPrimaryParent(node).getParentRef(), services);
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, Object> getBlogPostData(NodeRef node, ServiceRegistry services)
|
||||
{
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
data.put("node", node);
|
||||
String creator = (String)services.getNodeService().getProperty(node, ContentModel.PROP_CREATOR);
|
||||
//ALF-18527
|
||||
NodeRef person = services.getPersonService().getPersonOrNull(creator);
|
||||
if (person != null)
|
||||
{
|
||||
data.put("author", person);
|
||||
}
|
||||
|
||||
data.put("commentCount", CommentsLibJs.getCommentsCount(node, services));
|
||||
|
||||
// is the post published
|
||||
Serializable published = services.getNodeService().getProperty(node, ContentModel.PROP_PUBLISHED);
|
||||
boolean isPublished = published != null;
|
||||
if (isPublished)
|
||||
{
|
||||
data.put("releasedDate", published);
|
||||
}
|
||||
|
||||
// draft
|
||||
data.put("isDraft", !isPublished);
|
||||
|
||||
// set the isUpdated flag
|
||||
Date updatedDate = (Date) services.getNodeService().getProperty(node, ContentModel.PROP_UPDATED);
|
||||
boolean isUpdated = updatedDate != null;
|
||||
data.put("isUpdated", isUpdated);
|
||||
if (isUpdated)
|
||||
{
|
||||
data.put("updatedDate", updatedDate);
|
||||
}
|
||||
|
||||
// fetch standard created/modified dates
|
||||
data.put("createdDate", services.getNodeService().getProperty(node, ContentModel.PROP_CREATED));
|
||||
data.put("modifiedDate", services.getNodeService().getProperty(node, ContentModel.PROP_MODIFIED));
|
||||
|
||||
// does the external post require an update?
|
||||
Date lastUpdate = (Date) services.getNodeService().getProperty(node, BlogIntegrationModel.PROP_LAST_UPDATE);
|
||||
if (isPublished && lastUpdate != null)
|
||||
{
|
||||
// we either use the release or updated date
|
||||
Date modifiedDate = (Date) data.get("releasedDate");
|
||||
|
||||
if (isUpdated)
|
||||
{
|
||||
modifiedDate = (Date) data.get("updatedDate");
|
||||
}
|
||||
data.put("outOfDate", modifiedDate.getTime() - lastUpdate.getTime() > 5000L);
|
||||
}
|
||||
else
|
||||
{
|
||||
data.put("outOfDate", false);
|
||||
}
|
||||
|
||||
data.put("tags", services.getTaggingService().getTags(node));
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.blogs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.model.ForumModel;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
|
||||
/**
|
||||
* This class is a port of a previous JavaScript library used by the blog webscript containers.
|
||||
*
|
||||
* @author Neil Mc Erlean (based on existing JavaScript code)
|
||||
* @since 4.0
|
||||
*/
|
||||
class CommentsLibJs
|
||||
{
|
||||
// TODO It will likely be refactored into the Blog REST API class framework.
|
||||
|
||||
private static final String COMMENTS_TOPIC_NAME = "Comments";
|
||||
|
||||
public static int getCommentsCount(NodeRef node, ServiceRegistry services)
|
||||
{
|
||||
return getComments(node, services).size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all comment nodes for a given node.
|
||||
* @return an array of comments.
|
||||
*/
|
||||
public static List<ChildAssociationRef> getComments(NodeRef node, ServiceRegistry services)
|
||||
{
|
||||
List<ChildAssociationRef> result = new ArrayList<ChildAssociationRef>();
|
||||
|
||||
NodeRef commentsFolder = getCommentsFolder(node, services);
|
||||
if (commentsFolder != null)
|
||||
{
|
||||
List<ChildAssociationRef> children = services.getNodeService().getChildAssocs(commentsFolder, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
|
||||
if (!children.isEmpty())
|
||||
{
|
||||
result = children;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the folder that contains all the comments.
|
||||
*
|
||||
* We currently use the fm:discussable aspect where we
|
||||
* add a "Comments" topic to it.
|
||||
*/
|
||||
public static NodeRef getCommentsFolder(NodeRef node, ServiceRegistry services)
|
||||
{
|
||||
//FIXME These methods are from the original JavaScript. Should use the (soon to arrive) CommentService.
|
||||
NodeRef result = null;
|
||||
if (services.getNodeService().hasAspect(node, ForumModel.ASPECT_DISCUSSABLE))
|
||||
{
|
||||
List<ChildAssociationRef> forumFolders = services.getNodeService().getChildAssocs(node, ForumModel.ASSOC_DISCUSSION, RegexQNamePattern.MATCH_ALL);
|
||||
// The JavaScript was retrieving the first child under this child-assoc so we'll do the same.
|
||||
NodeRef forumFolder = forumFolders.get(0).getChildRef();
|
||||
|
||||
List<ChildAssociationRef> topicFolder = services.getNodeService().getChildAssocs(forumFolder, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, COMMENTS_TOPIC_NAME));
|
||||
result = topicFolder.isEmpty() ? null : topicFolder.get(0).getChildRef();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.blogs.blog;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.web.scripts.blogs.AbstractBlogWebScript;
|
||||
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;
|
||||
|
||||
/**
|
||||
* This class is the controller for the blog.get web script.
|
||||
*
|
||||
* @author Neil Mc Erlean (based on existing JavaScript webscript controllers)
|
||||
* @since 4.0
|
||||
*/
|
||||
public class BlogGet extends AbstractBlogWebScript
|
||||
{
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(SiteInfo site, NodeRef containerNodeRef,
|
||||
BlogPostInfo blog, WebScriptRequest req, JSONObject json, Status status, Cache cache)
|
||||
{
|
||||
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
|
||||
// (For now, we just supply the noderef, but when we have a
|
||||
// proper blog details object we'll use that)
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put(ITEM, containerNodeRef);
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.blogs.blog;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
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.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.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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(SiteInfo site, NodeRef containerNodeRef,
|
||||
BlogPostInfo blog, WebScriptRequest req, JSONObject json, Status status, Cache cache)
|
||||
{
|
||||
if (blog != null)
|
||||
{
|
||||
// They appear to have supplied a blog post itself...
|
||||
// Oh well, let's hope for the best!
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Blog post should not be updated via this web script.");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// Do the work
|
||||
updateBlog(containerNodeRef, json);
|
||||
|
||||
// Record it as done
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("item", containerNodeRef);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a post inside the passed forum node.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private void updateBlog(NodeRef node, JSONObject json)
|
||||
{
|
||||
Map<QName, Serializable> arr = BlogLibJs.getBlogPropertiesArray(json);
|
||||
|
||||
if (nodeService.hasAspect(node, BlogIntegrationModel.ASPECT_BLOG_DETAILS))
|
||||
{
|
||||
Map<QName, Serializable> properties = nodeService.getProperties(node);
|
||||
properties.putAll(arr);
|
||||
nodeService.setProperties(node, properties);
|
||||
}
|
||||
else
|
||||
{
|
||||
nodeService.addAspect(node, BlogIntegrationModel.ASPECT_BLOG_DETAILS, arr);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.blogs.post;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import org.alfresco.repo.web.scripts.blogs.AbstractBlogWebScript;
|
||||
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;
|
||||
|
||||
/**
|
||||
* This class is the controller for the blog-posts.get web script.
|
||||
*
|
||||
* @author Neil Mc Erlean (based on existing JavaScript webscript controllers)
|
||||
* @since 4.0
|
||||
*/
|
||||
public class BlogPostDelete extends AbstractBlogWebScript
|
||||
{
|
||||
protected static final String MSG_BLOG_DELETED = "blog-post.msg.deleted";
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(SiteInfo site, NodeRef nodeRef,
|
||||
BlogPostInfo blog, WebScriptRequest req, JSONObject json, Status status, Cache cache)
|
||||
{
|
||||
final ResourceBundle rb = getResources();
|
||||
|
||||
if (blog == null)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Blog Post Not Found");
|
||||
}
|
||||
|
||||
// TODO Get this from the BlogPostInfo Object
|
||||
final boolean isDraftBlogPost = blogService.isDraftBlogPost(blog.getNodeRef());
|
||||
|
||||
// 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)
|
||||
{
|
||||
addActivityEntry("deleted", blog, site, req, json, nodeRef);
|
||||
}
|
||||
|
||||
// Report it as deleted
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
String message = rb.getString(MSG_BLOG_DELETED);
|
||||
model.put("message",MessageFormat.format(message, blog.getNodeRef()));
|
||||
return model;
|
||||
}
|
||||
}
|
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.blogs.post;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.web.scripts.blogs.AbstractBlogWebScript;
|
||||
import org.alfresco.repo.web.scripts.blogs.BlogPostLibJs;
|
||||
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;
|
||||
|
||||
/**
|
||||
* This class is the controller for the blog-posts.get web script.
|
||||
*
|
||||
* @author Neil Mc Erlean (based on existing JavaScript webscript controllers)
|
||||
* @since 4.0
|
||||
*/
|
||||
public class BlogPostGet extends AbstractBlogWebScript
|
||||
{
|
||||
@Override
|
||||
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>();
|
||||
|
||||
// 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(POST, blog);
|
||||
|
||||
model.put("externalBlogConfig", BlogPostLibJs.hasExternalBlogConfiguration(node, services));
|
||||
|
||||
int contentLength = -1;
|
||||
String arg = req.getParameter("contentLength");
|
||||
if (arg != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
contentLength = Integer.parseInt(arg);
|
||||
}
|
||||
catch (NumberFormatException ignored)
|
||||
{
|
||||
// Intentionally empty
|
||||
}
|
||||
}
|
||||
|
||||
model.put("contentLength", contentLength);
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
@@ -1,229 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.blogs.posts;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
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.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.alfresco.util.UrlUtil;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.surf.util.URLDecoder;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
* @author Neil Mc Erlean (based on existing JavaScript webscript controllers)
|
||||
* @since 4.0
|
||||
*/
|
||||
public abstract class AbstractGetBlogWebScript extends AbstractBlogWebScript
|
||||
{
|
||||
private static final Log log = LogFactory.getLog(AbstractGetBlogWebScript.class);
|
||||
|
||||
@Override
|
||||
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>();
|
||||
|
||||
// process additional parameters. <index, count>
|
||||
PagingRequest pagingReq = parsePagingParams(req);
|
||||
pagingReq.setRequestTotalCountMax(pagingReq.getSkipCount() + pagingReq.getRequestTotalCountMax());
|
||||
|
||||
// begin and end date.
|
||||
// Legacy note: these dates are URL query parameters in int form.
|
||||
Date fromDate = parseDateParam(req, "fromDate");
|
||||
Date toDate = parseDateParam(req, "toDate");
|
||||
|
||||
String tag = req.getParameter("tag");
|
||||
if (tag == null || tag.length() == 0)
|
||||
{
|
||||
tag = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Tags can be full unicode strings, so decode
|
||||
tag = URLDecoder.decode(tag);
|
||||
}
|
||||
|
||||
// One webscript (blog-posts-new.get) uses a 'numdays' parameter as a 'fromDate'.
|
||||
// This is a hacky solution to this special case. FIXME
|
||||
if (this.getClass().equals(BlogPostsNewGet.class))
|
||||
{
|
||||
// Default is for 'now' minus seven days.
|
||||
final long oneDayInMilliseconds = 24 * 60 * 60 * 1000;
|
||||
final long sevenDaysInMilliseconds = 7 * oneDayInMilliseconds;
|
||||
fromDate = new Date(System.currentTimeMillis() - sevenDaysInMilliseconds);
|
||||
|
||||
// But if there is a numdays parameter then that changes the fromDate
|
||||
String numDays = req.getServiceMatch().getTemplateVars().get("numdays");
|
||||
if (numDays != null)
|
||||
{
|
||||
Integer numDaysInt = Integer.parseInt(numDays);
|
||||
fromDate = new Date(System.currentTimeMillis() - (numDaysInt * oneDayInMilliseconds));
|
||||
}
|
||||
}
|
||||
|
||||
// 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())
|
||||
{
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append("Retrieved ").append(blogPostList.getPage().size()).append(" blog posts in page.");
|
||||
log.debug(msg.toString());
|
||||
}
|
||||
|
||||
createFtlModel(req, model, container, pagingReq, blogPostList);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
protected void createFtlModel(WebScriptRequest req, Map<String, Object> model, NodeRef node, PagingRequest pagingReq,
|
||||
PagingResults<BlogPostInfo> blogPostList)
|
||||
{
|
||||
Map<String, Object> blogPostsData = new HashMap<String, Object>();
|
||||
|
||||
final Pair<Integer, Integer> totalResultCount = blogPostList.getTotalResultCount();
|
||||
int total = blogPostList.getPage().size();
|
||||
if (totalResultCount != null && totalResultCount.getFirst() != null)
|
||||
{
|
||||
total = totalResultCount.getFirst();
|
||||
}
|
||||
//FIXME What to do? null
|
||||
blogPostsData.put("total", total);
|
||||
blogPostsData.put("pageSize", pagingReq.getMaxItems());
|
||||
blogPostsData.put("startIndex", pagingReq.getSkipCount());
|
||||
blogPostsData.put("itemCount", blogPostList.getPage().size());
|
||||
|
||||
if (total == pagingReq.getRequestTotalCountMax())
|
||||
{
|
||||
blogPostsData.put("totalRecordsUpper", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
blogPostsData.put("totalRecordsUpper", false);
|
||||
}
|
||||
|
||||
List<Map<String, Object>> blogPostDataSets = new ArrayList<Map<String, Object>>(blogPostList.getPage().size());
|
||||
for (BlogPostInfo postInfo : blogPostList.getPage())
|
||||
{
|
||||
Map<String, Object> data = BlogPostLibJs.getBlogPostData(postInfo.getNodeRef(), services);
|
||||
blogPostDataSets.add(data);
|
||||
}
|
||||
blogPostsData.put("items", blogPostDataSets);
|
||||
|
||||
model.put("data", blogPostsData);
|
||||
|
||||
// fetch the contentLength param
|
||||
String contentLengthStr = req.getParameter("contentLength");
|
||||
int contentLength = contentLengthStr == null ? -1 : Integer.parseInt(contentLengthStr);
|
||||
model.put("contentLength", contentLength);
|
||||
|
||||
// assign the blog node
|
||||
model.put("blog", node);
|
||||
model.put("externalBlogConfig", BlogPostLibJs.hasExternalBlogConfiguration(node, services));
|
||||
}
|
||||
|
||||
private PagingRequest parsePagingParams(WebScriptRequest req)
|
||||
{
|
||||
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)
|
||||
{
|
||||
result = new Date(Long.parseLong(dateStr));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetches all posts of the given blog
|
||||
*/
|
||||
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(site, nonSiteContainer, fromDate, toDate, pagingReq);
|
||||
}
|
||||
else
|
||||
{
|
||||
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(
|
||||
SiteInfo site, NodeRef nonSiteContainer, Date fromDate, Date toDate, PagingRequest pagingReq);
|
||||
}
|
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @author Neil Mc Erlean (based on existing JavaScript webscript controllers)
|
||||
* @since 4.0
|
||||
*/
|
||||
public class BlogPostsGet extends AbstractGetBlogWebScript
|
||||
{
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
}
|
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.blogs.posts;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.alfresco.query.PagingRequest;
|
||||
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.
|
||||
* Based on the original JavaScript webscript controller
|
||||
*
|
||||
* @author Neil Mc Erlean (based on existing JavaScript webscript controllers)
|
||||
* @since 4.0
|
||||
*/
|
||||
public class BlogPostsMyDraftsGet extends AbstractGetBlogWebScript
|
||||
{
|
||||
@Override
|
||||
protected PagingResults<BlogPostInfo> getBlogResultsImpl(SiteInfo site, NodeRef node, Date fromDate, Date toDate, PagingRequest pagingReq)
|
||||
{
|
||||
String user = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
if(site != null)
|
||||
{
|
||||
return blogService.getDrafts(site.getShortName(), user, pagingReq);
|
||||
}
|
||||
else
|
||||
{
|
||||
return blogService.getDrafts(node, user, pagingReq);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.blogs.posts;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.alfresco.query.PagingRequest;
|
||||
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.
|
||||
*
|
||||
* @author Neil Mc Erlean (based on existing JavaScript webscript controllers)
|
||||
* @since 4.0
|
||||
*/
|
||||
public class BlogPostsMyPublishedGet extends AbstractGetBlogWebScript
|
||||
{
|
||||
@Override
|
||||
protected PagingResults<BlogPostInfo> getBlogResultsImpl(
|
||||
SiteInfo site, NodeRef node, Date fromDate, Date toDate, PagingRequest pagingReq)
|
||||
{
|
||||
String fullyAuthenticatedUser = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
if(site != null)
|
||||
{
|
||||
return blogService.getPublished(site.getShortName(), fromDate, toDate, fullyAuthenticatedUser, pagingReq);
|
||||
}
|
||||
else
|
||||
{
|
||||
return blogService.getPublished(node, fromDate, toDate, fullyAuthenticatedUser, pagingReq);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.blogs.posts;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
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.
|
||||
*
|
||||
* @author Neil Mc Erlean (based on existing JavaScript webscript controllers)
|
||||
* @since 4.0
|
||||
*/
|
||||
public class BlogPostsNewGet extends AbstractGetBlogWebScript
|
||||
{
|
||||
@Override
|
||||
protected PagingResults<BlogPostInfo> getBlogResultsImpl(
|
||||
SiteInfo site, NodeRef node, Date fromDate, Date toDate, PagingRequest pagingReq)
|
||||
{
|
||||
if(site != null)
|
||||
{
|
||||
return blogService.getPublished(site.getShortName(), fromDate, toDate, null, pagingReq);
|
||||
}
|
||||
else
|
||||
{
|
||||
return blogService.getPublished(node, fromDate, toDate, null, pagingReq);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,170 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.blogs.posts;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
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;
|
||||
|
||||
/**
|
||||
* This class is the controller for the blog-posts-mypublished.get web script.
|
||||
*
|
||||
* @author Neil Mc Erlean (based on existing JavaScript webscript controllers)
|
||||
* @since 4.0
|
||||
*/
|
||||
public class BlogPostsPerMonthGet extends AbstractGetBlogWebScript
|
||||
{
|
||||
@Override
|
||||
protected PagingResults<BlogPostInfo> getBlogResultsImpl(
|
||||
SiteInfo site, NodeRef node, Date fromDate, Date toDate, PagingRequest pagingReq)
|
||||
{
|
||||
if(site != null)
|
||||
{
|
||||
return blogService.getPublished(site.getShortName(), fromDate, toDate, null, pagingReq);
|
||||
}
|
||||
else
|
||||
{
|
||||
return blogService.getPublished(node, fromDate, toDate, null, pagingReq);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createFtlModel(WebScriptRequest req, Map<String, Object> model, NodeRef node, PagingRequest pagingReq, PagingResults<BlogPostInfo> blogPostList)
|
||||
{
|
||||
model.put(DATA, getBlogPostMonths(blogPostList));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ported from blog-posts-per-month.get.js
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private Date getBeginOfMonthDate(Date date)
|
||||
{
|
||||
//TODO These date processing methods are copied almost verbatim from JavaScript to preserve behaviour.
|
||||
// However they should be updated to use java.util.Calendar as the current implementation assumes a Gregorian calendar.
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(date.getYear(), date.getMonth(), 1);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date representing the last second of a month (23:59:59)
|
||||
* Ported from blog-posts-per-month.get.js
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private Date getEndOfMonthDate(Date date)
|
||||
{
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(date.getYear(), date.getMonth(), date.getDay());
|
||||
// In Gregorian calendar, this would be 31 for January, 30 for March, 28 or 29 for February.
|
||||
int lastDayOfSpecifiedMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||
calendar.set(date.getYear(), date.getMonth(), lastDayOfSpecifiedMonth, 23, 59, 59);
|
||||
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an object containing information about the month specified by date.
|
||||
* Ported from blog-posts-per-month.get.js
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private Map<String, Object> getMonthDataObject(Date date)
|
||||
{
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
data.put("year", date.getYear() + 1900);
|
||||
data.put("month", date.getMonth());
|
||||
data.put("firstPostInMonth", date);
|
||||
data.put("beginOfMonth", getBeginOfMonthDate(date));
|
||||
data.put("endOfMonth", getEndOfMonthDate(date));
|
||||
data.put("count", 1);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches data for each month for which posts exist, plus the count of each.
|
||||
* Note: If no posts could be found, this method will return the current month
|
||||
* but with a count of posts equals zero.
|
||||
* Ported from blog-posts-per-month.get.js
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private List<Map<String, Object>> getBlogPostMonths(PagingResults<BlogPostInfo> nodes)
|
||||
{
|
||||
// will hold the months information
|
||||
List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
|
||||
|
||||
// do we have posts?
|
||||
if (!nodes.getPage().isEmpty())
|
||||
{
|
||||
int currYear = -1;
|
||||
int currMonth = -1;
|
||||
Map<String, Object> currData = null;
|
||||
for (int x = 0; x < nodes.getPage().size(); x++)
|
||||
{
|
||||
NodeRef node = nodes.getPage().get(x).getNodeRef();
|
||||
Date date = (Date) nodeService.getProperty(node, ContentModel.PROP_PUBLISHED);
|
||||
|
||||
// is this a new month?
|
||||
if (currYear != date.getYear() + 1900 || currMonth != date.getMonth())
|
||||
{
|
||||
currYear = date.getYear() + 1900;
|
||||
currMonth = date.getMonth();
|
||||
currData = getMonthDataObject(date);
|
||||
data.add(currData);
|
||||
}
|
||||
// otherwise just increment the counter
|
||||
else
|
||||
{
|
||||
Object countObj = currData.get("count");
|
||||
Integer countInt = countObj == null ? 0 : (Integer)countObj;
|
||||
|
||||
currData.put("count", countInt + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if not, add the current month with count = 0
|
||||
else
|
||||
{
|
||||
Map<String, Object> emptyData = getMonthDataObject(new Date());
|
||||
emptyData.put("count", 0);
|
||||
data.add(emptyData);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
@@ -1,304 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.blogs.posts;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.web.scripts.blogs.AbstractBlogWebScript;
|
||||
import org.alfresco.repo.web.scripts.blogs.BlogPostLibJs;
|
||||
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.simple.JSONArray;
|
||||
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-posts.post web script.
|
||||
*
|
||||
* @author Neil Mc Erlean (based on existing JavaScript webscript controllers)
|
||||
* @since 4.0
|
||||
*/
|
||||
public class BlogPostsPost extends AbstractBlogWebScript
|
||||
{
|
||||
private static final Log log = LogFactory.getLog(BlogPostsPost.class);
|
||||
|
||||
// Injected services
|
||||
private TaggingService taggingService;
|
||||
|
||||
public void setTaggingService(TaggingService taggingService)
|
||||
{
|
||||
this.taggingService = taggingService;
|
||||
}
|
||||
|
||||
@Override
|
||||
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 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);
|
||||
|
||||
Map<String, Object> blogPostData = BlogPostLibJs.getBlogPostData(post.getNodeRef(), services);
|
||||
model.put(ITEM, blogPostData);
|
||||
model.put(EXTERNAL_BLOG_CONFIG, BlogPostLibJs.hasExternalBlogConfiguration(nodeRef, services));
|
||||
|
||||
boolean isDraft = blogPostData.get("isDraft") != null &&
|
||||
((Boolean)blogPostData.get("isDraft")).booleanValue();
|
||||
if (jsonPostParams.getSite() != null &&
|
||||
jsonPostParams.getContainer() != null &&
|
||||
jsonPostParams.getPage() != null &&
|
||||
!isDraft)
|
||||
{
|
||||
addActivityEntry("created", post, site, req, json, post.getNodeRef());
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
private JsonParams parsePostParams(JSONObject json)
|
||||
{
|
||||
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))
|
||||
{
|
||||
Object draft = json.get(DRAFT);
|
||||
if (draft instanceof Boolean)
|
||||
{
|
||||
result.setIsDraft((Boolean)draft);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.setIsDraft( Boolean.parseBoolean((String)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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Taken from JS
|
||||
* @param node NodeRef
|
||||
*/
|
||||
private void ensureTagScope(NodeRef node)
|
||||
{
|
||||
if (!taggingService.isTagScope(node))
|
||||
{
|
||||
taggingService.addTagScope(node);
|
||||
}
|
||||
|
||||
|
||||
// also check the parent (the site!)
|
||||
NodeRef parent = nodeService.getPrimaryParent(node).getParentRef();
|
||||
if (!taggingService.isTagScope(parent))
|
||||
{
|
||||
taggingService.addTagScope(parent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a blog post
|
||||
*/
|
||||
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();
|
||||
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append("Creating blog-post '").append(titleParam).append("'");
|
||||
if (isDraftParam)
|
||||
{
|
||||
msg.append(" DRAFT");
|
||||
}
|
||||
log.debug(msg.toString());
|
||||
}
|
||||
|
||||
List<String> tagsParam = new ArrayList<String>();
|
||||
if (jsonParams.getTags() != null)
|
||||
{
|
||||
tagsParam.addAll(jsonParams.getTags());
|
||||
}
|
||||
|
||||
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>();
|
||||
for (String tag : tagsParam)
|
||||
{
|
||||
if (!tag.trim().isEmpty())
|
||||
{
|
||||
nonEmptyTags.add(tag);
|
||||
}
|
||||
}
|
||||
if (!nonEmptyTags.isEmpty())
|
||||
{
|
||||
taggingService.setTags(newPostNode.getNodeRef(), nonEmptyTags);
|
||||
}
|
||||
|
||||
return newPostNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple POJO class for the parsed JSON from the POST body.
|
||||
*/
|
||||
class JsonParams
|
||||
{
|
||||
private String title;
|
||||
private String content;
|
||||
private boolean isDraft = false;
|
||||
private List<String> tags;
|
||||
private String site;
|
||||
private String container;
|
||||
private String page;
|
||||
|
||||
public String getTitle()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
public void setTitle(String title)
|
||||
{
|
||||
this.title = title;
|
||||
}
|
||||
public String getContent()
|
||||
{
|
||||
return content;
|
||||
}
|
||||
public void setContent(String content)
|
||||
{
|
||||
this.content = content;
|
||||
}
|
||||
public boolean getIsDraft()
|
||||
{
|
||||
return isDraft;
|
||||
}
|
||||
public void setIsDraft(boolean isDraft)
|
||||
{
|
||||
this.isDraft = isDraft;
|
||||
}
|
||||
public List<String> getTags()
|
||||
{
|
||||
return tags;
|
||||
}
|
||||
public void setTags(List<String> tags)
|
||||
{
|
||||
this.tags = tags;
|
||||
}
|
||||
public String getSite()
|
||||
{
|
||||
return site;
|
||||
}
|
||||
public void setSite(String site)
|
||||
{
|
||||
this.site = site;
|
||||
}
|
||||
public String getContainer()
|
||||
{
|
||||
return container;
|
||||
}
|
||||
public void setContainer(String container)
|
||||
{
|
||||
this.container = container;
|
||||
}
|
||||
public String getPage()
|
||||
{
|
||||
return page;
|
||||
}
|
||||
public void setPage(String page)
|
||||
{
|
||||
this.page = page;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.blogs.posts;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
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.
|
||||
*
|
||||
* @author Neil Mc Erlean (based on existing JavaScript webscript controllers)
|
||||
* @since 4.0
|
||||
*/
|
||||
public class BlogPostsPublishedExtGet extends AbstractGetBlogWebScript
|
||||
{
|
||||
@Override
|
||||
protected PagingResults<BlogPostInfo> getBlogResultsImpl(
|
||||
SiteInfo site, NodeRef node, Date fromDate, Date toDate, PagingRequest pagingReq)
|
||||
{
|
||||
if(site != null)
|
||||
{
|
||||
return blogService.getPublishedExternally(site.getShortName(), pagingReq);
|
||||
}
|
||||
else
|
||||
{
|
||||
return blogService.getPublishedExternally(node, pagingReq);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,77 +0,0 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean id="abstractBlogWebScript" parent="webscript" abstract="true">
|
||||
<property name="repository" ref="repositoryHelper"/>
|
||||
<property name="blogService" ref="BlogService"/>
|
||||
<property name="nodeService" ref="NodeService"/>
|
||||
<property name="siteService" ref="SiteService"/>
|
||||
<property name="serviceRegistry" ref="ServiceRegistry"/>
|
||||
<property name="activityService" ref="activityService"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<!-- repository/blogs/blog -->
|
||||
<bean id="webscript.org.alfresco.repository.blogs.blog.blog.get"
|
||||
class="org.alfresco.repo.web.scripts.blogs.blog.BlogGet"
|
||||
parent="abstractBlogWebScript">
|
||||
</bean>
|
||||
|
||||
<bean id="webscript.org.alfresco.repository.blogs.blog.blog.put"
|
||||
class="org.alfresco.repo.web.scripts.blogs.blog.BlogPut"
|
||||
parent="abstractBlogWebScript">
|
||||
</bean>
|
||||
|
||||
|
||||
<!-- repository/blogs/post -->
|
||||
<bean id="webscript.org.alfresco.repository.blogs.post.blog-post.delete"
|
||||
class="org.alfresco.repo.web.scripts.blogs.post.BlogPostDelete"
|
||||
parent="abstractBlogWebScript">
|
||||
</bean>
|
||||
|
||||
<bean id="webscript.org.alfresco.repository.blogs.post.blog-post.get"
|
||||
class="org.alfresco.repo.web.scripts.blogs.post.BlogPostGet"
|
||||
parent="abstractBlogWebScript">
|
||||
</bean>
|
||||
|
||||
|
||||
<!-- repository/blogs/posts -->
|
||||
<bean id="webscript.org.alfresco.repository.blogs.posts.blog-posts.get"
|
||||
class="org.alfresco.repo.web.scripts.blogs.posts.BlogPostsGet"
|
||||
parent="abstractBlogWebScript">
|
||||
</bean>
|
||||
|
||||
<bean id="webscript.org.alfresco.repository.blogs.posts.blog-posts-mydrafts.get"
|
||||
class="org.alfresco.repo.web.scripts.blogs.posts.BlogPostsMyDraftsGet"
|
||||
parent="abstractBlogWebScript">
|
||||
</bean>
|
||||
|
||||
<bean id="webscript.org.alfresco.repository.blogs.posts.blog-posts-mypublished.get"
|
||||
class="org.alfresco.repo.web.scripts.blogs.posts.BlogPostsMyPublishedGet"
|
||||
parent="abstractBlogWebScript">
|
||||
</bean>
|
||||
|
||||
<bean id="webscript.org.alfresco.repository.blogs.posts.blog-posts-publishedext.get"
|
||||
class="org.alfresco.repo.web.scripts.blogs.posts.BlogPostsPublishedExtGet"
|
||||
parent="abstractBlogWebScript">
|
||||
</bean>
|
||||
|
||||
<bean id="webscript.org.alfresco.repository.blogs.posts.blog-posts-new.get"
|
||||
class="org.alfresco.repo.web.scripts.blogs.posts.BlogPostsNewGet"
|
||||
parent="abstractBlogWebScript">
|
||||
</bean>
|
||||
|
||||
<bean id="webscript.org.alfresco.repository.blogs.posts.blog-posts-per-month.get"
|
||||
class="org.alfresco.repo.web.scripts.blogs.posts.BlogPostsPerMonthGet"
|
||||
parent="abstractBlogWebScript">
|
||||
</bean>
|
||||
|
||||
<bean id="webscript.org.alfresco.repository.blogs.posts.blog-posts.post"
|
||||
class="org.alfresco.repo.web.scripts.blogs.posts.BlogPostsPost"
|
||||
parent="abstractBlogWebScript">
|
||||
<property name="taggingService" ref="TaggingService"/>
|
||||
</bean>
|
||||
</beans>
|
@@ -1,14 +0,0 @@
|
||||
<#include "../slingshot-common.lib.ftl">
|
||||
<entry xmlns='http://www.w3.org/2005/Atom'>
|
||||
<title>Blog post created: ${htmlTitle?xml}</title>
|
||||
<link rel="alternate" type="text/html" href="" />
|
||||
<id>http://www.alfresco.org/rss/atom/${id}</id>
|
||||
<updated>${xmldate(date)}</updated>
|
||||
<summary type="html">
|
||||
<![CDATA["${htmlTitle}" blog post created by ${userName?html}.]]>
|
||||
</summary>
|
||||
<author>
|
||||
<name>${userName?xml}</name>
|
||||
<uri>${userId?xml}</uri>
|
||||
</author>
|
||||
</entry>
|
@@ -1,14 +0,0 @@
|
||||
<#include "../slingshot-common.lib.ftl">
|
||||
<entry xmlns='http://www.w3.org/2005/Atom'>
|
||||
<title>Blog post deleted: ${htmlTitle?xml}</title>
|
||||
<link rel="alternate" type="text/html" href="" />
|
||||
<id>http://www.alfresco.org/rss/atom/${id}</id>
|
||||
<updated>${xmldate(date)}</updated>
|
||||
<summary type="html">
|
||||
<![CDATA["${htmlTitle}" blog post deleted by ${userName?html}.]]>
|
||||
</summary>
|
||||
<author>
|
||||
<name>${userName?xml}</name>
|
||||
<uri>${userId?xml}</uri>
|
||||
</author>
|
||||
</entry>
|
@@ -1,14 +0,0 @@
|
||||
<#include "../slingshot-common.lib.ftl">
|
||||
<entry xmlns='http://www.w3.org/2005/Atom'>
|
||||
<title>Blog post updated: ${htmlTitle?xml}</title>
|
||||
<link rel="alternate" type="text/html" href="" />
|
||||
<id>http://www.alfresco.org/rss/atom/${id}</id>
|
||||
<updated>${xmldate(date)}</updated>
|
||||
<summary type="html">
|
||||
<![CDATA["${htmlTitle}" blog post updated by ${userName?html}.]]>
|
||||
</summary>
|
||||
<author>
|
||||
<name>${userName?xml}</name>
|
||||
<uri>${userId?xml}</uri>
|
||||
</author>
|
||||
</entry>
|
@@ -1,31 +0,0 @@
|
||||
<#--
|
||||
This template renders the blog data object.
|
||||
-->
|
||||
<#macro blogJSON item>
|
||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||
{
|
||||
"qnamePath": "${item.qnamePath}",
|
||||
"detailsUrl": "blog/node/${item.nodeRef?replace('://', '/')}",
|
||||
"blogPostsUrl": "blog/node/${item.nodeRef?replace('://', '/')}/posts",
|
||||
"type": "${item.properties["blg:blogImplementation"]!''}",
|
||||
"id": "${item.properties["blg:id"]!'0'}",
|
||||
"name": "${item.properties["blg:name"]!''}",
|
||||
"description": "${item.properties["blg:description"]!''}",
|
||||
"url": "${item.properties["blg:url"]!''}",
|
||||
"username": "${item.properties["blg:userName"]!''}",
|
||||
"password": "${item.properties["blg:password"]!''}",
|
||||
"permissions":
|
||||
{
|
||||
<#if item.getParent()?? && item.getTypeShort() != "st:site" >
|
||||
"create": ${(item.getParent()).hasPermission("CreateChildren")?string},
|
||||
"edit": ${(item.getParent()).hasPermission("Write")?string},
|
||||
"delete": ${(item.getParent()).hasPermission("Delete")?string}
|
||||
<#else>
|
||||
"create": ${item.hasPermission("CreateChildren")?string},
|
||||
"edit": ${item.hasPermission("Write")?string},
|
||||
"delete": ${item.hasPermission("Delete")?string}
|
||||
</#if>
|
||||
}
|
||||
}
|
||||
</#escape>
|
||||
</#macro>
|
@@ -1,49 +0,0 @@
|
||||
|
||||
/** Name of the blog details aspect. */
|
||||
const BLOG_DETAILS_ASPECT = "blg:blogDetails";
|
||||
|
||||
/**
|
||||
* Fetches the blog properties from the json object and adds them to an array
|
||||
* using the correct property names as indexes.
|
||||
*/
|
||||
function getBlogPropertiesArray()
|
||||
{
|
||||
var arr = new Array();
|
||||
if (json.has("blogType"))
|
||||
{
|
||||
arr["blg:blogImplementation"] = json.get("blogType");
|
||||
}
|
||||
if (json.has("blogId"))
|
||||
{
|
||||
arr["blg:id"] = json.get("blogId");
|
||||
}
|
||||
if (json.has("blogName"))
|
||||
{
|
||||
arr["blg:name"] = json.get("blogName");
|
||||
}
|
||||
if (json.has("blogDescription"))
|
||||
{
|
||||
arr["blg:description"] = json.get("blogDescription");
|
||||
}
|
||||
if (json.has("blogUrl"))
|
||||
{
|
||||
arr["blg:url"] = json.get("blogUrl");
|
||||
}
|
||||
if (json.has("username"))
|
||||
{
|
||||
arr["blg:userName"] = json.get("username");
|
||||
}
|
||||
if (json.has("password"))
|
||||
{
|
||||
arr["blg:password"] = json.get("password");
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data object of a blog node.
|
||||
*/
|
||||
function getBlogData(node)
|
||||
{
|
||||
return node;
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
<webscript>
|
||||
<shortname>Get blog</shortname>
|
||||
<description>Get the blog information.</description>
|
||||
<url>/api/blog/site/{site}/{container}/{path}</url>
|
||||
<url>/api/blog/site/{site}/{container}</url>
|
||||
<url>/api/blog/node/{store_type}/{store_id}/{id}</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction allow="readonly">required</transaction>
|
||||
<lifecycle>limited_support</lifecycle>
|
||||
</webscript>
|
@@ -1,4 +0,0 @@
|
||||
<#import "../blog.lib.ftl" as blogLib/>
|
||||
{
|
||||
"item" : <@blogLib.blogJSON item=item />
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
<webscript>
|
||||
<shortname>Put blog</shortname>
|
||||
<description>Updates a blog.</description>
|
||||
<url>/api/blog/site/{site}/{container}/{path}</url>
|
||||
<url>/api/blog/site/{site}/{container}</url>
|
||||
<url>/api/blog/node/{store_type}/{store_id}/{id}</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
<lifecycle>limited_support</lifecycle>
|
||||
</webscript>
|
@@ -1,4 +0,0 @@
|
||||
<#import "../blog.lib.ftl" as blogLib/>
|
||||
{
|
||||
"item" : <@blogLib.blogJSON item=item />
|
||||
}
|
@@ -1,116 +0,0 @@
|
||||
<#import "../generic-paged-results.lib.ftl" as gen/>
|
||||
|
||||
<#-- Renders a person object. -->
|
||||
<#macro renderPerson person fieldName>
|
||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||
"${fieldName}":
|
||||
{
|
||||
<#if person.assocs["cm:avatar"]??>
|
||||
"avatarRef": "${person.assocs["cm:avatar"][0].nodeRef?string}",
|
||||
</#if>
|
||||
"username": "${person.properties["cm:userName"]}",
|
||||
"firstName": "${person.properties["cm:firstName"]!""}",
|
||||
"lastName": "${person.properties["cm:lastName"]!""}"
|
||||
},
|
||||
</#escape>
|
||||
</#macro>
|
||||
|
||||
|
||||
<#macro addContent item>
|
||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||
<#assign safecontent=stringUtils.stripUnsafeHTML(item.node.content)>
|
||||
<#if (contentLength?? && contentLength > -1 && (safecontent?length > contentLength))>
|
||||
"content": "${safecontent?substring(0, contentLength)}",
|
||||
<#else>
|
||||
"content": "${safecontent}",
|
||||
</#if>
|
||||
</#escape>
|
||||
</#macro>
|
||||
|
||||
<#--
|
||||
This template renders a blog post.
|
||||
-->
|
||||
<#macro blogpostJSON item>
|
||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||
{
|
||||
"url": "blog/post/node/${item.node.nodeRef?replace('://','/')}",
|
||||
"commentsUrl": "/node/${item.node.nodeRef?replace('://','/')}/comments",
|
||||
"nodeRef": "${item.node.nodeRef}",
|
||||
"name": "${item.node.properties.name!''}",
|
||||
"title": "${item.node.properties.title!''}",
|
||||
<@addContent item=item />
|
||||
<#if item.author??>
|
||||
<@renderPerson person=item.author fieldName="author" />
|
||||
<#else>
|
||||
"author":
|
||||
{
|
||||
"username": "${item.node.properties.creator}"
|
||||
},
|
||||
</#if>
|
||||
"createdOn": "${formatDateRFC822(item.createdDate)}",
|
||||
"modifiedOn": "${formatDateRFC822(item.modifiedDate)}",
|
||||
"permissions":
|
||||
{
|
||||
"edit": ${item.node.hasPermission("Write")?string},
|
||||
"delete": ${item.node.hasPermission("Delete")?string}
|
||||
},
|
||||
"commentCount": ${item.commentCount?c},
|
||||
"tags": [<#list item.tags as x>"${x}"<#if x_has_next>, </#if></#list>],
|
||||
<#-- draft vs internal published -->
|
||||
"isDraft": ${item.isDraft?string},
|
||||
<#if (! item.isDraft)>
|
||||
"releasedOn": "${formatDateRFC822(item.releasedDate)}",
|
||||
</#if>
|
||||
<#-- true if the post has been updated -->
|
||||
"isUpdated": ${item.isUpdated?string},
|
||||
<#if (item.isUpdated)>
|
||||
"updatedOn": "${formatDateRFC822(item.updatedDate)}",
|
||||
</#if>
|
||||
<#if (item.node.properties["blg:published"]?? && item.node.properties["blg:published"] == true)>
|
||||
"publishedOn": "${formatDateRFC822(item.node.properties["blg:posted"])}",
|
||||
"updatedOn": "${formatDateRFC822(item.node.properties["blg:lastUpdate"])}",
|
||||
"postId": "${item.node.properties["blg:postId"]!''}",
|
||||
"postLink": "${item.node.properties["blg:link"]!''}",
|
||||
"outOfDate": ${item.outOfDate?string},
|
||||
</#if>
|
||||
<#-- external publishing - last to make sure that we correctly end the response without a comma -->
|
||||
"isPublished": ${(item.node.properties["blg:published"]!'false')?string}
|
||||
}
|
||||
</#escape>
|
||||
</#macro>
|
||||
|
||||
<#macro renderPostList>
|
||||
{
|
||||
"metadata":
|
||||
{
|
||||
"blogPermissions":
|
||||
{
|
||||
"create": ${blog.hasPermission("CreateChildren")?string},
|
||||
"edit": ${blog.hasPermission("Write")?string},
|
||||
"delete": ${blog.hasPermission("Delete")?string}
|
||||
},
|
||||
"externalBlogConfig": ${externalBlogConfig?string}
|
||||
},
|
||||
"totalRecordsUpper": ${data.totalRecordsUpper?string("true","false")},
|
||||
<@gen.pagedResults data=data ; item>
|
||||
<@blogpostJSON item=item />
|
||||
</@gen.pagedResults>
|
||||
}
|
||||
</#macro>
|
||||
|
||||
<#macro renderPost>
|
||||
{
|
||||
"metadata":
|
||||
{
|
||||
"externalBlogConfig": ${externalBlogConfig?string}
|
||||
},
|
||||
"item": <@blogpostJSON item=item />
|
||||
}
|
||||
</#macro>
|
||||
|
||||
<#function formatDateRFC822 dateItem>
|
||||
<# local temp=${.locale} -->
|
||||
<#setting locale="en_US">
|
||||
<#return dateItem?datetime?string("EEE, d MMM yyyy HH:mm:ss Z")>
|
||||
<# setting locale=temp -->
|
||||
</#function>
|
@@ -1,130 +0,0 @@
|
||||
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/comments/comments.lib.js">
|
||||
|
||||
const ASPECT_SYNDICATION = "cm:syndication";
|
||||
const PROP_PUBLISHED = "cm:published";
|
||||
const PROP_UPDATED = "cm:updated";
|
||||
|
||||
function setOrUpdateReleasedAndUpdatedDates(node)
|
||||
{
|
||||
// make sure the syndication aspect has been added
|
||||
if (!node.hasAspect(ASPECT_SYNDICATION))
|
||||
{
|
||||
node.addAspect(ASPECT_SYNDICATION, []);
|
||||
}
|
||||
|
||||
// (re-)enable permission inheritance which got disable for draft posts
|
||||
// only set if was previously draft - as only the owner/admin can do this
|
||||
if (!node.inheritsPermissions())
|
||||
{
|
||||
// MNT-12082
|
||||
node.removePermission("All", node.getOwner());
|
||||
node.setInheritsPermissions(true);
|
||||
}
|
||||
|
||||
// check whether the published date has been set
|
||||
if (!node.properties[PROP_PUBLISHED])
|
||||
{
|
||||
// set the published date
|
||||
node.properties[PROP_PUBLISHED] = new Date();
|
||||
node.save();
|
||||
}
|
||||
else
|
||||
{
|
||||
// set/update the updated date
|
||||
node.properties[PROP_UPDATED] = new Date();
|
||||
node.save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data of a blog post.
|
||||
*/
|
||||
function getBlogPostData(node)
|
||||
{
|
||||
var data = {};
|
||||
data.node = node;
|
||||
data.author = people.getPerson(node.properties["cm:creator"]);
|
||||
data.commentCount = getCommentsCount(node);
|
||||
|
||||
// is the post published
|
||||
var isPublished = (node.properties[PROP_PUBLISHED] !== null);
|
||||
if (isPublished)
|
||||
{
|
||||
data.releasedDate = node.properties[PROP_PUBLISHED];
|
||||
}
|
||||
|
||||
// draft
|
||||
data.isDraft = ! isPublished;
|
||||
|
||||
// set the isUpdated flag
|
||||
var isUpdated = (node.properties[PROP_UPDATED] !== null);
|
||||
data.isUpdated = isUpdated;
|
||||
if (isUpdated)
|
||||
{
|
||||
data.updatedDate = node.properties[PROP_UPDATED];
|
||||
}
|
||||
|
||||
// fetch standard created/modified dates
|
||||
data.createdDate = node.properties["cm:created"];
|
||||
data.modifiedDate = node.properties["cm:modified"];
|
||||
|
||||
// does the external post require an update?
|
||||
if (isPublished && (node.properties["blg:lastUpdate"] !== null))
|
||||
{
|
||||
// we either use the release or updated date
|
||||
var modifiedDate = data.releasedDate;
|
||||
if (isUpdated)
|
||||
{
|
||||
modifiedDate = data.updatedDate;
|
||||
}
|
||||
|
||||
if ((modifiedDate - node.properties["blg:lastUpdate"]) > 5000)
|
||||
{
|
||||
data.outOfDate = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
data.outOfDate = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
data.outOfDate = false;
|
||||
}
|
||||
|
||||
// tags
|
||||
if (node.tags !== null)
|
||||
{
|
||||
data.tags = node.tags;
|
||||
}
|
||||
else
|
||||
{
|
||||
data.tags = [];
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a blog configuration is available
|
||||
* This should at some point also check whether the configuration is enabled.
|
||||
*
|
||||
* @param node the node that should be checked. Will check all parents if
|
||||
* the node itself doesn't contain a configuration.
|
||||
* @return {boolean} whether a configuration could be found.
|
||||
*/
|
||||
function hasExternalBlogConfiguration(node)
|
||||
{
|
||||
if (node === null || !node.hasPermission("ReadProperties"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (node.hasAspect("blg:blogDetails"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return hasExternalBlogConfiguration(node.parent);
|
||||
}
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
<webscript>
|
||||
<shortname>Blog post publishing</shortname>
|
||||
<description>Performs external blog publishing functions on a blog post.</description>
|
||||
<url>/api/blog/post/site/{site}/{container}/{path}/publishing</url>
|
||||
<url>/api/blog/post/node/{store_type}/{store_id}/{id}/publishing</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
<lifecycle>limited_support</lifecycle>
|
||||
</webscript>
|
@@ -1,2 +0,0 @@
|
||||
<#import "../blogpost.lib.ftl" as blogpostLib/>
|
||||
<@blogpostLib.renderPost />
|
@@ -1,88 +0,0 @@
|
||||
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/requestutils.lib.js">
|
||||
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/blogs/blogpost.lib.js">
|
||||
|
||||
const POST_ACTION = "publish";
|
||||
const UPDATE_ACTION = "update";
|
||||
const REMOVE_ACTION = "unpublish";
|
||||
|
||||
/**
|
||||
* Validates the action to execute.
|
||||
* @return the action name to be used for the blog-post action or null if the specified action is invalid
|
||||
*/
|
||||
function validateAction(node, action)
|
||||
{
|
||||
var blogAction = null;
|
||||
var isPublished = false;
|
||||
if ((node.hasAspect("blg:blogPost")) && (node.properties["blg:published"] == true))
|
||||
{
|
||||
isPublished = true;
|
||||
}
|
||||
|
||||
// make sure we have a real JavaScript object, otherwise switch won't work correctly
|
||||
action = "" + action;
|
||||
switch (action)
|
||||
{
|
||||
case POST_ACTION:
|
||||
blogAction = (isPublished ? "" : "post");
|
||||
break;
|
||||
case UPDATE_ACTION:
|
||||
blogAction = (isPublished ? "update" : "");
|
||||
break;
|
||||
case REMOVE_ACTION:
|
||||
blogAction = (isPublished ? "remove" : "");
|
||||
break;
|
||||
}
|
||||
|
||||
if (blogAction === null)
|
||||
{
|
||||
// set an error status
|
||||
status.setCode(status.STATUS_BAD_REQUEST, "Invalid action specified (node in wrong state?)");
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return blogAction;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Publishe, update or removes the blog from/to the external blog
|
||||
*/
|
||||
function executeAction(node, action)
|
||||
{
|
||||
// get the blog action to call (the names differ from the constants defined above)
|
||||
var blogAction = validateAction(node, action);
|
||||
if (blogAction != null)
|
||||
{
|
||||
var blog = actions.create("blog-post");
|
||||
blog.parameters.action = blogAction;
|
||||
blog.execute(node);
|
||||
|
||||
// check whether we got an error - if result is non-empty
|
||||
if (blog.parameters["result"].length > 0)
|
||||
{
|
||||
status.setCode(status.STATUS_INTERNAL_SERVER_ERROR, blog.parameters["result"]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function main()
|
||||
{
|
||||
// get requested node
|
||||
var node = getRequestNode();
|
||||
if (status.getCode() != status.STATUS_OK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// fetch and execute the action
|
||||
var action = json.get("action");
|
||||
executeAction(node, action);
|
||||
|
||||
// get the updated data for the blog post
|
||||
model.item = getBlogPostData(node);
|
||||
model.externalBlogConfig = hasExternalBlogConfiguration(node);
|
||||
}
|
||||
|
||||
main();
|
@@ -1,10 +0,0 @@
|
||||
<webscript>
|
||||
<shortname>Delete blog post</shortname>
|
||||
<description>Deletes a blog post.</description>
|
||||
<url>/api/blog/post/site/{site}/{container}/{path}</url>
|
||||
<url>/api/blog/post/node/{store_type}/{store_id}/{id}</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
<lifecycle>limited_support</lifecycle>
|
||||
</webscript>
|
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"message" : "${message}"
|
||||
}
|
@@ -1 +0,0 @@
|
||||
blog-post.msg.deleted=Blog {0} deleted
|
@@ -1 +0,0 @@
|
||||
blog-post.msg.deleted=Blog {0} gel\u00f6scht
|
@@ -1 +0,0 @@
|
||||
blog-post.msg.deleted=Blog {0} eliminado
|
@@ -1 +0,0 @@
|
||||
blog-post.msg.deleted=Blog {0} supprim\u00e9
|
@@ -1 +0,0 @@
|
||||
blog-post.msg.deleted=Blog {0} eliminato
|
@@ -1 +0,0 @@
|
||||
blog-post.msg.deleted=\u30d6\u30ed\u30b0 "{0}" \u304c\u524a\u9664\u3055\u308c\u307e\u3057\u305f
|
@@ -1 +0,0 @@
|
||||
blog-post.msg.deleted=Bloggen {0} ble slettet
|
@@ -1 +0,0 @@
|
||||
blog-post.msg.deleted=Blog {0} verwijderd
|
@@ -1 +0,0 @@
|
||||
blog-post.msg.deleted=Blog {0} exclu\u00eddo
|
@@ -1 +0,0 @@
|
||||
blog-post.msg.deleted=\u0411\u043b\u043e\u0433 {0} \u0443\u0434\u0430\u043b\u0435\u043d
|
@@ -1 +0,0 @@
|
||||
blog-post.msg.deleted=\u5df2\u5220\u9664\u535a\u5ba2 {0}
|
@@ -1,10 +0,0 @@
|
||||
<webscript>
|
||||
<shortname>Get all blogs</shortname>
|
||||
<description>Gets all blogs.</description>
|
||||
<url>/api/blog/post/site/{site}/{container}/{path}</url>
|
||||
<url>/api/blog/post/node/{store_type}/{store_id}/{id}</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction allow="readonly">required</transaction>
|
||||
<lifecycle>limited_support</lifecycle>
|
||||
</webscript>
|
@@ -1,2 +0,0 @@
|
||||
<#import "../blogpost.lib.ftl" as blogpostLib/>
|
||||
<@blogpostLib.renderPost />
|
@@ -1,10 +0,0 @@
|
||||
<webscript>
|
||||
<shortname>Update blog post</shortname>
|
||||
<description>Updates a blog post.</description>
|
||||
<url>/api/blog/post/site/{site}/{container}/{path}</url>
|
||||
<url>/api/blog/post/node/{store_type}/{store_id}/{id}</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
<lifecycle>limited_support</lifecycle>
|
||||
</webscript>
|
@@ -1,2 +0,0 @@
|
||||
<#import "../blogpost.lib.ftl" as blogpostLib/>
|
||||
<@blogpostLib.renderPost />
|
@@ -1,91 +0,0 @@
|
||||
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/requestutils.lib.js">
|
||||
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/blogs/blogpost.lib.js">
|
||||
|
||||
/**
|
||||
* Updates the draft mode part of the post
|
||||
*/
|
||||
function updateBlogPostDraftMode(postNode)
|
||||
{
|
||||
// make sure the user doesn't try to put a non-draft
|
||||
// post back into draft node
|
||||
var currentDraft = (postNode.properties[PROP_PUBLISHED] == undefined);
|
||||
var isDraft = json.has("draft") && json.get("draft").toString() == "true";
|
||||
|
||||
// requested draft, previously non-draft: throw an exception
|
||||
if (isDraft && !currentDraft)
|
||||
{
|
||||
// set an error
|
||||
status.setCode(status.STATUS_BAD_REQUEST, "Cannot put a published post back into draft mode");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isDraft)
|
||||
{
|
||||
setOrUpdateReleasedAndUpdatedDates(postNode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a blog post node
|
||||
*/
|
||||
function updateBlogPost(postNode)
|
||||
{
|
||||
// fetch the new data
|
||||
var title = "";
|
||||
if (json.has("title"))
|
||||
{
|
||||
title = json.get("title");
|
||||
}
|
||||
var content = "";
|
||||
if (json.has("content"))
|
||||
{
|
||||
content = json.get("content");
|
||||
}
|
||||
var tags = [];
|
||||
if (json.has("tags"))
|
||||
{
|
||||
// get the tags JSONArray and copy it into a real javascript array object
|
||||
var tmp = json.get("tags");
|
||||
for (var x=0; x < tmp.length(); x++)
|
||||
{
|
||||
tags.push(tmp.get(x));
|
||||
}
|
||||
}
|
||||
|
||||
// update the node
|
||||
postNode.properties["cm:title"] = title;
|
||||
postNode.mimetype = "text/html";
|
||||
postNode.content = content
|
||||
postNode.tags = tags;
|
||||
postNode.save();
|
||||
|
||||
updateBlogPostDraftMode(postNode);
|
||||
}
|
||||
|
||||
function main()
|
||||
{
|
||||
// get requested node
|
||||
var node = getRequestNode();
|
||||
if (status.getCode() != status.STATUS_OK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// update blog post
|
||||
updateBlogPost(node);
|
||||
|
||||
model.item = getBlogPostData(node);
|
||||
model.externalBlogConfig = hasExternalBlogConfiguration(node);
|
||||
|
||||
if (json.has("site") && json.has("container") && json.has("page") && !model.item.isDraft)
|
||||
{
|
||||
var data =
|
||||
{
|
||||
title: model.item.node.properties.title,
|
||||
page: json.get("page") + "?postId=" + model.item.node.properties.name
|
||||
}
|
||||
activities.postActivity("org.alfresco.blog.post-updated", json.get("site"), "blog", jsonUtils.toJSONString(data));
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
@@ -1,11 +0,0 @@
|
||||
<webscript>
|
||||
<shortname>Get blog posts (draft)</shortname>
|
||||
<description>Gets all draft posts for a blog.</description>
|
||||
<url>/api/blog/site/{site}/{container}/{path}/posts/mydrafts</url>
|
||||
<url>/api/blog/site/{site}/{container}/posts/mydrafts</url>
|
||||
<url>/api/blog/node/{store_type}/{store_id}/{id}/posts/mydrafts</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction allow="readonly">required</transaction>
|
||||
<lifecycle>limited_support</lifecycle>
|
||||
</webscript>
|
@@ -1,2 +0,0 @@
|
||||
<#import "../blogpost.lib.ftl" as blogpostLib/>
|
||||
<@blogpostLib.renderPostList />
|
@@ -1,11 +0,0 @@
|
||||
<webscript>
|
||||
<shortname>Get blog posts (published)</shortname>
|
||||
<description>Gets all published posts for a blog.</description>
|
||||
<url>/api/blog/site/{site}/{container}/{path}/posts/mypublished</url>
|
||||
<url>/api/blog/site/{site}/{container}/posts/mypublished</url>
|
||||
<url>/api/blog/node/{store_type}/{store_id}/{id}/posts/mypublished</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction allow="readonly">required</transaction>
|
||||
<lifecycle>limited_support</lifecycle>
|
||||
</webscript>
|
@@ -1,2 +0,0 @@
|
||||
<#import "../blogpost.lib.ftl" as blogpostLib/>
|
||||
<@blogpostLib.renderPostList />
|
@@ -1,11 +0,0 @@
|
||||
<webscript>
|
||||
<shortname>Get blog posts for a number of days</shortname>
|
||||
<description>Get all posts for a blog that were created within the specified number of days.</description>
|
||||
<url>/api/blog/site/{site}/{container}/{path}/posts/new?numdays={numdays}</url>
|
||||
<url>/api/blog/site/{site}/{container}/posts/new?numdays={numdays}</url>
|
||||
<url>/api/blog/node/{store_type}/{store_id}/{id}/posts/new?numdays={numdays}</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction allow="readonly">required</transaction>
|
||||
<lifecycle>limited_support</lifecycle>
|
||||
</webscript>
|
@@ -1,2 +0,0 @@
|
||||
<#import "../blogpost.lib.ftl" as blogpostLib/>
|
||||
<@blogpostLib.renderPostList />
|
@@ -1,11 +0,0 @@
|
||||
<webscript>
|
||||
<shortname>Get blog posts per month</shortname>
|
||||
<description>Gets all months for which there are blog posts plus the number of posts in each.</description>
|
||||
<url>/api/blog/site/{site}/{container}/{path}/postspermonth</url>
|
||||
<url>/api/blog/site/{site}/{container}/postspermonth</url>
|
||||
<url>/api/blog/node/{store_type}/{store_id}/{id}/postspermonth</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction allow="readonly">required</transaction>
|
||||
<lifecycle>limited_support</lifecycle>
|
||||
</webscript>
|
@@ -1,17 +0,0 @@
|
||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||
{
|
||||
"items" : [
|
||||
<#list data as item>
|
||||
{
|
||||
"firstPostInMonth" : "${item.firstPostInMonth?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}",
|
||||
"beginOfMonth" : "${item.beginOfMonth?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}",
|
||||
"endOfMonth" : "${item.endOfMonth?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}",
|
||||
"year" : ${item.year?c},
|
||||
"month" : ${item.month?c}, <#-- Note: January -->
|
||||
"postCount" : ${item.count?c}
|
||||
}
|
||||
<#if item_has_next>,</#if>
|
||||
</#list>
|
||||
]
|
||||
}
|
||||
</#escape>
|
@@ -1,11 +0,0 @@
|
||||
<webscript>
|
||||
<shortname>Get all externally published posts</shortname>
|
||||
<description>Gets all externally published posts for a blog.</description>
|
||||
<url>/api/blog/site/{site}/{container}/{path}/posts/publishedext</url>
|
||||
<url>/api/blog/site/{site}/{container}/posts/publishedext</url>
|
||||
<url>/api/blog/node/{store_type}/{store_id}/{id}/posts/publishedext</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction allow="readonly">required</transaction>
|
||||
<lifecycle>limited_support</lifecycle>
|
||||
</webscript>
|
@@ -1,2 +0,0 @@
|
||||
<#import "../blogpost.lib.ftl" as blogpostLib/>
|
||||
<@blogpostLib.renderPostList />
|
@@ -1,11 +0,0 @@
|
||||
<webscript>
|
||||
<shortname>Get blog posts</shortname>
|
||||
<description>Gets all posts for a blog.</description>
|
||||
<url>/api/blog/site/{site}/{container}/{path}/posts</url>
|
||||
<url>/api/blog/site/{site}/{container}/posts</url>
|
||||
<url>/api/blog/node/{store_type}/{store_id}/{id}/posts</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction allow="readonly">required</transaction>
|
||||
<lifecycle>limited_support</lifecycle>
|
||||
</webscript>
|
@@ -1,2 +0,0 @@
|
||||
<#import "../blogpost.lib.ftl" as blogpostLib/>
|
||||
<@blogpostLib.renderPostList />
|
@@ -1,11 +0,0 @@
|
||||
<webscript>
|
||||
<shortname>Create blog post</shortname>
|
||||
<description>Creates a new blog post.</description>
|
||||
<url>/api/blog/site/{site}/{container}/{path}/posts</url>
|
||||
<url>/api/blog/site/{site}/{container}/posts</url>
|
||||
<url>/api/blog/node/{store_type}/{store_id}/{id}/posts</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
<lifecycle>limited_support</lifecycle>
|
||||
</webscript>
|
@@ -1,2 +0,0 @@
|
||||
<#import "../blogpost.lib.ftl" as blogpostLib/>
|
||||
<@blogpostLib.renderPost />
|
@@ -890,13 +890,6 @@
|
||||
parent="baseArchivedNodeWebScript">
|
||||
</bean>
|
||||
|
||||
|
||||
<!-- -->
|
||||
<!-- BlogService REST API -->
|
||||
<!-- -->
|
||||
<import resource="blogs/web-scripts-blog-context.xml"/>
|
||||
|
||||
|
||||
<!-- -->
|
||||
<!-- Workflow Service REST API -->
|
||||
<!-- -->
|
||||
|
@@ -40,7 +40,6 @@ import org.junit.runners.Suite;
|
||||
org.alfresco.repo.web.scripts.quickshare.QuickShareRestApiTest.class,
|
||||
org.alfresco.repo.web.scripts.admin.AdminWebScriptTest.class,
|
||||
org.alfresco.repo.web.scripts.audit.AuditWebScriptTest.class,
|
||||
org.alfresco.repo.web.scripts.blogs.BlogServiceTest.class,
|
||||
org.alfresco.repo.web.scripts.dictionary.DictionaryRestApiTest.class,
|
||||
org.alfresco.repo.web.scripts.activities.feed.control.FeedControlTest.class,
|
||||
org.alfresco.repo.web.scripts.forms.FormRestApiGet_Test.class,
|
||||
|
@@ -57,7 +57,6 @@ public class ReadOnlyTransactionInGetRestApiTest extends BaseWebScriptTest
|
||||
{
|
||||
private static final String TEST_SITE_NAME = "readOnlyTestSite";
|
||||
|
||||
private static final String URL_GET_SITE_BLOG = "/api/blog/site/" + TEST_SITE_NAME + "/blog";
|
||||
private static final String URL_GET_SITE_LINKS = "/api/links/site/" + TEST_SITE_NAME + "/links?page=1&pageSize=10";
|
||||
private static final String URL_GET_SITE_LINK = "/api/links/link/site/" + TEST_SITE_NAME + "/links/123456789";
|
||||
private static final String URL_GET_SITE_TAGS = "/api/tagscopes/site/" + TEST_SITE_NAME + "/tags";
|
||||
@@ -131,16 +130,6 @@ public class ReadOnlyTransactionInGetRestApiTest extends BaseWebScriptTest
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
}
|
||||
|
||||
public void testGetSiteBlog() throws Exception
|
||||
{
|
||||
// TODO: Fixme - This REST API still requires a readwrite transaction to be successful
|
||||
// Also add tests for all other blog GET REST APIs
|
||||
|
||||
Response response = sendRequest(new GetRequest(URL_GET_SITE_BLOG), 200);
|
||||
logResponse(response);
|
||||
assertEquals(Status.STATUS_OK, response.getStatus());
|
||||
}
|
||||
|
||||
public void testGetSiteLinks() throws Exception
|
||||
{
|
||||
Response response = sendRequest(new GetRequest(URL_GET_SITE_LINKS), 200);
|
||||
|
@@ -33,7 +33,6 @@ import org.alfresco.repo.web.scripts.action.RunningActionRestApiTest;
|
||||
import org.alfresco.repo.web.scripts.activities.feed.control.FeedControlTest;
|
||||
import org.alfresco.repo.web.scripts.admin.AdminWebScriptTest;
|
||||
import org.alfresco.repo.web.scripts.audit.AuditWebScriptTest;
|
||||
import org.alfresco.repo.web.scripts.blogs.BlogServiceTest;
|
||||
import org.alfresco.repo.web.scripts.comment.CommentsApiTest;
|
||||
import org.alfresco.repo.web.scripts.custommodel.CustomModelImportTest;
|
||||
import org.alfresco.repo.web.scripts.dictionary.DictionaryRestApiTest;
|
||||
@@ -79,7 +78,6 @@ public class WebScriptTestSuite extends TestSuite
|
||||
suite.addTestSuite( QuickShareRestApiTest.class );
|
||||
suite.addTestSuite( AdminWebScriptTest.class );
|
||||
suite.addTestSuite( AuditWebScriptTest.class );
|
||||
suite.addTestSuite( BlogServiceTest.class );
|
||||
suite.addTestSuite( DictionaryRestApiTest.class );
|
||||
suite.addTestSuite( FeedControlTest.class );
|
||||
suite.addTestSuite( FormRestApiGet_Test.class );
|
||||
|
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.blogs;
|
||||
|
||||
import org.alfresco.repo.blog.BlogServiceImplTest;
|
||||
import org.alfresco.service.cmr.blog.BlogService;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
|
||||
/**
|
||||
* This class is a holder for the various test classes associated with the {@link BlogService}.
|
||||
* It is not (at the time of writing) intended to be incorporated into the automatic build
|
||||
* which will find the various test classes and run them individually.
|
||||
*
|
||||
* @author Neil Mc Erlean
|
||||
* @since 4.0
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({
|
||||
BlogServiceImplTest.class,
|
||||
BlogServiceTest.class
|
||||
})
|
||||
public class AllBlogTests
|
||||
{
|
||||
// Intentionally empty
|
||||
}
|
@@ -1,998 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.blogs;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.activities.feed.FeedGenerator;
|
||||
import org.alfresco.repo.activities.post.lookup.PostLookup;
|
||||
import org.alfresco.repo.management.subsystems.ChildApplicationContextFactory;
|
||||
import org.alfresco.repo.node.archive.NodeArchiveService;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.site.SiteModel;
|
||||
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
|
||||
import org.alfresco.service.cmr.activities.ActivityService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.alfresco.service.cmr.site.SiteVisibility;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.PropertyMap;
|
||||
import org.alfresco.util.testing.category.LuceneTests;
|
||||
import org.alfresco.util.testing.category.RedundantTests;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONStringer;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
|
||||
|
||||
/**
|
||||
* Unit Test to test Blog Web Script API
|
||||
*
|
||||
* @author mruflin
|
||||
*/
|
||||
@Category(LuceneTests.class)
|
||||
public class BlogServiceTest extends BaseWebScriptTest
|
||||
{
|
||||
@SuppressWarnings("unused")
|
||||
private static Log logger = LogFactory.getLog(BlogServiceTest.class);
|
||||
|
||||
private MutableAuthenticationService authenticationService;
|
||||
private AuthenticationComponent authenticationComponent;
|
||||
private PersonService personService;
|
||||
private SiteService siteService;
|
||||
private NodeArchiveService nodeArchiveService;
|
||||
private ActivityService activityService;
|
||||
private FeedGenerator feedGenerator;
|
||||
private PostLookup postLookup;
|
||||
|
||||
private static final String USER_ONE = "UserOneSecondToo";
|
||||
private static final String USER_TWO = "UserTwoSecondToo";
|
||||
private static final String SITE_SHORT_NAME_BLOG = "BlogSiteShortNameTest";
|
||||
private static final String COMPONENT_BLOG = "blog";
|
||||
|
||||
private static final String URL_BLOG_POST = "/api/blog/post/site/" + SITE_SHORT_NAME_BLOG + "/" + COMPONENT_BLOG + "/";
|
||||
private static final String URL_BLOG_CORE = "/api/blog/site/" + SITE_SHORT_NAME_BLOG + "/" + COMPONENT_BLOG;
|
||||
private static final String URL_BLOG_POSTS = URL_BLOG_CORE + "/posts";
|
||||
private static final String URL_MY_DRAFT_BLOG_POSTS = "/api/blog/site/" + SITE_SHORT_NAME_BLOG +
|
||||
"/" + COMPONENT_BLOG + "/posts/mydrafts";
|
||||
private static final String URL_MY_PUBLISHED_BLOG_POSTS = "/api/blog/site/" + SITE_SHORT_NAME_BLOG +
|
||||
"/" + COMPONENT_BLOG + "/posts/mypublished";
|
||||
|
||||
private static final String URL_DELETE_COMMENT = "api/comment/node/{0}/{1}/{2}?site={3}&itemtitle={4}&page={5}";
|
||||
|
||||
private List<String> posts;
|
||||
private List<String> drafts;
|
||||
|
||||
|
||||
// General methods
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
this.authenticationService = (MutableAuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService");
|
||||
this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent");
|
||||
this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService");
|
||||
this.siteService = (SiteService)getServer().getApplicationContext().getBean("SiteService");
|
||||
this.nodeArchiveService = (NodeArchiveService)getServer().getApplicationContext().getBean("nodeArchiveService");
|
||||
this.activityService = (ActivityService)getServer().getApplicationContext().getBean("activityService");
|
||||
ChildApplicationContextFactory activitiesFeed = (ChildApplicationContextFactory)getServer().getApplicationContext().getBean("ActivitiesFeed");
|
||||
ApplicationContext activitiesFeedCtx = activitiesFeed.getApplicationContext();
|
||||
this.feedGenerator = (FeedGenerator)activitiesFeedCtx.getBean("feedGenerator");
|
||||
this.postLookup = (PostLookup)activitiesFeedCtx.getBean("postLookup");
|
||||
|
||||
// Authenticate as user
|
||||
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
|
||||
|
||||
// Create test site
|
||||
// - only create the site if it doesn't already exist
|
||||
SiteInfo siteInfo = this.siteService.getSite(SITE_SHORT_NAME_BLOG);
|
||||
if (siteInfo == null)
|
||||
{
|
||||
this.siteService.createSite("BlogSitePreset", SITE_SHORT_NAME_BLOG, "BlogSiteTitle", "BlogSiteDescription", SiteVisibility.PUBLIC);
|
||||
}
|
||||
|
||||
// Create users
|
||||
createUser(USER_ONE, SiteModel.SITE_COLLABORATOR, SITE_SHORT_NAME_BLOG);
|
||||
createUser(USER_TWO, SiteModel.SITE_COLLABORATOR, SITE_SHORT_NAME_BLOG);
|
||||
|
||||
// Blank our lists used to track things the test creates
|
||||
posts = new ArrayList<String>(5);
|
||||
drafts = new ArrayList<String>(5);
|
||||
|
||||
// Do tests as inviter user
|
||||
this.authenticationComponent.setCurrentUser(USER_ONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
super.tearDown();
|
||||
|
||||
// admin user required to delete things
|
||||
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
|
||||
|
||||
SiteInfo siteInfo = this.siteService.getSite(SITE_SHORT_NAME_BLOG);
|
||||
if (siteInfo != null)
|
||||
{
|
||||
// delete invite site
|
||||
siteService.deleteSite(SITE_SHORT_NAME_BLOG);
|
||||
nodeArchiveService.purgeArchivedNode(nodeArchiveService.getArchivedNode(siteInfo.getNodeRef()));
|
||||
}
|
||||
|
||||
|
||||
// delete the users
|
||||
personService.deletePerson(USER_ONE);
|
||||
if (this.authenticationService.authenticationExists(USER_ONE))
|
||||
{
|
||||
this.authenticationService.deleteAuthentication(USER_ONE);
|
||||
}
|
||||
|
||||
personService.deletePerson(USER_TWO);
|
||||
if (this.authenticationService.authenticationExists(USER_TWO))
|
||||
{
|
||||
this.authenticationService.deleteAuthentication(USER_TWO);
|
||||
}
|
||||
}
|
||||
|
||||
private void createUser(String userName, String role, String siteMembership)
|
||||
{
|
||||
// if user with given user name doesn't already exist then create user
|
||||
if (this.authenticationService.authenticationExists(userName) == false)
|
||||
{
|
||||
// create user
|
||||
this.authenticationService.createAuthentication(userName, "password".toCharArray());
|
||||
|
||||
// create person properties
|
||||
PropertyMap personProps = new PropertyMap();
|
||||
personProps.put(ContentModel.PROP_USERNAME, userName);
|
||||
personProps.put(ContentModel.PROP_FIRSTNAME, "FirstName123");
|
||||
personProps.put(ContentModel.PROP_LASTNAME, "LastName123");
|
||||
personProps.put(ContentModel.PROP_EMAIL, "FirstName123.LastName123@email.com");
|
||||
personProps.put(ContentModel.PROP_JOBTITLE, "JobTitle123");
|
||||
personProps.put(ContentModel.PROP_JOBTITLE, "Organisation123");
|
||||
|
||||
// create person node for user
|
||||
this.personService.createPerson(personProps);
|
||||
}
|
||||
|
||||
// add the user as a member with the given role
|
||||
this.siteService.setMembership(siteMembership, userName, role);
|
||||
}
|
||||
|
||||
|
||||
// Test helper methods
|
||||
|
||||
private JSONObject getRequestObject(String title, String content, String[] tags, boolean isDraft)
|
||||
throws Exception
|
||||
{
|
||||
JSONObject post = new JSONObject();
|
||||
if (title != null)
|
||||
{
|
||||
post.put("title", title);
|
||||
}
|
||||
if (content != null)
|
||||
{
|
||||
post.put("content", content);
|
||||
}
|
||||
if (tags != null)
|
||||
{
|
||||
JSONArray arr = new JSONArray();
|
||||
for (String s : tags)
|
||||
{
|
||||
arr.put(s);
|
||||
}
|
||||
post.put("tags", arr);
|
||||
}
|
||||
post.put("draft", isDraft);
|
||||
return post;
|
||||
}
|
||||
|
||||
private JSONObject createPost(String title, String content, String[] tags, boolean isDraft, int expectedStatus)
|
||||
throws Exception
|
||||
{
|
||||
JSONObject post = getRequestObject(title, content, tags, isDraft);
|
||||
Response response = sendRequest(new PostRequest(URL_BLOG_POSTS, post.toString(), "application/json"), expectedStatus);
|
||||
|
||||
if (expectedStatus != 200)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
//logger.debug(response.getContentAsString());
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
JSONObject item = result.getJSONObject("item");
|
||||
if (isDraft)
|
||||
{
|
||||
this.drafts.add(item.getString("name"));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.posts.add(item.getString("name"));
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
private JSONObject updatePost(String name, String title, String content, String[] tags, boolean isDraft, int expectedStatus)
|
||||
throws Exception
|
||||
{
|
||||
JSONObject post = getRequestObject(title, content, tags, isDraft);
|
||||
Response response = sendRequest(new PutRequest(URL_BLOG_POST + name, post.toString(), "application/json"), expectedStatus);
|
||||
|
||||
if (expectedStatus != 200)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
return result.getJSONObject("item");
|
||||
}
|
||||
|
||||
private JSONObject getPost(String name, int expectedStatus)
|
||||
throws Exception
|
||||
{
|
||||
Response response = sendRequest(new GetRequest(URL_BLOG_POST + name), expectedStatus);
|
||||
if (expectedStatus == 200)
|
||||
{
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
return result.getJSONObject("item");
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String getCommentsUrl(String nodeRef)
|
||||
{
|
||||
return "/api/node/" + nodeRef.replace("://", "/") + "/comments";
|
||||
}
|
||||
|
||||
private String getCommentUrl(String nodeRef)
|
||||
{
|
||||
return "/api/comment/node/" + nodeRef.replace("://", "/");
|
||||
}
|
||||
|
||||
private String getDeleteCommentUrl(NodeRef commentNodeRef)
|
||||
{
|
||||
String itemTitle = "Test Title";
|
||||
String page = "document-details";
|
||||
|
||||
String URL = MessageFormat.format(URL_DELETE_COMMENT, new Object[] { commentNodeRef.getStoreRef().getProtocol(),
|
||||
commentNodeRef.getStoreRef().getIdentifier(), commentNodeRef.getId(), SITE_SHORT_NAME_BLOG, itemTitle, page});
|
||||
return URL;
|
||||
}
|
||||
|
||||
private JSONObject createComment(String nodeRef, String title, String content, int expectedStatus)
|
||||
throws Exception
|
||||
{
|
||||
JSONObject comment = new JSONObject();
|
||||
comment.put("title", title);
|
||||
comment.put("content", content);
|
||||
comment.put("site", SITE_SHORT_NAME_BLOG);
|
||||
Response response = sendRequest(new PostRequest(getCommentsUrl(nodeRef), comment.toString(), "application/json"), expectedStatus);
|
||||
|
||||
if (expectedStatus != 200)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
//logger.debug("Comment created: " + response.getContentAsString());
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
return result.getJSONObject("item");
|
||||
}
|
||||
|
||||
private JSONObject updateComment(String nodeRef, String title, String content, int expectedStatus)
|
||||
throws Exception
|
||||
{
|
||||
JSONObject comment = new JSONObject();
|
||||
comment.put("title", title);
|
||||
comment.put("content", content);
|
||||
Response response = sendRequest(new PutRequest(getCommentUrl(nodeRef), comment.toString(), "application/json"), expectedStatus);
|
||||
|
||||
if (expectedStatus != 200)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
//logger.debug("Comment updated: " + response.getContentAsString());
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
return result.getJSONObject("item");
|
||||
}
|
||||
|
||||
|
||||
// Tests
|
||||
|
||||
public void testCreateDraftPost() throws Exception
|
||||
{
|
||||
String title = "test";
|
||||
String content = "test";
|
||||
JSONObject item = createPost(title, content, null, true, 200);
|
||||
|
||||
// check that the values
|
||||
assertEquals(title, item.get("title"));
|
||||
assertEquals(content, item.get("content"));
|
||||
assertEquals(true, item.get("isDraft"));
|
||||
|
||||
// check that other user doesn't have access to the draft
|
||||
this.authenticationComponent.setCurrentUser(USER_TWO);
|
||||
getPost(item.getString("name"), 404);
|
||||
this.authenticationComponent.setCurrentUser(USER_ONE);
|
||||
|
||||
// Now we'll GET my-drafts to ensure that the post is there.
|
||||
Response response = sendRequest(new GetRequest(URL_MY_DRAFT_BLOG_POSTS), 200);
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
assertTrue("Wrong number of posts", result.length() > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.0
|
||||
*/
|
||||
@Test
|
||||
@Category({LuceneTests.class, RedundantTests.class})
|
||||
public void testCreateDraftPostWithTagsAndComment() throws Exception
|
||||
{
|
||||
String[] tags = new String[]{"foo", "bar"};
|
||||
String title = "test";
|
||||
String content = "test";
|
||||
JSONObject item = createPost(title, content, tags, true, 200);
|
||||
|
||||
// check that the values
|
||||
assertEquals(title, item.get("title"));
|
||||
assertEquals(content, item.get("content"));
|
||||
assertEquals(true, item.get("isDraft"));
|
||||
JSONArray reportedTags = (JSONArray)item.get("tags");
|
||||
assertEquals("Tags size was wrong.", 2, reportedTags.length());
|
||||
List<String> recoveredTagsList = Arrays.asList(new String[]{reportedTags.getString(0), reportedTags.getString(1)});
|
||||
assertEquals("Tags were wrong.", Arrays.asList(tags), recoveredTagsList);
|
||||
|
||||
// comment on the blog post.
|
||||
NodeRef blogPostNode = new NodeRef(item.getString("nodeRef"));
|
||||
// Currently (mid-Swift dev) there is no Java CommentService, so we have to post a comment via the REST API.
|
||||
String commentsPostUrl = "/api/node/" + blogPostNode.getStoreRef().getProtocol() +
|
||||
"/" + blogPostNode.getStoreRef().getIdentifier() + "/" +
|
||||
blogPostNode.getId() + "/comments";
|
||||
|
||||
String jsonToPost = new JSONStringer().object()
|
||||
.key("title").value("Commented blog title")
|
||||
.key("content").value("Some content.")
|
||||
.endObject().toString();
|
||||
|
||||
Response response = sendRequest(new PostRequest(commentsPostUrl, jsonToPost, "application/json"), 200);
|
||||
|
||||
// check that other user doesn't have access to the draft
|
||||
this.authenticationComponent.setCurrentUser(USER_TWO);
|
||||
getPost(item.getString("name"), 404);
|
||||
this.authenticationComponent.setCurrentUser(USER_ONE);
|
||||
|
||||
// Now we'll GET my-drafts to ensure that the post is there.
|
||||
response = sendRequest(new GetRequest(URL_MY_DRAFT_BLOG_POSTS), 200);
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
|
||||
// Ensure it reports the tag correctly on GET.
|
||||
JSONArray items = result.getJSONArray("items");
|
||||
JSONArray tagsArray = items.getJSONObject(0).getJSONArray("tags");
|
||||
assertEquals("Wrong number of tags", 2, tagsArray.length());
|
||||
assertEquals("Tag wrong", tags[0], tagsArray.getString(0));
|
||||
assertEquals("Tag wrong", tags[1], tagsArray.getString(1));
|
||||
|
||||
// Ensure the comment count is accurate
|
||||
assertEquals("Wrong comment count", 1, items.getJSONObject(0).getInt("commentCount"));
|
||||
|
||||
// and that there is content at the commentsURL.
|
||||
String commentsUrl = "/api" + items.getJSONObject(0).getString("commentsUrl");
|
||||
response = sendRequest(new GetRequest(commentsUrl), 200);
|
||||
|
||||
|
||||
// Now get blog-post by tag.
|
||||
// 1. No such tag
|
||||
response = sendRequest(new GetRequest(URL_BLOG_POSTS + "?tag=NOSUCHTAG"), 200);
|
||||
result = new JSONObject(response.getContentAsString());
|
||||
|
||||
assertEquals(0, result.getInt("total"));
|
||||
|
||||
// tag created above
|
||||
response = sendRequest(new GetRequest(URL_BLOG_POSTS + "?tag=foo"), 200);
|
||||
result = new JSONObject(response.getContentAsString());
|
||||
|
||||
assertEquals(1, result.getInt("total"));
|
||||
|
||||
//TODO More assertions on recovered node.
|
||||
}
|
||||
|
||||
public void testCreatePublishedPost() throws Exception
|
||||
{
|
||||
String title = "published";
|
||||
String content = "content";
|
||||
|
||||
JSONObject item = createPost(title, content, null, false, 200);
|
||||
final String postName = item.getString("name");
|
||||
|
||||
// check the values
|
||||
assertEquals(title, item.get("title"));
|
||||
assertEquals(content, item.get("content"));
|
||||
assertEquals(false, item.get("isDraft"));
|
||||
|
||||
// check that user two has access to it as well
|
||||
this.authenticationComponent.setCurrentUser(USER_TWO);
|
||||
getPost(item.getString("name"), 200);
|
||||
this.authenticationComponent.setCurrentUser(USER_ONE);
|
||||
|
||||
// Now we'll GET my-published to ensure that the post is there.
|
||||
Response response = sendRequest(new GetRequest(URL_MY_PUBLISHED_BLOG_POSTS), 200);
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
|
||||
// we should have posts.size + drafts.size together
|
||||
assertEquals(this.posts.size() + this.drafts.size(), result.getInt("total"));
|
||||
|
||||
// Finally, we'll delete the blog-post to test the REST DELETE call.
|
||||
response = sendRequest(new DeleteRequest(URL_BLOG_POST + postName), 200);
|
||||
|
||||
}
|
||||
|
||||
public void testCreateEmptyPost() throws Exception
|
||||
{
|
||||
JSONObject item = createPost(null, null, null, false, 200);
|
||||
|
||||
// check the values
|
||||
assertEquals("", item.get("title"));
|
||||
assertEquals("", item.get("content"));
|
||||
assertEquals(false, item.get("isDraft"));
|
||||
|
||||
// check that user two has access to it as well
|
||||
this.authenticationComponent.setCurrentUser(USER_TWO);
|
||||
getPost(item.getString("name"), 200);
|
||||
this.authenticationComponent.setCurrentUser(USER_ONE);
|
||||
}
|
||||
|
||||
public void testUpdated() throws Exception
|
||||
{
|
||||
JSONObject item = createPost("test", "test", null, false, 200);
|
||||
String name = item.getString("name");
|
||||
assertEquals(false, item.getBoolean("isUpdated"));
|
||||
|
||||
item = updatePost(name, "new title", "new content", null, false, 200);
|
||||
assertEquals(true, item.getBoolean("isUpdated"));
|
||||
assertEquals("new title", item.getString("title"));
|
||||
assertEquals("new content", item.getString("content"));
|
||||
}
|
||||
|
||||
public void testUpdateWithEmptyValues() throws Exception
|
||||
{
|
||||
JSONObject item = createPost("test", "test", null, false, 200);
|
||||
String name = item.getString("name");
|
||||
assertEquals(false, item.getBoolean("isUpdated"));
|
||||
|
||||
item = updatePost(item.getString("name"), null, null, null, false, 200);
|
||||
assertEquals("", item.getString("title"));
|
||||
assertEquals("", item.getString("content"));
|
||||
}
|
||||
|
||||
public void testPublishThroughUpdate() throws Exception
|
||||
{
|
||||
JSONObject item = createPost("test", "test", null, true, 200);
|
||||
String name = item.getString("name");
|
||||
assertEquals(true, item.getBoolean("isDraft"));
|
||||
|
||||
// check that user two does not have access
|
||||
this.authenticationComponent.setCurrentUser(USER_TWO);
|
||||
getPost(name, 404);
|
||||
this.authenticationComponent.setCurrentUser(USER_ONE);
|
||||
|
||||
item = updatePost(name, "new title", "new content", null, false, 200);
|
||||
assertEquals("new title", item.getString("title"));
|
||||
assertEquals("new content", item.getString("content"));
|
||||
assertEquals(false, item.getBoolean("isDraft"));
|
||||
|
||||
// check that user two does have access
|
||||
this.authenticationComponent.setCurrentUser(USER_TWO);
|
||||
getPost(name, 200);
|
||||
this.authenticationComponent.setCurrentUser(USER_ONE);
|
||||
}
|
||||
|
||||
public void testCannotDoUnpublish() throws Exception
|
||||
{
|
||||
JSONObject item = createPost("test", "test", null, false, 200);
|
||||
String name = item.getString("name");
|
||||
assertEquals(false, item.getBoolean("isDraft"));
|
||||
|
||||
item = updatePost(name, "new title", "new content", null, true, 400); // should return bad request
|
||||
}
|
||||
|
||||
public void testGetAll() throws Exception
|
||||
{
|
||||
String url = URL_BLOG_POSTS;
|
||||
Response response = sendRequest(new GetRequest(url), 200);
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
JSONObject blog;
|
||||
|
||||
// We shouldn't have any posts at this point
|
||||
assertEquals(0, this.posts.size());
|
||||
assertEquals(0, this.drafts.size());
|
||||
|
||||
assertEquals(0, result.getInt("total"));
|
||||
assertEquals(0, result.getInt("startIndex"));
|
||||
assertEquals(0, result.getInt("itemCount"));
|
||||
assertEquals(0, result.getJSONArray("items").length());
|
||||
|
||||
// Check that the permissions are correct
|
||||
JSONObject metadata = result.getJSONObject("metadata");
|
||||
JSONObject perms = metadata.getJSONObject("blogPermissions");
|
||||
assertEquals(false, metadata.getBoolean("externalBlogConfig"));
|
||||
assertEquals(false, perms.getBoolean("delete")); // No container yet
|
||||
assertEquals(true, perms.getBoolean("edit"));
|
||||
assertEquals(true, perms.getBoolean("create"));
|
||||
|
||||
|
||||
// Create a draft and a full post
|
||||
String TITLE_1 = "Published";
|
||||
String TITLE_2 = "Draft";
|
||||
String TITLE_3 = "Another Published";
|
||||
createPost(TITLE_1, "Stuff", null, false, Status.STATUS_OK);
|
||||
createPost(TITLE_2, "Draft Stuff", null, true, Status.STATUS_OK);
|
||||
|
||||
// Check now
|
||||
response = sendRequest(new GetRequest(url), 200);
|
||||
result = new JSONObject(response.getContentAsString());
|
||||
assertEquals(2, result.getInt("total"));
|
||||
assertEquals(0, result.getInt("startIndex"));
|
||||
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);
|
||||
assertEquals(TITLE_1, blog.get("title"));
|
||||
assertEquals(false, blog.getBoolean("isDraft"));
|
||||
perms = blog.getJSONObject("permissions");
|
||||
assertEquals(true, perms.getBoolean("delete"));
|
||||
assertEquals(true, perms.getBoolean("edit"));
|
||||
|
||||
blog = result.getJSONArray("items").getJSONObject(1);
|
||||
assertEquals(TITLE_2, blog.get("title"));
|
||||
assertEquals(true, blog.getBoolean("isDraft"));
|
||||
perms = blog.getJSONObject("permissions");
|
||||
assertEquals(true, perms.getBoolean("delete"));
|
||||
assertEquals(true, perms.getBoolean("edit"));
|
||||
|
||||
|
||||
// Add a third post
|
||||
createPost(TITLE_3, "Still Stuff", null, false, Status.STATUS_OK);
|
||||
|
||||
response = sendRequest(new GetRequest(url), 200);
|
||||
result = new JSONObject(response.getContentAsString());
|
||||
assertEquals(3, result.getInt("total"));
|
||||
assertEquals(0, result.getInt("startIndex"));
|
||||
assertEquals(3, result.getInt("itemCount"));
|
||||
assertEquals(3, result.getJSONArray("items").length());
|
||||
|
||||
// Published then draft, newest first
|
||||
blog = result.getJSONArray("items").getJSONObject(0);
|
||||
assertEquals(TITLE_3, blog.get("title"));
|
||||
blog = result.getJSONArray("items").getJSONObject(1);
|
||||
assertEquals(TITLE_1, blog.get("title"));
|
||||
blog = result.getJSONArray("items").getJSONObject(2);
|
||||
assertEquals(TITLE_2, blog.get("title"));
|
||||
|
||||
|
||||
// Ensure that paging behaves properly
|
||||
response = sendRequest(new GetRequest(url + "?pageSize=2&startIndex=0"), 200);
|
||||
result = new JSONObject(response.getContentAsString());
|
||||
assertEquals(3, result.getInt("total"));
|
||||
assertEquals(0, result.getInt("startIndex"));
|
||||
assertEquals(2, result.getInt("itemCount"));
|
||||
assertEquals(2, result.getJSONArray("items").length());
|
||||
|
||||
assertEquals(TITLE_3, result.getJSONArray("items").getJSONObject(0).get("title"));
|
||||
assertEquals(TITLE_1, result.getJSONArray("items").getJSONObject(1).get("title"));
|
||||
|
||||
|
||||
response = sendRequest(new GetRequest(url + "?pageSize=2&startIndex=1"), 200);
|
||||
result = new JSONObject(response.getContentAsString());
|
||||
assertEquals(3, result.getInt("total"));
|
||||
assertEquals(1, result.getInt("startIndex"));
|
||||
assertEquals(2, result.getInt("itemCount"));
|
||||
assertEquals(2, result.getJSONArray("items").length());
|
||||
|
||||
assertEquals(TITLE_1, result.getJSONArray("items").getJSONObject(0).get("title"));
|
||||
assertEquals(TITLE_2, result.getJSONArray("items").getJSONObject(1).get("title"));
|
||||
|
||||
|
||||
response = sendRequest(new GetRequest(url + "?pageSize=2&startIndex=2"), 200);
|
||||
result = new JSONObject(response.getContentAsString());
|
||||
assertEquals(3, result.getInt("total"));
|
||||
assertEquals(2, result.getInt("startIndex"));
|
||||
assertEquals(1, result.getInt("itemCount"));
|
||||
assertEquals(1, result.getJSONArray("items").length());
|
||||
|
||||
assertEquals(TITLE_2, result.getJSONArray("items").getJSONObject(0).get("title"));
|
||||
|
||||
|
||||
// Switch user, check that permissions are correct
|
||||
// (Drafts won't be seen)
|
||||
this.authenticationComponent.setCurrentUser(USER_TWO);
|
||||
|
||||
response = sendRequest(new GetRequest(url), 200);
|
||||
result = new JSONObject(response.getContentAsString());
|
||||
assertEquals(2, result.getInt("total"));
|
||||
assertEquals(0, result.getInt("startIndex"));
|
||||
assertEquals(2, result.getInt("itemCount"));
|
||||
|
||||
assertEquals(2, result.getJSONArray("items").length());
|
||||
blog = result.getJSONArray("items").getJSONObject(0);
|
||||
assertEquals(TITLE_3, blog.get("title"));
|
||||
assertEquals(false, blog.getBoolean("isDraft"));
|
||||
perms = blog.getJSONObject("permissions");
|
||||
assertEquals(false, perms.getBoolean("delete"));
|
||||
assertEquals(true, perms.getBoolean("edit"));
|
||||
|
||||
blog = result.getJSONArray("items").getJSONObject(1);
|
||||
assertEquals(TITLE_1, blog.get("title"));
|
||||
assertEquals(false, blog.getBoolean("isDraft"));
|
||||
perms = blog.getJSONObject("permissions");
|
||||
assertEquals(false, perms.getBoolean("delete"));
|
||||
assertEquals(true, perms.getBoolean("edit"));
|
||||
}
|
||||
|
||||
public void testGetNew() throws Exception
|
||||
{
|
||||
String url = URL_BLOG_POSTS + "/new";
|
||||
Response response = sendRequest(new GetRequest(url), 200);
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
|
||||
// we should have posts.size
|
||||
assertEquals(this.posts.size(), result.getInt("total"));
|
||||
}
|
||||
|
||||
public void testGetDrafts() throws Exception
|
||||
{
|
||||
String url = URL_BLOG_POSTS + "/mydrafts";
|
||||
Response response = sendRequest(new GetRequest(URL_BLOG_POSTS), 200);
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
|
||||
// we should have drafts.size resultss
|
||||
assertEquals(this.drafts.size(), result.getInt("total"));
|
||||
|
||||
// the second user should have zero
|
||||
this.authenticationComponent.setCurrentUser(USER_TWO);
|
||||
response = sendRequest(new GetRequest(url), 200);
|
||||
result = new JSONObject(response.getContentAsString());
|
||||
assertEquals(0, result.getInt("total"));
|
||||
this.authenticationComponent.setCurrentUser(USER_ONE);
|
||||
|
||||
}
|
||||
|
||||
public void testMyPublished() throws Exception
|
||||
{
|
||||
String url = URL_BLOG_POSTS + "/mypublished";
|
||||
Response response = sendRequest(new GetRequest(url), 200);
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
|
||||
// we should have posts.size results
|
||||
assertEquals(this.drafts.size(), result.getInt("total"));
|
||||
|
||||
// the second user should have zero
|
||||
this.authenticationComponent.setCurrentUser(USER_TWO);
|
||||
response = sendRequest(new GetRequest(url), 200);
|
||||
result = new JSONObject(response.getContentAsString());
|
||||
assertEquals(0, result.getInt("total"));
|
||||
this.authenticationComponent.setCurrentUser(USER_ONE);
|
||||
}
|
||||
|
||||
public void testComments() throws Exception
|
||||
{
|
||||
JSONObject item = createPost("test", "test", null, false, 200);
|
||||
String name = item.getString("name");
|
||||
String nodeRef = item.getString("nodeRef");
|
||||
|
||||
JSONObject commentOne = createComment(nodeRef, "comment", "content", 200);
|
||||
JSONObject commentTwo = createComment(nodeRef, "comment", "content", 200);
|
||||
|
||||
// fetch the comments
|
||||
Response response = sendRequest(new GetRequest(getCommentsUrl(nodeRef)), 200);
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
assertEquals(2, result.getInt("total"));
|
||||
|
||||
// add another one
|
||||
JSONObject commentThree = createComment(nodeRef, "comment", "content", 200);
|
||||
|
||||
response = sendRequest(new GetRequest(getCommentsUrl(nodeRef)), 200);
|
||||
result = new JSONObject(response.getContentAsString());
|
||||
assertEquals(3, result.getInt("total"));
|
||||
|
||||
// delete the last comment
|
||||
response = sendRequest(new DeleteRequest(getCommentUrl(commentThree.getString("nodeRef"))), 200);
|
||||
|
||||
response = sendRequest(new GetRequest(getCommentsUrl(nodeRef)), 200);
|
||||
result = new JSONObject(response.getContentAsString());
|
||||
assertEquals(2, result.getInt("total"));
|
||||
|
||||
JSONObject commentTwoUpdated = updateComment(commentTwo.getString("nodeRef"), "new title", "new content", 200);
|
||||
assertEquals("new title", commentTwoUpdated.getString("title"));
|
||||
assertEquals("new content", commentTwoUpdated.getString("content"));
|
||||
}
|
||||
|
||||
/**
|
||||
* REPO-828 (MNT-16401)
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testDeleteCommentPostActivity() throws Exception
|
||||
{
|
||||
this.authenticationComponent.setCurrentUser(USER_ONE);
|
||||
JSONObject item = createPost("testActivity", "test", null, false, 200);
|
||||
assertNotNull(item);
|
||||
postLookup.execute();
|
||||
feedGenerator.execute();
|
||||
int activityNumStart = activityService.getSiteFeedEntries(SITE_SHORT_NAME_BLOG).size();
|
||||
String nodeRef = item.getString("nodeRef");
|
||||
JSONObject commentOne = createComment(nodeRef, "comment", "content", 200);
|
||||
assertNotNull(item);
|
||||
postLookup.execute();
|
||||
feedGenerator.execute();
|
||||
int activityNumNext = activityService.getSiteFeedEntries(SITE_SHORT_NAME_BLOG).size();
|
||||
assertEquals("The activity feeds were not generated after adding a comment", activityNumStart + 1, activityNumNext);
|
||||
activityNumStart = activityNumNext;
|
||||
NodeRef commentNodeRef = new NodeRef(commentOne.getString("nodeRef"));
|
||||
Response resp = sendRequest(new DeleteRequest(getDeleteCommentUrl(commentNodeRef)), 200);
|
||||
assertTrue(resp.getStatus() == 200);
|
||||
postLookup.execute();
|
||||
feedGenerator.execute();
|
||||
activityNumNext = activityService.getSiteFeedEntries(SITE_SHORT_NAME_BLOG).size();
|
||||
assertEquals("The activity feeds were not generated after deleting a comment", activityNumStart + 1, activityNumNext);
|
||||
}
|
||||
|
||||
/**
|
||||
* You can attach information to the blog container relating
|
||||
* to integration with external blogs.
|
||||
* This tests that feature
|
||||
*/
|
||||
public void testBlogIntegration() throws Exception
|
||||
{
|
||||
// Try to fetch the details on a new site
|
||||
Response response = sendRequest(new GetRequest(URL_BLOG_CORE), 200);
|
||||
String json = response.getContentAsString();
|
||||
JSONObject result = new JSONObject(json);
|
||||
|
||||
assertEquals("No item in:\n"+json, true, result.has("item"));
|
||||
JSONObject item = result.getJSONObject("item");
|
||||
|
||||
assertEquals("Missing key in: " + item, true, item.has("qnamePath"));
|
||||
assertEquals("Missing key in: " + item, true, item.has("detailsUrl"));
|
||||
assertEquals("Missing key in: " + item, true, item.has("blogPostsUrl"));
|
||||
|
||||
// Blog properties are empty to start
|
||||
assertEquals("", item.getString("type"));
|
||||
assertEquals("", item.getString("name"));
|
||||
assertEquals("", item.getString("description"));
|
||||
assertEquals("", item.getString("url"));
|
||||
assertEquals("", item.getString("username"));
|
||||
assertEquals("", item.getString("password"));
|
||||
|
||||
|
||||
// Have it updated
|
||||
JSONObject blog = new JSONObject();
|
||||
blog.put("blogType", "wordpress");
|
||||
blog.put("blogName", "A Blog!");
|
||||
blog.put("username", "guest");
|
||||
sendRequest(new PutRequest(URL_BLOG_CORE, blog.toString(), "application/json"), Status.STATUS_OK);
|
||||
|
||||
// Check again now
|
||||
response = sendRequest(new GetRequest(URL_BLOG_CORE), 200);
|
||||
json = response.getContentAsString();
|
||||
result = new JSONObject(json);
|
||||
|
||||
assertEquals("No item in:\n"+json, true, result.has("item"));
|
||||
item = result.getJSONObject("item");
|
||||
|
||||
assertEquals("Missing key in: " + item, true, item.has("qnamePath"));
|
||||
assertEquals("Missing key in: " + item, true, item.has("detailsUrl"));
|
||||
assertEquals("Missing key in: " + item, true, item.has("blogPostsUrl"));
|
||||
|
||||
// Blog properties should now be set
|
||||
assertEquals("wordpress", item.getString("type"));
|
||||
assertEquals("A Blog!", item.getString("name"));
|
||||
assertEquals("", item.getString("description"));
|
||||
assertEquals("", item.getString("url"));
|
||||
assertEquals("guest", item.getString("username"));
|
||||
assertEquals("", item.getString("password"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Does some stress tests.
|
||||
*
|
||||
* Currently observed errors:
|
||||
* 1. [repo.action.AsynchronousActionExecutionQueueImpl] Failed to execute asynchronous action: Action[ id=485211db-f117-4976-9530-ab861a19f563, node=null ]
|
||||
* org.alfresco.repo.security.permissions.AccessDeniedException: Access Denied. You do not have the appropriate permissions to perform this operation.
|
||||
*
|
||||
* 2. JSONException, but with root cause being
|
||||
* get(assocs) failed on instance of org.alfresco.repo.template.TemplateNode
|
||||
* The problematic instruction:
|
||||
* ----------
|
||||
* ==> if person.assocs["cm:avatar"]?? [on line 4, column 7 in org/alfresco/repository/blogs/blogpost.lib.ftl]
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void _testTagsStressTest() throws Exception
|
||||
{
|
||||
final List<Exception> exceptions = Collections.synchronizedList(new ArrayList<Exception>());
|
||||
List<Thread> threads = new ArrayList<Thread>();
|
||||
|
||||
System.err.println("Creating and starting threads...");
|
||||
for (int x=0; x < 3; x++)
|
||||
{
|
||||
Thread t = new Thread(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
// set the correct user
|
||||
authenticationComponent.setCurrentUser(USER_ONE);
|
||||
|
||||
// now do some requests
|
||||
try
|
||||
{
|
||||
for (int y=0; y < 3; y++)
|
||||
{
|
||||
off_testPostTags();
|
||||
off_testClearTags();
|
||||
}
|
||||
System.err.println("------------- SUCCEEDED ---------------");
|
||||
} catch (Exception e)
|
||||
{
|
||||
System.err.println("------------- ERROR ---------------");
|
||||
exceptions.add(e);
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}});
|
||||
|
||||
threads.add(t);
|
||||
t.start();
|
||||
}
|
||||
/*for (Thread t : threads)
|
||||
{
|
||||
t.start();
|
||||
}*/
|
||||
|
||||
for (Thread t : threads)
|
||||
{
|
||||
t.join();
|
||||
}
|
||||
|
||||
System.err.println("------------- STACK TRACES ---------------");
|
||||
for (Exception e : exceptions)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.err.println("------------- STACK TRACES END ---------------");
|
||||
if (exceptions.size() > 0)
|
||||
{
|
||||
throw exceptions.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void off_testPostTags() throws Exception
|
||||
{
|
||||
String[] tags = { "first", "test" };
|
||||
JSONObject item = createPost("tagtest", "tagtest", tags, false, 200);
|
||||
assertEquals(2, item.getJSONArray("tags").length());
|
||||
assertEquals("first", item.getJSONArray("tags").get(0));
|
||||
assertEquals("test", item.getJSONArray("tags").get(1));
|
||||
|
||||
item = updatePost(item.getString("name"), null, null, new String[] { "First", "Test", "Second" }, false, 200);
|
||||
assertEquals(3, item.getJSONArray("tags").length());
|
||||
assertEquals("first", item.getJSONArray("tags").get(0));
|
||||
assertEquals("test", item.getJSONArray("tags").get(1));
|
||||
assertEquals("second", item.getJSONArray("tags").get(2));
|
||||
}
|
||||
|
||||
public void off_testClearTags() throws Exception
|
||||
{
|
||||
String[] tags = { "abc", "def"};
|
||||
JSONObject item = createPost("tagtest", "tagtest", tags, false, 200);
|
||||
assertEquals(2, item.getJSONArray("tags").length());
|
||||
|
||||
item = updatePost(item.getString("name"), null, null, new String[0], false, 200);
|
||||
assertEquals(0, item.getJSONArray("tags").length());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for <a href=https://issues.alfresco.com/jira/browse/MNT-11964>MNT-11964</a>
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testBlogPermission() throws Exception
|
||||
{
|
||||
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
|
||||
|
||||
String siteName = SITE_SHORT_NAME_BLOG + GUID.generate();
|
||||
this.siteService.createSite("BlogSitePreset", siteName, "BlogSiteTitle", "BlogSiteDescription", SiteVisibility.PUBLIC);
|
||||
|
||||
String userName = USER_ONE + GUID.generate();
|
||||
createUser(userName, SiteModel.SITE_COLLABORATOR, siteName);
|
||||
|
||||
// Check permissions for admin
|
||||
checkBlogPermissions(siteName);
|
||||
|
||||
// Check permissions for user
|
||||
this.authenticationComponent.setCurrentUser(userName);
|
||||
checkBlogPermissions(siteName);
|
||||
|
||||
// Cleanup
|
||||
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
|
||||
this.siteService.deleteSite(siteName);
|
||||
|
||||
// Create a new site as user
|
||||
this.authenticationComponent.setCurrentUser(userName);
|
||||
siteName = SITE_SHORT_NAME_BLOG + GUID.generate();
|
||||
this.siteService.createSite("BlogSitePreset", siteName, "BlogSiteTitle", "BlogSiteDescription", SiteVisibility.PUBLIC);
|
||||
|
||||
// Check permissions for user
|
||||
checkBlogPermissions(siteName);
|
||||
|
||||
// Check permissions for admin
|
||||
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
|
||||
checkBlogPermissions(siteName);
|
||||
|
||||
// Cleanup
|
||||
this.siteService.deleteSite(siteName);
|
||||
this.personService.deletePerson(userName);
|
||||
}
|
||||
|
||||
private void checkBlogPermissions(String siteName) throws Exception
|
||||
{
|
||||
String url = "/api/blog/site/" + siteName + "/" + COMPONENT_BLOG;
|
||||
Response response = sendRequest(new GetRequest(url), 200);
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
|
||||
assertTrue("The user sould have permission to create a new blog.", result.getJSONObject("item").getJSONObject("permissions").getBoolean("create"));
|
||||
}
|
||||
}
|
@@ -1,28 +1,28 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.calendar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -120,7 +120,7 @@ public class CalendarRestApiTest extends BaseWebScriptTest
|
||||
SiteInfo siteInfo = this.siteService.getSite(SITE_SHORT_NAME_CALENDAR);
|
||||
if (siteInfo == null)
|
||||
{
|
||||
this.siteService.createSite("CalendarSitePreset", SITE_SHORT_NAME_CALENDAR, "CalendarSiteTitle", "BlogSiteDescription", SiteVisibility.PUBLIC);
|
||||
this.siteService.createSite("CalendarSitePreset", SITE_SHORT_NAME_CALENDAR, "CalendarSiteTitle", "CalendarSiteDescription", SiteVisibility.PUBLIC);
|
||||
}
|
||||
|
||||
// Ensure the calendar container is there
|
||||
|
@@ -78,7 +78,7 @@ import org.springframework.extensions.webscripts.WebScriptException;
|
||||
|
||||
/**
|
||||
* TODO: Fix the loose transaction handling.
|
||||
* TODO: Rationalise with other v0 Comment REST API tests (eg. see BlogServiceTest ... etc). See also ACE-5437.
|
||||
* TODO: Rationalise with other v0 Comment REST API tests. See also ACE-5437.
|
||||
*/
|
||||
public class CommentsApiTest extends BaseWebScriptTest
|
||||
{
|
||||
|
Reference in New Issue
Block a user