use of io.kamax.mxisd.controller.directory.v1.io.UserDirectorySearchResult in project mxisd by kamax-io.
the class UserDirectoryController method search.
@RequestMapping(path = "/search", method = RequestMethod.POST)
public String search(HttpServletRequest request, @RequestParam("access_token") String accessToken) throws IOException {
UserDirectorySearchRequest searchQuery = parser.parse(request, UserDirectorySearchRequest.class);
URI target = URI.create(request.getRequestURL().toString());
UserDirectorySearchResult result = mgr.search(target, accessToken, searchQuery.getSearchTerm());
return gson.toJson(result);
}
use of io.kamax.mxisd.controller.directory.v1.io.UserDirectorySearchResult in project mxisd by kamax-io.
the class GenericSqlDirectoryProvider method search.
public UserDirectorySearchResult search(String searchTerm, GenericSqlProviderConfig.Query query) {
try (Connection conn = pool.get()) {
log.info("Will execute query: {}", query.getValue());
try (PreparedStatement stmt = conn.prepareStatement(query.getValue())) {
setParameters(stmt, searchTerm);
try (ResultSet rSet = stmt.executeQuery()) {
UserDirectorySearchResult result = new UserDirectorySearchResult();
result.setLimited(false);
while (rSet.next()) {
processRow(rSet).ifPresent(e -> {
if (StringUtils.equalsIgnoreCase("localpart", query.getType())) {
e.setUserId(new MatrixID(e.getUserId(), mxCfg.getDomain()).getId());
}
result.addResult(e);
});
}
return result;
}
}
} catch (SQLException e) {
throw new InternalServerError(e);
}
}
use of io.kamax.mxisd.controller.directory.v1.io.UserDirectorySearchResult in project mxisd by kamax-io.
the class RestDirectoryProviderTest method byNameFound.
@Test
public void byNameFound() {
stubFor(post(urlEqualTo(endpoint)).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(byNameResponse)));
UserDirectorySearchResult result = p.searchByDisplayName(byNameSearch);
assertTrue(!result.isLimited());
assertTrue(result.getResults().size() == 1);
UserDirectorySearchResult.Result entry = result.getResults().get(0);
assertNotNull(entry);
assertTrue(StringUtils.equals(byNameAvatar, entry.getAvatarUrl()));
assertTrue(StringUtils.equals(byNameDisplay, entry.getDisplayName()));
assertTrue(StringUtils.equals(new MatrixID(byNameId, domain).getId(), entry.getUserId()));
verify(postRequestedFor(urlMatching(endpoint)).withHeader("Content-Type", containing("application/json")).withRequestBody(equalTo(byNameRequest)));
}
use of io.kamax.mxisd.controller.directory.v1.io.UserDirectorySearchResult in project mxisd by kamax-io.
the class RestDirectoryProviderTest method byThreepidFound.
@Test
public void byThreepidFound() {
stubFor(post(urlEqualTo(endpoint)).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(new String(byThreepidResponse.getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8))));
UserDirectorySearchResult result = p.searchBy3pid(byThreepidSearch);
assertTrue(!result.isLimited());
assertTrue(result.getResults().size() == 1);
UserDirectorySearchResult.Result entry = result.getResults().get(0);
assertNotNull(entry);
assertTrue(StringUtils.equals(byThreepidAvatar, entry.getAvatarUrl()));
assertTrue(StringUtils.equals(byThreepidDisplay, entry.getDisplayName()));
assertTrue(StringUtils.equals(new MatrixID(byThreepidId, domain).getId(), entry.getUserId()));
verify(postRequestedFor(urlMatching(endpoint)).withHeader("Content-Type", containing("application/json")).withRequestBody(equalTo(byThreepidRequest)));
}
use of io.kamax.mxisd.controller.directory.v1.io.UserDirectorySearchResult in project mxisd by kamax-io.
the class RestDirectoryProviderTest method byThreepidNotFound.
@Test
public void byThreepidNotFound() {
stubFor(post(urlEqualTo(endpoint)).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(byThreepidEmptyResponse)));
UserDirectorySearchResult result = p.searchBy3pid(byThreepidSearch);
assertTrue(!result.isLimited());
assertTrue(result.getResults().isEmpty());
verify(postRequestedFor(urlMatching(endpoint)).withHeader("Content-Type", containing("application/json")).withRequestBody(equalTo(byThreepidRequest)));
}
Aggregations