use of org.cerberus.crud.service.impl.TestCaseExecutionService 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