use of org.cerberus.crud.entity.TestCaseCountry in project cerberus-source by cerberustesting.
the class ReadTestCase method findTestCaseByTest.
// </editor-fold>
private AnswerItem findTestCaseByTest(String system, String test, ApplicationContext appContext, HttpServletRequest request) throws JSONException {
AnswerItem answer = new AnswerItem();
JSONObject object = new JSONObject();
testCaseService = appContext.getBean(ITestCaseService.class);
testCaseCountryService = appContext.getBean(ITestCaseCountryService.class);
testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);
int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));
int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));
String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");
String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "tec.test,tec.testcase,tec.application,project,ticket,description,behaviororvalueexpected,readonly,bugtrackernewurl,deploytype,mavengroupid");
String[] columnToSort = sColumns.split(",");
List<String> individualLike = new ArrayList(Arrays.asList(ParameterParserUtil.parseStringParam(request.getParameter("sLike"), "").split(",")));
// Get Sorting information
int numberOfColumnToSort = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortingCols"), "1"));
int columnToSortParameter = 0;
String sort = "asc";
StringBuilder sortInformation = new StringBuilder();
for (int c = 0; c < numberOfColumnToSort; c++) {
columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_" + c), "0"));
sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_" + c), "asc");
String columnName = columnToSort[columnToSortParameter];
sortInformation.append(columnName).append(" ").append(sort);
if (c != numberOfColumnToSort - 1) {
sortInformation.append(" , ");
}
}
Map<String, List<String>> individualSearch = new HashMap<String, List<String>>();
for (int a = 0; a < columnToSort.length; a++) {
if (null != request.getParameter("sSearch_" + a) && !request.getParameter("sSearch_" + a).isEmpty()) {
List<String> search = new ArrayList(Arrays.asList(request.getParameter("sSearch_" + a).split(",")));
if (individualLike.contains(columnToSort[a])) {
individualSearch.put(columnToSort[a] + ":like", search);
} else {
individualSearch.put(columnToSort[a], search);
}
}
}
AnswerList testCaseList = testCaseService.readByTestByCriteria(system, test, startPosition, length, sortInformation.toString(), searchParameter, individualSearch);
AnswerList testCaseCountryList = testCaseCountryService.readByTestTestCase(system, test, null);
/**
* Find the list of labels
*/
AnswerList testCaseLabelList = testCaseLabelService.readByTestTestCase(test, null);
LinkedHashMap<String, JSONObject> testCaseWithCountry = new LinkedHashMap();
for (TestCaseCountry country : (List<TestCaseCountry>) testCaseCountryList.getDataList()) {
String key = country.getTest() + "_" + country.getTestCase();
if (testCaseWithCountry.containsKey(key)) {
testCaseWithCountry.get(key).put(country.getCountry(), country.getCountry());
} else {
testCaseWithCountry.put(key, new JSONObject().put(country.getCountry(), country.getCountry()));
}
}
/**
* Iterate on the label retrieved and generate HashMap based on the key
* Test_TestCase
*/
LinkedHashMap<String, JSONArray> testCaseWithLabel = new LinkedHashMap();
for (TestCaseLabel label : (List<TestCaseLabel>) testCaseLabelList.getDataList()) {
String key = label.getTest() + "_" + label.getTestcase();
if (testCaseWithLabel.containsKey(key)) {
JSONObject jo = new JSONObject().put("name", label.getLabel().getLabel()).put("color", label.getLabel().getColor()).put("description", label.getLabel().getDescription());
testCaseWithLabel.get(key).put(jo);
} else {
JSONObject jo = new JSONObject().put("name", label.getLabel().getLabel()).put("color", label.getLabel().getColor()).put("description", label.getLabel().getDescription());
testCaseWithLabel.put(key, new JSONArray().put(jo));
}
}
JSONArray jsonArray = new JSONArray();
if (testCaseList.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
// the service was able to perform the query, then we should get all values
for (TestCase testCase : (List<TestCase>) testCaseList.getDataList()) {
String key = testCase.getTest() + "_" + testCase.getTestCase();
JSONObject value = convertToJSONObject(testCase);
value.put("hasPermissionsDelete", testCaseService.hasPermissionsDelete(testCase, request));
value.put("hasPermissionsUpdate", testCaseService.hasPermissionsUpdate(testCase, request));
value.put("hasPermissionsCreate", testCaseService.hasPermissionsCreate(testCase, request));
value.put("countryList", testCaseWithCountry.get(key));
value.put("labels", testCaseWithLabel.get(key));
jsonArray.put(value);
}
}
// object.put("hasPermissions", testCaseService.hasPermissions(request));
object.put("hasPermissionsCreate", testCaseService.hasPermissionsCreate(null, request));
object.put("contentTable", jsonArray);
object.put("iTotalRecords", testCaseList.getTotalRows());
object.put("iTotalDisplayRecords", testCaseList.getTotalRows());
answer.setItem(object);
answer.setResultMessage(testCaseList.getResultMessage());
return answer;
}
use of org.cerberus.crud.entity.TestCaseCountry in project cerberus-source by cerberustesting.
the class DuplicateTestCase method getCountryList.
private List<TestCaseCountry> getCountryList(String targetTest, String targetTestCase, HttpServletRequest request) throws CerberusException, JSONException, UnsupportedEncodingException {
List<TestCaseCountry> countryList = new ArrayList();
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IInvariantService invariantService = appContext.getBean(InvariantService.class);
IFactoryTestCaseCountry testCaseCountryFactory = appContext.getBean(IFactoryTestCaseCountry.class);
// TODO: handle if the response does not turn ok
AnswerList answer = invariantService.readByIdname("COUNTRY");
for (Invariant country : (List<Invariant>) answer.getDataList()) {
String countrySelected = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter(country.getValue()), "");
if ("".equals(countrySelected)) {
countryList.add(testCaseCountryFactory.create(targetTest, targetTestCase, country.getValue()));
}
}
return countryList;
}
use of org.cerberus.crud.entity.TestCaseCountry in project cerberus-source by cerberustesting.
the class TestCaseCountryDAO method readByVarious1.
@Override
public AnswerList readByVarious1(String system, String test, String testCase) {
AnswerList answer = new AnswerList();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
List<TestCaseCountry> testCaseCountryList = new ArrayList<TestCaseCountry>();
StringBuilder query = new StringBuilder();
query.append("SELECT * FROM testcasecountry tcc ");
if (!Strings.isNullOrEmpty(system)) {
query.append(" LEFT OUTER JOIN testcase tc on tc.test = tcc.test and tc.testcase = tcc.testcase ");
query.append(" LEFT OUTER JOIN application app on app.application = tc.application ");
}
query.append(" WHERE 1=1");
if (!Strings.isNullOrEmpty(system)) {
query.append(" AND app.`system` = ?");
}
if (!Strings.isNullOrEmpty(test)) {
query.append(" AND tcc.test = ?");
}
if (testCase != null) {
query.append(" AND tcc.testcase = ?");
}
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
LOG.debug("SQL.param.test : " + test);
LOG.debug("SQL.param.testCase : " + testCase);
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
int i = 1;
if (!Strings.isNullOrEmpty(system)) {
preStat.setString(i++, system);
}
if (!Strings.isNullOrEmpty(test)) {
preStat.setString(i++, test);
}
if (testCase != null) {
preStat.setString(i++, testCase);
}
ResultSet resultSet = preStat.executeQuery();
try {
// gets the data
while (resultSet.next()) {
testCaseCountryList.add(this.loadFromResultSet(resultSet));
}
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
answer = new AnswerList(testCaseCountryList, testCaseCountryList.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!"));
} finally {
if (resultSet != null) {
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 {
if (preStat != null) {
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 (!this.databaseSpring.isOnTransaction()) {
if (connection != null) {
connection.close();
}
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
answer.setResultMessage(msg);
return answer;
}
use of org.cerberus.crud.entity.TestCaseCountry in project cerberus-source by cerberustesting.
the class TestCaseCountryDAO method findTestCaseCountryByKey.
@Override
public TestCaseCountry findTestCaseCountryByKey(String test, String testCase, String country) throws CerberusException {
final String query = "SELECT * FROM testcasecountry tcc WHERE test = ? AND testcase = ? AND country = ? ";
TestCaseCountry result = null;
boolean throwException = false;
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setString(1, test);
preStat.setString(2, testCase);
preStat.setString(3, country);
ResultSet resultSet = preStat.executeQuery();
try {
if (resultSet.first()) {
result = factoryTestCaseCountry.create(test, testCase, country);
} else {
throwException = true;
}
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
} finally {
resultSet.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn(e.toString());
}
}
if (throwException) {
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
}
return result;
}
use of org.cerberus.crud.entity.TestCaseCountry in project cerberus-source by cerberustesting.
the class TestCaseCountryDAO method readByKey.
@Override
public AnswerItem readByKey(String test, String testCase, String country) {
AnswerItem answer = new AnswerItem();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
TestCaseCountry result = new TestCaseCountry();
final String query = "SELECT * FROM testcasecountry tcc WHERE test = ? AND testcase = ? AND country = ?";
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setString(1, test);
preStat.setString(2, testCase);
preStat.setString(3, country);
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"));
answer.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%", "Unable to retrieve the entry!"));
} finally {
if (preStat != null) {
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 (!this.databaseSpring.isOnTransaction()) {
if (connection != null) {
connection.close();
}
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
answer.setResultMessage(msg);
return answer;
}
Aggregations