use of org.cerberus.engine.entity.MessageEvent in project cerberus-source by cerberustesting.
the class TestCaseExecutionDAO method findTagList.
@Override
public AnswerList findTagList(int tagnumber) {
AnswerList response = new AnswerList();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
List<String> list = null;
StringBuilder query = new StringBuilder();
query.append("SELECT DISTINCT exe.tag FROM testcaseexecution exe WHERE tag != ''");
if (tagnumber != 0) {
query.append("ORDER BY id desc LIMIT ");
query.append(tagnumber);
}
query.append(";");
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
ResultSet resultSet = preStat.executeQuery();
try {
list = new ArrayList<String>();
while (resultSet.next()) {
list.add(resultSet.getString("exe.tag"));
}
msg.setDescription(msg.getDescription().replace("%ITEM%", "TagList").replace("%OPERATION%", "SELECT"));
} 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!"));
} 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!"));
} 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!"));
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn(e.toString());
}
}
response.setResultMessage(msg);
response.setDataList(list);
return response;
}
use of org.cerberus.engine.entity.MessageEvent in project cerberus-source by cerberustesting.
the class TestCaseExecutionDAO method readDistinctValuesByCriteria.
@Override
public AnswerList<List<String>> readDistinctValuesByCriteria(String system, String test, String searchParameter, Map<String, List<String>> individualSearch, String columnName) {
AnswerList answer = new AnswerList();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
List<String> distinctValues = new ArrayList<>();
List<String> individalColumnSearchValues = new ArrayList<String>();
final StringBuffer query = new StringBuffer();
query.append("SELECT distinct ");
query.append(columnName);
query.append(" as distinctValues FROM testcaseexecution exe ");
query.append("where exe.`start`> '").append(DateUtil.getMySQLTimestampTodayDeltaMinutes(-360000)).append("' ");
if (!StringUtil.isNullOrEmpty(searchParameter)) {
query.append("and (exe.`id` like ? ");
query.append(" or exe.`test` like ? ");
query.append(" or exe.`testCase` like ? ");
query.append(" or exe.`build` like ? ");
query.append(" or exe.`revision` like ? ");
query.append(" or exe.`environment` like ? ");
query.append(" or exe.`country` like ? ");
query.append(" or exe.`browser` like ? ");
query.append(" or exe.`version` like ? ");
query.append(" or exe.`platform` like ? ");
query.append(" or exe.`browserfullversion` like ? ");
query.append(" or exe.`start` like ? ");
query.append(" or exe.`end` like ? ");
query.append(" or exe.`controlstatus` like ? ");
query.append(" or exe.`controlmessage` like ? ");
query.append(" or exe.`application` like ? ");
query.append(" or exe.`ip` like ? ");
query.append(" or exe.`url` like ? ");
query.append(" or exe.`port` like ? ");
query.append(" or exe.`tag` like ? ");
query.append(" or exe.`finished` like ? ");
query.append(" or exe.`status` like ? ");
query.append(" or exe.`crbversion` like ? ");
query.append(" or exe.`executor` like ? ");
query.append(" or exe.`screensize` like ? )");
}
if (individualSearch != null && !individualSearch.isEmpty()) {
query.append(" and ( 1=1 ");
for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {
query.append(" and ");
query.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));
individalColumnSearchValues.addAll(entry.getValue());
}
query.append(" ) ");
}
query.append(" order by ").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 (!Strings.isNullOrEmpty(searchParameter)) {
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
preStat.setString(i++, "%" + searchParameter + "%");
}
for (String individualColumnSearchValue : individalColumnSearchValues) {
preStat.setString(i++, individualColumnSearchValue);
}
try (ResultSet resultSet = preStat.executeQuery();
ResultSet rowSet = stm.executeQuery("SELECT FOUND_ROWS()")) {
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 exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.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.engine.entity.MessageEvent in project cerberus-source by cerberustesting.
the class TestCaseExecutionDataDAO method readLastCacheEntry.
@Override
public AnswerItem<TestCaseExecutionData> readLastCacheEntry(String system, String environment, String country, String property, int cacheExpire) {
AnswerItem ans = new AnswerItem();
TestCaseExecutionData result = null;
final String query = "select * from testcaseexecutiondata exd WHERE System=? and Environment=? and Country=? and FromCache='N' and Property=? and Start >= NOW()- INTERVAL ? SECOND and `index`=1 and jsonResult is not null and RC = 'OK' order by id desc;";
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
LOG.debug("SQL.param.system : " + system);
LOG.debug("SQL.param.property : " + property);
LOG.debug("SQL.param.cacheExpire : " + String.valueOf(cacheExpire));
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
int i = 1;
preStat.setString(i++, system);
preStat.setString(i++, environment);
preStat.setString(i++, country);
preStat.setString(i++, property);
preStat.setInt(i++, cacheExpire);
ResultSet resultSet = preStat.executeQuery();
try {
if (resultSet.first()) {
result = loadFromResultSet(resultSet);
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
ans.setItem(result);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
}
} 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%", exception.toString()));
} 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%", exception.toString()));
} 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%", exception.toString()));
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
// sets the message
ans.setResultMessage(msg);
return ans;
}
use of org.cerberus.engine.entity.MessageEvent in project cerberus-source by cerberustesting.
the class TestCaseExecutionDataDAO method readByKey.
@Override
public AnswerItem<TestCaseExecutionData> readByKey(long id, String property, int index) {
AnswerItem ans = new AnswerItem();
TestCaseExecutionData result = null;
final String query = "SELECT * FROM testcaseexecutiondata exd WHERE id = ? AND property = ? AND `index` = ?";
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
LOG.debug("SQL.param.id : " + String.valueOf(id));
LOG.debug("SQL.param.property : " + property);
LOG.debug("SQL.param.index : " + String.valueOf(index));
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setLong(1, id);
preStat.setString(2, property);
preStat.setInt(3, index);
ResultSet resultSet = preStat.executeQuery();
try {
if (resultSet.first()) {
result = loadFromResultSet(resultSet);
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
ans.setItem(result);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
}
} 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%", exception.toString()));
} 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%", exception.toString()));
} 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%", exception.toString()));
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
// sets the message
ans.setResultMessage(msg);
return ans;
}
use of org.cerberus.engine.entity.MessageEvent in project cerberus-source by cerberustesting.
the class TestCaseExecutionFileDAO method readByKey.
@Override
public AnswerItem<TestCaseExecutionFile> readByKey(long id) {
AnswerItem ans = new AnswerItem();
TestCaseExecutionFile result = null;
final String query = "SELECT * FROM `testcaseexecutionfile` exf WHERE `id` = ?";
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
LOG.debug("SQL.param.id : " + id);
}
try (Connection connection = this.databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(query)) {
preStat.setLong(1, id);
try (ResultSet resultSet = preStat.executeQuery()) {
if (resultSet.first()) {
result = loadFromResultSet(resultSet);
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
ans.setItem(result);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
}
} 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%", exception.toString()));
}
} 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%", exception.toString()));
}
// sets the message
ans.setResultMessage(msg);
return ans;
}
Aggregations