Issue #2699 fixed assumption that usersearch was exact

usersearch returns matches for any part of string
added method to restrict to exact matches only


Former-commit-id: cfa3c9e0e8 [formerly 74daa7109149073c615d13c25092f6d08a77b936]
Former-commit-id: 6ea009a2e1
This commit is contained in:
Brian Clements 2014-02-03 15:21:32 -06:00
parent 23f17b3f63
commit aff354a3d7
4 changed files with 60 additions and 31 deletions

View file

@ -70,6 +70,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConn
* added utility methods for subscription status
* Jan 30, 2014 2698 bclement removed unneeded nickname changed event
* Jan 31, 2014 2700 bclement added addToRoster, fixed add to group when in roster, but blocked
* Feb 3, 2014 2699 bclement fixed assumption that username search was exact
*
* </pre>
*
@ -225,7 +226,7 @@ public class ContactsManager {
if (entry == null) {
// we dont have user as a contact at all
// ensure that the user object is up-to-date
user = findUser(user.getName());
user = update(user);
String alias = user.getAlias();
if (StringUtils.isBlank(alias)) {
alias = user.getName();
@ -249,7 +250,7 @@ public class ContactsManager {
if (entry == null) {
// we dont have user as a contact at all
// ensure that the user object is up-to-date
user = findUser(user.getName());
user = update(user);
String alias = user.getAlias();
if (StringUtils.isBlank(alias)) {
alias = user.getName();
@ -534,27 +535,26 @@ public class ContactsManager {
/**
* Perform an XMPP search for user. Includes any local alias information.
* Only return non-null on an exact match.
*
* @param username
* The part of the userid before the '@'
* @return null if not found
*/
private UserId findUser(String username) {
List<UserId> results;
try {
results = search.byUsername(username);
UserId rval = search.byExactUsername(username);
if (rval != null) {
String alias = localAliases.get(rval.getNormalizedId());
if (alias != null) {
rval.setAlias(alias);
}
}
return rval;
} catch (XMPPException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
return null;
}
for (UserId id : results) {
String alias = localAliases.get(id.getNormalizedId());
if (alias != null) {
id.setAlias(alias);
}
}
// since we are searching by ID, there should be 0 or 1 result
return results.isEmpty() ? null : results.iterator().next();
}
/**
@ -635,6 +635,19 @@ public class ContactsManager {
return rval != null ? rval : entry;
}
/**
* Get updated alias information for user. This will attempt to get local
* alias information, if non available, it will return alias from user
* search, if both fail, it will return the same object.
*
* @param user
* @return
*/
public UserId update(UserId user) {
UserId updated = findUser(user.getName());
return updated != null ? updated : user;
}
/**
* @param entry
* @return true if we are blocked from seeing updates from user in entry

View file

@ -47,6 +47,7 @@ import com.raytheon.uf.common.status.UFStatus;
* ------------ ---------- ----------- --------------------------
* Nov 22, 2013 2561 bclement Initial creation
* Jan 24, 2014 2701 bclement distinction between userid and username
* Feb 3, 2014 2699 bclement fixed assumption that username search was exact
*
* </pre>
*
@ -82,7 +83,8 @@ public class UserSearch {
}
/**
* Search by username (the part of the user id before the @)
* Search by username (the part of the user id before the @). This is case
* sensitive and matches any part of the string (^.*username.*$).
*
* @param name
* @return list of user ids that match that name
@ -93,7 +95,28 @@ public class UserSearch {
}
/**
* Search for users by single criteria
* Search by username (the part of the user id before the @). This only
* returns a match if the entire username matches the entire entry.
*
* @param username
* @return null if none found
* @throws XMPPException
*/
public UserId byExactUsername(String username) throws XMPPException {
List<UserId> results = byUsername(username);
UserId rval = null;
for (UserId result : results) {
if (result.getName().equals(username)) {
rval = result;
break;
}
}
return rval;
}
/**
* Search for users by single criteria. This is case sensitive and matches
* any part of the string (^.*value.*$).
*
* @param field
* @param value

View file

@ -19,8 +19,6 @@
**/
package com.raytheon.uf.viz.collaboration.ui.prefs;
import java.util.List;
import org.eclipse.jface.preference.IPersistentPreferenceStore;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
@ -51,6 +49,7 @@ import com.raytheon.uf.viz.core.VizApp;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 24, 2014 2700 bclement Initial creation
* Feb 3, 2014 2699 bclement fixed assumption that username search was exact
*
* </pre>
*
@ -198,11 +197,8 @@ public class AutoSubscribePropertyListener implements IPropertyChangeListener {
private String getDisplayName(UserId fromID) {
String rval = null;
try {
List<UserId> users = search.byUsername(fromID.getName());
if ( users != null && !users.isEmpty()){
UserId user = users.get(0);
return user.getAlias();
}
UserId user = search.byExactUsername(fromID.getName());
return user != null ? user.getAlias() : null;
} catch (XMPPException e) {
log.error("Unable to get display name for user: " + fromID,
e);

View file

@ -19,9 +19,7 @@
**/
package com.raytheon.uf.viz.collaboration.ui.prefs;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.jface.preference.IPersistentPreferenceStore;
@ -47,6 +45,7 @@ import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants.HandleOpti
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 3, 2014 2699 bclement Initial creation
* Feb 3, 2014 2699 bclement fixed assumption that username search was exact
*
* </pre>
*
@ -58,7 +57,7 @@ public class HandleUtil {
private static final IUFStatusHandler log = UFStatus
.getHandler(HandleUtil.class);
private static Map<String, String> fullNameMap = new HashMap<String, String>();
private static final Map<String, String> fullNameMap = new HashMap<String, String>();
/**
* @return default session handle from preferences
@ -120,16 +119,14 @@ public class HandleUtil {
if (fullName == null) {
String username = account.getName();
UserSearch search = conn.createSearch();
List<UserId> ids;
UserId result = null;
try {
ids = search.byUsername(username);
result = search.byExactUsername(username);
} catch (XMPPException e) {
log.error("Unable to search by username: " + username, e);
ids = Collections.emptyList();
}
if (!ids.isEmpty()) {
UserId id = ids.iterator().next();
rval = id.getAlias();
if (result != null) {
rval = result.getAlias();
fullNameMap.put(account.getNormalizedId(), rval);
} else {
log.warn("Unable to find collaboration account via server search: "