Skip to content
Snippets Groups Projects
Commit 4803e441 authored by William Enright's avatar William Enright Committed by Larbi Gharib
Browse files

User profile lookups now merge results from logon name and full name queries

Change-Id: I2fb411f8c22572f57a852a2d408a5191eada6240
parent 5707afb6
No related branches found
No related tags found
No related merge requests found
......@@ -148,4 +148,14 @@ public class UserProfile implements DatabaseObject {
return null;
}
@Override
public boolean equals(Object obj) {
UserProfile profile = (UserProfile) obj;
return (profile.getUsername().equals(this.username) &&
profile.getFirstName().equals(this.firstName) &&
profile.getLastName().equals(this.lastName));
}
}
......@@ -37,8 +37,8 @@ import net.jami.jams.common.objects.user.UserGroupMapping;
import net.jami.jams.common.objects.user.UserProfile;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import static net.jami.jams.server.Server.dataStore;
import static net.jami.jams.server.Server.nameServer;
......@@ -59,11 +59,25 @@ public class SearchDirectoryServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
List<UserProfile> userProfiles = new ArrayList<>();
userAuthenticationModule.getAuthSources().forEach((k, v) -> {
List<UserProfile> profiles = v.searchUserProfiles(req.getParameter("queryString"), "FULL_TEXT_NAME");
if(profiles == null || profiles.size() == 0){
// check logon names if nothing was found
profiles = v.searchUserProfiles(req.getParameter("queryString"), "LOGON_NAME");
List<UserProfile> profiles;
if (req.getParameter("queryString").equals("*"))
profiles = v.searchUserProfiles(req.getParameter("queryString"), "FULL_TEXT_NAME");
else {
profiles = v.searchUserProfiles(req.getParameter("queryString"), "FULL_TEXT_NAME");
List<UserProfile> profiles2 = v.searchUserProfiles(req.getParameter("queryString"), "LOGON_NAME");
for (Iterator<UserProfile> it = profiles.iterator(); it.hasNext();) {
UserProfile p = it.next();
for (UserProfile p2: profiles2) {
if (p2.equals(p))
it.remove();
}
}
profiles.addAll(profiles2);
}
profiles.parallelStream().forEach(profile -> {
StatementList statementList = new StatementList();
StatementElement statementElement = new StatementElement("username", "=", profile.getUsername(), "");
......@@ -89,16 +103,14 @@ public class SearchDirectoryServlet extends HttpServlet {
// update user group mappings table
userProfiles.forEach(profile -> {
List<UserGroupMapping> mappings = dataStore.getUserGroupMappingsDao().getObjects(null);
for(UserGroupMapping mapping: mappings) {
List<String> list = new ArrayList<>();
if (mapping.getUsername().equals(profile.getUsername())) {
String[] splits = mapping.getGroups().split(",");
for (int i = 0; i < splits.length; i++) {
for (int i = 0; i < splits.length; i++)
list.add(splits[i]);
}
}
if (!list.isEmpty())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment