use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.
the class ReadTag method findTagList.
// </editor-fold>
private AnswerItem findTagList(ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException {
AnswerItem item = new AnswerItem();
JSONObject object = new JSONObject();
tagService = appContext.getBean(TagService.class);
int startPosition = 0;
if (request.getParameter("iDisplayStartPage") != null) {
startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStartPage"), "0"));
startPosition--;
startPosition = startPosition * 30;
} else {
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"), "1"));
String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "id,tag,campaign,description");
String[] columnToSort = sColumns.split(",");
String columnName = columnToSort[columnToSortParameter];
String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "desc");
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(",")));
individualSearch.put(columnToSort[a], search);
}
}
AnswerList resp = tagService.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 (Tag tagCur : (List<Tag>) resp.getDataList()) {
jsonArray.put(convertTagToJSONObject(tagCur));
}
}
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 ReadTag method findDistinctValuesOfColumn.
private AnswerItem findDistinctValuesOfColumn(ApplicationContext appContext, HttpServletRequest request, String columnName) throws JSONException {
AnswerItem answer = new AnswerItem();
JSONObject object = new JSONObject();
tagService = appContext.getBean(TagService.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(",");
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(",")));
individualSearch.put(columnToSort[a], search);
}
}
AnswerList tagList = tagService.readDistinctValuesByCriteria(null, searchParameter, individualSearch, columnName);
object.put("distinctValues", tagList.getDataList());
answer.setItem(object);
answer.setResultMessage(tagList.getResultMessage());
return answer;
}
use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.
the class ReadTestCaseExecution method findExecutionListByTag.
private AnswerItem findExecutionListByTag(ApplicationContext appContext, HttpServletRequest request, String Tag) throws CerberusException, ParseException, JSONException {
AnswerItem answer = new AnswerItem(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));
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"), "test,testCase,application,priority,status,description,bugId,function");
String[] columnToSort = sColumns.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(",")));
individualSearch.put(columnToSort[a], search);
}
}
List<TestCaseExecution> testCaseExecutions = readExecutionByTagList(appContext, Tag, startPosition, length, sortInformation.toString(), searchParameter, individualSearch);
JSONArray executionList = new JSONArray();
JSONObject statusFilter = getStatusList(request);
JSONObject countryFilter = getCountryList(request, appContext);
LinkedHashMap<String, JSONObject> ttc = new LinkedHashMap<String, JSONObject>();
String globalStart = "";
String globalEnd = "";
String globalStatus = "Finished";
/**
* Find the list of labels
*/
AnswerList testCaseLabelList = testCaseLabelService.readByTestTestCase(null, null);
for (TestCaseExecution testCaseExecution : testCaseExecutions) {
try {
if (testCaseExecution.getStart() != 0) {
if ((globalStart.isEmpty()) || (globalStart.compareTo(String.valueOf(testCaseExecution.getStart())) > 0)) {
globalStart = String.valueOf(testCaseExecution.getStart());
}
}
if (testCaseExecution.getEnd() != 0) {
if ((globalEnd.isEmpty()) || (globalEnd.compareTo(String.valueOf(testCaseExecution.getEnd())) < 0)) {
globalEnd = String.valueOf(testCaseExecution.getEnd());
}
}
if (testCaseExecution.getControlStatus().equalsIgnoreCase("PE")) {
globalStatus = "Pending...";
}
String controlStatus = testCaseExecution.getControlStatus();
if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {
JSONObject execution = testCaseExecutionToJSONObject(testCaseExecution);
String execKey = testCaseExecution.getEnvironment() + " " + testCaseExecution.getCountry() + " " + testCaseExecution.getBrowser();
String testCaseKey = testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase();
JSONObject execTab = new JSONObject();
executionList.put(testCaseExecutionToJSONObject(testCaseExecution));
JSONObject ttcObject = new JSONObject();
if (ttc.containsKey(testCaseKey)) {
ttcObject = ttc.get(testCaseKey);
execTab = ttcObject.getJSONObject("execTab");
execTab.put(execKey, execution);
ttcObject.put("execTab", execTab);
} else {
ttcObject.put("test", testCaseExecution.getTest());
ttcObject.put("testCase", testCaseExecution.getTestCase());
ttcObject.put("function", testCaseExecution.getTestCaseObj().getFunction());
ttcObject.put("shortDesc", testCaseExecution.getTestCaseObj().getDescription());
ttcObject.put("status", testCaseExecution.getStatus());
ttcObject.put("application", testCaseExecution.getApplication());
ttcObject.put("priority", testCaseExecution.getTestCaseObj().getPriority());
ttcObject.put("bugId", new JSONObject("{\"bugId\":\"" + testCaseExecution.getTestCaseObj().getBugID() + "\",\"bugTrackerUrl\":\"" + testCaseExecution.getApplicationObj().getBugTrackerUrl().replace("%BUGID%", testCaseExecution.getTestCaseObj().getBugID()) + "\"}"));
ttcObject.put("comment", testCaseExecution.getTestCaseObj().getComment());
execTab.put(execKey, execution);
ttcObject.put("execTab", execTab);
/**
* 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));
}
}
ttcObject.put("labels", testCaseWithLabel.get(testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase()));
}
ttc.put(testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase(), ttcObject);
}
} catch (JSONException ex) {
LOG.warn(ex);
}
}
JSONObject jsonResponse = new JSONObject();
jsonResponse.put("globalEnd", globalEnd.toString());
jsonResponse.put("globalStart", globalStart.toString());
jsonResponse.put("globalStatus", globalStatus);
jsonResponse.put("testList", ttc.values());
jsonResponse.put("iTotalRecords", ttc.size());
jsonResponse.put("iTotalDisplayRecords", ttc.size());
answer.setItem(jsonResponse);
answer.setResultMessage(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));
return answer;
}
use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.
the class ReadTestCaseExecution method findExecutionListBySystem.
private AnswerItem findExecutionListBySystem(String system, ApplicationContext appContext, HttpServletRequest request) throws ParseException, JSONException {
AnswerItem answer = new AnswerItem(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));
/**
* Parse all parameters used in the search.
*/
String charset = request.getCharacterEncoding();
/**
* Parse parameters - list of values
*/
List<String> testList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("test"), null, charset);
List<String> applicationList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("application"), null, charset);
List<String> projectList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("project"), null, charset);
List<String> tcstatusList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("tcstatus"), null, charset);
List<String> groupList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("group"), null, charset);
List<String> tcactiveList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("tcactive"), null, charset);
List<String> priorityList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("priority"), null, charset);
List<String> targetsprintList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("targetsprint"), null, charset);
List<String> targetrevisionList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("targetrevision"), null, charset);
List<String> creatorList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("creator"), null, charset);
List<String> implementerList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("implementer"), null, charset);
List<String> environmentList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("environment"), null, charset);
List<String> buildList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("build"), null, charset);
List<String> revisionList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("revision"), null, charset);
List<String> countryList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("country"), null, charset);
List<String> browserList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("browser"), null, charset);
List<String> tcestatusList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("tcestatus"), null, charset);
// Sorts the lists
if (countryList != null) {
Collections.sort(countryList);
}
if (browserList != null) {
Collections.sort(browserList);
}
/**
* Parse parameters - free text
*/
String bugid = StringEscapeUtils.escapeHtml4(request.getParameter("bugid"));
String ticket = StringEscapeUtils.escapeHtml4(request.getParameter("ticket"));
String ip = StringEscapeUtils.escapeHtml4(request.getParameter("ip"));
String port = StringEscapeUtils.escapeHtml4(request.getParameter("port"));
String tag = StringEscapeUtils.escapeHtml4(request.getParameter("tag"));
String browserversion = StringEscapeUtils.escapeHtml4(request.getParameter("browserversion"));
String comment = StringEscapeUtils.escapeHtml4(request.getParameter("comment"));
/**
* Gets regular executions (not in queue)
*/
AnswerList answerExecutions = testCaseExecutionService.readBySystemByVarious(system, testList, applicationList, projectList, tcstatusList, groupList, tcactiveList, priorityList, targetsprintList, targetrevisionList, creatorList, implementerList, buildList, revisionList, environmentList, countryList, browserList, tcestatusList, ip, port, tag, browserversion, comment, bugid, ticket);
List<TestCaseExecution> testCaseExecutions = (List<TestCaseExecution>) answerExecutions.getDataList();
/**
* Get list of Execution in Queue by Tag
*/
ITestCaseExecutionQueueService testCaseExecutionInQueueService = appContext.getBean(ITestCaseExecutionQueueService.class);
AnswerList answerExecutionsInQueue = testCaseExecutionInQueueService.readBySystemByVarious(system, testList, applicationList, projectList, tcstatusList, groupList, tcactiveList, priorityList, targetsprintList, targetrevisionList, creatorList, implementerList, buildList, revisionList, environmentList, countryList, browserList, tcestatusList, ip, port, tag, browserversion, comment, bugid, ticket);
List<TestCaseExecutionQueue> testCaseExecutionsInQueue = (List<TestCaseExecutionQueue>) answerExecutionsInQueue.getDataList();
/**
* Merge Test Case Executions
*/
List<TestCaseExecution> allTestCaseExecutions = hashExecution(testCaseExecutions, testCaseExecutionsInQueue);
JSONArray executionList = new JSONArray();
LinkedHashMap<String, JSONObject> ttc = new LinkedHashMap<String, JSONObject>();
for (TestCaseExecution testCaseExecution : allTestCaseExecutions) {
try {
JSONObject execution = testCaseExecutionToJSONObject(testCaseExecution);
// the key is country and browser
String execKey = testCaseExecution.getCountry() + " " + testCaseExecution.getBrowser();
String testCaseKey = testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase();
JSONObject execTab = new JSONObject();
executionList.put(testCaseExecutionToJSONObject(testCaseExecution));
JSONObject ttcObject = new JSONObject();
if (ttc.containsKey(testCaseKey)) {
ttcObject = ttc.get(testCaseKey);
execTab = ttcObject.getJSONObject("execTab");
execTab.put(execKey, execution);
ttcObject.put("execTab", execTab);
} else {
ttcObject.put("test", testCaseExecution.getTest());
ttcObject.put("testCase", testCaseExecution.getTestCase());
ttcObject.put("function", testCaseExecution.getTestCaseObj().getFunction());
ttcObject.put("shortDesc", testCaseExecution.getTestCaseObj().getDescription());
ttcObject.put("status", testCaseExecution.getTestCaseObj().getStatus());
ttcObject.put("application", testCaseExecution.getApplication());
ttcObject.put("bugId", testCaseExecution.getTestCaseObj().getBugID());
ttcObject.put("ticket", testCaseExecution.getTestCaseObj().getTicket());
ttcObject.put("comment", testCaseExecution.getTestCaseObj().getComment());
ttcObject.put("priority", testCaseExecution.getTestCaseObj().getPriority());
ttcObject.put("status", testCaseExecution.getStatus());
ttcObject.put("group", testCaseExecution.getTestCaseObj().getGroup());
execTab.put(execKey, execution);
ttcObject.put("execTab", execTab);
}
ttc.put(testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase(), ttcObject);
} catch (JSONException ex) {
LOG.warn(ex);
}
}
JSONObject jsonResponse = new JSONObject();
jsonResponse.put("contentTable", ttc.values());
jsonResponse.put("iTotalRecords", ttc.size());
jsonResponse.put("iTotalDisplayRecords", ttc.size());
answer.setItem(jsonResponse);
answer.setResultMessage(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));
return answer;
}
use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.
the class ReadTestCaseExecution method findTestCaseExecutionList.
private AnswerItem findTestCaseExecutionList(ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException, CerberusException {
AnswerItem answer = new AnswerItem(new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED));
AnswerList testCaseExecutionList = new AnswerList();
JSONObject object = new JSONObject();
testCaseExecutionService = appContext.getBean(TestCaseExecutionService.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"), "");
int columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_0"), "0"));
String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "test,description,active,automated,tdatecrea");
String[] columnToSort = sColumns.split(",");
String columnName = columnToSort[columnToSortParameter];
String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");
Map<String, List<String>> individualSearch = new HashMap<>();
List<String> individualLike = new ArrayList(Arrays.asList(ParameterParserUtil.parseStringParam(request.getParameter("sLike"), "").split(",")));
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);
}
}
}
testCaseExecutionList = testCaseExecutionService.readByCriteria(startPosition, length, columnName.concat(" ").concat(sort), searchParameter, individualSearch, individualLike);
JSONArray jsonArray = new JSONArray();
if (testCaseExecutionList.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
// the service was able to perform the query, then we should get all values
for (TestCaseExecution testCaseExecution : (List<TestCaseExecution>) testCaseExecutionList.getDataList()) {
jsonArray.put(testCaseExecution.toJson(true).put("hasPermissions", userHasPermissions));
}
}
object.put("contentTable", jsonArray);
object.put("hasPermissions", userHasPermissions);
object.put("iTotalRecords", testCaseExecutionList.getTotalRows());
object.put("iTotalDisplayRecords", testCaseExecutionList.getTotalRows());
answer.setItem(object);
answer.setResultMessage(testCaseExecutionList.getResultMessage());
return answer;
}
Aggregations