Skip to content
Snippets Groups Projects
Commit d36a82c5 authored by William Enright's avatar William Enright
Browse files

directory search: changed error code with no users found, fixed empty...

directory search: changed error code with no users found, fixed empty searchResult retuning null instead of empty array

Change-Id: Ib54abb2647b297bd317bd193243380cb43d48528
parent 81818b1f
No related branches found
No related tags found
No related merge requests found
......@@ -67,18 +67,13 @@ public class SearchDirectoryServlet extends HttpServlet {
else {
profiles = v.searchUserProfiles(req.getParameter("queryString"), "FULL_TEXT_NAME");
List<UserProfile> profiles2 = v.searchUserProfiles(req.getParameter("queryString"), "LOGON_NAME");
if (profiles != null) {
for (Iterator<UserProfile> it = profiles.iterator(); it.hasNext(); ) {
UserProfile p = it.next();
for (UserProfile p2 : profiles2) {
if (p2.equals(p))
it.remove();
}
for (Iterator<UserProfile> it = profiles.iterator(); it.hasNext(); ) {
UserProfile p = it.next();
for (UserProfile p2 : profiles2) {
if (p2.equals(p))
it.remove();
}
}
if (profiles == null)
profiles = new ArrayList<>();
profiles.addAll(profiles2);
}
......@@ -122,7 +117,9 @@ public class SearchDirectoryServlet extends HttpServlet {
}
dataStore.updateUserProfile(profile);
});
resp.getOutputStream().write(JsonStream.serialize(userProfiles).getBytes());
if (!userProfiles.isEmpty()) {
resp.getOutputStream().write(JsonStream.serialize(userProfiles).getBytes());
resp.setStatus(200);
} else resp.sendError(404, "No users were found!");
}
}
......@@ -32,6 +32,7 @@ import org.ldaptive.SearchOperation;
import org.ldaptive.SearchRequest;
import org.ldaptive.SearchResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
......@@ -55,7 +56,7 @@ public class UserProfileService {
connection.open();
SearchOperation search = new SearchOperation(connectionFactory);
SearchResponse res = search.execute(buildRequest(queryString,field, exactMatch));
if (res.getEntries().size() == 0) return null;
if (res.getEntries().size() == 0) return new ArrayList<>();
return res.getEntries().stream().map(UserProfileService::profileFromResponse).collect(Collectors.toList());
} catch (Exception e) {
log.error("Could not search LDAP directory with error " + e.toString());
......
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