use of com.google.refine.extension.database.DatabaseConfiguration in project OpenRefine by OpenRefine.
the class PgSQLConnectionManagerTest 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 = mySqlTestTable;
// DBExtensionTestUtils.initTestData(testDbConfig);
DatabaseService.DBType.registerDatabase(PgSQLDatabaseService.DB_NAME, PgSQLDatabaseService.getInstance());
}
use of com.google.refine.extension.database.DatabaseConfiguration in project OpenRefine by OpenRefine.
the class TestQueryCommand method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (!hasValidCSRFToken(request)) {
respondCSRFError(response);
return;
}
DatabaseConfiguration dbConfig = getJdbcConfiguration(request);
String query = request.getParameter("query");
if (logger.isDebugEnabled()) {
logger.debug("TestQueryCommand::Post::DatabaseConfiguration::{}::Query::{} ", dbConfig, query);
}
// ProjectManager.singleton.setBusy(true);
try {
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json");
Writer w = response.getWriter();
JsonGenerator writer = ParsingUtilities.mapper.getFactory().createGenerator(w);
try {
DatabaseInfo databaseInfo = DatabaseService.get(dbConfig.getDatabaseType()).testQuery(dbConfig, query);
ObjectMapper mapperObj = new ObjectMapper();
response.setStatus(HttpStatus.SC_OK);
String jsonStr = mapperObj.writeValueAsString(databaseInfo);
if (logger.isDebugEnabled()) {
logger.debug("TestQueryCommand::Post::Result::{} ", jsonStr);
}
writer.writeStartObject();
writer.writeStringField("code", "ok");
writer.writeStringField("QueryResult", jsonStr);
writer.writeEndObject();
} catch (DatabaseServiceException e) {
logger.error("TestQueryCommand::Post::DatabaseServiceException::{}", e);
sendError(HttpStatus.SC_BAD_REQUEST, response, e);
} catch (Exception e) {
logger.error("TestQueryCommand::Post::Exception::{}", e);
sendError(HttpStatus.SC_BAD_REQUEST, response, e);
} finally {
writer.flush();
writer.close();
w.close();
}
} catch (Exception e) {
logger.error("TestQueryCommand::Post::Exception::{}", e);
throw new ServletException(e);
}
// finally {
// // ProjectManager.singleton.setBusy(false);
// }
}
use of com.google.refine.extension.database.DatabaseConfiguration in project OpenRefine by OpenRefine.
the class ConnectCommand method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (!hasValidCSRFToken(request)) {
respondCSRFError(response);
return;
}
DatabaseConfiguration databaseConfiguration = getJdbcConfiguration(request);
if (logger.isDebugEnabled()) {
logger.debug("ConnectCommand::Post::{}", databaseConfiguration);
}
// ProjectManager.singleton.setBusy(true);
try {
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json");
Writer w = response.getWriter();
JsonGenerator writer = ParsingUtilities.mapper.getFactory().createGenerator(w);
ObjectMapper mapperObj = new ObjectMapper();
try {
DatabaseInfo databaseInfo = DatabaseService.get(databaseConfiguration.getDatabaseType()).connect(databaseConfiguration);
String databaseInfoString = mapperObj.writeValueAsString(databaseInfo);
response.setStatus(HttpStatus.SC_OK);
writer.writeStartObject();
writer.writeStringField("code", "ok");
writer.writeStringField("databaseInfo", databaseInfoString);
writer.writeEndObject();
} catch (DatabaseServiceException e) {
logger.error("ConnectCommand::Post::DatabaseServiceException::{}", e);
sendError(HttpStatus.SC_UNAUTHORIZED, response, e);
} catch (Exception e) {
logger.error("ConnectCommand::Post::Exception::{}", e);
sendError(HttpStatus.SC_UNAUTHORIZED, response, e);
} finally {
writer.flush();
writer.close();
w.close();
}
} catch (Exception e) {
logger.error("ConnectCommand::Post::Exception::{}", e);
throw new ServletException(e);
}
// finally {
// // ProjectManager.singleton.setBusy(false);
// }
}
use of com.google.refine.extension.database.DatabaseConfiguration in project OpenRefine by OpenRefine.
the class ExecuteQueryCommand method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (!hasValidCSRFToken(request)) {
respondCSRFError(response);
return;
}
DatabaseConfiguration databaseConfiguration = getJdbcConfiguration(request);
String query = request.getParameter("queryString");
if (logger.isDebugEnabled()) {
logger.debug("QueryCommand::Post::DatabaseConfiguration::{}::Query::{} ", databaseConfiguration, query);
}
// ProjectManager.singleton.setBusy(true);
try {
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json");
Writer w = response.getWriter();
JsonGenerator writer = ParsingUtilities.mapper.getFactory().createGenerator(w);
try {
DatabaseInfo databaseInfo = DatabaseService.get(databaseConfiguration.getDatabaseType()).executeQuery(databaseConfiguration, query);
ObjectMapper mapperObj = new ObjectMapper();
response.setStatus(HttpStatus.SC_OK);
String jsonStr = mapperObj.writeValueAsString(databaseInfo);
if (logger.isDebugEnabled()) {
logger.debug("QueryCommand::Post::Result::{} ", jsonStr);
}
writer.writeStartObject();
writer.writeStringField("code", "ok");
writer.writeStringField("QueryResult", jsonStr);
writer.writeEndObject();
} catch (DatabaseServiceException e) {
logger.error("QueryCommand::Post::DatabaseServiceException::{}", e);
sendError(HttpStatus.SC_BAD_REQUEST, response, e);
} catch (Exception e) {
logger.error("QueryCommand::Post::Exception::{}", e);
sendError(HttpStatus.SC_BAD_REQUEST, response, e);
} finally {
writer.flush();
writer.close();
w.close();
}
} catch (Exception e) {
logger.error("QueryCommand::Post::Exception::{}", e);
throw new ServletException(e);
}
// finally {
// // ProjectManager.singleton.setBusy(false);
// }
}
use of com.google.refine.extension.database.DatabaseConfiguration in project OpenRefine by OpenRefine.
the class SavedConnectionCommand method doDelete.
@Override
public void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (logger.isDebugEnabled()) {
logger.debug("SavedConnectionCommand::Delete Connection: {}", request.getParameter("connectionName"));
}
String connectionName = request.getParameter("connectionName");
DatabaseConfiguration savedConn = DatabaseUtils.getSavedConnection(connectionName);
if (savedConn == null) {
// logger.error("Connection With name:: {} does not exist!", request.getParameter("connectionName"));
response.sendError(HttpStatus.SC_BAD_REQUEST, "Connection with name " + connectionName + " does not exists!");
response.flushBuffer();
return;
}
try {
DatabaseUtils.deleteSavedConnections(connectionName);
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json");
writeSavedConnectionResponse(response);
} catch (Exception e) {
logger.error("Exception while Deleting Connection with name: {}, error:{}", connectionName, e);
}
}
Aggregations