use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.
the class ReadTestCaseExecutionByTag method getCountryList.
private JSONObject getCountryList(HttpServletRequest request, ApplicationContext appContext) {
JSONObject countryList = new JSONObject();
try {
IInvariantService invariantService = appContext.getBean(InvariantService.class);
// TODO: handle if the response does not turn ok
AnswerList answer = invariantService.readByIdname("COUNTRY");
for (Invariant country : (List<Invariant>) answer.getDataList()) {
countryList.put(country.getValue(), ParameterParserUtil.parseStringParam(request.getParameter(country.getValue()), "off"));
}
} catch (JSONException ex) {
LOG.error("Error on getCountryList : " + ex);
}
return countryList;
}
use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.
the class ReadTestCaseExecutionByTag method generateLabelStats.
private JSONObject generateLabelStats(ApplicationContext appContext, HttpServletRequest request, List<TestCaseExecution> testCaseExecutions, JSONObject statusFilter, JSONObject countryFilter) throws JSONException {
JSONObject jsonResult = new JSONObject();
boolean stickers = request.getParameter("stickers") != null;
boolean requirement = request.getParameter("requirement") != null;
if (stickers || requirement) {
testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);
AnswerList testCaseLabelList = testCaseLabelService.readByTestTestCase(null, null);
SummaryStatisticsDTO total = new SummaryStatisticsDTO();
total.setEnvironment("Total");
/**
* 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()) {
if ((Label.TYPE_STICKER.equals(label.getLabel().getType()) && stickers) || (Label.TYPE_REQUIREMENT.equals(label.getLabel().getType()) && requirement)) {
String key = label.getTest() + "_" + label.getTestcase();
JSONObject jo = new JSONObject().put("name", label.getLabel().getLabel()).put("color", label.getLabel().getColor()).put("description", label.getLabel().getDescription());
if (testCaseWithLabel.containsKey(key)) {
testCaseWithLabel.get(key).put(jo);
} else {
testCaseWithLabel.put(key, new JSONArray().put(jo));
}
}
}
/**
* For All execution, get all label and generate statistics
*/
LinkedHashMap<String, SummaryStatisticsDTO> labelPerTestcaseExecution = new LinkedHashMap();
for (TestCaseExecution testCaseExecution : testCaseExecutions) {
String controlStatus = testCaseExecution.getControlStatus();
if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {
// Get label for current test_testcase
JSONArray labelsForTestCase = testCaseWithLabel.get(testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase());
if (labelsForTestCase != null) {
for (int index = 0; index < labelsForTestCase.length(); index++) {
JSONObject j = labelsForTestCase.getJSONObject(index);
if (labelPerTestcaseExecution.containsKey(j.get("name"))) {
labelPerTestcaseExecution.get(j.get("name").toString()).updateStatisticByStatus(controlStatus);
} else {
SummaryStatisticsDTO stat = new SummaryStatisticsDTO();
stat.setLabel(j);
stat.updateStatisticByStatus(controlStatus);
labelPerTestcaseExecution.put(j.get("name").toString(), stat);
}
total.updateStatisticByStatus(controlStatus);
}
}
}
}
jsonResult.put("labelStats", extractSummaryData(labelPerTestcaseExecution, total, true));
}
return jsonResult;
}
use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.
the class ReadTestCaseExecutionQueue method findExecutionInQueueList.
private AnswerItem findExecutionInQueueList(ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException {
AnswerItem item = new AnswerItem();
JSONObject object = new JSONObject();
executionService = appContext.getBean(ITestCaseExecutionQueueService.class);
int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));
int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));
/*int sEcho = Integer.valueOf(request.getParameter("sEcho"));*/
String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");
int columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_0"), "2"));
String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "id,test,testcase,country,environment,browser,tag");
String[] columnToSort = sColumns.split(",");
String columnName = columnToSort[columnToSortParameter];
String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "desc");
List<String> individualLike = new ArrayList(Arrays.asList(request.getParameter("sLike").split(",")));
Map<String, List<String>> individualSearch = new HashMap<>();
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 resp = executionService.readByCriteria(startPosition, length, columnName, sort, searchParameter, individualSearch);
JSONArray jsonArray = new JSONArray();
if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
// the service was able to perform the query, then we should get all values
for (TestCaseExecutionQueue exec : (List<TestCaseExecutionQueue>) resp.getDataList()) {
jsonArray.put(convertTestCaseExecutionInQueueToJSONObject(exec));
}
}
object.put("hasPermissions", userHasPermissions);
object.put("contentTable", jsonArray);
object.put("iTotalRecords", resp.getTotalRows());
object.put("iTotalDisplayRecords", resp.getTotalRows());
item.setItem(object);
item.setResultMessage(resp.getResultMessage());
return item;
}
use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.
the class ReadTestDataLib method findDistinctValuesOfColumn.
private AnswerItem findDistinctValuesOfColumn(ApplicationContext appContext, HttpServletRequest request, String columnName) throws JSONException {
AnswerItem answer = new AnswerItem();
JSONObject object = new JSONObject();
testDataLibService = appContext.getBean(ITestDataLibService.class);
String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");
String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "test,testcase,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(",")));
Map<String, List<String>> individualSearch = new HashMap<>();
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 = testDataLibService.readDistinctValuesByCriteria(searchParameter, individualSearch, columnName);
object.put("distinctValues", testCaseList.getDataList());
answer.setItem(object);
answer.setResultMessage(testCaseList.getResultMessage());
return answer;
}
use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.
the class ReadTestDataLib method findTestDataLibNameList.
/**
* Handles the auto-complete requests and retrieves a limited list of
* strings that match (totally or partially) the name entered by the user.
*
* @param appContext - context object used to get the required beans
* @param nameToSearch - value used to perform the auto complete
* @param limit - limit number of the records that should be retrieved
* @return object containing values that match the name
* @throws JSONException
*/
private AnswerItem findTestDataLibNameList(String nameToSearch, int limit, boolean like, ApplicationContext appContext) throws JSONException {
AnswerItem ansItem = new AnswerItem();
JSONObject object = new JSONObject();
ITestDataLibService testDataService = appContext.getBean(ITestDataLibService.class);
AnswerList ansList = testDataService.readNameListByName(nameToSearch, limit, like);
JSONArray jsonArray = new JSONArray();
if (ansList.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
// the service was able to perform the query, then we should get all values
for (TestDataLib testDataLib : (List<TestDataLib>) ansList.getDataList()) {
jsonArray.put(convertTestDataLibToJSONObject(testDataLib, false));
}
}
// recordsFiltered do lado do servidor
object.put("contentTable", jsonArray);
object.put("iTotalRecords", ansList.getTotalRows());
object.put("iTotalDisplayRecords", ansList.getTotalRows());
// recordsFiltered
ansItem.setResultMessage(ansList.getResultMessage());
ansItem.setItem(object);
return ansItem;
}
Aggregations