Search in sources :

Example 1 with UserDirectorySearchResult

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);
}
Also used : UserDirectorySearchRequest(io.kamax.mxisd.controller.directory.v1.io.UserDirectorySearchRequest) URI(java.net.URI) UserDirectorySearchResult(io.kamax.mxisd.controller.directory.v1.io.UserDirectorySearchResult)

Example 2 with UserDirectorySearchResult

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);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MatrixID(io.kamax.matrix.MatrixID) UserDirectorySearchResult(io.kamax.mxisd.controller.directory.v1.io.UserDirectorySearchResult) InternalServerError(io.kamax.mxisd.exception.InternalServerError)

Example 3 with UserDirectorySearchResult

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)));
}
Also used : MatrixID(io.kamax.matrix.MatrixID) UserDirectorySearchResult(io.kamax.mxisd.controller.directory.v1.io.UserDirectorySearchResult) Test(org.junit.Test)

Example 4 with UserDirectorySearchResult

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)));
}
Also used : MatrixID(io.kamax.matrix.MatrixID) UserDirectorySearchResult(io.kamax.mxisd.controller.directory.v1.io.UserDirectorySearchResult) Test(org.junit.Test)

Example 5 with UserDirectorySearchResult

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)));
}
Also used : UserDirectorySearchResult(io.kamax.mxisd.controller.directory.v1.io.UserDirectorySearchResult) Test(org.junit.Test)

Aggregations

UserDirectorySearchResult (io.kamax.mxisd.controller.directory.v1.io.UserDirectorySearchResult)6 Test (org.junit.Test)4 MatrixID (io.kamax.matrix.MatrixID)3 UserDirectorySearchRequest (io.kamax.mxisd.controller.directory.v1.io.UserDirectorySearchRequest)1 InternalServerError (io.kamax.mxisd.exception.InternalServerError)1 URI (java.net.URI)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1