use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.
the class TestCaseExecutionQueueDAO method readByVarious1.
@Override
public AnswerList readByVarious1(String tag, List<String> stateList, boolean withDependencies) throws CerberusException {
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
AnswerList answer = new AnswerList();
final StringBuilder query = new StringBuilder();
query.append("SELECT * FROM testcaseexecutionqueue exq ");
if (withDependencies) {
query.append("left join testcase tec on exq.Test = tec.Test and exq.TestCase = tec.TestCase ");
query.append("left join application app on tec.application = app.application ");
}
query.append("where exq.tag = ? ");
query.append(SqlUtil.createWhereInClause(" AND exq.state", stateList, true));
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query.toString());
LOG.debug("SQL.param.tag : " + tag);
}
List<TestCaseExecutionQueue> testCaseExecutionInQueueList = new ArrayList<TestCaseExecutionQueue>();
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
preStat.setString(1, tag);
try {
ResultSet resultSet = preStat.executeQuery();
try {
while (resultSet.next()) {
if (withDependencies) {
testCaseExecutionInQueueList.add(this.loadWithDependenciesFromResultSet(resultSet));
} else {
testCaseExecutionInQueueList.add(this.loadFromResultSet(resultSet));
}
}
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecutionInQueue").replace("%OPERATION%", "SELECT"));
answer = new AnswerList(testCaseExecutionInQueueList, testCaseExecutionInQueueList.size());
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
testCaseExecutionInQueueList = null;
} catch (FactoryCreationException ex) {
LOG.error("Unable to execute query : " + ex.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
} finally {
resultSet.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
testCaseExecutionInQueueList = null;
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
testCaseExecutionInQueueList = null;
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn(e.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
}
}
answer.setResultMessage(msg);
return answer;
}
use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.
the class TestCaseExecutionQueueDAO method readDistinctValuesByCriteria.
@Override
public AnswerList readDistinctValuesByCriteria(String columnName, String sort, String searchTerm, Map<String, List<String>> individualSearch, String column) {
AnswerList answer = new AnswerList();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
List<String> distinctValues = new ArrayList<>();
StringBuilder searchSQL = new StringBuilder();
List<String> individalColumnSearchValues = new ArrayList<String>();
StringBuilder query = new StringBuilder();
query.append("SELECT distinct exq.");
query.append(columnName);
query.append(" as distinctValues FROM testcaseexecutionqueue exq");
query.append(" where 1=1");
if (!StringUtil.isNullOrEmpty(searchTerm)) {
searchSQL.append(" and (exq.ID like ?");
searchSQL.append(" or exq.Test like ?");
searchSQL.append(" or exq.TestCase like ?");
searchSQL.append(" or exq.Country like ?");
searchSQL.append(" or exq.Environment like ?");
searchSQL.append(" or exq.Browser like ?");
searchSQL.append(" or exq.Tag like ?");
searchSQL.append(" or exq.State like ?)");
}
if (individualSearch != null && !individualSearch.isEmpty()) {
searchSQL.append(" and ( 1=1 ");
for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {
searchSQL.append(" and exq.");
searchSQL.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));
individalColumnSearchValues.addAll(entry.getValue());
}
searchSQL.append(" )");
}
query.append(searchSQL);
query.append(" group by ifnull(exq.").append(columnName).append(",'')");
query.append(" order by exq.").append(columnName).append(" asc");
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query.toString());
}
try (Connection connection = databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(query.toString());
Statement stm = connection.createStatement()) {
int i = 1;
if (!StringUtil.isNullOrEmpty(searchTerm)) {
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
}
for (String individualColumnSearchValue : individalColumnSearchValues) {
preStat.setString(i++, individualColumnSearchValue);
}
try (ResultSet resultSet = preStat.executeQuery();
ResultSet rowSet = stm.executeQuery("SELECT FOUND_ROWS()")) {
// gets the data
while (resultSet.next()) {
distinctValues.add(resultSet.getString("distinctValues") == null ? "" : resultSet.getString("distinctValues"));
}
// get the total number of rows
int nrTotalRows = 0;
if (rowSet != null && rowSet.next()) {
nrTotalRows = rowSet.getInt(1);
}
if (distinctValues.size() >= MAX_ROW_SELECTED) {
// Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList.
LOG.error("Partial Result in the query.");
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));
answer = new AnswerList(distinctValues, nrTotalRows);
} else if (distinctValues.size() <= 0) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
answer = new AnswerList(distinctValues, nrTotalRows);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
answer = new AnswerList(distinctValues, nrTotalRows);
}
} catch (SQLException e) {
LOG.warn("Unable to execute query : " + e.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
}
} catch (Exception e) {
LOG.warn("Unable to execute query : " + e.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
} finally {
// We always set the result message
answer.setResultMessage(msg);
}
answer.setResultMessage(msg);
answer.setDataList(distinctValues);
return answer;
}
use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.
the class TestCaseExecutionQueueDAO method readDistinctEnvCountryBrowserByTag.
@Override
public AnswerList readDistinctEnvCountryBrowserByTag(String tag) {
AnswerList answer = new AnswerList();
StringBuilder query = new StringBuilder();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
query.append("SELECT exq.* FROM testcaseexecutionqueue exq WHERE tag = ? GROUP BY Environment, Country, Browser");
Connection connection = this.databaseSpring.connect();
List<TestCaseExecutionQueue> EnvCountryBrowserList = new ArrayList<TestCaseExecutionQueue>();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
preStat.setString(1, tag);
try {
ResultSet resultSet = preStat.executeQuery();
try {
while (resultSet.next()) {
EnvCountryBrowserList.add(this.loadFromResultSet(resultSet));
}
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecutionInQueue").replace("%OPERATION%", "SELECT"));
answer = new AnswerList(EnvCountryBrowserList, EnvCountryBrowserList.size());
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
EnvCountryBrowserList = null;
} catch (FactoryCreationException ex) {
LOG.warn("Unable to execute query : " + ex.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
EnvCountryBrowserList = null;
} finally {
if (resultSet != null) {
resultSet.close();
}
}
} catch (SQLException ex) {
LOG.warn("Unable to execute query : " + ex.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
EnvCountryBrowserList = null;
} finally {
if (preStat != null) {
preStat.close();
}
}
} catch (SQLException ex) {
LOG.warn(ex.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
LOG.warn("Unable to execute query : " + ex.toString());
}
}
answer.setResultMessage(msg);
return answer;
}
use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.
the class TestCaseExecutionQueueDAO method readByVarious2.
@Override
public AnswerList readByVarious2(List<String> stateList) throws CerberusException {
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
AnswerList answer = new AnswerList();
final StringBuilder query = new StringBuilder();
query.append("SELECT exq.id, exq.manualexecution, app.System, cea.environment, cea.country, cea.application, cea.poolsize, exq.robotIP, rbt.host, exq.DebugFlag, app.type ");
query.append("from testcaseexecutionqueue exq ");
query.append("left join testcase tec on tec.test=exq.test and tec.testcase=exq.testcase ");
query.append("left join application app on app.application=tec.application ");
query.append("left join robot rbt on rbt.robot=exq.robot ");
query.append("left join countryenvironmentparameters cea on cea.system=app.system and cea.environment=exq.environment and cea.country=exq.country and cea.application=tec.application ");
query.append("WHERE 1=1 ");
query.append(SqlUtil.createWhereInClause(" AND exq.state", stateList, true));
query.append("order by exq.priority, exq.id asc;");
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query.toString());
}
List<TestCaseExecutionQueueToTreat> testCaseExecutionInQueueList = new ArrayList<TestCaseExecutionQueueToTreat>();
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
ResultSet resultSet = preStat.executeQuery();
try {
while (resultSet.next()) {
testCaseExecutionInQueueList.add(loadQueueToTreatFromResultSet(resultSet));
}
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecutionInQueue").replace("%OPERATION%", "SELECT"));
answer = new AnswerList(testCaseExecutionInQueueList, testCaseExecutionInQueueList.size());
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
testCaseExecutionInQueueList = null;
} finally {
resultSet.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
testCaseExecutionInQueueList = null;
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
testCaseExecutionInQueueList = null;
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn(e.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
}
}
answer.setResultMessage(msg);
return answer;
}
use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.
the class TestCaseExecutionQueueDAO method readDistinctColumnByTag.
@Override
public AnswerList readDistinctColumnByTag(String tag, boolean env, boolean country, boolean browser, boolean app) {
AnswerList answer = new AnswerList();
StringBuilder query = new StringBuilder();
StringBuilder distinct = new StringBuilder();
int prev = 0;
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
if (!(!env && !country && !app && !browser)) {
if (env) {
distinct.append("exq.Environment");
prev++;
}
if (country) {
if (prev != 0) {
prev = 0;
distinct.append(",");
}
distinct.append("exq.Country");
prev++;
}
if (browser) {
if (prev != 0) {
prev = 0;
distinct.append(",");
}
distinct.append("exq.Browser");
prev++;
}
if (app) {
if (prev != 0) {
prev = 0;
distinct.append(",");
}
distinct.append("tec.Application");
}
query.append("SELECT tec.test, tec.testcase, exq.tag, ");
query.append(distinct.toString());
query.append(" FROM testcase tec LEFT JOIN testcaseexecutionqueue exq ON exq.Test = tec.Test AND exq.TestCase = tec.TestCase WHERE tag = ? GROUP BY ");
query.append(distinct.toString());
} else {
// If there is no distinct, select nothing
query.append("SELECT * FROM testcaseexecutionqueue exq WHERE 1=0 AND tag = ?");
}
Connection connection = this.databaseSpring.connect();
List<TestCaseExecutionQueue> column = new ArrayList<TestCaseExecutionQueue>();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
preStat.setString(1, tag);
try {
ResultSet resultSet = preStat.executeQuery();
try {
while (resultSet.next()) {
TestCaseExecutionQueue tmp = new TestCaseExecutionQueue();
tmp.setTest(resultSet.getString("tec.test"));
tmp.setTestCase(resultSet.getString("tec.testcase"));
tmp.setTag(resultSet.getString("exq.tag"));
if (env) {
tmp.setEnvironment(resultSet.getString("Environment"));
} else {
tmp.setEnvironment("");
}
if (country) {
tmp.setCountry(resultSet.getString("Country"));
} else {
tmp.setCountry("");
}
if (browser) {
tmp.setBrowser(resultSet.getString("Browser"));
} else {
tmp.setBrowser("");
}
if (app) {
Application application = factoryApplication.create(resultSet.getString("Application"));
tmp.setApplicationObj(application);
}
column.add(tmp);
}
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));
answer = new AnswerList(column, column.size());
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
column = null;
} finally {
if (resultSet != null) {
resultSet.close();
}
}
} catch (SQLException ex) {
LOG.warn("Unable to execute query : " + ex.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
column = null;
} finally {
if (preStat != null) {
preStat.close();
}
}
} catch (SQLException ex) {
LOG.warn(ex.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
LOG.warn("Unable to execute query : " + ex.toString());
}
}
answer.setResultMessage(msg);
return answer;
}
Aggregations