diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/blogpost.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/blogpost.lib.ftl index 0cc4eee526..e199f8f186 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/blogpost.lib.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/blogpost.lib.ftl @@ -4,57 +4,64 @@ <#macro addContent item> - <#assign maxTextLength=512> - <#if (! contentFormat??) || contentFormat == "" || contentFormat == "full"> - "content" : "${item.node.content?j_string}", - <#elseif contentFormat == "htmlDigest"> - <#if (item.node.content?length > maxTextLength)> - "content" : "${item.node.content?substring(0, maxTextLength)?j_string}", - <#else> - "content" : "${item.node.content?j_string}", - - <#elseif contentFormat == "textDigest"> - <#assign croppedTextContent=cropContent(item.node.properties.content, maxTextLength)> - "content" : "${croppedTextContent?j_string}", - <#else> - <#-- no content returned --> - + <#assign maxTextLength=512> + <#if (! contentFormat??) || contentFormat == "" || contentFormat == "full"> + "content" : "${item.node.content?j_string}", + <#elseif contentFormat == "htmlDigest"> + <#if (item.node.content?length > maxTextLength)> + "content" : "${item.node.content?substring(0, maxTextLength)?j_string}", + <#else> + "content" : "${item.node.content?j_string}", + + <#elseif contentFormat == "textDigest"> + <#assign croppedTextContent=cropContent(item.node.properties.content, maxTextLength)> + "content" : "${croppedTextContent?j_string}", + <#else> + <#-- no content returned --> + <#-- - This template renders a blog post. + This template renders a blog post. --> <#macro blogpostJSON item> { - "url" : "blog/post/node/${item.node.nodeRef?replace('://','/')}", - "commentsUrl" : "/node/${item.node.nodeRef?replace('://','/')}/comments", - "nodeRef" : "${item.node.nodeRef}", - "name" : "${(item.node.properties.name!'')?j_string}", + "url" : "blog/post/node/${item.node.nodeRef?replace('://','/')}", + "commentsUrl" : "/node/${item.node.nodeRef?replace('://','/')}/comments", + "nodeRef" : "${item.node.nodeRef}", + "name" : "${(item.node.properties.name!'')?j_string}", "title" : "${(item.node.properties.title!'')?j_string}", - <@addContent item=item /> - "author" : "${item.node.properties.creator?j_string}", - "createdOn" : "${item.createdDate?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}", - "modifiedOn" : "${item.modifiedDate?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}", - "permissions" : {"edit" : true, "publishExt" : true, "delete" : true}, - "commentCount" : ${item.commentCount?c}, - "tags" : <@renderTags tags=item.tags />, - - <#-- draft vs internal published --> - "isDraft" : ${item.isDraft?string}, - <#-- true if the post has been updated --> - "isUpdated" : ${item.isUpdated?string}, - - <#-- external publishing --> - "isPublished" : ${(item.node.properties["blg:published"]!'false')?string}, - <#if (item.node.properties["blg:published"]?? && item.node.properties["blg:published"] == true)> - "publishedOn" : "${item.node.properties["blg:posted"]?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}", - "updatedOn" : "${item.node.properties["blg:lastUpdate"]?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}", - "postId" : "${item.node.properties["blg:postId"]!''}", - "postLink" : "${item.node.properties["blg:link"]!''}", - "outOfDate" : ${item.outOfDate?string} - - + <@addContent item=item /> + "author" : "${item.node.properties.creator?j_string}", + "createdOn" : "${item.createdDate?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}", + "modifiedOn" : "${item.modifiedDate?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}", + "permissions" : {"edit" : true, "publishExt" : true, "delete" : true}, + "commentCount" : ${item.commentCount?c}, + "tags" : <@renderTags tags=item.tags />, + + <#-- draft vs internal published --> + "isDraft" : ${item.isDraft?string}, + <#if (! item.isDraft)> + "releasedOn" : "${item.releasedDate?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}", + + + <#-- true if the post has been updated --> + "isUpdated" : ${item.isUpdated?string}, + <#if (item.isUpdated)> + "updatedOn" : "${item.updatedDate?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}", + + + <#-- external publishing --> + "isPublished" : ${(item.node.properties["blg:published"]!'false')?string}, + <#if (item.node.properties["blg:published"]?? && item.node.properties["blg:published"] == true)> + "publishedOn" : "${item.node.properties["blg:posted"]?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}", + "updatedOn" : "${item.node.properties["blg:lastUpdate"]?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}", + "postId" : "${item.node.properties["blg:postId"]!''}", + "postLink" : "${item.node.properties["blg:link"]!''}", + "outOfDate" : ${item.outOfDate?string} + + } diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/blogpost.lib.js b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/blogpost.lib.js index 7584c637c2..383024ce1d 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/blogpost.lib.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/blogpost.lib.js @@ -1,24 +1,39 @@ +const ASPECT_RELEASED = "blg:released"; +const PROP_RELEASED = "blg:released"; +const ASPECT_UPDATED = "cm:contentupdated"; +const PROP_UPDATED = "cm:contentupdatedate"; + function setOrUpdateReleasedAndUpdatedDates(node) { // check whether we already got the date tracking aspect, // in this case we got an update - if (node.hasAspect("blg:releaseDetails")) + if (node.hasAspect(ASPECT_RELEASED)) { - // just update the modified date - node.properties["blg:updated"] = new Date(); - node.save(); + if (node.hasAspect(ASPECT_UPDATED)) + { + // just update the modified date + node.properties[PROP_UPDATED] = new Date(); + node.save(); + } + else + { + // add the updated aspect + var props = new Array(); + props[PROP_UPDATED] = new Date(); + node.addAspect(ASPECT_UPDATED, props); + } } else { - // attach the released/update date tracking aspect + // attach the released aspect var props = new Array(); - props["blg:released"] = new Date(); - props["blg:updated"] = new Date(); - node.addAspect("blg:releaseDetails", props); + var now = new Date(); + props[PROP_RELEASED] = now; + node.addAspect(ASPECT_RELEASED, props); - // re-enable permission inheritance + // re-enable permission inheritance which got disable for the draft node.setInheritsPermissions(true); } } @@ -33,25 +48,23 @@ function getBlogPostData(node) data.commentCount = getCommentsCount(node); // draft - data.isDraft = (! node.hasAspect("blg:releaseDetails")) || - (node.properties["blg:released"] == undefined); - - // use the released date if it exists - var createdDate = node.properties["cm:created"]; - if (node.hasAspect("blg:releaseDetails") && node.properties["blg:released"] != undefined) - { - createdDate = node.properties["blg:released"]; - } - data.createdDate = createdDate; - var modifiedDate = node.properties["cm:modified"]; - if (node.hasAspect("blg:releaseDetails") && node.properties["blg:updated"] != undefined) - { - modifiedDate = node.properties["blg:updated"]; - } - data.modifiedDate = modifiedDate; + data.isDraft = ! node.hasAspect(ASPECT_RELEASED); // set the isUpdated flag - data.isUpdated = (modifiedDate - createdDate) > 5000; + data.isUpdated = node.hasAspect(ASPECT_UPDATED); + + // fetch all available dates + data.createdDate = node.properties["cm:created"]; + data.modifiedDate = node.properties["cm:modified"]; + + if (node.hasAspect(ASPECT_RELEASED)) + { + data.releasedDate = node.properties[PROP_RELEASED]; + } + if (node.hasAspect(ASPECT_UPDATED)) + { + data.updatedDate = node.properties[PROP_UPDATED]; + } // does the external post require an update? if ((node.properties["blg:lastUpdate"] != undefined)) 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 66c4a6ff6d..94b677b5ad 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 @@ -8,8 +8,7 @@ function updateBlogPostDraftMode(postNode) { // make sure the user doesn't try to put a non-draft // post back into draft node - var currentDraft = (! postNode.hasAspect("blg:releaseDetails")) || - (postNode.properties["blg:released"] == undefined); + var currentDraft = ! postNode.hasAspect("blg:released"); var isDraft = json.has("draft") && json.get("draft").toString() == "true"; // requested draft, previously non-draft: throw an exception diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-mydrafts.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-mydrafts.get.js index 7cac7371ec..f685fe5778 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-mydrafts.get.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-mydrafts.get.js @@ -13,7 +13,7 @@ function getBlogPostList(node, index, count) "+PATH:\"" + node.qnamePath + "/*\" "; // add the drafts part - luceneQuery += "-ASPECT:\"{http://www.alfresco.org/model/blogintegration/1.0}releaseDetails\" " + + luceneQuery += "-ASPECT:\"{http://www.alfresco.org/model/blogintegration/1.0}released\" " + "+@cm\\:creator:\"" + person.properties.userName + "\""; var sortAttribute = "@{http://www.alfresco.org/model/content/1.0}created"; diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-mypublished.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-mypublished.get.js index a1b6c9529b..c7ff915885 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-mypublished.get.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-mypublished.get.js @@ -13,7 +13,7 @@ function getBlogPostList(node, index, count) " +PATH:\"" + node.qnamePath + "/*\" "; // add the drafts part - luceneQuery += "+ASPECT:\"{http://www.alfresco.org/model/blogintegration/1.0}releaseDetails\" " + + luceneQuery += "+ASPECT:\"{http://www.alfresco.org/model/blogintegration/1.0}released\" " + "+@cm\\:creator:\"" + person.properties.userName + "\""; diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-new.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-new.get.js index 0c24319fef..77913513c7 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-new.get.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-new.get.js @@ -15,10 +15,10 @@ function getBlogPostList(node, numdays, index, count) // query information var luceneQuery = " +TYPE:\"{http://www.alfresco.org/model/content/1.0}content\"" + " +PATH:\"" + node.qnamePath + "/*\" " + - " +ASPECT:\"{http://www.alfresco.org/model/blogintegration/1.0}releaseDetails\" " + + " +ASPECT:\"{http://www.alfresco.org/model/blogintegration/1.0}released\" " + getCreationDateRangeQuery(fromDate, null); - var sortAttribute = "@{http://www.alfresco.org/model/content/1.0}created"; + var sortAttribute = "@{http://www.alfresco.org/model/blogintegration/1.0}released"; // get the data return getPagedResultsDataByLuceneQuery(node, luceneQuery, sortAttribute, false, index, count, getBlogPostData); diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-per-month.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-per-month.get.js index 81a8f01724..d3a9e28732 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-per-month.get.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-per-month.get.js @@ -44,8 +44,9 @@ function getBlogPostMonths(node) { // query information var luceneQuery = " +TYPE:\"{http://www.alfresco.org/model/content/1.0}content\"" + - " +PATH:\"" + node.qnamePath + "/*\" "; - var sortAttribute = "@{http://www.alfresco.org/model/content/1.0}created"; + " +PATH:\"" + node.qnamePath + "/*\" " + + " +ASPECT:\"{http://www.alfresco.org/model/blogintegration/1.0}released\" "; + var sortAttribute = "@{http://www.alfresco.org/model/blogintegration/1.0}released"; nodes = search.luceneSearch(node.nodeRef.storeRef.toString(), luceneQuery, sortAttribute, true); // will hold the months information 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 1a1c438a19..7b10be716b 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 @@ -14,10 +14,10 @@ function getBlogPostList(node, fromDate, toDate, tag, index, count) // include all published + my drafts luceneQuery += " ((" + - " -ASPECT:\"{http://www.alfresco.org/model/blogintegration/1.0}releaseDetails\" " + + " -ASPECT:\"{http://www.alfresco.org/model/blogintegration/1.0}released\" " + "+@cm\\:creator:\"" + person.properties.userName + "\"" + ") OR (" + - " +ASPECT:\"{http://www.alfresco.org/model/blogintegration/1.0}releaseDetails\" " + + " +ASPECT:\"{http://www.alfresco.org/model/blogintegration/1.0}released\" " + ")) "; // date query ? @@ -32,7 +32,7 @@ function getBlogPostList(node, fromDate, toDate, tag, index, count) 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/blogintegration/1.0}released"; // get the data return getPagedResultsDataByLuceneQuery(node, luceneQuery, sortAttribute, false, index, count, getBlogPostData); diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/discussions/post.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/discussions/post.lib.ftl index e45849335d..a2f66b5206 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/discussions/post.lib.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/discussions/post.lib.ftl @@ -56,6 +56,10 @@ "createdOn" : "${post.properties.created?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}", "modifiedOn" : "${post.properties.modified?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}", "author" : "${post.properties.creator?j_string}", + "isUpdated" : ${post.hasAspect("cm:contentupdated")?string}, + <#if (post.hasAspect("cm:contentupdated"))> + "updatedOn" : "${post.properties["cm:contentupdatedate"]?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}", + <@addContent post=post /> "replyCount" : <#if post.sourceAssocs["cm:references"]??>${post.sourceAssocs["cm:references"]?size?c}<#else>0, "permissions" : { "edit": true, "delete" : true, "reply" : true } diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/discussions/posts/forum-post.put.js b/config/alfresco/templates/webscripts/org/alfresco/repository/discussions/posts/forum-post.put.js index 7106d67416..9e53166f8a 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/discussions/posts/forum-post.put.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/discussions/posts/forum-post.put.js @@ -35,6 +35,12 @@ function updatePost(topic, post) post.content = content; post.save(); + // add the content updated aspect + var now = new Date(); + var props = new Array(); + props["cm:contentupdatedate"] = now; + post.addAspect("cm:contentupdated", props); + // Only set the tags if it is a topic post // as we currently don't support individual post tagging if (topic != null) 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 0d2746fefe..37e560bdb3 100644 --- a/source/java/org/alfresco/repo/web/scripts/blog/BlogServiceTest.java +++ b/source/java/org/alfresco/repo/web/scripts/blog/BlogServiceTest.java @@ -327,9 +327,6 @@ public class BlogServiceTest extends BaseWebScriptTest String name = item.getString("name"); assertEquals(false, item.getBoolean("isUpdated")); - // wait for 5 sec - Thread.sleep(5000); - item = updatePost(name, "new title", "new content", null, false, 200); assertEquals(true, item.getBoolean("isUpdated")); assertEquals("new title", item.getString("title")); diff --git a/source/java/org/alfresco/repo/web/scripts/discussion/DiscussionServiceTest.java b/source/java/org/alfresco/repo/web/scripts/discussion/DiscussionServiceTest.java index fdfdae69a1..31b56ad740 100644 --- a/source/java/org/alfresco/repo/web/scripts/discussion/DiscussionServiceTest.java +++ b/source/java/org/alfresco/repo/web/scripts/discussion/DiscussionServiceTest.java @@ -160,13 +160,13 @@ public class DiscussionServiceTest extends BaseWebScriptTest return item; } - private JSONObject updatePost(String name, String title, String content, boolean isDraft, int expectedStatus) + private JSONObject updatePost(String nodeRef, String title, String content, int expectedStatus) throws Exception { JSONObject post = new JSONObject(); post.put("title", title); post.put("content", content); - MockHttpServletResponse response = putRequest(URL_FORUM_POST + name, expectedStatus, post.toString(), "application/json"); + MockHttpServletResponse response = putRequest(getPostUrl(nodeRef), expectedStatus, post.toString(), "application/json"); if (expectedStatus != 200) { @@ -219,24 +219,6 @@ public class DiscussionServiceTest extends BaseWebScriptTest 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); - MockHttpServletResponse response = putRequest(getPostUrl(nodeRef), expectedStatus, comment.toString(), "application/json"); - - if (expectedStatus != 200) - { - return null; - } - - //logger.debug("Comment updated: " + response.getContentAsString()); - JSONObject result = new JSONObject(response.getContentAsString()); - return result.getJSONObject("item"); - } - // Tests @@ -254,6 +236,30 @@ public class DiscussionServiceTest extends BaseWebScriptTest getPost(item.getString("name"), 200); } + public void testUpdateForumPost() throws Exception + { + String title = "test"; + String content = "test"; + JSONObject item = createPost(title, content, 200); + + // check that the values + assertEquals(title, item.get("title")); + assertEquals(content, item.get("content")); + assertEquals(false, item.getBoolean("isUpdated")); + + // fetch the post + getPost(item.getString("name"), 200); + + String title2 = "test"; + String content2 = "test"; + item = updatePost(item.getString("nodeRef"), title2, content2, 200); + + // check that the values + assertEquals(title2, item.get("title")); + assertEquals(content2, item.get("content")); + assertEquals(true, item.getBoolean("isUpdated")); + } + public void testGetAll() throws Exception { String url = URL_FORUM_POSTS; @@ -308,6 +314,27 @@ public class DiscussionServiceTest extends BaseWebScriptTest assertEquals(1, item.getInt("replyCount")); } + public void testUpdateReply() throws Exception + { + // create a root post + JSONObject item = createPost("test", "test", 200); + String postName = item.getString("name"); + String postNodeRef = item.getString("nodeRef"); + + // add a reply + JSONObject reply = createReply(postNodeRef, "test", "test", 200); + String replyNodeRef = reply.getString("nodeRef"); + assertEquals("test", reply.getString("title")); + assertEquals("test", reply.getString("content")); + assertEquals(false, reply.getBoolean("isUpdated")); + + // now update it + JSONObject reply2 = updatePost(reply.getString("nodeRef"), "test2", "test2", 200); + assertEquals("test2", reply2.getString("title")); + assertEquals("test2", reply2.getString("content")); + assertEquals(true, reply2.getBoolean("isUpdated")); + } + /* public void testDeleteReplyPost() throws Exception {