diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/comments/comments.lib.js b/config/alfresco/templates/webscripts/org/alfresco/repository/comments/comments.lib.js index 58018e8375..b2cd129299 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/comments/comments.lib.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/comments/comments.lib.js @@ -48,14 +48,8 @@ function getOrCreateCommentsFolder(node) { var commentsFolder = getCommentsFolder(node); if (commentsFolder == null) - { - // add the aspect, which will create the forum as well as the comments topic - node.addAspect("fm:discussable"); - var forumFolder = node.childAssocs["fm:discussion"][0]; - if (forumFolder !== null) - { - commentsFolder = forumFolder.createNode(COMMENTS_TOPIC_NAME, "fm:topic", "cm:contains"); - } + { + commentsFolder = commentService.createCommentsFolder(node); } return commentsFolder; } diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/filters.lib.js b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/filters.lib.js index c21c5d6276..021e494853 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/filters.lib.js +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/filters.lib.js @@ -20,7 +20,7 @@ var Filters = }], language: "lucene", templates: null, - variablePath: false + variablePath: true }; optional = optional || {}; @@ -106,7 +106,6 @@ var Filters = column: "@{http://www.alfresco.org/model/content/1.0}" + dateField, ascending: false }]; - filterParams.variablePath = true; filterParams.query = filterQuery + filterQueryDefaults; break; @@ -114,8 +113,6 @@ var Filters = filterQuery = "+PATH:\"" + parsedArgs.rootNode.qnamePath + "//*\""; filterQuery += " +ASPECT:\"{http://www.alfresco.org/model/content/1.0}workingcopy\""; filterQuery += " +@cm\\:workingCopyOwner:" + person.properties.userName; - - filterParams.variablePath = true; filterParams.query = filterQuery; break; @@ -123,8 +120,6 @@ var Filters = filterQuery = "+PATH:\"" + parsedArgs.rootNode.qnamePath + "//*\""; filterQuery += " +ASPECT:\"{http://www.alfresco.org/model/content/1.0}workingcopy\""; filterQuery += " -@cm\\:workingCopyOwner:" + person.properties.userName; - - filterParams.variablePath = true; filterParams.query = filterQuery; break; @@ -140,20 +135,20 @@ var Filters = foundOne = true; filterQuery += "ID:\"" + favourite + "\""; } - filterParams.variablePath = true; filterParams.query = filterQuery.length > 0 ? "+PATH:\"" + parsedArgs.rootNode.qnamePath + "//*\" +(" + filterQuery + ")" : "+ID:\"\""; break; case "node": + filterParams.variablePath = false; filterParams.query = "+ID:\"" + parsedArgs.rootNode.nodeRef + "\""; break; case "tag": - filterParams.variablePath = true; filterParams.query = "+PATH:\"" + parsedArgs.rootNode.qnamePath + "//*\" +PATH:\"/cm:taggable/cm:" + search.ISO9075Encode(filterData) + "/member\""; break; default: + filterParams.variablePath = false; filterQuery = "+PATH:\"" + parsedArgs.parentNode.qnamePath + "/*\""; filterParams.query = filterQuery + filterQueryDefaults; break; diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index 82aa18ba3f..dd297b817a 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -597,4 +597,13 @@ ${imap.server.enabled} + + + + commentService + + + + + \ No newline at end of file diff --git a/source/java/org/alfresco/repo/web/scripts/comment/ScriptCommentService.java b/source/java/org/alfresco/repo/web/scripts/comment/ScriptCommentService.java new file mode 100644 index 0000000000..8fe56ccd80 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/comment/ScriptCommentService.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.web.scripts.comment; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.jscript.BaseScopableProcessorExtension; +import org.alfresco.repo.jscript.Scopeable; +import org.alfresco.repo.jscript.ScriptNode; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.service.ServiceRegistry; +import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; +import org.alfresco.service.namespace.RegexQNamePattern; + +/** + * Temporary comment service API to start encapsulation of comment logic. + * + * NOTE: this has been added to resolve a specific issue and needs re-consideration + * + * @author Roy Wetherall + */ +public class ScriptCommentService extends BaseScopableProcessorExtension +{ + private static final String COMMENTS_TOPIC_NAME = "Comments"; + + private ServiceRegistry serviceRegistry; + private NodeService nodeService; + + public void setServiceRegistry(ServiceRegistry serviceRegistry) + { + this.serviceRegistry = serviceRegistry; + this.nodeService = serviceRegistry.getNodeService(); + } + + public ScriptNode createCommentsFolder(ScriptNode node) + { + final NodeRef nodeRef = node.getNodeRef(); + + NodeRef commentsFolder = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() + { + public NodeRef doWork() throws Exception + { + NodeRef commentsFolder = null; + nodeService.addAspect(nodeRef, QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "discussable"), null); + List assocs = nodeService.getChildAssocs(nodeRef, QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "discussion"), RegexQNamePattern.MATCH_ALL); + if (assocs.size() != 0) + { + NodeRef forumFolder = assocs.get(0).getChildRef(); + + Map props = new HashMap(1); + props.put(ContentModel.PROP_NAME, COMMENTS_TOPIC_NAME); + commentsFolder = nodeService.createNode( + forumFolder, + ContentModel.ASSOC_CONTAINS, + QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, COMMENTS_TOPIC_NAME), + QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "topic"), + props).getChildRef(); + } + return commentsFolder; + } + + }, AuthenticationUtil.getAdminUserName()); + + return new ScriptNode(commentsFolder, serviceRegistry, getScope()); + } + + +} diff --git a/source/java/org/alfresco/repo/web/scripts/invitation/InvitationTest.java b/source/java/org/alfresco/repo/web/scripts/invitation/InvitationTest.java index 5567ea243a..b50060e054 100644 --- a/source/java/org/alfresco/repo/web/scripts/invitation/InvitationTest.java +++ b/source/java/org/alfresco/repo/web/scripts/invitation/InvitationTest.java @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.List; import org.alfresco.model.ContentModel; +import org.alfresco.repo.action.executer.MailActionExecuter; import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.site.SiteModel; @@ -94,6 +95,11 @@ public class InvitationTest extends BaseWebScriptTest this.siteService = (SiteService)getServer().getApplicationContext().getBean("SiteService"); this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService"); + // TODO MER 20/11/2009 Bodge - turn off email sending to prevent errors during unit testing + // (or sending out email by accident from tests) + MailActionExecuter mail = (MailActionExecuter) getServer().getApplicationContext().getBean("mail"); + mail.setTestMode(true); + this.authenticationComponent.setSystemUserAsCurrentUser(); // Create users diff --git a/source/java/org/alfresco/repo/web/scripts/invite/InviteServiceTest.java b/source/java/org/alfresco/repo/web/scripts/invite/InviteServiceTest.java index cb7ec8bffc..e64a4b13de 100644 --- a/source/java/org/alfresco/repo/web/scripts/invite/InviteServiceTest.java +++ b/source/java/org/alfresco/repo/web/scripts/invite/InviteServiceTest.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.Set; import org.alfresco.model.ContentModel; +import org.alfresco.repo.action.executer.MailActionExecuter; import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.invitation.WorkflowModelNominatedInvitation; import org.alfresco.repo.security.authentication.AuthenticationComponent; @@ -136,6 +137,11 @@ public class InviteServiceTest extends BaseWebScriptTest this.namespaceService = (NamespaceService) getServer().getApplicationContext().getBean("NamespaceService"); this.transactionService = (TransactionService) getServer().getApplicationContext() .getBean("TransactionService"); + + // TODO MER 20/11/2009 Bodge - turn off email sending to prevent errors during unit testing + // (or sending out email by accident from tests) + MailActionExecuter mail = (MailActionExecuter) getServer().getApplicationContext().getBean("mail"); + mail.setTestMode(true); // redeploy invite process definition in case it has been modified WorkflowDefinition inviteWfDefinition = this.workflowService.getDefinitionByName( diff --git a/source/java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java b/source/java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java index 847870abc8..9becc77c42 100644 --- a/source/java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java +++ b/source/java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java @@ -33,6 +33,7 @@ import java.util.Map; import java.util.Set; import org.alfresco.model.ContentModel; +import org.alfresco.repo.action.executer.MailActionExecuter; import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.site.SiteModel; @@ -94,6 +95,11 @@ public class SiteServiceTest extends BaseWebScriptTest this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService"); this.authorityService = (AuthorityService)getServer().getApplicationContext().getBean("AuthorityService"); + // TODO MER 20/11/2009 Bodge - turn off email sending to prevent errors during unit testing + // (or sending out email by accident from tests) + MailActionExecuter mail = (MailActionExecuter)getServer().getApplicationContext().getBean("mail"); + mail.setTestMode(true); + this.authenticationComponent.setSystemUserAsCurrentUser(); // Create users