Search in sources :

Example 1 with TestCaseExecutionService

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;
}
Also used : TestCaseExecutionService(org.cerberus.crud.service.impl.TestCaseExecutionService) ITestCaseExecutionService(org.cerberus.crud.service.ITestCaseExecutionService) AnswerList(org.cerberus.util.answer.AnswerList) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) AnswerItem(org.cerberus.util.answer.AnswerItem) JSONObject(org.json.JSONObject) AnswerList(org.cerberus.util.answer.AnswerList) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 TestCaseExecution (org.cerberus.crud.entity.TestCaseExecution)1 ITestCaseExecutionService (org.cerberus.crud.service.ITestCaseExecutionService)1 TestCaseExecutionService (org.cerberus.crud.service.impl.TestCaseExecutionService)1 MessageEvent (org.cerberus.engine.entity.MessageEvent)1 AnswerItem (org.cerberus.util.answer.AnswerItem)1 AnswerList (org.cerberus.util.answer.AnswerList)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1