Search in sources :

Example 41 with AnswerItem

use of org.cerberus.util.answer.AnswerItem 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;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) HashMap(java.util.HashMap) TagService(org.cerberus.crud.service.impl.TagService) ITagService(org.cerberus.crud.service.ITagService) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) AnswerItem(org.cerberus.util.answer.AnswerItem) JSONObject(org.json.JSONObject) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) Tag(org.cerberus.crud.entity.Tag)

Example 42 with AnswerItem

use of org.cerberus.util.answer.AnswerItem 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;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) TagService(org.cerberus.crud.service.impl.TagService) ITagService(org.cerberus.crud.service.ITagService) ArrayList(java.util.ArrayList) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 43 with AnswerItem

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

Example 44 with AnswerItem

use of org.cerberus.util.answer.AnswerItem 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;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) MessageEvent(org.cerberus.engine.entity.MessageEvent) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) AnswerItem(org.cerberus.util.answer.AnswerItem) LinkedHashMap(java.util.LinkedHashMap) JSONObject(org.json.JSONObject) AnswerList(org.cerberus.util.answer.AnswerList) List(java.util.List) ArrayList(java.util.ArrayList) TestCaseExecutionQueue(org.cerberus.crud.entity.TestCaseExecutionQueue) ITestCaseExecutionQueueService(org.cerberus.crud.service.ITestCaseExecutionQueueService)

Example 45 with AnswerItem

use of org.cerberus.util.answer.AnswerItem in project cerberus-source by cerberustesting.

the class ReadTestCaseExecution method processRequest.

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 * @throws org.cerberus.exception.CerberusException
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException, ParseException {
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    response.setContentType("application/json");
    response.setCharacterEncoding("utf8");
    testCaseExecutionService = appContext.getBean(ITestCaseExecutionService.class);
    // Calling Servlet Transversal Util.
    ServletUtil.servletStart(request);
    try {
        JSONObject jsonResponse = new JSONObject();
        AnswerItem answer = new AnswerItem(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));
        // Data/Filter Parameters.
        String Tag = ParameterParserUtil.parseStringParam(request.getParameter("Tag"), "");
        String value = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");
        String test = ParameterParserUtil.parseStringParam(request.getParameter("test"), "");
        String testCase = ParameterParserUtil.parseStringParam(request.getParameter("testCase"), "");
        String system = ParameterParserUtil.parseStringParam(request.getParameter("system"), "");
        long executionId = ParameterParserUtil.parseLongParam(request.getParameter("executionId"), 0);
        boolean likeColumn = ParameterParserUtil.parseBooleanParam(request.getParameter("likeColumn"), false);
        // Switch Parameters.
        boolean executionWithDependency = ParameterParserUtil.parseBooleanParam("executionWithDependency", false);
        String columnName = ParameterParserUtil.parseStringParam(request.getParameter("columnName"), "");
        boolean byColumns = ParameterParserUtil.parseBooleanParam(request.getParameter("byColumns"), false);
        if (!Strings.isNullOrEmpty(columnName)) {
            // If columnName is present, then return the distinct value of this column.
            answer = findValuesForColumnFilter(system, test, appContext, request, columnName);
            jsonResponse = (JSONObject) answer.getItem();
        } else if (!Tag.equals("") && byColumns) {
            // Return the columns to display in the execution table
            answer = findExecutionColumns(appContext, request, Tag);
            jsonResponse = (JSONObject) answer.getItem();
        } else if (!Tag.equals("") && !byColumns) {
            // Return the list of execution for the execution table
            answer = findExecutionListByTag(appContext, request, Tag);
            jsonResponse = (JSONObject) answer.getItem();
        } else if (!system.isEmpty()) {
            // find execution by system, the remaining parameters are parsed after avoiding the extra processing
            answer = findExecutionListBySystem(system, appContext, request);
            jsonResponse = (JSONObject) answer.getItem();
        } else if (!test.equals("") && !testCase.equals("")) {
            TestCaseExecution lastExec = testCaseExecutionService.findLastTestCaseExecutionNotPE(test, testCase);
            JSONObject result = new JSONObject();
            if (lastExec != null) {
                result.put("id", lastExec.getId());
                result.put("queueId", lastExec.getQueueID());
                result.put("controlStatus", lastExec.getControlStatus());
                result.put("env", lastExec.getEnvironment());
                result.put("country", lastExec.getCountry());
                result.put("end", new Date(lastExec.getEnd())).toString();
            }
            jsonResponse.put("contentTable", result);
        } else if (executionId != 0 && !executionWithDependency) {
            answer = testCaseExecutionService.readByKeyWithDependency(executionId);
            TestCaseExecution tce = (TestCaseExecution) answer.getItem();
            jsonResponse.put("testCaseExecution", tce.toJson(true));
        } else if (executionId != 0 && executionWithDependency) {
        } else {
            answer = findTestCaseExecutionList(appContext, true, request);
            jsonResponse = (JSONObject) answer.getItem();
        }
        jsonResponse.put("messageType", answer.getResultMessage().getMessage().getCodeString());
        jsonResponse.put("message", answer.getResultMessage().getDescription());
        response.getWriter().print(jsonResponse.toString());
    } catch (JSONException ex) {
        LOG.warn(ex);
        // returns a default error message with the json format that is able to be parsed by the client-side
        response.getWriter().print(AnswerUtil.createGenericErrorAnswer());
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) JSONObject(org.json.JSONObject) MessageEvent(org.cerberus.engine.entity.MessageEvent) JSONException(org.json.JSONException) ITestCaseExecutionService(org.cerberus.crud.service.ITestCaseExecutionService) AnswerItem(org.cerberus.util.answer.AnswerItem) Date(java.util.Date)

Aggregations

AnswerItem (org.cerberus.util.answer.AnswerItem)322 MessageEvent (org.cerberus.engine.entity.MessageEvent)212 JSONObject (org.json.JSONObject)206 ApplicationContext (org.springframework.context.ApplicationContext)98 AnswerList (org.cerberus.util.answer.AnswerList)90 ArrayList (java.util.ArrayList)78 JSONArray (org.json.JSONArray)74 PolicyFactory (org.owasp.html.PolicyFactory)74 List (java.util.List)72 JSONException (org.json.JSONException)69 HashMap (java.util.HashMap)60 ILogEventService (org.cerberus.crud.service.ILogEventService)58 SQLException (java.sql.SQLException)57 Connection (java.sql.Connection)55 PreparedStatement (java.sql.PreparedStatement)53 Answer (org.cerberus.util.answer.Answer)53 ResultSet (java.sql.ResultSet)52 CerberusException (org.cerberus.exception.CerberusException)44 IOException (java.io.IOException)34 ServletException (javax.servlet.ServletException)24