diff --git a/config/alfresco/action-services-context.xml b/config/alfresco/action-services-context.xml
index 4bf0309303..56d8746fd6 100644
--- a/config/alfresco/action-services-context.xml
+++ b/config/alfresco/action-services-context.xml
@@ -202,6 +202,8 @@
+
+
@@ -215,6 +217,8 @@
+
+
diff --git a/source/java/org/alfresco/repo/action/constraint/FolderContentsParameterConstraint.java b/source/java/org/alfresco/repo/action/constraint/FolderContentsParameterConstraint.java
index e873458562..2778fd05f7 100644
--- a/source/java/org/alfresco/repo/action/constraint/FolderContentsParameterConstraint.java
+++ b/source/java/org/alfresco/repo/action/constraint/FolderContentsParameterConstraint.java
@@ -27,13 +27,13 @@ import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
+import org.alfresco.repo.model.Repository;
import org.alfresco.service.cmr.dictionary.DictionaryService;
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.cmr.repository.StoreRef;
-import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchService;
+import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
@@ -50,6 +50,10 @@ public class FolderContentsParameterConstraint extends BaseParameterConstraint
private DictionaryService dictionaryService;
+ private NamespaceService namespaceService;
+
+ private Repository repository;
+
private String searchPath;
private List nodeInclusionFilter = Collections.emptyList();
@@ -74,6 +78,16 @@ public class FolderContentsParameterConstraint extends BaseParameterConstraint
this.dictionaryService = dictionaryService;
}
+ public void setNamespaceService(NamespaceService namespaceService)
+ {
+ this.namespaceService = namespaceService;
+ }
+
+ public void setRepository(Repository repository)
+ {
+ this.repository = repository;
+ }
+
/**
* This optional property defines a list of file extensions which should be included in the result set from
* this class. By implication, all other file extensions will be excluded. (The dot should not be specified
@@ -102,19 +116,18 @@ public class FolderContentsParameterConstraint extends BaseParameterConstraint
* @see org.alfresco.service.cmr.action.ParameterConstraint#getAllowableValues()
*/
protected Map getAllowableValuesImpl()
- {
- ResultSet resultSet = searchService.query(
- StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,
- SearchService.LANGUAGE_LUCENE,
- "PATH:\"" + searchPath + "\"");
+ {
+ List nodeRefs = searchService.selectNodes(repository.getRootHome(),
+ this.searchPath, null, this.namespaceService, false);
+
NodeRef rootFolder = null;
- if (resultSet.length() == 0)
+ if (nodeRefs.size() == 0)
{
throw new AlfrescoRuntimeException("The path '" + searchPath + "' did not return any results.");
}
else
{
- rootFolder = resultSet.getNodeRef(0);
+ rootFolder = nodeRefs.get(0);
}
Map result = new HashMap(23);
diff --git a/source/java/org/alfresco/repo/invitation/site/InviteSender.java b/source/java/org/alfresco/repo/invitation/site/InviteSender.java
index 74d9cdbdc0..d1d9ebad1b 100644
--- a/source/java/org/alfresco/repo/invitation/site/InviteSender.java
+++ b/source/java/org/alfresco/repo/invitation/site/InviteSender.java
@@ -42,7 +42,6 @@ import org.alfresco.repo.action.executer.MailActionExecuter;
import org.alfresco.repo.admin.SysAdminParams;
import org.alfresco.repo.i18n.MessageService;
import org.alfresco.repo.model.Repository;
-import org.alfresco.repo.search.SearcherException;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionService;
@@ -51,16 +50,13 @@ import org.alfresco.service.cmr.invitation.InvitationException;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
-import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.repository.TemplateService;
-import org.alfresco.service.cmr.search.ResultSet;
-import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteService;
+import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.util.ModelUtil;
-import org.alfresco.util.UrlUtil;
import org.springframework.extensions.surf.util.ParameterCheck;
import org.springframework.extensions.surf.util.URLEncoder;
@@ -98,6 +94,7 @@ public class InviteSender
private final FileFolderService fileFolderService;
private final SysAdminParams sysAdminParams;
private final RepoAdminService repoAdminService;
+ private final NamespaceService namespaceService;
public InviteSender(ServiceRegistry services, Repository repository, MessageService messageService)
{
@@ -109,6 +106,7 @@ public class InviteSender
this.fileFolderService = services.getFileFolderService();
this.sysAdminParams = services.getSysAdminParams();
this.repoAdminService = services.getRepoAdminService();
+ this.namespaceService = services.getNamespaceService();
this.repository = repository;
this.messageService = messageService;
}
@@ -216,36 +214,20 @@ public class InviteSender
private NodeRef getEmailTemplateNodeRef()
{
- StoreRef spacesStore = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
- String query = " PATH:\"app:company_home/app:dictionary/app:email_templates/cm:invite/cm:invite-email.html.ftl\"";
-
- SearchParameters searchParams = new SearchParameters();
- searchParams.addStore(spacesStore);
- searchParams.setLanguage(SearchService.LANGUAGE_LUCENE);
- searchParams.setQuery(query);
-
- ResultSet results = null;
- try
+ List nodeRefs = searchService.selectNodes(repository.getRootHome(),
+ "app:company_home/app:dictionary/app:email_templates/cm:invite/cm:invite-email.html.ftl", null,
+ this.namespaceService, false);
+
+ if (nodeRefs.size() == 1)
{
- results = searchService.query(searchParams);
- List nodeRefs = results.getNodeRefs();
- if (nodeRefs.size() == 1) {
- // Now localise this
- NodeRef base = nodeRefs.get(0);
- NodeRef local = fileFolderService.getLocalizedSibling(base);
- return local;
- }
- else
- throw new InvitationException("Cannot find the email template!");
+ // Now localise this
+ NodeRef base = nodeRefs.get(0);
+ NodeRef local = fileFolderService.getLocalizedSibling(base);
+ return local;
}
- catch (SearcherException e)
+ else
{
- throw new InvitationException("Cannot find the email template!", e);
- }
- finally
- {
- if (results != null)
- results.close();
+ throw new InvitationException("Cannot find the email template!");
}
}
diff --git a/source/java/org/alfresco/repo/invitation/site/InviteSenderTest.java b/source/java/org/alfresco/repo/invitation/site/InviteSenderTest.java
index cf3d76adf6..cb3984d2e4 100644
--- a/source/java/org/alfresco/repo/invitation/site/InviteSenderTest.java
+++ b/source/java/org/alfresco/repo/invitation/site/InviteSenderTest.java
@@ -59,12 +59,14 @@ import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
+import org.alfresco.service.cmr.search.QueryParameterDefinition;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteService;
+import org.alfresco.service.namespace.NamespacePrefixResolver;
import org.mockito.ArgumentCaptor;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -349,6 +351,9 @@ public class InviteSenderTest extends TestCase
List nodeRefs = Arrays.asList(template);
when(results.getNodeRefs()).thenReturn(nodeRefs);
when(searchService.query((SearchParameters) any())).thenReturn(results);
+ when(searchService.selectNodes(any(NodeRef.class), any(String.class),
+ any(QueryParameterDefinition[].class), any(NamespacePrefixResolver.class), eq(false)))
+ .thenReturn(nodeRefs);
return searchService;
}
diff --git a/source/java/org/alfresco/repo/site/script/ScriptSiteService.java b/source/java/org/alfresco/repo/site/script/ScriptSiteService.java
index 9ecbab7987..625c54e037 100644
--- a/source/java/org/alfresco/repo/site/script/ScriptSiteService.java
+++ b/source/java/org/alfresco/repo/site/script/ScriptSiteService.java
@@ -154,6 +154,43 @@ public class ScriptSiteService extends BaseScopableProcessorExtension
return (SiteServiceImpl.SITE_MANAGER.equals(role));
}
+ /**
+ * Retrieves the sites available in the repository. The returned list can optionally be filtered by name and site
+ * preset. If no filters are specified then all the available sites are returned.
+ *
+ * NOTE: If the filter starts with a * a Lucene based search will be performed, this may discover a wider range
+ * of results i.e. those sites that contain the search term as opposed to those that start with the search term,
+ * but newly created sites may not be found until the underlying search indexes are updated.
+ *
+ * @param filter inclusion filter for returned sites. Only sites whose cm:name OR cm:title
+ * OR cm:description start with the filter string will be returned.
+ * @param sitePresetFilter site preset filter
+ * @param size max results size crop if >0
+ * @return Site[] a list of the site filtered as appropriate
+ */
+ public Site[] getSites(String filter, String sitePresetFilter, int size)
+ {
+ // reset filter if necessary
+ if (filter != null && (filter.length() == 0 || filter.equals("*")))
+ {
+ filter = null;
+ }
+
+ if (filter != null && (filter.startsWith("*")))
+ {
+ // findSites will add the wildcard so remove here
+ filter = filter.substring(1, filter.length());
+
+ // use findSites to do a "contains" search
+ return findSites(filter, sitePresetFilter, size);
+ }
+ else
+ {
+ // use listSites to do a canned query (will provide consistent results)
+ return listSites(filter, sitePresetFilter, size);
+ }
+ }
+
/**
* List the sites available in the repository. The returned list can optionally be filtered by name and site
* preset.
diff --git a/source/java/org/alfresco/repo/site/script/test_siteService.js b/source/java/org/alfresco/repo/site/script/test_siteService.js
index e455c2bd82..8f07047440 100644
--- a/source/java/org/alfresco/repo/site/script/test_siteService.js
+++ b/source/java/org/alfresco/repo/site/script/test_siteService.js
@@ -75,6 +75,28 @@ function testFindSites()
test.assertEquals(1, sites.length);
}
+function testGetSites()
+{
+ // get all the sites
+ var sites = siteService.getSites(null, null, -1);
+ test.assertEquals(preexistingSiteCount + 2, sites.length);
+
+ sites = siteService.getSites("*", null, -1);
+ test.assertEquals(preexistingSiteCount + 2, sites.length);
+
+ // get all sites whose name starts with "site"
+ sites = siteService.getSites("site", null, -1);
+ test.assertEquals(2, sites.length);
+
+ // get all sites whose name starts with "short"
+ sites = siteService.getSites("short", null, -1);
+ test.assertEquals(0, sites.length);
+
+ // get all sites with "short" in the name
+ sites = siteService.getSites("*short", null, -1);
+ test.assertEquals(2, sites.length);
+}
+
function testMembership()
{
var site = siteService.getSite("siteShortName");
@@ -226,6 +248,7 @@ function testSiteCustomProperties()
testCRUD();
testListSites();
testFindSites();
+testGetSites();
testMembership();
testContainer();
testPermissions();
diff --git a/source/java/org/alfresco/repo/template/NodeSearchResultsMap.java b/source/java/org/alfresco/repo/template/NodeSearchResultsMap.java
index d8e3aed43e..a30ff8659f 100644
--- a/source/java/org/alfresco/repo/template/NodeSearchResultsMap.java
+++ b/source/java/org/alfresco/repo/template/NodeSearchResultsMap.java
@@ -18,10 +18,8 @@
*/
package org.alfresco.repo.template;
-import java.util.List;
-
-import org.alfresco.repo.search.impl.lucene.AbstractLuceneQueryParser;
import org.alfresco.service.ServiceRegistry;
+import org.alfresco.service.cmr.repository.NodeRef;
/**
* Provides functionality to execute a Lucene search for a single node by NodeRef.
@@ -49,14 +47,8 @@ public class NodeSearchResultsMap extends BaseSearchResultsMap
TemplateNode result = null;
if (key != null)
{
- String ref = "ID:" + AbstractLuceneQueryParser.escape(key.toString());
-
- List results = query(ref);
-
- if (results.size() != 0)
- {
- result = results.get(0);
- }
+ NodeRef nodeRef = new NodeRef((String)key);
+ result = new TemplateNode(nodeRef, services, this.parent.getImageResolver());
}
return result;
}