use of org.cerberus.engine.entity.MessageEvent in project cerberus-source by cerberustesting.
the class TestCaseExecutionFileDAO method create.
@Override
public Answer create(TestCaseExecutionFile object) {
MessageEvent msg = null;
StringBuilder query = new StringBuilder();
query.append("INSERT INTO testcaseexecutionfile (`exeid`, `level`, `fileDesc`, `fileName`, `fileType`, `usrcreated`) ");
query.append("VALUES (?,?,?,?,?,?)");
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query.toString());
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
preStat.setLong(1, object.getExeId());
preStat.setString(2, object.getLevel());
preStat.setString(3, object.getFileDesc());
preStat.setString(4, object.getFileName());
preStat.setString(5, object.getFileType());
preStat.setString(6, object.getUsrCreated());
preStat.executeUpdate();
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT"));
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) {
// 23000 is the sql state for duplicate entries
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString()));
} else {
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.error("Unable to close connection : " + exception.toString());
}
}
return new Answer(msg);
}
use of org.cerberus.engine.entity.MessageEvent in project cerberus-source by cerberustesting.
the class TestCaseExecutionFileDAO method readByKey.
@Override
public AnswerItem<TestCaseExecutionFile> readByKey(long exeId, String level, String fileDesc) {
AnswerItem ans = new AnswerItem();
TestCaseExecutionFile result = null;
StringBuilder query = new StringBuilder("SELECT * FROM `testcaseexecutionfile` exf WHERE `exeid` = ? and `level` = ? ");
if (fileDesc != null) {
query.append("and `filedesc` = ? ");
}
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 : " + exeId);
LOG.debug("SQL.param.id : " + level);
LOG.debug("SQL.param.id : " + fileDesc);
}
try (Connection connection = this.databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(query.toString())) {
preStat.setLong(1, exeId);
preStat.setString(2, level);
if (fileDesc != null) {
preStat.setString(3, fileDesc);
}
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;
}
use of org.cerberus.engine.entity.MessageEvent in project cerberus-source by cerberustesting.
the class TestCaseExecutionFileDAO method update.
@Override
public Answer update(TestCaseExecutionFile object) {
MessageEvent msg = null;
final String query = "UPDATE testcaseexecutionfile SET exeid = ?, level = ?, `filedesc` = ?, `filename` = ?, filetype = ?, usrmodif = ?, datemodif = ? WHERE id = ?";
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setLong(1, object.getExeId());
preStat.setString(2, object.getLevel());
preStat.setString(3, object.getFileDesc());
preStat.setString(4, object.getFileName());
preStat.setString(5, object.getFileType());
preStat.setString(6, object.getUsrModif());
preStat.setTimestamp(7, object.getDateModif());
preStat.setLong(8, object.getId());
preStat.executeUpdate();
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));
} 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());
}
}
return new Answer(msg);
}
use of org.cerberus.engine.entity.MessageEvent 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.engine.entity.MessageEvent in project cerberus-source by cerberustesting.
the class TestCaseExecutionQueueDAO method updateToCancelled.
@Override
public Answer updateToCancelled(long id, String comment) {
MessageEvent msg = null;
String query = "UPDATE `" + TABLE + "` " + "SET `" + COLUMN_STATE + "` = 'CANCELLED', `" + COLUMN_REQUEST_DATE + "` = now(), `" + COLUMN_DATEMODIF + "` = now(), `" + COLUMN_COMMENT + "` = ? " + "WHERE `" + COLUMN_ID + "` = ? " + "AND `" + COLUMN_STATE + "` IN ('ERROR','QUEUED')";
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
LOG.debug("SQL.param.id : " + id);
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
int i = 1;
preStat.setString(i++, comment);
preStat.setLong(i++, id);
int updateResult = preStat.executeUpdate();
if (updateResult <= 0) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_NOUPDATE);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%DESCRIPTION%", "Unable to move state to CANCELLED for execution in queue " + id + " (update result: " + updateResult + "). Maybe execution is no longuer in ERROR or QUEUED ?"));
LOG.warn("Unable to move state to CANCELLED for execution in queue " + id + " (update result: " + updateResult + "). Maybe execution is no longuer in ERROR or QUEUED ?");
// throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));
}
} 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());
}
}
return new Answer(msg);
}
Aggregations