- 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:
Michael Ru
2008-07-11 10:12:53 +00:00
parent cd93a049c3
commit 735e6f3961
15 changed files with 272 additions and 60 deletions

View File

@@ -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("&", "&amp;")}" />
<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>

View File

@@ -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("&", "&amp;")}</link>
<guid>${id}</guid>
<description>${username} added blog post ${title!'unknown'}.</description>
</item>

View File

@@ -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("&", "&amp;")}" />
<id>${id}</id>
<updated>${xmldate(date)}</updated>
<summary type="html">
<![CDATA[${username} deleted blog post ${title}.]]>
</summary>
<author>
<name>${userId!""}</name>
</author>
</entry>

View File

@@ -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("&", "&amp;")}</link>
<guid>${id}</guid>
<description>${username} deleted blog post ${title}.</description>
</item>

View File

@@ -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("&", "&amp;")}" />
<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>

View File

@@ -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("&", "&amp;")}</link>
<guid>${id}</guid>
<description>${username} updated blog post ${title}.</description>
</item>

View File

@@ -25,7 +25,21 @@ function main()
return;
}
var title = node.properties.title;
var tags = node.properties.tags;
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();

View File

@@ -32,22 +32,21 @@ function updateBlogPostDraftMode(postNode)
function updateBlogPost(postNode)
{
// fetch the new data
var title = null;
var title = "";
if (json.has("title"))
{
title = json.get("title");
}
var content = null;
var content = "";
if (json.has("content"))
{
content = json.get("content");
}
var tags = null;
var tags = [];
if (json.has("tags"))
{
// get the tags JSONArray and copy it into a real javascript array object
var tmp = json.get("tags");
tags = new Array();
for (var x=0; x < tmp.length(); x++)
{
tags.push(tmp.get(x));
@@ -55,37 +54,39 @@ function updateBlogPost(postNode)
}
// update the node
if (title !== null)
{
postNode.properties.title = title;
}
if (content !== null)
{
postNode.mimetype = "text/html";
postNode.content = content
}
/*if (tags !== null)
{
postNode.tags = tags;
}*/
postNode.properties.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;
}
// get requested node
var node = getRequestNode();
if (status.getCode() != status.STATUS_OK)
{
return;
}
// update blog post
updateBlogPost(node);
model.item = getBlogPostData(node);
// update blog post
updateBlogPost(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();

View File

@@ -6,25 +6,31 @@
/**
* Fetches all posts of the given blog
*/
function getBlogPostList(node, fromDate, toDate, index, count)
function getBlogPostList(node, fromDate, toDate, tag, index, count)
{
// query information
var luceneQuery = " +TYPE:\"{http://www.alfresco.org/model/content/1.0}content\"" +
" +PATH:\"" + node.qnamePath + "/*\" ";
" +PATH:\"" + node.qnamePath + "/*\"";
// include all published + my drafts
luceneQuery += "((" +
luceneQuery += " ((" +
" -ASPECT:\"{http://www.alfresco.org/model/blogintegration/1.0}releaseDetails\" " +
"+@cm\\:creator:\"" + person.properties.userName + "\"" +
") OR (" +
" +ASPECT:\"{http://www.alfresco.org/model/blogintegration/1.0}releaseDetails\" " +
"))";
")) ";
// date query ?
if (fromDate != null || toDate != null)
{
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";
@@ -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
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";
}

View File

@@ -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/blogs/blogpost.lib.js">
function ensureTagScope(node)
{
if (! node.isTagScope)
{
node.isTagScope = true;
}
}
/**
* Creates a blog post
*/
function createBlogPost(blogNode)
{
// fetch the data required to create the post
var title = null;
var title = "";
if (json.has("title"))
{
title = json.get("title");
}
var content = null;
var content = "";
if (json.has("content"))
{
content = json.get("content");
}
var tags = null;
var tags = [];
if (json.has("tags"))
{
// get the tags JSONArray and copy it into a real javascript array object
var tmp = json.get("tags");
tags = new Array();
for (var x=0; x < tmp.length(); x++)
{
tags.push(tmp.get(x));
@@ -37,19 +44,10 @@ function createBlogPost(blogNode)
var postNode = blogNode.createNode(nodeName, "cm:content");
// set values where supplied
if (title !== null)
{
postNode.properties.title = title;
}
if (content !== null)
{
postNode.mimetype = "text/html";
postNode.content = content;
}
/*if (tags !== null)
{
postNode.tags = tags;
}*/
postNode.properties.title = title;
postNode.mimetype = "text/html";
postNode.content = content;
postNode.tags = tags;
postNode.save();
// check whether it is in draft mode
@@ -76,9 +74,22 @@ function main()
{
return;
}
ensureTagScope(node);
var post = createBlogPost(node);
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();

View File

@@ -0,0 +1,5 @@
<#macro tagJSON item>
{
"name" : "${item.name?j_string}",
"count" : ${item.count}
}</#macro>

View File

@@ -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>

View File

@@ -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();

View File

@@ -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>

View File

@@ -343,8 +343,8 @@ public class BlogServiceTest extends BaseWebScriptTest
assertEquals(false, item.getBoolean("isUpdated"));
item = updatePost(item.getString("name"), null, null, null, false, 200);
assertEquals("test", item.getString("title"));
assertEquals("test", item.getString("content"));
assertEquals("", item.getString("title"));
assertEquals("", item.getString("content"));
}
public void testPublishThroughUpdate() throws Exception
@@ -466,22 +466,22 @@ public class BlogServiceTest extends BaseWebScriptTest
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);
assertEquals(2, item.getJSONArray("tags").length());
assertEquals("First", item.getJSONArray("tags").get(0));
assertEquals("Test", item.getJSONArray("tags").get(0));
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(0));
assertEquals("Second", item.getJSONArray("tags").get(0));
assertEquals("first", item.getJSONArray("tags").get(0));
assertEquals("test", item.getJSONArray("tags").get(1));
assertEquals("second", item.getJSONArray("tags").get(2));
}
public void _testClearTags() throws Exception
public void testClearTags() throws Exception
{
String[] tags = { "abc", "def"};
JSONObject item = createPost("tagtest", "tagtest", tags, false, 200);