Search in sources :

Example 1 with SummaryStatisticsBugTrackerDTO

use of org.cerberus.dto.SummaryStatisticsBugTrackerDTO in project cerberus-source by cerberustesting.

the class ReadTestCaseExecutionByTag method generateBugStats.

private JSONObject generateBugStats(HttpServletRequest request, List<TestCaseExecution> testCaseExecutions, JSONObject statusFilter, JSONObject countryFilter) throws JSONException {
    JSONObject jsonResult = new JSONObject();
    SummaryStatisticsBugTrackerDTO stat = new SummaryStatisticsBugTrackerDTO();
    String bugsToReport = "KO,FA";
    stat.setNbExe(1);
    int totalBugReported = 0;
    int totalBugToReport = 0;
    int totalBugToReportReported = 0;
    int totalBugToClean = 0;
    HashMap<String, SummaryStatisticsBugTrackerDTO> statMap = new HashMap<String, SummaryStatisticsBugTrackerDTO>();
    for (TestCaseExecution testCaseExecution : testCaseExecutions) {
        String controlStatus = testCaseExecution.getControlStatus();
        if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {
            String key = "";
            if (bugsToReport.contains(testCaseExecution.getControlStatus())) {
                totalBugToReport++;
            }
            if ((testCaseExecution.getTestCaseObj() != null) && (!StringUtil.isNullOrEmpty(testCaseExecution.getTestCaseObj().getBugID()))) {
                key = testCaseExecution.getTestCaseObj().getBugID();
                stat = statMap.get(key);
                totalBugReported++;
                if (stat == null) {
                    stat = new SummaryStatisticsBugTrackerDTO();
                    stat.setNbExe(1);
                    stat.setBugId(testCaseExecution.getTestCaseObj().getBugID());
                    stat.setBugIdURL(testCaseExecution.getApplicationObj().getBugTrackerUrl().replace("%BUGID%", testCaseExecution.getTestCaseObj().getBugID()));
                    stat.setExeIdLastStatus(testCaseExecution.getControlStatus());
                    stat.setExeIdFirst(testCaseExecution.getId());
                    stat.setExeIdLast(testCaseExecution.getId());
                    stat.setTestFirst(testCaseExecution.getTest());
                    stat.setTestLast(testCaseExecution.getTest());
                    stat.setTestCaseFirst(testCaseExecution.getTestCase());
                    stat.setTestCaseLast(testCaseExecution.getTestCase());
                } else {
                    stat.setNbExe(stat.getNbExe() + 1);
                    stat.setExeIdLastStatus(testCaseExecution.getControlStatus());
                    stat.setExeIdLast(testCaseExecution.getId());
                    stat.setTestLast(testCaseExecution.getTest());
                    stat.setTestCaseLast(testCaseExecution.getTestCase());
                }
                if (!(bugsToReport.contains(testCaseExecution.getControlStatus()))) {
                    totalBugToClean++;
                    stat.setToClean(true);
                } else {
                    totalBugToReportReported++;
                }
                statMap.put(key, stat);
            }
        }
    }
    Gson gson = new Gson();
    JSONArray dataArray = new JSONArray();
    for (String key : statMap.keySet()) {
        SummaryStatisticsBugTrackerDTO sumStats = statMap.get(key);
        dataArray.put(new JSONObject(gson.toJson(sumStats)));
    }
    jsonResult.put("BugTrackerStat", dataArray);
    jsonResult.put("totalBugToReport", totalBugToReport);
    jsonResult.put("totalBugToReportReported", totalBugToReportReported);
    jsonResult.put("totalBugReported", totalBugReported);
    jsonResult.put("totalBugToClean", totalBugToClean);
    return jsonResult;
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JSONArray(org.json.JSONArray) Gson(com.google.gson.Gson) SummaryStatisticsBugTrackerDTO(org.cerberus.dto.SummaryStatisticsBugTrackerDTO)

Aggregations

Gson (com.google.gson.Gson)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 TestCaseExecution (org.cerberus.crud.entity.TestCaseExecution)1 SummaryStatisticsBugTrackerDTO (org.cerberus.dto.SummaryStatisticsBugTrackerDTO)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1