use of com.google.refine.extension.database.DatabaseConfiguration in project OpenRefine by OpenRefine.
the class SavedConnectionCommand method writeSavedConnectionResponse.
/**
* @param response
* @throws IOException
* @throws JSONException
*/
private void writeSavedConnectionResponse(HttpServletResponse response) throws IOException {
Writer w = response.getWriter();
try {
List<DatabaseConfiguration> savedConnections = DatabaseUtils.getSavedConnections();
JsonGenerator writer = ParsingUtilities.mapper.getFactory().createGenerator(w);
writer.writeStartObject();
writer.writeArrayFieldStart(DatabaseUtils.SAVED_CONNECTION_KEY);
int size = savedConnections.size();
for (int i = 0; i < size; i++) {
writer.writeStartObject();
DatabaseConfiguration dbConfig = (DatabaseConfiguration) savedConnections.get(i);
writer.writeStringField("connectionName", dbConfig.getConnectionName());
writer.writeStringField("databaseType", dbConfig.getDatabaseType());
writer.writeStringField("databaseHost", dbConfig.getDatabaseHost());
writer.writeNumberField("databasePort", dbConfig.getDatabasePort());
writer.writeStringField("databaseName", dbConfig.getDatabaseName());
String dbPasswd = dbConfig.getDatabasePassword();
if (dbPasswd != null && !dbPasswd.isEmpty()) {
dbPasswd = DatabaseUtils.decrypt(dbConfig.getDatabasePassword());
}
// writer.value(dbConfig.getDatabasePassword());
writer.writeStringField("databasePassword", dbPasswd);
writer.writeStringField("databaseSchema", dbConfig.getDatabaseSchema());
writer.writeStringField("databaseUser", dbConfig.getDatabaseUser());
writer.writeEndObject();
}
writer.writeEndArray();
writer.writeEndObject();
writer.flush();
writer.close();
// logger.info("Saved Connection Get Response sent");
} finally {
w.flush();
w.close();
}
}
use of com.google.refine.extension.database.DatabaseConfiguration in project OpenRefine by OpenRefine.
the class SavedConnectionCommand method doPut.
@Override
public void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (logger.isDebugEnabled()) {
logger.debug("databaseType::{} ", request.getParameter("databaseHost"));
}
// logger.info("databaseHost::{} " , request.getParameter("databaseServer"));
DatabaseConfiguration jdbcConfig = getJdbcConfiguration(request);
StringBuilder sb = new StringBuilder();
boolean error = false;
if (jdbcConfig.getConnectionName() == null) {
sb.append("Connection Name, ");
error = true;
}
if (jdbcConfig.getDatabaseHost() == null) {
sb.append("Database Host, ");
error = true;
}
if (jdbcConfig.getDatabaseUser() == null) {
sb.append("Database User, ");
error = true;
}
if (jdbcConfig.getDatabaseName() == null) {
sb.append("Database Name, ");
error = true;
}
if (error) {
sb.append(" is missing");
logger.debug("Connection Parameter errors::{}", sb.toString());
response.sendError(HttpStatus.SC_BAD_REQUEST, sb.toString());
}
if (logger.isDebugEnabled()) {
logger.debug("Connection Config:: {}", jdbcConfig.getConnectionName());
}
if (jdbcConfig.getDatabasePassword() != null) {
jdbcConfig.setDatabasePassword(DatabaseUtils.encrypt(jdbcConfig.getDatabasePassword()));
}
DatabaseUtils.editSavedConnections(jdbcConfig);
try {
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json");
writeSavedConnectionResponse(response);
} catch (Exception e) {
logger.error("Exception while loading settings {}", e);
}
}
use of com.google.refine.extension.database.DatabaseConfiguration in project OpenRefine by OpenRefine.
the class ExecuteQueryCommandTest method beforeTest.
@BeforeTest
@Parameters({ "mySqlDbName", "mySqlDbHost", "mySqlDbPort", "mySqlDbUser", "mySqlDbPassword", "mySqlTestTable" })
public void beforeTest(@Optional(DEFAULT_MYSQL_DB_NAME) String mySqlDbName, @Optional(DEFAULT_MYSQL_HOST) String mySqlDbHost, @Optional(DEFAULT_MYSQL_PORT) String mySqlDbPort, @Optional(DEFAULT_MYSQL_USER) String mySqlDbUser, @Optional(DEFAULT_MYSQL_PASSWORD) String mySqlDbPassword, @Optional(DEFAULT_TEST_TABLE) String mySqlTestTable) {
MockitoAnnotations.initMocks(this);
testDbConfig = new DatabaseConfiguration();
testDbConfig.setDatabaseHost(mySqlDbHost);
testDbConfig.setDatabaseName(mySqlDbName);
testDbConfig.setDatabasePassword(mySqlDbPassword);
testDbConfig.setDatabasePort(Integer.parseInt(mySqlDbPort));
testDbConfig.setDatabaseType(MySQLDatabaseService.DB_NAME);
testDbConfig.setDatabaseUser(mySqlDbUser);
testDbConfig.setUseSSL(false);
testTable = mySqlTestTable;
// DBExtensionTestUtils.initTestData(testDbConfig);
DatabaseService.DBType.registerDatabase(MySQLDatabaseService.DB_NAME, MySQLDatabaseService.getInstance());
}
use of com.google.refine.extension.database.DatabaseConfiguration in project OpenRefine by OpenRefine.
the class MariaDBDatabaseServiceTest method beforeTest.
@BeforeTest
@Parameters({ "mariadbDbName", "mariadbDbHost", "mariadbDbPort", "mariadbDbUser", "mariadbDbPassword", "mariadbTestTable" })
public void beforeTest(@Optional(DEFAULT_MARIADB_NAME) String mariaDbName, @Optional(DEFAULT_MARIADB_HOST) String mariaDbHost, @Optional(DEFAULT_MARIADB_PORT) String mariaDbPort, @Optional(DEFAULT_MARIADB_USER) String mariaDbUser, @Optional(DEFAULT_MARIADB_PASSWORD) String mariaDbPassword, @Optional(DEFAULT_TEST_TABLE) String mariaDbTestTable) {
MockitoAnnotations.initMocks(this);
testDbConfig = new DatabaseConfiguration();
testDbConfig.setDatabaseHost(mariaDbHost);
testDbConfig.setDatabaseName(mariaDbName);
testDbConfig.setDatabasePassword(mariaDbPassword);
testDbConfig.setDatabasePort(Integer.parseInt(mariaDbPort));
testDbConfig.setDatabaseType(MariaDBDatabaseService.DB_NAME);
testDbConfig.setDatabaseUser(mariaDbUser);
testDbConfig.setUseSSL(false);
testTable = mariaDbTestTable;
// DBExtensionTestUtils.initTestData(testDbConfig);
DatabaseService.DBType.registerDatabase(MariaDBDatabaseService.DB_NAME, MariaDBDatabaseService.getInstance());
}
use of com.google.refine.extension.database.DatabaseConfiguration in project OpenRefine by OpenRefine.
the class PgSQLDatabaseServiceTest method beforeTest.
@BeforeTest
@Parameters({ "pgSqlDbName", "pgSqlDbHost", "pgSqlDbPort", "pgSqlDbUser", "pgSqlDbPassword", "pgSqlTestTable" })
public void beforeTest(@Optional(DEFAULT_PGSQL_DB_NAME) String pgSqlDbName, @Optional(DEFAULT_PGSQL_HOST) String pgSqlDbHost, @Optional(DEFAULT_PGSQL_PORT) String pgSqlDbPort, @Optional(DEFAULT_PGSQL_USER) String pgSqlDbUser, @Optional(DEFAULT_PGSQL_PASSWORD) String pgSqlDbPassword, @Optional(DEFAULT_TEST_TABLE) String pgSqlTestTable) {
MockitoAnnotations.initMocks(this);
testDbConfig = new DatabaseConfiguration();
testDbConfig.setDatabaseHost(pgSqlDbHost);
testDbConfig.setDatabaseName(pgSqlDbName);
testDbConfig.setDatabasePassword(pgSqlDbPassword);
testDbConfig.setDatabasePort(Integer.parseInt(pgSqlDbPort));
testDbConfig.setDatabaseType(PgSQLDatabaseService.DB_NAME);
testDbConfig.setDatabaseUser(pgSqlDbUser);
testDbConfig.setUseSSL(false);
testTable = pgSqlTestTable;
// DBExtensionTestUtils.initTestData(testDbConfig);
DatabaseService.DBType.registerDatabase(PgSQLDatabaseService.DB_NAME, PgSQLDatabaseService.getInstance());
}
Aggregations