Search in sources :

Example 16 with UserDirectorySearchResult

use of io.kamax.mxisd.http.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(MatrixID.asAcceptable(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) UserDirectorySearchResult(io.kamax.mxisd.http.io.UserDirectorySearchResult) InternalServerError(io.kamax.mxisd.exception.InternalServerError)

Example 17 with UserDirectorySearchResult

use of io.kamax.mxisd.http.io.UserDirectorySearchResult in project mxisd by kamax-io.

the class WordpressDirectoryProvider method search.

public UserDirectorySearchResult search(String searchTerm, String query) {
    try (Connection conn = wordpress.getConnection()) {
        log.info("Will execute query: {}", query);
        try (PreparedStatement stmt = conn.prepareStatement(query)) {
            setParameters(stmt, searchTerm);
            try (ResultSet rSet = stmt.executeQuery()) {
                UserDirectorySearchResult result = new UserDirectorySearchResult();
                result.setLimited(false);
                while (rSet.next()) {
                    processRow(rSet).ifPresent(e -> {
                        try {
                            e.setUserId(MatrixID.from(e.getUserId(), mxCfg.getDomain()).valid().getId());
                            result.addResult(e);
                        } catch (IllegalArgumentException ex) {
                            log.warn("Ignoring result {} - Invalid characters for a Matrix ID", e.getUserId());
                        }
                    });
                }
                return result;
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
        throw new InternalServerError(e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) UserDirectorySearchResult(io.kamax.mxisd.http.io.UserDirectorySearchResult) InternalServerError(io.kamax.mxisd.exception.InternalServerError)

Aggregations

UserDirectorySearchResult (io.kamax.mxisd.http.io.UserDirectorySearchResult)17 Test (org.junit.Test)9 InternalServerError (io.kamax.mxisd.exception.InternalServerError)5 UserDirectorySearchRequest (io.kamax.mxisd.http.io.UserDirectorySearchRequest)4 IOException (java.io.IOException)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 MatrixErrorInfo (io.kamax.matrix.MatrixErrorInfo)1 ExecDirectoryStore (io.kamax.mxisd.backend.exec.ExecDirectoryStore)1 ExecConfig (io.kamax.mxisd.config.ExecConfig)1 LdapConfig (io.kamax.mxisd.config.ldap.LdapConfig)1 HttpMatrixException (io.kamax.mxisd.exception.HttpMatrixException)1 URI (java.net.URI)1 Charset (java.nio.charset.Charset)1 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)1 CursorLdapReferralException (org.apache.directory.api.ldap.model.cursor.CursorLdapReferralException)1