diff --git a/source/java/org/alfresco/web/bean/users/DeleteUserDialog.java b/source/java/org/alfresco/web/bean/users/DeleteUserDialog.java index ffcaafd8da..d6cf7d0153 100644 --- a/source/java/org/alfresco/web/bean/users/DeleteUserDialog.java +++ b/source/java/org/alfresco/web/bean/users/DeleteUserDialog.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2011 Alfresco Software Limited. + * Copyright (C) 2005-2013 Alfresco Software Limited. * * This file is part of Alfresco * @@ -124,9 +124,7 @@ public class DeleteUserDialog extends BaseDialogBean // define the query to find people by their first or last name String search = ISO9075.encode(this.searchCriteria); - List> filter = new ArrayList>(); - filter.add(new Pair(ContentModel.PROP_FIRSTNAME, search)); - filter.add(new Pair(ContentModel.PROP_LASTNAME, search)); + List> filter = Utils.generatePersonFilter(search); if (logger.isDebugEnabled()) { diff --git a/source/java/org/alfresco/web/ui/common/Utils.java b/source/java/org/alfresco/web/ui/common/Utils.java index 1b8d254d33..4012ea9ce3 100644 --- a/source/java/org/alfresco/web/ui/common/Utils.java +++ b/source/java/org/alfresco/web/ui/common/Utils.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2013 Alfresco Software Limited. * * This file is part of Alfresco * @@ -98,6 +98,9 @@ public final class Utils extends StringUtils private static final Log logger = LogFactory.getLog(Utils.class); + /** RegEx to split a String on the first space. */ + public static final String ON_FIRST_SPACE = " +"; + static { tagWhiteList.add("STRIKE"); @@ -1132,9 +1135,54 @@ public final class Utils extends StringUtils filter.add(new Pair(ContentModel.PROP_FIRSTNAME, term)); filter.add(new Pair(ContentModel.PROP_LASTNAME, term)); filter.add(new Pair(ContentModel.PROP_USERNAME, term)); + + // In order to support queries for "Alan Smithee", we'll parse these tokens + // and add them in to the query. + Pair tokenisedName = tokeniseName(term); + if (tokenisedName != null) + { + filter.add(new Pair(ContentModel.PROP_FIRSTNAME, tokenisedName.getFirst())); + filter.add(new Pair(ContentModel.PROP_LASTNAME, tokenisedName.getSecond())); + } + return filter; } + /** + * This method will tokenise a name string in order to extract first name, last name - if possible. + * The split is simple - it's made on the first whitespace within the trimmed nameFilter String. So + *

+ * "Luke Skywalker" becomes ["Luke", "Skywalker"]. + *

+ * "Jar Jar Binks" becomes ["Jar", "Jar Binks"]. + *

+ * "C-3PO" becomes null. + * + * @param nameFilter + * @return A Pair if the String is valid, else null. + */ + private static Pair tokeniseName(String nameFilter) + { + Pair result = null; + + if (nameFilter != null) + { + final String trimmedNameFilter = nameFilter.trim(); + + // We can only have a first name and a last name if we have at least 3 characters e.g. "A B". + if (trimmedNameFilter.length() > 3) + { + final String[] tokens = trimmedNameFilter.split(ON_FIRST_SPACE, 2); + if (tokens.length == 2) + { + result = new Pair(tokens[0], tokens[1]); + } + } + } + + return result; + } + /** * How many results should a person search return up to? This is needed * because the JSF components do paging differently. diff --git a/source/java/org/alfresco/web/ui/repo/component/property/BaseAssociationEditor.java b/source/java/org/alfresco/web/ui/repo/component/property/BaseAssociationEditor.java index b84cc314f8..081e9b6bee 100644 --- a/source/java/org/alfresco/web/ui/repo/component/property/BaseAssociationEditor.java +++ b/source/java/org/alfresco/web/ui/repo/component/property/BaseAssociationEditor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2011 Alfresco Software Limited. + * Copyright (C) 2005-2013 Alfresco Software Limited. * * This file is part of Alfresco * @@ -1032,15 +1032,9 @@ public abstract class BaseAssociationEditor extends UIInput } else if(type.equals(ContentModel.TYPE_PERSON.toString())) { - // If the association's target is the person type search on the - // firstName and lastName properties instead of the name property - List> filter = new ArrayList>(); - if (contains != null && contains.length() > 0) - { - String search = contains.trim(); - filter.add(new Pair(ContentModel.PROP_FIRSTNAME, search)); - filter.add(new Pair(ContentModel.PROP_LASTNAME, search)); - } + List> filter = (contains != null && contains.trim().length() > 0) + ? Utils.generatePersonFilter(contains.trim()) + : null; // Always sort by last name, then first name List> sort = new ArrayList>();