Search in sources :

Example 1 with ApiResult

use of com.searchcode.app.model.ApiResult in project searchcode-server by boyter.

the class ApiTest method testSaveRetrieve.

public void testSaveRetrieve() {
    String randomApiString = this.getRandomString();
    this.api.saveApi(new ApiResult(0, randomApiString, "privateKey", "", ""));
    ApiResult apiResult = this.api.getApiByPublicKey(randomApiString);
    assertThat(apiResult.getPublicKey()).isEqualTo(randomApiString);
    assertThat(apiResult.getPrivateKey()).isEqualTo("privateKey");
    this.api.deleteApiByPublicKey(randomApiString);
}
Also used : ApiResult(com.searchcode.app.model.ApiResult)

Example 2 with ApiResult

use of com.searchcode.app.model.ApiResult in project searchcode-server by boyter.

the class ApiTest method testMultipleRetrieveCache.

public void testMultipleRetrieveCache() {
    String randomApiString = this.getRandomString();
    this.api.saveApi(new ApiResult(0, randomApiString, "privateKey", "", ""));
    for (int i = 0; i < 500; i++) {
        ApiResult apiResult = this.api.getApiByPublicKey(randomApiString);
        assertThat(apiResult.getPublicKey()).isEqualTo(randomApiString);
        assertThat(apiResult.getPrivateKey()).isEqualTo("privateKey");
    }
    this.api.deleteApiByPublicKey(randomApiString);
}
Also used : ApiResult(com.searchcode.app.model.ApiResult)

Example 3 with ApiResult

use of com.searchcode.app.model.ApiResult in project searchcode-server by boyter.

the class ApiTest method testGetAllApi.

public void testGetAllApi() {
    String randomApi1 = this.getRandomString();
    String randomApi2 = this.getRandomString();
    this.api.saveApi(new ApiResult(0, randomApi1, "privateKey", "", ""));
    this.api.saveApi(new ApiResult(0, randomApi2, "privateKey", "", ""));
    assertThat(this.api.getAllApi().size()).isEqualTo(2);
    this.api.deleteApiByPublicKey(randomApi1);
    this.api.deleteApiByPublicKey(randomApi2);
}
Also used : ApiResult(com.searchcode.app.model.ApiResult)

Example 4 with ApiResult

use of com.searchcode.app.model.ApiResult in project searchcode-server by boyter.

the class ApiService method createKeys.

/**
     * Creates a public and private key with access to the API
     * TODO allow creation of permissions for keys
     */
public ApiResult createKeys() {
    String publicKey = "APIK-" + RandomStringUtils.randomAlphanumeric(27);
    String privateKey = RandomStringUtils.randomAlphanumeric(32);
    ApiResult apiResult = new ApiResult(-1, publicKey, privateKey, Values.EMPTYSTRING, Values.EMPTYSTRING);
    this.api.saveApi(apiResult);
    return apiResult;
}
Also used : ApiResult(com.searchcode.app.model.ApiResult)

Example 5 with ApiResult

use of com.searchcode.app.model.ApiResult in project searchcode-server by boyter.

the class Api method getAllApi.

public synchronized List<ApiResult> getAllApi() {
    List<ApiResult> apiResults = new ArrayList<>();
    Connection connection = null;
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    try {
        connection = this.dbConfig.getConnection();
        preparedStatement = connection.prepareStatement("select rowid,publickey,privatekey,lastused,data from api;");
        resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            int rowId = resultSet.getInt("rowid");
            String d_publicKey = resultSet.getString("publickey");
            String privateKey = resultSet.getString("privatekey");
            String lastUsed = resultSet.getString("lastused");
            String data = resultSet.getString("data");
            apiResults.add(new ApiResult(rowId, d_publicKey, privateKey, lastUsed, data));
        }
    } catch (SQLException ex) {
        Singleton.getLogger().severe(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
    } finally {
        this.helpers.closeQuietly(resultSet);
        this.helpers.closeQuietly(preparedStatement);
    }
    return apiResults;
}
Also used : ApiResult(com.searchcode.app.model.ApiResult) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Aggregations

ApiResult (com.searchcode.app.model.ApiResult)18 Api (com.searchcode.app.dao.Api)10 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)1