diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/search/personsearch.get.html.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/search/personsearch.get.html.ftl index 4bc6803cfd..cad39d92a4 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/search/personsearch.get.html.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/search/personsearch.get.html.ftl @@ -24,7 +24,13 @@ <#list search.results as row> - + <#if (row.assocs["cm:avatar"]?exists)> + <#assign avatarURL = row.assocs["cm:avatar"][0].url> + <#else> + <#assign avatarURL = "/images/icons/default_avatar.png"> + + + diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/search/personsearch.get.portlet.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/search/personsearch.get.portlet.ftl index 5ef6ccd3c5..1262c0ac2e 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/search/personsearch.get.portlet.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/search/personsearch.get.portlet.ftl @@ -5,9 +5,16 @@
${row.firstName} ${row.lastName}<#if row.properties.firstName??>${row.properties.firstName}<#if row.properties.lastName??> ${row.properties.lastName}

-<#list search.results as row> +<#list search.results as row> + + <#if (row.assocs["cm:avatar"]?exists)> + <#assign avatarURL = row.assocs["cm:avatar"][0].url> + <#else> + <#assign avatarURL = "/images/icons/default_avatar.png"> + - + + diff --git a/source/java/org/alfresco/repo/web/scripts/search/PersonSearchTest.java b/source/java/org/alfresco/repo/web/scripts/search/PersonSearchTest.java new file mode 100644 index 0000000000..8491536c6c --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/search/PersonSearchTest.java @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2009-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.search; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.security.authentication.AuthenticationComponent; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.web.scripts.BaseWebScriptTest; +import org.alfresco.service.cmr.security.AuthenticationService; +import org.alfresco.service.cmr.security.AuthorityService; +import org.alfresco.service.cmr.security.PersonService; +import org.alfresco.util.PropertyMap; +import org.alfresco.web.scripts.Status; +import org.alfresco.web.scripts.TestWebScriptServer.GetRequest; +import org.alfresco.web.scripts.TestWebScriptServer.Response; + +/** + * Unit test for PersonSearch Web Script. + * + * /alfresco/service/api/search/person?q=* + * @author Mark Rogers + */ +public class PersonSearchTest extends BaseWebScriptTest +{ + private AuthenticationService authenticationService; + private AuthenticationComponent authenticationComponent; + private PersonService personService; + private AuthorityService authorityService; + + private static final String USER_ONE = "PersonSearchTestOne"; + private static final String USER_TWO = "PersonSearchTestTwo"; + private static final String USER_THREE = "PersonSearchTestThree"; + + @Override + protected void setUp() throws Exception + { + super.setUp(); + + this.authenticationService = (AuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService"); + this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent"); + this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService"); + this.authorityService = (AuthorityService)getServer().getApplicationContext().getBean("AuthorityService"); + this.authenticationComponent.setSystemUserAsCurrentUser(); + + // Create users + createUser(USER_ONE); + createUser(USER_TWO); + createUser(USER_THREE); + + // Do tests as user one + this.authenticationComponent.setCurrentUser(USER_ONE); + } + + private void createUser(String userName) + { + if (this.authenticationService.authenticationExists(userName) == false) + { + this.authenticationService.createAuthentication(userName, "PWD".toCharArray()); + + PropertyMap ppOne = new PropertyMap(4); + ppOne.put(ContentModel.PROP_USERNAME, userName); + ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName"); + ppOne.put(ContentModel.PROP_LASTNAME, "lastName"); + ppOne.put(ContentModel.PROP_EMAIL, "email@email.com"); + ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle"); + + this.personService.createPerson(ppOne); + } + } + + @Override + protected void tearDown() throws Exception + { + super.tearDown(); + this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); + } + + /** + * This is a basic sanity check of the search/person script. + * @throws Exception + */ + public void testSearch() throws Exception + { + /** + * Do the first query for default format and all results + */ + { + Response response = sendRequest(new GetRequest("/api/search/person?q=*"), Status.STATUS_OK); +// JSONObject top = new JSONObject(response.getContentAsString()); +// logger.debug(response.getContentAsString()); + System.out.println(response.getContentAsString()); + } + + /** + * Same search with HTML format + */ + { + Response response = sendRequest(new GetRequest("/api/search/person.html?q=*"), Status.STATUS_OK); +// JSONObject top = new JSONObject(response.getContentAsString()); +// logger.debug(response.getContentAsString()); + System.out.println(response.getContentAsString()); + } + + + /** + * Negative test - missing mandatory parameter + * + * Should really be a INVALID_REQUEST + */ + sendRequest(new GetRequest("/api/search/person?"), Status.STATUS_INTERNAL_SERVER_ERROR); + } + + public void testPortletSearch() throws Exception + { + /** + * Do the first query for default format and all results + */ + { + Response response = sendRequest(new GetRequest("/api/search/person.portlet?q=*"), Status.STATUS_OK); +// JSONObject top = new JSONObject(response.getContentAsString()); +// logger.debug(response.getContentAsString()); + System.out.println(response.getContentAsString()); + } + } + + public void testAtomSearch() throws Exception + { + /** + * Do the first query for default format and all results + */ + { + Response response = sendRequest(new GetRequest("/api/search/person.atom?q=*"), Status.STATUS_OK); +// JSONObject top = new JSONObject(response.getContentAsString()); +// logger.debug(response.getContentAsString()); + System.out.println(response.getContentAsString()); + } + } + + + +}
${row.firstName} ${row.lastName}<#if row.properties.firstName??>${row.properties.firstName}<#if row.properties.lastName??> ${row.properties.lastName}