mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
- added activities for blog posts
- added tagging support for blog git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9809 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
<#assign username=userId>
|
||||||
|
<#if firstName?exists>
|
||||||
|
<#assign username = firstName + " " + lastName>
|
||||||
|
</#if>
|
||||||
|
<entry xmlns='http://www.w3.org/2005/Atom'>
|
||||||
|
<title>New blog post: ${title!'unknown'}</title>
|
||||||
|
<link rel="alternate" type="text/html" href="${(browsePostUrl!'')?replace("&", "&")}" />
|
||||||
|
<id>${id}</id>
|
||||||
|
<updated>${xmldate(date)}</updated>
|
||||||
|
<summary type="html">
|
||||||
|
<![CDATA[${username} added blog post <a href="${(browsePostUrl!'')}">${title!'unknown'}</a>.]]>
|
||||||
|
</summary>
|
||||||
|
<author>
|
||||||
|
<name>${userId!""}</name>
|
||||||
|
</author>
|
||||||
|
</entry>
|
||||||
|
|
@@ -0,0 +1,11 @@
|
|||||||
|
<#assign username=userId>
|
||||||
|
<#if firstName?exists>
|
||||||
|
<#assign username = firstName + " " + lastName>
|
||||||
|
</#if>
|
||||||
|
<item>
|
||||||
|
<title>New blog post: ${title!"unknown"}</title>
|
||||||
|
<link>${(browsePostUrl!'')?replace("&", "&")}</link>
|
||||||
|
<guid>${id}</guid>
|
||||||
|
<description>${username} added blog post ${title!'unknown'}.</description>
|
||||||
|
</item>
|
||||||
|
|
@@ -0,0 +1,17 @@
|
|||||||
|
<#assign username=userId>
|
||||||
|
<#if firstName?exists>
|
||||||
|
<#assign username = firstName + " " + lastName>
|
||||||
|
</#if>
|
||||||
|
<entry xmlns='http://www.w3.org/2005/Atom'>
|
||||||
|
<title>Blog post deleted: ${title!'unknown'}</title>
|
||||||
|
<link rel="alternate" type="text/html" href="${(browsePostListUrl!'')?replace("&", "&")}" />
|
||||||
|
<id>${id}</id>
|
||||||
|
<updated>${xmldate(date)}</updated>
|
||||||
|
<summary type="html">
|
||||||
|
<![CDATA[${username} deleted blog post ${title}.]]>
|
||||||
|
</summary>
|
||||||
|
<author>
|
||||||
|
<name>${userId!""}</name>
|
||||||
|
</author>
|
||||||
|
</entry>
|
||||||
|
|
@@ -0,0 +1,11 @@
|
|||||||
|
<#assign username=userId>
|
||||||
|
<#if firstName?exists>
|
||||||
|
<#assign username = firstName + " " + lastName>
|
||||||
|
</#if>
|
||||||
|
<item>
|
||||||
|
<title>Blog post deleted: ${title!"unknown"}</title>
|
||||||
|
<link>${(browsePostListURL!'')?replace("&", "&")}</link>
|
||||||
|
<guid>${id}</guid>
|
||||||
|
<description>${username} deleted blog post ${title}.</description>
|
||||||
|
</item>
|
||||||
|
|
@@ -0,0 +1,17 @@
|
|||||||
|
<#assign username=userId>
|
||||||
|
<#if firstName?exists>
|
||||||
|
<#assign username = firstName + " " + lastName>
|
||||||
|
</#if>
|
||||||
|
<entry xmlns='http://www.w3.org/2005/Atom'>
|
||||||
|
<title>Blog post updated: ${title!'unknown'}</title>
|
||||||
|
<link rel="alternate" type="text/html" href="${(browsePostUrl!'')?replace("&", "&")}" />
|
||||||
|
<id>${id}</id>
|
||||||
|
<updated>${xmldate(date)}</updated>
|
||||||
|
<summary type="html">
|
||||||
|
<![CDATA[${username} updated blog post <a href="${(browsePostUrl!'')}">${title}</a>.]]>
|
||||||
|
</summary>
|
||||||
|
<author>
|
||||||
|
<name>${userId!""}</name>
|
||||||
|
</author>
|
||||||
|
</entry>
|
||||||
|
|
@@ -0,0 +1,11 @@
|
|||||||
|
<#assign username=userId>
|
||||||
|
<#if firstName?exists>
|
||||||
|
<#assign username = firstName + " " + lastName>
|
||||||
|
</#if>
|
||||||
|
<item>
|
||||||
|
<title>Blog post updated: ${title!"unknown"}</title>
|
||||||
|
<link>${(browsePostUrl!'')?replace("&", "&")}</link>
|
||||||
|
<guid>${id}</guid>
|
||||||
|
<description>${username} updated blog post ${title}.</description>
|
||||||
|
</item>
|
||||||
|
|
@@ -25,7 +25,21 @@ function main()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var title = node.properties.title;
|
||||||
|
var tags = node.properties.tags;
|
||||||
|
|
||||||
deleteBlogPost(node);
|
deleteBlogPost(node);
|
||||||
|
|
||||||
|
// post an activitiy item, but only if we got a site
|
||||||
|
if (url.templateArgs.site != null)
|
||||||
|
{
|
||||||
|
var browsePostListUrl = '/page/site/' + url.templateArgs.site + '/blog-postlist?container=' + url.templateArgs.container;
|
||||||
|
var data = {
|
||||||
|
title: title,
|
||||||
|
browsePostListUrl: browsePostListUrl
|
||||||
|
}
|
||||||
|
activities.postActivity("org.alfresco.blog.post-deleted", url.templateArgs.site, url.templateArgs.container, jsonUtils.toJSONString(data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
@@ -32,22 +32,21 @@ function updateBlogPostDraftMode(postNode)
|
|||||||
function updateBlogPost(postNode)
|
function updateBlogPost(postNode)
|
||||||
{
|
{
|
||||||
// fetch the new data
|
// fetch the new data
|
||||||
var title = null;
|
var title = "";
|
||||||
if (json.has("title"))
|
if (json.has("title"))
|
||||||
{
|
{
|
||||||
title = json.get("title");
|
title = json.get("title");
|
||||||
}
|
}
|
||||||
var content = null;
|
var content = "";
|
||||||
if (json.has("content"))
|
if (json.has("content"))
|
||||||
{
|
{
|
||||||
content = json.get("content");
|
content = json.get("content");
|
||||||
}
|
}
|
||||||
var tags = null;
|
var tags = [];
|
||||||
if (json.has("tags"))
|
if (json.has("tags"))
|
||||||
{
|
{
|
||||||
// get the tags JSONArray and copy it into a real javascript array object
|
// get the tags JSONArray and copy it into a real javascript array object
|
||||||
var tmp = json.get("tags");
|
var tmp = json.get("tags");
|
||||||
tags = new Array();
|
|
||||||
for (var x=0; x < tmp.length(); x++)
|
for (var x=0; x < tmp.length(); x++)
|
||||||
{
|
{
|
||||||
tags.push(tmp.get(x));
|
tags.push(tmp.get(x));
|
||||||
@@ -55,19 +54,10 @@ function updateBlogPost(postNode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update the node
|
// update the node
|
||||||
if (title !== null)
|
|
||||||
{
|
|
||||||
postNode.properties.title = title;
|
postNode.properties.title = title;
|
||||||
}
|
|
||||||
if (content !== null)
|
|
||||||
{
|
|
||||||
postNode.mimetype = "text/html";
|
postNode.mimetype = "text/html";
|
||||||
postNode.content = content
|
postNode.content = content
|
||||||
}
|
|
||||||
/*if (tags !== null)
|
|
||||||
{
|
|
||||||
postNode.tags = tags;
|
postNode.tags = tags;
|
||||||
}*/
|
|
||||||
postNode.save();
|
postNode.save();
|
||||||
|
|
||||||
updateBlogPostDraftMode(postNode);
|
updateBlogPostDraftMode(postNode);
|
||||||
@@ -86,6 +76,17 @@ function main()
|
|||||||
updateBlogPost(node);
|
updateBlogPost(node);
|
||||||
|
|
||||||
model.item = getBlogPostData(node);
|
model.item = getBlogPostData(node);
|
||||||
|
|
||||||
|
// post an activitiy item, but only if we got a site
|
||||||
|
if (url.templateArgs.site != null && ! model.item.isDraft)
|
||||||
|
{
|
||||||
|
var browsePostUrl = '/page/site/' + url.templateArgs.site + '/blog-postview?container=' + url.templateArgs.container + '&postId=' + node.name;
|
||||||
|
var data = {
|
||||||
|
title: node.properties.title,
|
||||||
|
browsePostUrl: browsePostUrl
|
||||||
|
}
|
||||||
|
activities.postActivity("org.alfresco.blog.post-updated", url.templateArgs.site, url.templateArgs.container, jsonUtils.toJSONString(data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
@@ -6,19 +6,19 @@
|
|||||||
/**
|
/**
|
||||||
* Fetches all posts of the given blog
|
* Fetches all posts of the given blog
|
||||||
*/
|
*/
|
||||||
function getBlogPostList(node, fromDate, toDate, index, count)
|
function getBlogPostList(node, fromDate, toDate, tag, index, count)
|
||||||
{
|
{
|
||||||
// query information
|
// query information
|
||||||
var luceneQuery = " +TYPE:\"{http://www.alfresco.org/model/content/1.0}content\"" +
|
var luceneQuery = " +TYPE:\"{http://www.alfresco.org/model/content/1.0}content\"" +
|
||||||
" +PATH:\"" + node.qnamePath + "/*\" ";
|
" +PATH:\"" + node.qnamePath + "/*\"";
|
||||||
|
|
||||||
// include all published + my drafts
|
// include all published + my drafts
|
||||||
luceneQuery += "((" +
|
luceneQuery += " ((" +
|
||||||
" -ASPECT:\"{http://www.alfresco.org/model/blogintegration/1.0}releaseDetails\" " +
|
" -ASPECT:\"{http://www.alfresco.org/model/blogintegration/1.0}releaseDetails\" " +
|
||||||
"+@cm\\:creator:\"" + person.properties.userName + "\"" +
|
"+@cm\\:creator:\"" + person.properties.userName + "\"" +
|
||||||
") OR (" +
|
") OR (" +
|
||||||
" +ASPECT:\"{http://www.alfresco.org/model/blogintegration/1.0}releaseDetails\" " +
|
" +ASPECT:\"{http://www.alfresco.org/model/blogintegration/1.0}releaseDetails\" " +
|
||||||
"))";
|
")) ";
|
||||||
|
|
||||||
// date query ?
|
// date query ?
|
||||||
if (fromDate != null || toDate != null)
|
if (fromDate != null || toDate != null)
|
||||||
@@ -26,6 +26,12 @@ function getBlogPostList(node, fromDate, toDate, index, count)
|
|||||||
luceneQuery += getCreationDateRangeQuery(fromDate, toDate);
|
luceneQuery += getCreationDateRangeQuery(fromDate, toDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// is a tag selected?
|
||||||
|
if (tag != null)
|
||||||
|
{
|
||||||
|
luceneQuery += " +PATH:\"/cm:taggable/cm:" + tag /*ISO9075.encode(tag)*/ + "/member\" ";
|
||||||
|
}
|
||||||
|
|
||||||
var sortAttribute = "@{http://www.alfresco.org/model/content/1.0}created";
|
var sortAttribute = "@{http://www.alfresco.org/model/content/1.0}created";
|
||||||
|
|
||||||
// get the data
|
// get the data
|
||||||
@@ -65,8 +71,11 @@ function main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// selected tag
|
||||||
|
var tag = args["tag"] != undefined && args["tag"].length > 0 ? args["tag"] : null;
|
||||||
|
|
||||||
// fetch and assign the data
|
// fetch and assign the data
|
||||||
model.data = getBlogPostList(node, fromDate, toDate, index, count);
|
model.data = getBlogPostList(node, fromDate, toDate, tag, index, count);
|
||||||
model.contentFormat = (args["contentFormat"] != undefined) ? args["contentFormat"] : "full";
|
model.contentFormat = (args["contentFormat"] != undefined) ? args["contentFormat"] : "full";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,28 +2,35 @@
|
|||||||
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/nodenameutils.lib.js">
|
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/nodenameutils.lib.js">
|
||||||
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/blogs/blogpost.lib.js">
|
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/blogs/blogpost.lib.js">
|
||||||
|
|
||||||
|
function ensureTagScope(node)
|
||||||
|
{
|
||||||
|
if (! node.isTagScope)
|
||||||
|
{
|
||||||
|
node.isTagScope = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a blog post
|
* Creates a blog post
|
||||||
*/
|
*/
|
||||||
function createBlogPost(blogNode)
|
function createBlogPost(blogNode)
|
||||||
{
|
{
|
||||||
// fetch the data required to create the post
|
// fetch the data required to create the post
|
||||||
var title = null;
|
var title = "";
|
||||||
if (json.has("title"))
|
if (json.has("title"))
|
||||||
{
|
{
|
||||||
title = json.get("title");
|
title = json.get("title");
|
||||||
}
|
}
|
||||||
var content = null;
|
var content = "";
|
||||||
if (json.has("content"))
|
if (json.has("content"))
|
||||||
{
|
{
|
||||||
content = json.get("content");
|
content = json.get("content");
|
||||||
}
|
}
|
||||||
var tags = null;
|
var tags = [];
|
||||||
if (json.has("tags"))
|
if (json.has("tags"))
|
||||||
{
|
{
|
||||||
// get the tags JSONArray and copy it into a real javascript array object
|
// get the tags JSONArray and copy it into a real javascript array object
|
||||||
var tmp = json.get("tags");
|
var tmp = json.get("tags");
|
||||||
tags = new Array();
|
|
||||||
for (var x=0; x < tmp.length(); x++)
|
for (var x=0; x < tmp.length(); x++)
|
||||||
{
|
{
|
||||||
tags.push(tmp.get(x));
|
tags.push(tmp.get(x));
|
||||||
@@ -37,19 +44,10 @@ function createBlogPost(blogNode)
|
|||||||
var postNode = blogNode.createNode(nodeName, "cm:content");
|
var postNode = blogNode.createNode(nodeName, "cm:content");
|
||||||
|
|
||||||
// set values where supplied
|
// set values where supplied
|
||||||
if (title !== null)
|
|
||||||
{
|
|
||||||
postNode.properties.title = title;
|
postNode.properties.title = title;
|
||||||
}
|
|
||||||
if (content !== null)
|
|
||||||
{
|
|
||||||
postNode.mimetype = "text/html";
|
postNode.mimetype = "text/html";
|
||||||
postNode.content = content;
|
postNode.content = content;
|
||||||
}
|
|
||||||
/*if (tags !== null)
|
|
||||||
{
|
|
||||||
postNode.tags = tags;
|
postNode.tags = tags;
|
||||||
}*/
|
|
||||||
postNode.save();
|
postNode.save();
|
||||||
|
|
||||||
// check whether it is in draft mode
|
// check whether it is in draft mode
|
||||||
@@ -77,8 +75,21 @@ function main()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ensureTagScope(node);
|
||||||
|
|
||||||
var post = createBlogPost(node);
|
var post = createBlogPost(node);
|
||||||
model.item = getBlogPostData(post);
|
model.item = getBlogPostData(post);
|
||||||
|
|
||||||
|
// post an activitiy item, but only if we got a site
|
||||||
|
if (url.templateArgs.site != null && ! model.item.isDraft)
|
||||||
|
{
|
||||||
|
var browsePostUrl = '/page/site/' + url.templateArgs.site + '/blog-postview?container=' + url.templateArgs.container + '&postId=' + post.name;
|
||||||
|
var data = {
|
||||||
|
title: post.properties.title,
|
||||||
|
browsePostUrl: browsePostUrl
|
||||||
|
}
|
||||||
|
activities.postActivity("org.alfresco.blog.post-created", url.templateArgs.site, url.templateArgs.container, jsonUtils.toJSONString(data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
@@ -0,0 +1,5 @@
|
|||||||
|
<#macro tagJSON item>
|
||||||
|
{
|
||||||
|
"name" : "${item.name?j_string}",
|
||||||
|
"count" : ${item.count}
|
||||||
|
}</#macro>
|
@@ -0,0 +1,11 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>Tagscope tags</shortname>
|
||||||
|
<description>Get all tags of the nearest available tagscope</description>
|
||||||
|
<url>/api/node/{store_type}/{store_id}/{id}/tagscopetags</url>
|
||||||
|
<url>/api/site/{site}/tagscopetags</url>
|
||||||
|
<url>/api/site/{site}/{container}/tagscopetags</url>
|
||||||
|
<url>/api/site/{site}/{container}/{path}/tagscopetags</url>
|
||||||
|
<format default="json"/>
|
||||||
|
<authentication>user</authentication>
|
||||||
|
<transaction>required</transaction>
|
||||||
|
</webscript>
|
@@ -0,0 +1,62 @@
|
|||||||
|
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/requestutils.lib.js">
|
||||||
|
|
||||||
|
function findTargetNode()
|
||||||
|
{
|
||||||
|
if (url.templateArgs.site != undefined)
|
||||||
|
{
|
||||||
|
var siteId = url.templateArgs.site;
|
||||||
|
var containerId = url.templateArgs.container;
|
||||||
|
var path = url.templateArgs.path;
|
||||||
|
|
||||||
|
// fetch site
|
||||||
|
var site = siteService.getSite(siteId);
|
||||||
|
if (site === null)
|
||||||
|
{
|
||||||
|
status.setCode(status.STATUS_NOT_FOUND, "Site " + siteId + " does not exist");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else if (containerId == undefined)
|
||||||
|
{
|
||||||
|
return site;
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetch container
|
||||||
|
node = site.getContainer(containerId);
|
||||||
|
if (node === null)
|
||||||
|
{
|
||||||
|
status.setCode(status.STATUS_NOT_FOUND, "Unable to fetch container '" + containerId + "' of site '" + siteId + "'. (No write permission?)");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else if (path == undefined)
|
||||||
|
{
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
node = node.childByNamePath(path);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return findFromReference();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function main()
|
||||||
|
{
|
||||||
|
var node = findTargetNode();
|
||||||
|
|
||||||
|
// fetch the nearest available tagscope
|
||||||
|
var scope = node.tagScope;
|
||||||
|
if (scope == null)
|
||||||
|
{
|
||||||
|
//status.setCode(status.STATUS_BAD_REQUEST, "No tag scope could be found for the given resource");
|
||||||
|
//return null;
|
||||||
|
model.noscopefound=true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
model.tags = scope.tags;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
@@ -0,0 +1,15 @@
|
|||||||
|
<#if (noscopefound?? && noscopefound)>
|
||||||
|
{
|
||||||
|
"tags" : []
|
||||||
|
}
|
||||||
|
<#else>
|
||||||
|
{
|
||||||
|
"tags" : [
|
||||||
|
<#import "tagging.lib.ftl" as taggingLib/>
|
||||||
|
<#list tags as item>
|
||||||
|
<@taggingLib.tagJSON item=item />
|
||||||
|
<#if item_has_next>,</#if>
|
||||||
|
</#list>
|
||||||
|
]
|
||||||
|
}
|
||||||
|
</#if>
|
@@ -343,8 +343,8 @@ public class BlogServiceTest extends BaseWebScriptTest
|
|||||||
assertEquals(false, item.getBoolean("isUpdated"));
|
assertEquals(false, item.getBoolean("isUpdated"));
|
||||||
|
|
||||||
item = updatePost(item.getString("name"), null, null, null, false, 200);
|
item = updatePost(item.getString("name"), null, null, null, false, 200);
|
||||||
assertEquals("test", item.getString("title"));
|
assertEquals("", item.getString("title"));
|
||||||
assertEquals("test", item.getString("content"));
|
assertEquals("", item.getString("content"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPublishThroughUpdate() throws Exception
|
public void testPublishThroughUpdate() throws Exception
|
||||||
@@ -466,22 +466,22 @@ public class BlogServiceTest extends BaseWebScriptTest
|
|||||||
assertEquals("new content", commentTwoUpdated.getString("content"));
|
assertEquals("new content", commentTwoUpdated.getString("content"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void _testPostTags() throws Exception
|
public void testPostTags() throws Exception
|
||||||
{
|
{
|
||||||
String[] tags = { "First", "Test" };
|
String[] tags = { "first", "test" };
|
||||||
JSONObject item = createPost("tagtest", "tagtest", tags, false, 200);
|
JSONObject item = createPost("tagtest", "tagtest", tags, false, 200);
|
||||||
assertEquals(2, item.getJSONArray("tags").length());
|
assertEquals(2, item.getJSONArray("tags").length());
|
||||||
assertEquals("First", item.getJSONArray("tags").get(0));
|
assertEquals("first", item.getJSONArray("tags").get(0));
|
||||||
assertEquals("Test", 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);
|
item = updatePost(item.getString("name"), null, null, new String[] { "First", "Test", "Second" }, false, 200);
|
||||||
assertEquals(3, item.getJSONArray("tags").length());
|
assertEquals(3, item.getJSONArray("tags").length());
|
||||||
assertEquals("First", item.getJSONArray("tags").get(0));
|
assertEquals("first", item.getJSONArray("tags").get(0));
|
||||||
assertEquals("Test", item.getJSONArray("tags").get(0));
|
assertEquals("test", item.getJSONArray("tags").get(1));
|
||||||
assertEquals("Second", item.getJSONArray("tags").get(0));
|
assertEquals("second", item.getJSONArray("tags").get(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void _testClearTags() throws Exception
|
public void testClearTags() throws Exception
|
||||||
{
|
{
|
||||||
String[] tags = { "abc", "def"};
|
String[] tags = { "abc", "def"};
|
||||||
JSONObject item = createPost("tagtest", "tagtest", tags, false, 200);
|
JSONObject item = createPost("tagtest", "tagtest", tags, false, 200);
|
||||||
|
Reference in New Issue
Block a user