use of org.cerberus.dto.PropertyListDTO in project cerberus-source by cerberustesting.
the class TestCaseCountryPropertiesDAO method findTestCaseCountryPropertiesByValue1.
@Override
public AnswerList findTestCaseCountryPropertiesByValue1(int testDataLib, String name, String country, String propertyType) {
AnswerList ansList = new AnswerList();
MessageEvent rs;
List<TestListDTO> listOfTests = new ArrayList<TestListDTO>();
StringBuilder query = new StringBuilder();
query.append("select count(*) as total, tccp.property, t.Test, tc.TestCase, t.Description as testDescription, tc.Description as testCaseDescription, tc.Application, ");
query.append("tc.TcActive as Active, tc.`Group`, tc.UsrCreated, tc.`Status` ");
query.append("from testcasecountryproperties tccp ");
query.append("inner join test t on t.test = tccp.test ");
query.append("inner join testcase tc on t.test = tccp.test and t.test = tc.test ");
query.append("inner join testdatalib tdl on tdl.`name` = tccp.value1 and ");
query.append("(tccp.Country = tdl.Country or tdl.country='') and tccp.test = t.test and tccp.testcase = tc.testcase ");
query.append("where tccp.`Type` LIKE ? and tdl.TestDataLibID = ? ");
query.append("and tdl.`Name` LIKE ? and (tdl.Country = ? or tdl.country='') ");
query.append("group by tccp.test, tccp.testcase, tccp.property ");
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
preStat.setString(1, propertyType);
preStat.setInt(2, testDataLib);
preStat.setString(3, name);
preStat.setString(4, country);
HashMap<String, TestListDTO> map = new HashMap<String, TestListDTO>();
// the key is the test + ":" +testcasenumber
HashMap<String, List<PropertyListDTO>> auxiliaryMap = new HashMap<String, List<PropertyListDTO>>();
String key, test, testCase;
ResultSet resultSet = preStat.executeQuery();
try {
while (resultSet.next()) {
TestListDTO testList;
TestCaseListDTO testCaseDTO;
List<PropertyListDTO> propertiesList;
test = resultSet.getString("Test");
testCase = resultSet.getString("TestCase");
// gets the info from test cases that match the desired information
if (map.containsKey(test)) {
testList = map.get(test);
} else {
testList = new TestListDTO();
testList.setDescription(resultSet.getString("testDescription"));
testList.setTest(test);
}
// TESTCASE
key = test + ":" + testCase;
if (!auxiliaryMap.containsKey(key)) {
// means that we must associate a new test case with a test
testCaseDTO = new TestCaseListDTO();
testCaseDTO.setTestCaseDescription(resultSet.getString("testCaseDescription"));
testCaseDTO.setTestCaseNumber(testCase);
testCaseDTO.setApplication(resultSet.getString("Application"));
testCaseDTO.setCreator(resultSet.getString("tc.UsrCreated"));
testCaseDTO.setStatus(resultSet.getString("Status"));
testCaseDTO.setGroup(resultSet.getString("Group"));
testCaseDTO.setIsActive(resultSet.getString("Active"));
testList.getTestCaseList().add(testCaseDTO);
map.put(test, testList);
propertiesList = new ArrayList<PropertyListDTO>();
} else {
propertiesList = auxiliaryMap.get(key);
}
PropertyListDTO prop = new PropertyListDTO();
prop.setNrCountries(resultSet.getInt("total"));
prop.setPropertyName(resultSet.getString("property"));
propertiesList.add(prop);
// stores the information about the properties
auxiliaryMap.put(key, propertiesList);
}
// assigns the list of tests retrieved by the query to the list
listOfTests = new ArrayList<TestListDTO>(map.values());
// assigns the list of properties to the correct testcaselist
for (TestListDTO list : listOfTests) {
for (TestCaseListDTO cases : list.getTestCaseList()) {
cases.setPropertiesList(auxiliaryMap.get(list.getTest() + ":" + cases.getTestCaseNumber()));
}
}
if (listOfTests.isEmpty()) {
rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
} else {
rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
rs.setDescription(rs.getDescription().replace("%ITEM%", "List of Test Cases").replace("%OPERATION%", "Select"));
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
rs.setDescription(rs.getDescription().replace("%DESCRIPTION%", "Unable to get the list of test cases."));
} finally {
if (resultSet != null) {
resultSet.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
rs.setDescription(rs.getDescription().replace("%DESCRIPTION%", "Unable to get the list of test cases."));
} finally {
if (preStat != null) {
preStat.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
rs.setDescription(rs.getDescription().replace("%DESCRIPTION%", "Unable to get the list of test cases."));
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn(e.toString());
}
}
ansList.setResultMessage(rs);
ansList.setDataList(listOfTests);
return ansList;
}
Aggregations