diff --git a/config/alfresco/templates/activities/org/alfresco/blog/post-created.atomentry.ftl b/config/alfresco/templates/activities/org/alfresco/blog/post-created.atomentry.ftl new file mode 100644 index 0000000000..adedaa7149 --- /dev/null +++ b/config/alfresco/templates/activities/org/alfresco/blog/post-created.atomentry.ftl @@ -0,0 +1,17 @@ +<#assign username=userId> +<#if firstName?exists> + <#assign username = firstName + " " + lastName> + + + New blog post: ${title!'unknown'} + + ${id} + ${xmldate(date)} + + ${title!'unknown'}.]]> + + + ${userId!""} + + + diff --git a/config/alfresco/templates/activities/org/alfresco/blog/post-created.rss.ftl b/config/alfresco/templates/activities/org/alfresco/blog/post-created.rss.ftl new file mode 100644 index 0000000000..3c678be6b5 --- /dev/null +++ b/config/alfresco/templates/activities/org/alfresco/blog/post-created.rss.ftl @@ -0,0 +1,11 @@ +<#assign username=userId> +<#if firstName?exists> + <#assign username = firstName + " " + lastName> + + + New blog post: ${title!"unknown"} + ${(browsePostUrl!'')?replace("&", "&")} + ${id} + ${username} added blog post ${title!'unknown'}. + + diff --git a/config/alfresco/templates/activities/org/alfresco/blog/post-deleted.atomentry.ftl b/config/alfresco/templates/activities/org/alfresco/blog/post-deleted.atomentry.ftl new file mode 100644 index 0000000000..cc6f392065 --- /dev/null +++ b/config/alfresco/templates/activities/org/alfresco/blog/post-deleted.atomentry.ftl @@ -0,0 +1,17 @@ +<#assign username=userId> +<#if firstName?exists> + <#assign username = firstName + " " + lastName> + + + Blog post deleted: ${title!'unknown'} + + ${id} + ${xmldate(date)} + + + + + ${userId!""} + + + diff --git a/config/alfresco/templates/activities/org/alfresco/blog/post-deleted.rss.ftl b/config/alfresco/templates/activities/org/alfresco/blog/post-deleted.rss.ftl new file mode 100644 index 0000000000..03530ed7c4 --- /dev/null +++ b/config/alfresco/templates/activities/org/alfresco/blog/post-deleted.rss.ftl @@ -0,0 +1,11 @@ +<#assign username=userId> +<#if firstName?exists> + <#assign username = firstName + " " + lastName> + + + Blog post deleted: ${title!"unknown"} + ${(browsePostListURL!'')?replace("&", "&")} + ${id} + ${username} deleted blog post ${title}. + + diff --git a/config/alfresco/templates/activities/org/alfresco/blog/post-updated.atomentry.ftl b/config/alfresco/templates/activities/org/alfresco/blog/post-updated.atomentry.ftl new file mode 100644 index 0000000000..b79c5801c4 --- /dev/null +++ b/config/alfresco/templates/activities/org/alfresco/blog/post-updated.atomentry.ftl @@ -0,0 +1,17 @@ +<#assign username=userId> +<#if firstName?exists> + <#assign username = firstName + " " + lastName> + + + Blog post updated: ${title!'unknown'} + + ${id} + ${xmldate(date)} + + ${title}.]]> + + + ${userId!""} + + + diff --git a/config/alfresco/templates/activities/org/alfresco/blog/post-updated.rss.ftl b/config/alfresco/templates/activities/org/alfresco/blog/post-updated.rss.ftl new file mode 100644 index 0000000000..42babc51b2 --- /dev/null +++ b/config/alfresco/templates/activities/org/alfresco/blog/post-updated.rss.ftl @@ -0,0 +1,11 @@ +<#assign username=userId> +<#if firstName?exists> + <#assign username = firstName + " " + lastName> + + + Blog post updated: ${title!"unknown"} + ${(browsePostUrl!'')?replace("&", "&")} + ${id} + ${username} updated blog post ${title}. + + diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/post/blog-post.delete.js b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/post/blog-post.delete.js index c6f6c22946..036aa1d0f2 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/post/blog-post.delete.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/post/blog-post.delete.js @@ -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(); diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/post/blog-post.put.js b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/post/blog-post.put.js index 24cc07b7e7..66c38300b1 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/post/blog-post.put.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/post/blog-post.put.js @@ -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(); diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts.get.js index ea96dc1a46..1a1c438a19 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts.get.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts.get.js @@ -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"; } diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts.post.js b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts.post.js index fcff82d779..eb0104c95b 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts.post.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts.post.js @@ -2,28 +2,35 @@ +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(); diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/tagging/tagging.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/tagging/tagging.lib.ftl new file mode 100644 index 0000000000..d910a76af5 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/tagging/tagging.lib.ftl @@ -0,0 +1,5 @@ +<#macro tagJSON item> +{ + "name" : "${item.name?j_string}", + "count" : ${item.count} +} diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/tagging/tagscope-tags.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/tagging/tagscope-tags.get.desc.xml new file mode 100644 index 0000000000..777c580f94 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/tagging/tagscope-tags.get.desc.xml @@ -0,0 +1,11 @@ + + Tagscope tags + Get all tags of the nearest available tagscope + /api/node/{store_type}/{store_id}/{id}/tagscopetags + /api/site/{site}/tagscopetags + /api/site/{site}/{container}/tagscopetags + /api/site/{site}/{container}/{path}/tagscopetags + + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/tagging/tagscope-tags.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/tagging/tagscope-tags.get.js new file mode 100644 index 0000000000..901e2df6a0 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/tagging/tagscope-tags.get.js @@ -0,0 +1,62 @@ + + +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(); diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/tagging/tagscope-tags.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/tagging/tagscope-tags.get.json.ftl new file mode 100644 index 0000000000..0f5127a7cf --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/tagging/tagscope-tags.get.json.ftl @@ -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>, + + ] + } + \ No newline at end of file diff --git a/source/java/org/alfresco/repo/web/scripts/blog/BlogServiceTest.java b/source/java/org/alfresco/repo/web/scripts/blog/BlogServiceTest.java index 120b1af817..0d2746fefe 100644 --- a/source/java/org/alfresco/repo/web/scripts/blog/BlogServiceTest.java +++ b/source/java/org/alfresco/repo/web/scripts/blog/BlogServiceTest.java @@ -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);