use of org.cerberus.crud.entity.TestCaseLabel in project cerberus-source by cerberustesting.
the class FactoryTestCaseLabel method create.
@Override
public TestCaseLabel create(Integer id, String test, String testCase, Integer labelId, String usrCreated, Timestamp dateCreated, String usrModif, Timestamp dateModif, Label label) {
TestCaseLabel testCaseLabel = new TestCaseLabel();
testCaseLabel.setDateCreated(dateCreated);
testCaseLabel.setDateModif(dateModif);
testCaseLabel.setId(id);
testCaseLabel.setLabelId(labelId);
testCaseLabel.setTest(test);
testCaseLabel.setTestcase(testCase);
testCaseLabel.setUsrCreated(usrCreated);
testCaseLabel.setUsrModif(usrModif);
testCaseLabel.setLabel(label);
return testCaseLabel;
}
use of org.cerberus.crud.entity.TestCaseLabel in project cerberus-source by cerberustesting.
the class TestCaseLabelDAO method readByKeyTech.
@Override
public AnswerItem<TestCaseLabel> readByKeyTech(Integer id) {
AnswerItem<TestCaseLabel> ans = new AnswerItem();
TestCaseLabel result = null;
final String query = "SELECT * FROM `testcaselabel` tel 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.label : " + id);
}
try (Connection connection = databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(query)) {
// prepare and execute query
preStat.setInt(1, id);
try (ResultSet resultSet = preStat.executeQuery()) {
// parse query
if (resultSet.first()) {
result = loadFromResultSet(resultSet, null);
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 (Exception e) {
LOG.warn("Unable to readByKey TestCaseLabel: " + e.getMessage());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
} finally {
ans.setResultMessage(msg);
}
return ans;
}
use of org.cerberus.crud.entity.TestCaseLabel in project cerberus-source by cerberustesting.
the class TestCaseLabelDAO method readByTestTestCase.
@Override
public AnswerList readByTestTestCase(String test, String testCase) {
AnswerList response = new AnswerList();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
List<TestCaseLabel> objectList = new ArrayList<>();
StringBuilder query = new StringBuilder();
// SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that
// were applied -- used for pagination p
query.append("SELECT SQL_CALC_FOUND_ROWS * FROM testcaselabel tel ");
query.append(" LEFT OUTER JOIN label lab on lab.id = tel.labelId ");
query.append(" WHERE 1=1");
if (!Strings.isNullOrEmpty(test)) {
query.append(" AND tel.test = ?");
}
if (testCase != null) {
query.append(" AND tel.testcase = ?");
}
// 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(test)) {
preStat.setString(i++, test);
}
if (testCase != null) {
preStat.setString(i++, testCase);
}
try (ResultSet resultSet = preStat.executeQuery();
ResultSet rowSet = stm.executeQuery("SELECT FOUND_ROWS()")) {
// gets the data
while (resultSet.next()) {
Label label = labelDAO.loadFromResultSet(resultSet);
TestCaseLabel tcl = this.loadFromResultSet(resultSet, label);
objectList.add(tcl);
}
// get the total number of rows
int nrTotalRows = 0;
if (rowSet != null && rowSet.next()) {
nrTotalRows = rowSet.getInt(1);
}
if (objectList.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));
response = new AnswerList(objectList, nrTotalRows);
} else if (objectList.size() <= 0) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
response = new AnswerList(objectList, nrTotalRows);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
response = new AnswerList(objectList, nrTotalRows);
}
response.setDataList(objectList);
} 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 readByTestTestCase TestCaseLabel: " + e.getMessage());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
} finally {
response.setResultMessage(msg);
}
return response;
}
Aggregations