Best Cerberus-source code snippet using org.cerberus.dto.TreeNode.getId
Source:ReadTestCaseExecutionByTag.java
...184 }185 }186 private JSONObject testCaseExecutionToJSONObject(TestCaseExecution testCaseExecution) throws JSONException {187 JSONObject result = new JSONObject();188 result.put("ID", String.valueOf(testCaseExecution.getId()));189 result.put("QueueID", String.valueOf(testCaseExecution.getQueueID()));190 result.put("Test", JavaScriptUtils.javaScriptEscape(testCaseExecution.getTest()));191 result.put("TestCase", JavaScriptUtils.javaScriptEscape(testCaseExecution.getTestCase()));192 result.put("Environment", JavaScriptUtils.javaScriptEscape(testCaseExecution.getEnvironment()));193 result.put("Start", testCaseExecution.getStart());194 result.put("End", testCaseExecution.getEnd());195 result.put("Country", JavaScriptUtils.javaScriptEscape(testCaseExecution.getCountry()));196 result.put("RobotDecli", JavaScriptUtils.javaScriptEscape(testCaseExecution.getRobotDecli()));197 result.put("ManualExecution", JavaScriptUtils.javaScriptEscape(testCaseExecution.getManualExecution()));198 if (testCaseExecution.getExecutor() != null) {199 result.put("Executor", JavaScriptUtils.javaScriptEscape(testCaseExecution.getExecutor()));200 }201 result.put("ControlStatus", JavaScriptUtils.javaScriptEscape(testCaseExecution.getControlStatus()));202 result.put("ControlMessage", JavaScriptUtils.javaScriptEscape(testCaseExecution.getControlMessage()));203 result.put("Status", JavaScriptUtils.javaScriptEscape(testCaseExecution.getStatus()));204 result.put("NbExecutions", String.valueOf(testCaseExecution.getNbExecutions()));205 result.put("previousExeId", testCaseExecution.getPreviousExeId());206 if (testCaseExecution.getPreviousExeStatus() != null) {207 result.put("previousExeControlStatus", JavaScriptUtils.javaScriptEscape(testCaseExecution.getPreviousExeStatus()));208 }209 if (testCaseExecution.getQueueState() != null) {210 result.put("QueueState", JavaScriptUtils.javaScriptEscape(testCaseExecution.getQueueState()));211 }212 List<JSONObject> testCaseDep = new ArrayList<>();213 if (testCaseExecution.getTestCaseExecutionQueueDepList() != null) {214 for (TestCaseExecutionQueueDep tce : testCaseExecution.getTestCaseExecutionQueueDepList()) {215 JSONObject obj = new JSONObject();216 obj.put("test", tce.getDepTest());217 obj.put("testcase", tce.getDepTestCase());218 testCaseDep.add(obj);219 }220 }221 result.put("TestCaseDep", testCaseDep);222 return result;223 }224 private JSONObject getStatusList(HttpServletRequest request) {225 JSONObject statusList = new JSONObject();226 try {227 statusList.put("OK", ParameterParserUtil.parseStringParam(request.getParameter("OK"), "off"));228 statusList.put("KO", ParameterParserUtil.parseStringParam(request.getParameter("KO"), "off"));229 statusList.put("NA", ParameterParserUtil.parseStringParam(request.getParameter("NA"), "off"));230 statusList.put("NE", ParameterParserUtil.parseStringParam(request.getParameter("NE"), "off"));231 statusList.put("WE", ParameterParserUtil.parseStringParam(request.getParameter("WE"), "off"));232 statusList.put("PE", ParameterParserUtil.parseStringParam(request.getParameter("PE"), "off"));233 statusList.put("FA", ParameterParserUtil.parseStringParam(request.getParameter("FA"), "off"));234 statusList.put("CA", ParameterParserUtil.parseStringParam(request.getParameter("CA"), "off"));235 statusList.put("QU", ParameterParserUtil.parseStringParam(request.getParameter("QU"), "off"));236 statusList.put("QE", ParameterParserUtil.parseStringParam(request.getParameter("QE"), "off"));237 } catch (JSONException ex) {238 LOG.error("Error on getStatusList : " + ex, ex);239 }240 return statusList;241 }242 private JSONObject getCountryList(HttpServletRequest request, ApplicationContext appContext) {243 JSONObject countryList = new JSONObject();244 try {245 IInvariantService invariantService = appContext.getBean(InvariantService.class);246 for (Invariant country : (List<Invariant>) invariantService.readByIdName("COUNTRY")) {247 countryList.put(country.getValue(), ParameterParserUtil.parseStringParam(request.getParameter(country.getValue()), "off"));248 }249 } catch (JSONException | CerberusException ex) {250 LOG.error("Error on getCountryList : " + ex, ex);251 }252 return countryList;253 }254 private JSONObject generateTestCaseExecutionTable(ApplicationContext appContext, List<TestCaseExecution> testCaseExecutions, JSONObject statusFilter, JSONObject countryFilter, List<TestCaseLabel> testCaseLabelList, boolean fullList) {255 JSONObject testCaseExecutionTable = new JSONObject();256 LinkedHashMap<String, JSONObject> ttc = new LinkedHashMap<>();257 LinkedHashMap<String, JSONObject> columnMap = new LinkedHashMap<>();258 for (TestCaseExecution testCaseExecution : testCaseExecutions) {259 try {260 String controlStatus = testCaseExecution.getControlStatus();261 String previousControlStatus = testCaseExecution.getPreviousExeStatus();262 // We check is Country and status is inside the fitered values.263 if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {264 JSONObject executionJSON = testCaseExecutionToJSONObject(testCaseExecution);265 String execKey = testCaseExecution.getEnvironment() + " " + testCaseExecution.getCountry() + " " + testCaseExecution.getRobotDecli();266 String testCaseKey = testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase();267 JSONObject execTab = new JSONObject();268 JSONObject ttcObject = new JSONObject();269 if (ttc.containsKey(testCaseKey)) {270 // We add an execution entry into the testcase line.271 ttcObject = ttc.get(testCaseKey);272 execTab = ttcObject.getJSONObject("execTab");273 execTab.put(execKey, executionJSON);274 ttcObject.put("execTab", execTab);275 // Nb Total Executions276 Integer nbExeTot = (Integer) ttcObject.get("NbExe");277 nbExeTot += testCaseExecution.getNbExecutions();278 ttcObject.put("NbExe", nbExeTot);279 // Nb Total Executions280 Integer nbRetryTot = (Integer) ttcObject.get("NbRetry");281 nbRetryTot += testCaseExecution.getNbExecutions() - 1;282 ttcObject.put("NbRetry", nbRetryTot);283 // Nb Total Usefull Executions284 Integer nbExeUsefullTot = (Integer) ttcObject.get("NbExeUsefull");285 nbExeUsefullTot++;286 ttcObject.put("NbExeUsefull", nbExeUsefullTot);287 // Nb Total Usefull Executions in QU or OK status288 Integer nbExeTmp;289 if (isToHide(controlStatus, previousControlStatus)) {290 nbExeTmp = (Integer) ttcObject.get("NbExeUsefullToHide");291 ttcObject.put("NbExeUsefullToHide", ++nbExeTmp);292 }293 if (isNotBug(controlStatus)) {294 nbExeTmp = (Integer) ttcObject.get("NbExeUsefullOK");295 ttcObject.put("NbExeUsefullOK", ++nbExeTmp);296 }297 if (isBug(controlStatus)) {298 nbExeTmp = (Integer) ttcObject.get("NbExeUsefullHasBug");299 ttcObject.put("NbExeUsefullHasBug", ++nbExeTmp);300 }301 if (isPending(controlStatus)) {302 nbExeTmp = (Integer) ttcObject.get("NbExeUsefullIsPending");303 ttcObject.put("NbExeUsefullIsPending", ++nbExeTmp);304 }305 } else {306 // We add a new testcase entry (with The current execution).307 ttcObject.put("test", testCaseExecution.getTest());308 ttcObject.put("testCase", testCaseExecution.getTestCase());309 ttcObject.put("shortDesc", testCaseExecution.getDescription());310 ttcObject.put("status", testCaseExecution.getStatus());311 ttcObject.put("application", testCaseExecution.getApplication());312 if (testCaseExecution.getApplicationObj() != null && testCaseExecution.getApplicationObj().getBugTrackerUrl() != null313 && !"".equals(testCaseExecution.getApplicationObj().getBugTrackerUrl()) && testCaseExecution.getTestCaseObj().getBugs() != null) {314 ttcObject.put("AppBugURL", testCaseExecution.getApplicationObj().getBugTrackerUrl());315 }316 boolean testExist = ((testCaseExecution.getTestCaseObj() != null) && (testCaseExecution.getTestCaseObj().getTest() != null));317 if (testExist) {318 ttcObject.put("priority", testCaseExecution.getTestCaseObj().getPriority());319 ttcObject.put("comment", testCaseExecution.getTestCaseObj().getComment());320 ttcObject.put("bugs", testCaseExecution.getTestCaseObj().getBugsActive());321 } else {322 ttcObject.put("function", "");323 ttcObject.put("priority", 0);324 ttcObject.put("comment", "");325 ttcObject.put("bugs", new JSONArray());326 }327 // Flag that report if test case still exist.328 ttcObject.put("testExist", testExist);329 // Adding nb of execution on retry.330 ttcObject.put("NbRetry", (testCaseExecution.getNbExecutions() - 1));331 // Adding nb of execution on retry.332 ttcObject.put("NbExe", (testCaseExecution.getNbExecutions()));333 // Nb Total Usefull Executions334 ttcObject.put("NbExeUsefull", 1);335 // Nb Total Usefull Executions in QU or OK status336 if (isToHide(controlStatus, previousControlStatus)) {337 ttcObject.put("NbExeUsefullToHide", 1);338 } else {339 ttcObject.put("NbExeUsefullToHide", 0);340 }341 // Nb Total Usefull Executions in QU or OK status342 if (isNotBug(controlStatus)) {343 ttcObject.put("NbExeUsefullOK", 1);344 } else {345 ttcObject.put("NbExeUsefullOK", 0);346 }347 // Nb Total Usefull Executions in QU or OK status348 if (isBug(controlStatus)) {349 ttcObject.put("NbExeUsefullHasBug", 1);350 } else {351 ttcObject.put("NbExeUsefullHasBug", 0);352 }353 // Nb Total Usefull Executions in QU or OK status354 if (isPending(controlStatus)) {355 ttcObject.put("NbExeUsefullIsPending", 1);356 } else {357 ttcObject.put("NbExeUsefullIsPending", 0);358 }359 execTab.put(execKey, executionJSON);360 ttcObject.put("execTab", execTab);361 /**362 * Iterate on the label retrieved and generate HashMap363 * based on the key Test_TestCase364 */365 LinkedHashMap<String, JSONArray> testCaseWithLabel = new LinkedHashMap<>();366 for (TestCaseLabel label : (List<TestCaseLabel>) testCaseLabelList) {367 if (Label.TYPE_STICKER.equals(label.getLabel().getType())) { // We only display STICKER Type Label in Reporting By Tag Page..368 String key = label.getTest() + "_" + label.getTestcase();369 JSONObject jo = new JSONObject().put("name", label.getLabel().getLabel()).put("color", label.getLabel().getColor()).put("description", label.getLabel().getDescription());370 if (testCaseWithLabel.containsKey(key)) {371 testCaseWithLabel.get(key).put(jo);372 } else {373 testCaseWithLabel.put(key, new JSONArray().put(jo));374 }375 }376 }377 ttcObject.put("labels", testCaseWithLabel.get(testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase()));378 }379 ttc.put(testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase(), ttcObject);380 JSONObject column = new JSONObject();381 column.put("country", testCaseExecution.getCountry());382 column.put("environment", testCaseExecution.getEnvironment());383 column.put("robotDecli", testCaseExecution.getRobotDecli());384 columnMap.put(testCaseExecution.getRobotDecli() + "_" + testCaseExecution.getCountry() + "_" + testCaseExecution.getEnvironment(), column);385 }386 TreeMap<String, JSONObject> bugMap = new TreeMap<>();387 HashMap<String, Boolean> bugMapUniq = new HashMap<>();388 int nbTOCLEAN = 0;389 int nbPENDING = 0;390 int nbTOREPORT = 0;391 // building Bug Status.392 for (Map.Entry<String, JSONObject> entry : ttc.entrySet()) {393 JSONObject val = entry.getValue();394 JSONArray bugA = new JSONArray(val.getString("bugs"));395 int nbBug = bugA.length();396 if (nbBug > 0) {397 for (int i = 0; i < nbBug; i++) {398 bugMapUniq.put(bugA.getJSONObject(i).getString("id"), true);399 String key = bugA.getJSONObject(i).getString("id") + "#" + val.getString("test") + "#" + val.getString("testCase");400 if (bugMap.containsKey(key)) {401 JSONObject bugO = bugMap.get(key);402 } else {403 JSONObject bugO = new JSONObject();404 bugO.put("test", val.getString("test"));405 bugO.put("testCase", val.getString("testCase"));406 bugO.put("bug", bugA.getJSONObject(i).getString("id"));407 bugO.put("NbExeUsefullHasBug", val.getInt("NbExeUsefullHasBug"));408 bugO.put("testExist", val.getBoolean("testExist"));409 bugO.put("NbExeUsefull", val.getInt("NbExeUsefull"));410 bugO.put("NbExeUsefullIsPending", val.getInt("NbExeUsefullIsPending"));411 if (val.getInt("NbExeUsefullIsPending") > 0) {412 bugO.put("status", "STILL RUNNING...");413 nbPENDING++;414 } else {415 if (val.getInt("NbExeUsefull") == val.getInt("NbExeUsefullOK")) {416 bugO.put("status", "TO CLEAN");417 nbTOCLEAN++;418 }419 }420 bugMap.put(key, bugO);421 }422 }423 } else {424 if (val.getInt("NbExeUsefullHasBug") > 0) {425 String key = val.getString("test") + "#" + val.getString("testCase");426 JSONObject bugO = new JSONObject();427 bugO.put("test", val.getString("test"));428 bugO.put("testCase", val.getString("testCase"));429 bugO.put("bug", "");430 bugO.put("NbExeUsefullHasBug", val.getInt("NbExeUsefullHasBug"));431 bugO.put("testExist", val.getBoolean("testExist"));432 bugO.put("NbExeUsefull", val.getInt("NbExeUsefull"));433 bugO.put("NbExeUsefullIsPending", val.getInt("NbExeUsefullIsPending"));434 bugO.put("status", "TO REPORT...");435 nbTOREPORT++;436 bugMap.put(key, bugO);437 }438 }439 }440 JSONObject bugRes = new JSONObject();441 bugRes.put("bugSummary", bugMap.values());442 bugRes.put("nbTOREPORT", nbTOREPORT);443 bugRes.put("nbPENDING", nbPENDING);444 bugRes.put("nbTOCLEAN", nbTOCLEAN);445 bugRes.put("nbBugs", bugMapUniq.size());446 testCaseExecutionTable.put("bugContent", bugRes);447 // Now loading only necessary records to final structure (filtering testcase that have all usefull executions OK of QU).448 if (fullList) {449 testCaseExecutionTable.put("tableContent", ttc.values());450 testCaseExecutionTable.put("iTotalRecords", ttc.size());451 testCaseExecutionTable.put("iTotalDisplayRecords", ttc.size());452 } else {453 LinkedHashMap<String, JSONObject> newttc = new LinkedHashMap<>();454 for (Map.Entry<String, JSONObject> entry : ttc.entrySet()) {455 String key = entry.getKey();456 JSONObject val = entry.getValue();457 if ((val.getInt("NbExeUsefullToHide") != val.getInt("NbExeUsefull")) // One of the execution of the test case has a status <> QU and OK458 || (val.getJSONArray("bugs").length() > 0) // At least 1 bug has been assigned to the testcase.459 ) {460 newttc.put(key, val);461 }462 }463 testCaseExecutionTable.put("tableContent", newttc.values());464 testCaseExecutionTable.put("iTotalRecords", newttc.size());465 testCaseExecutionTable.put("iTotalDisplayRecords", newttc.size());466 }467 Map<String, JSONObject> treeMap = new TreeMap<>(columnMap);468 testCaseExecutionTable.put("tableColumns", treeMap.values());469 } catch (JSONException ex) {470 LOG.error("Error on generateTestCaseExecutionTable : " + ex, ex);471 } catch (Exception ex) {472 LOG.error("Error on generateTestCaseExecutionTable : " + ex, ex);473 }474 }475 return testCaseExecutionTable;476 }477 // We hide is status is QU of OK and there were no previous execution.478 private boolean isToHide(String controlStatus, String previousControlStatus) {479 return (controlStatus.equals(TestCaseExecution.CONTROLSTATUS_QU) && (StringUtil.isNullOrEmpty(previousControlStatus))480 || controlStatus.equals(TestCaseExecution.CONTROLSTATUS_OK));481 }482 private boolean isPending(String controlStatus) {483 return (controlStatus.equals(TestCaseExecution.CONTROLSTATUS_QU) || controlStatus.equals(TestCaseExecution.CONTROLSTATUS_WE) || controlStatus.equals(TestCaseExecution.CONTROLSTATUS_PE));484 }485 private boolean isBug(String controlStatus) {486 return (controlStatus.equals(TestCaseExecution.CONTROLSTATUS_FA) || controlStatus.equals(TestCaseExecution.CONTROLSTATUS_KO));487 }488 private boolean isNotBug(String controlStatus) {489 return (controlStatus.equals(TestCaseExecution.CONTROLSTATUS_OK) || controlStatus.equals(TestCaseExecution.CONTROLSTATUS_QE));490 }491 private JSONObject generateManualExecutionTable(ApplicationContext appContext, List<TestCaseExecution> testCaseExecutions, JSONObject statusFilter, JSONObject countryFilter) {492 JSONObject manualExecutionTable = new JSONObject();493 HashMap<String, JSONObject> manualExecutions = new HashMap<>();494 int totalManualExecution = 0;495 int totalManualWEExecution = 0;496 for (TestCaseExecution testCaseExecution : testCaseExecutions) {497 try {498 String controlStatus = testCaseExecution.getControlStatus();499 boolean isManual = StringUtil.parseBoolean(testCaseExecution.getManualExecution());500 // We check is Country and status is inside the fitered values.501 if (countryFilter.get(testCaseExecution.getCountry()).equals("on")) {502 if (isManual) {503 totalManualExecution++;504 String executor = "NoExecutorDefined";505 if (!StringUtil.isNullOrEmpty(testCaseExecution.getExecutor())) {506 executor = testCaseExecution.getExecutor();507 }508 if (manualExecutions.containsKey(executor)) {509 JSONObject executorObj = manualExecutions.get(executor);510 JSONArray array = (JSONArray) executorObj.get("executionList");511 array.put(testCaseExecution.getId());512 JSONArray arrayWE = (JSONArray) executorObj.get("executionWEList");513 if (controlStatus.equals(TestCaseExecution.CONTROLSTATUS_WE)) {514 arrayWE.put(testCaseExecution.getId());515 }516 executorObj.put("executionList", array);517 executorObj.put("executionWEList", arrayWE);518 executorObj.put("executor", executor);519 manualExecutions.put(executor, executorObj);520 } else {521 JSONObject executorObj = new JSONObject();522 JSONArray array = new JSONArray();523 array.put(testCaseExecution.getId());524 JSONArray arrayWE = new JSONArray();525 if (controlStatus.equals(TestCaseExecution.CONTROLSTATUS_WE)) {526 arrayWE.put(testCaseExecution.getId());527 }528 executorObj.put("executionList", array);529 executorObj.put("executionWEList", arrayWE);530 executorObj.put("executor", executor);531 manualExecutions.put(executor, executorObj);532 }533 if (controlStatus.equals(TestCaseExecution.CONTROLSTATUS_WE)) {534 totalManualWEExecution++;535 }536 }537 }538 JSONArray array = new JSONArray();539 for (Map.Entry<String, JSONObject> entry : manualExecutions.entrySet()) {540 Object key = entry.getKey();541 JSONObject val = entry.getValue();542 array.put(val);543 }544 manualExecutionTable.put("perExecutor", array);545 manualExecutionTable.put("totalExecution", totalManualExecution);546 manualExecutionTable.put("totalWEExecution", totalManualWEExecution);547 } catch (JSONException ex) {548 LOG.error("Error on generateManualExecutionTable : " + ex, ex);549 } catch (Exception ex) {550 LOG.error("Error on generateManualExecutionTable : " + ex, ex);551 }552 }553 return manualExecutionTable;554 }555 private JSONObject generateTestFolderChart(List<TestCaseExecution> testCaseExecutions, String tag, JSONObject statusFilter, JSONObject countryFilter) throws JSONException {556 JSONObject jsonResult = new JSONObject();557 Map<String, JSONObject> axisMap = new HashMap<String, JSONObject>();558 String globalStart = "";559 String globalEnd = "";560 long globalStartL = 0;561 long globalEndL = 0;562 String globalStatus = "Finished";563 for (TestCaseExecution testCaseExecution : testCaseExecutions) {564 String key;565 JSONObject control = new JSONObject();566 JSONObject function = new JSONObject();567 String controlStatus = testCaseExecution.getControlStatus();568 if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {569 key = testCaseExecution.getTest();570 controlStatus = testCaseExecution.getControlStatus();571 control.put("value", 1);572 control.put("color", getColor(controlStatus));573 control.put("label", controlStatus);574 function.put("name", key);575 if (axisMap.containsKey(key)) {576 function = axisMap.get(key);577 if (function.has(controlStatus)) {578 int prec = function.getJSONObject(controlStatus).getInt("value");579 control.put("value", prec + 1);580 }581 }582 function.put(controlStatus, control);583 axisMap.put(key, function);584 }585 if (testCaseExecution.getStart() != 0) {586 if ((globalStartL == 0) || (globalStartL > testCaseExecution.getStart())) {587 globalStartL = testCaseExecution.getStart();588 globalStart = String.valueOf(new Date(testCaseExecution.getStart()));589 }590 }591 if (!testCaseExecution.getControlStatus().equalsIgnoreCase("PE") && testCaseExecution.getEnd() != 0) {592 if ((globalEndL == 0) || (globalEndL < testCaseExecution.getEnd())) {593 globalEndL = testCaseExecution.getEnd();594 globalEnd = String.valueOf(new Date(testCaseExecution.getEnd()));595 }596 }597 if (testCaseExecution.getControlStatus().equalsIgnoreCase("PE")) {598 globalStatus = "Pending...";599 }600 }601 Gson gson = new Gson();602 List<JSONObject> axisList = new ArrayList<>();603 for (Map.Entry<String, JSONObject> entry : axisMap.entrySet()) {604 String key = entry.getKey();605 JSONObject value = entry.getValue();606 axisList.add(value);607 }608 Collections.sort(axisList, new SortExecution());609 jsonResult.put("axis", axisList);610 jsonResult.put("tag", tag);611 jsonResult.put("globalEnd", gson.toJson(new Timestamp(globalEndL)).replace("\"", ""));612 jsonResult.put("globalStart", globalStart);613 jsonResult.put("globalStatus", globalStatus);614 return jsonResult;615 }616 class SortExecution implements Comparator<JSONObject> {617 // Used for sorting in ascending order of618 // name value.619 @Override620 public int compare(JSONObject a, JSONObject b) {621 if (a != null && b != null) {622 try {623 String aS = (String) a.get("name");624 String bS = (String) b.get("name");625 return aS.compareToIgnoreCase(bS);626 } catch (JSONException ex) {627 LOG.error("JSON Error Exception", ex);628 return 1;629 }630 } else {631 return 1;632 }633 }634 }635 private JSONObject generateStats(HttpServletRequest request, List<TestCaseExecution> testCaseExecutions, JSONObject statusFilter, JSONObject countryFilter, boolean splitStats) throws JSONException {636 JSONObject jsonResult = new JSONObject();637 boolean env = request.getParameter("env") != null || !splitStats;638 boolean country = request.getParameter("country") != null || !splitStats;639 boolean robotDecli = request.getParameter("robotDecli") != null || !splitStats;640 boolean app = request.getParameter("app") != null || !splitStats;641 HashMap<String, SummaryStatisticsDTO> statMap = new HashMap<String, SummaryStatisticsDTO>();642 for (TestCaseExecution testCaseExecution : testCaseExecutions) {643 String controlStatus = testCaseExecution.getControlStatus();644 if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {645 StringBuilder key = new StringBuilder();646 key.append((env) ? testCaseExecution.getEnvironment() : "");647 key.append("_");648 key.append((country) ? testCaseExecution.getCountry() : "");649 key.append("_");650 key.append((robotDecli) ? testCaseExecution.getRobotDecli() : "");651 key.append("_");652 key.append((app) ? testCaseExecution.getApplication() : "");653 SummaryStatisticsDTO stat = new SummaryStatisticsDTO();654 stat.setEnvironment(testCaseExecution.getEnvironment());655 stat.setCountry(testCaseExecution.getCountry());656 stat.setRobotDecli(testCaseExecution.getRobotDecli());657 stat.setApplication(testCaseExecution.getApplication());658 statMap.put(key.toString(), stat);659 }660 }661 jsonResult.put("contentTable", getStatByEnvCountryRobotDecli(testCaseExecutions, statMap, env, country, robotDecli, app, statusFilter, countryFilter, splitStats));662 return jsonResult;663 }664 private JSONObject generateBugStats(HttpServletRequest request, List<TestCaseExecution> testCaseExecutions, JSONObject statusFilter, JSONObject countryFilter) throws JSONException {665 JSONObject jsonResult = new JSONObject();666 SummaryStatisticsBugTrackerDTO stat = new SummaryStatisticsBugTrackerDTO();667 String bugsToReport = "KO,FA";668 stat.setNbExe(1);669 int totalBugReported = 0;670 int totalBugToReport = 0;671 int totalBugToReportReported = 0;672 int totalBugToClean = 0;673 HashMap<String, SummaryStatisticsBugTrackerDTO> statMap = new HashMap<>();674 for (TestCaseExecution testCaseExecution : testCaseExecutions) {675 String controlStatus = testCaseExecution.getControlStatus();676 if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {677 String key = "";678 if (bugsToReport.contains(testCaseExecution.getControlStatus())) {679 totalBugToReport++;680 }681 if ((testCaseExecution.getTestCaseObj() != null) && (testCaseExecution.getTestCaseObj().getBugs().length() > 0)) {682 JSONArray arr = testCaseExecution.getTestCaseObj().getBugs();683 for (int i = 0; i < arr.length(); i++) {684 JSONObject bug = (JSONObject) arr.get(i);685 key = bug.getString("id");686 stat = statMap.get(key);687 totalBugReported++;688 if (stat == null) {689 stat = new SummaryStatisticsBugTrackerDTO();690 stat.setNbExe(1);691 stat.setBugId(key);692 stat.setBugIdURL(testCaseExecution.getApplicationObj().getBugTrackerUrl().replace("%BUGID%", key));693 stat.setExeIdLastStatus(testCaseExecution.getControlStatus());694 stat.setExeIdFirst(testCaseExecution.getId());695 stat.setExeIdLast(testCaseExecution.getId());696 stat.setTestFirst(testCaseExecution.getTest());697 stat.setTestLast(testCaseExecution.getTest());698 stat.setTestCaseFirst(testCaseExecution.getTestCase());699 stat.setTestCaseLast(testCaseExecution.getTestCase());700 } else {701 stat.setNbExe(stat.getNbExe() + 1);702 stat.setExeIdLastStatus(testCaseExecution.getControlStatus());703 stat.setExeIdLast(testCaseExecution.getId());704 stat.setTestLast(testCaseExecution.getTest());705 stat.setTestCaseLast(testCaseExecution.getTestCase());706 }707 if (!(bugsToReport.contains(testCaseExecution.getControlStatus()))) {708 totalBugToClean++;709 stat.setToClean(true);710 } else {711 totalBugToReportReported++;712 }713 statMap.put(key, stat);714 }715 }716 }717 }718 Gson gson = new Gson();719 JSONArray dataArray = new JSONArray();720 for (String key : statMap.keySet()) {721 SummaryStatisticsBugTrackerDTO sumStats = statMap.get(key);722 dataArray.put(new JSONObject(gson.toJson(sumStats)));723 }724 jsonResult.put("BugTrackerStat", dataArray);725 jsonResult.put("totalBugToReport", totalBugToReport);726 jsonResult.put("totalBugToReportReported", totalBugToReportReported);727 jsonResult.put("totalBugReported", totalBugReported);728 jsonResult.put("totalBugToClean", totalBugToClean);729 return jsonResult;730 }731 private JSONObject getStatByEnvCountryRobotDecli(List<TestCaseExecution> testCaseExecutions, HashMap<String, SummaryStatisticsDTO> statMap, boolean env, boolean country, boolean robotDecli, boolean app, JSONObject statusFilter, JSONObject countryFilter, boolean splitStats) throws JSONException {732 SummaryStatisticsDTO total = new SummaryStatisticsDTO();733 total.setEnvironment("Total");734 for (TestCaseExecution testCaseExecution : testCaseExecutions) {735 String controlStatus = testCaseExecution.getControlStatus();736 if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on") || !splitStats) {737 StringBuilder key = new StringBuilder();738 key.append((env) ? testCaseExecution.getEnvironment() : "");739 key.append("_");740 key.append((country) ? testCaseExecution.getCountry() : "");741 key.append("_");742 key.append((robotDecli) ? testCaseExecution.getRobotDecli() : "");743 key.append("_");744 key.append((app) ? testCaseExecution.getApplication() : "");745 if (statMap.containsKey(key.toString())) {746 statMap.get(key.toString()).updateStatisticByStatus(testCaseExecution.getControlStatus());747 }748 total.updateStatisticByStatus(testCaseExecution.getControlStatus());749 }750 }751 return extractSummaryData(statMap, total, splitStats);752 }753 private JSONObject extractSummaryData(HashMap<String, SummaryStatisticsDTO> summaryMap, SummaryStatisticsDTO total, boolean splitStats) throws JSONException {754 JSONObject extract = new JSONObject();755 Gson gson = new Gson();756 if (splitStats) {757 JSONArray dataArray = new JSONArray();758 //sort keys759 TreeMap<String, SummaryStatisticsDTO> sortedKeys = new TreeMap<String, SummaryStatisticsDTO>(summaryMap);760 for (String key : sortedKeys.keySet()) {761 SummaryStatisticsDTO sumStats = summaryMap.get(key);762 //percentage values763 sumStats.updatePercentageStatistics();764 dataArray.put(new JSONObject(gson.toJson(sumStats)));765 }766 extract.put("split", dataArray);767 }768 total.updatePercentageStatistics();769 extract.put("total", new JSONObject(gson.toJson(total)));770 return extract;771 }772 private String getColor(String controlStatus) {773 String color = null;774 if ("OK".equals(controlStatus)) {775 color = TestCaseExecution.CONTROLSTATUS_OK_COL;776 } else if ("KO".equals(controlStatus)) {777 color = TestCaseExecution.CONTROLSTATUS_KO_COL;778 } else if ("FA".equals(controlStatus)) {779 color = TestCaseExecution.CONTROLSTATUS_FA_COL;780 } else if ("CA".equals(controlStatus)) {781 color = TestCaseExecution.CONTROLSTATUS_CA_COL;782 } else if ("NA".equals(controlStatus)) {783 color = TestCaseExecution.CONTROLSTATUS_NA_COL;784 } else if ("NE".equals(controlStatus)) {785 color = TestCaseExecution.CONTROLSTATUS_NE_COL;786 } else if ("WE".equals(controlStatus)) {787 color = TestCaseExecution.CONTROLSTATUS_WE_COL;788 } else if ("PE".equals(controlStatus)) {789 color = TestCaseExecution.CONTROLSTATUS_PE_COL;790 } else if ("QU".equals(controlStatus)) {791 color = TestCaseExecution.CONTROLSTATUS_QU_COL;792 } else if ("QE".equals(controlStatus)) {793 color = TestCaseExecution.CONTROLSTATUS_QE_COL;794 } else {795 color = "#000000";796 }797 return color;798 }799 private JSONObject convertTagToJSONObject(Tag tag) throws JSONException {800 Gson gson = new Gson();801 JSONObject result = new JSONObject(gson.toJson(tag));802 return result;803 }804 private JSONObject generateLabelStats(ApplicationContext appContext, HttpServletRequest request, List<TestCaseExecution> testCaseExecutions, JSONObject statusFilter, JSONObject countryFilter, List<TestCaseLabel> testCaseLabelList) throws JSONException {805 JSONObject jsonResult = new JSONObject();806 labelService = appContext.getBean(LabelService.class);807 TreeNode node;808 JSONArray jsonArraySTICKER = new JSONArray();809 JSONArray jsonArrayREQUIREMENT = new JSONArray();810 AnswerList<Label> resp = labelService.readByVarious(new ArrayList<>(), new ArrayList<>(asList(Label.TYPE_STICKER, Label.TYPE_REQUIREMENT)));811 // Building Label inputlist with target layout812 if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {813 HashMap<Integer, TreeNode> inputList = new HashMap<>();814 for (Label label : (List<Label>) resp.getDataList()) {815 String text = "";816 text += "<span class='label label-primary' style='background-color:" + label.getColor() + "' data-toggle='tooltip' data-labelid='" + label.getId() + "' title='' data-original-title=''>" + label.getLabel() + "</span>";817 text += "<span style='margin-left: 5px; margin-right: 5px;' class=''>" + label.getDescription() + "</span>";818 text += "%STATUSBAR%";819 text += "%COUNTER1TEXT%";820 text += "%COUNTER1WITHCHILDTEXT%";821 text += "%NBNODESWITHCHILDTEXT%";822 // Specific pills823 //text += "<span class='badge badge-pill badge-secondary'>666</span>";824 // Standard pills825 List<String> attributList = new ArrayList<>();826 if (Label.TYPE_REQUIREMENT.equals(label.getType())) {827 if (!StringUtil.isNullOrEmpty(label.getReqType()) && !"unknown".equalsIgnoreCase(label.getReqType())) {828 attributList.add("<span class='badge badge-pill badge-secondary'>" + label.getReqType() + "</span>");829 }830 if (!StringUtil.isNullOrEmpty(label.getReqStatus()) && !"unknown".equalsIgnoreCase(label.getReqStatus())) {831 attributList.add("<span class='badge badge-pill badge-secondary'>" + label.getReqStatus() + "</span>");832 }833 if (!StringUtil.isNullOrEmpty(label.getReqCriticity()) && !"unknown".equalsIgnoreCase(label.getReqCriticity())) {834 attributList.add("<span class='badge badge-pill badge-secondary'>" + label.getReqCriticity() + "</span>");835 }836 }837 // Create Node.838 node = new TreeNode(label.getId() + "-" + label.getSystem() + "-" + label.getLabel(), label.getSystem(), label.getLabel(), label.getId(), label.getParentLabelID(), text, null, null, false);839 node.setCounter1(0);840 node.setCounter1WithChild(0);841 node.setTags(attributList);842 node.setType(label.getType());843 node.setCounter1Text("<span style='background-color:#000000' class='cnt1 badge badge-pill badge-secondary'>%COUNTER1%</span>");844 node.setCounter1WithChildText("<span class='cnt1WC badge badge-pill badge-secondary'>%COUNTER1WITHCHILD%</span>");845 node.setNbNodesText("<span style='background-color:#337ab7' class='nbNodes badge badge-pill badge-primary'>%NBNODESWITHCHILD%</span>");846 node.setLabelObj(label);847 inputList.put(node.getId(), node);848// LOG.debug("Label : " + node.getId() + " T : " + node);849 }850 HashMap<String, List<Integer>> testCaseWithLabel1 = new HashMap<>();851 for (TestCaseLabel label : (List<TestCaseLabel>) testCaseLabelList) {852// LOG.debug("TCLabel : " + label.getLabel() + " T : " + label.getTest() + " C : " + label.getTestcase() + " Type : " + label.getLabel().getType());853 if ((Label.TYPE_STICKER.equals(label.getLabel().getType()))854 || (Label.TYPE_REQUIREMENT.equals(label.getLabel().getType()))) {855 String key = label.getTest() + "_" + label.getTestcase();856 List<Integer> curLabelIdList = new ArrayList<>();857 if (testCaseWithLabel1.get(key) != null) {858 curLabelIdList = testCaseWithLabel1.get(key);859 curLabelIdList.add(label.getLabelId());860 testCaseWithLabel1.put(key, curLabelIdList);861// LOG.debug(" ADDED");862 } else {863 curLabelIdList.add(label.getLabelId());864 testCaseWithLabel1.put(key, curLabelIdList);865// LOG.debug(" ADDED");866 }867 }868 }869 /**870 * For All execution, get all labels from the test case and add if871 * those labels were in the list add the stats of executions into872 * the counters.873 */874 for (TestCaseExecution testCaseExecution : testCaseExecutions) {875// LOG.debug("Exe : " + testCaseExecution.getId() + " T : " + testCaseExecution.getTest() + " C : " + testCaseExecution.getTestCase());876 String controlStatus = testCaseExecution.getControlStatus();877 if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {878 //Get label for current test_testcase879 List<Integer> labelsForTestCase = testCaseWithLabel1.get(testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase());880 if (labelsForTestCase != null) {881 for (Integer integer : labelsForTestCase) {882// LOG.debug(" T : " + testCaseExecution.getTest() + " C : " + testCaseExecution.getTestCase() + " T : " + integer);883 TreeNode curTreenode = inputList.get(integer);884 if (curTreenode != null) {885// LOG.debug(" K : " + titi.getKey() + " C : " + titi.getCounter1());886 curTreenode.setCounter1(curTreenode.getCounter1() + 1);887 curTreenode.setCounter1WithChild(curTreenode.getCounter1WithChild() + 1);888 switch (testCaseExecution.getControlStatus()) {889 case TestCaseExecution.CONTROLSTATUS_OK:890 curTreenode.setNbOK(curTreenode.getNbOK() + 1);891 break;892 case TestCaseExecution.CONTROLSTATUS_KO:893 curTreenode.setNbKO(curTreenode.getNbKO() + 1);894 break;895 case TestCaseExecution.CONTROLSTATUS_FA:896 curTreenode.setNbFA(curTreenode.getNbFA() + 1);897 break;898 case TestCaseExecution.CONTROLSTATUS_NA:899 curTreenode.setNbNA(curTreenode.getNbNA() + 1);900 break;901 case TestCaseExecution.CONTROLSTATUS_NE:902 curTreenode.setNbNE(curTreenode.getNbNE() + 1);903 break;904 case TestCaseExecution.CONTROLSTATUS_WE:905 curTreenode.setNbWE(curTreenode.getNbWE() + 1);906 break;907 case TestCaseExecution.CONTROLSTATUS_PE:908 curTreenode.setNbPE(curTreenode.getNbPE() + 1);909 break;910 case TestCaseExecution.CONTROLSTATUS_QE:911 curTreenode.setNbQE(curTreenode.getNbQE() + 1);912 break;913 case TestCaseExecution.CONTROLSTATUS_QU:914 curTreenode.setNbQU(curTreenode.getNbQU() + 1);915 break;916 case TestCaseExecution.CONTROLSTATUS_CA:917 curTreenode.setNbCA(curTreenode.getNbCA() + 1);918 break;919 }920 inputList.put(curTreenode.getId(), curTreenode);921 }922 }923 }924 }925 }926 // Build Tres.927 List<TreeNode> finalList;928 jsonArraySTICKER = new JSONArray();929 jsonArrayREQUIREMENT = new JSONArray();930 finalList = labelService.hierarchyConstructor(inputList);931 for (TreeNode treeNode : finalList) {932 if (treeNode.getCounter1WithChild() > 0) {933 if (Label.TYPE_STICKER.equals(treeNode.getType())) {934 jsonArraySTICKER.put(treeNode.toJson());...
getId
Using AI Code Generation
1var id = node.getId();2var parent = node.getParent();3var children = node.getChildren();4var child = node.getChild(0);5var childrenCount = node.getChildrenCount();6var depth = node.getDepth();7var isLeaf = node.isLeaf();8var isRoot = node.isRoot();9var isChild = node.isChild(parent);10var isDescendant = node.isDescendant(parent);11var isAncestor = node.isAncestor(child);
getId
Using AI Code Generation
1node.getId();2var node = new org.cerberus.dto.TreeNode();3node.setId(1);4node.getId();5var node = new org.cerberus.dto.TreeNode();6node.setId("1");7node.getId();8var node = new org.cerberus.dto.TreeNode();9node.setId(1.2);10node.getId();11var node = new org.cerberus.dto.TreeNode();12node.setId("1.2");13node.getId();14var node = new org.cerberus.dto.TreeNode();15node.setId(true);16node.getId();17var node = new org.cerberus.dto.TreeNode();18node.setId("true");19node.getId();20var node = new org.cerberus.dto.TreeNode();21node.setId(false);22node.getId();23var node = new org.cerberus.dto.TreeNode();24node.setId("false");25node.getId();26var node = new org.cerberus.dto.TreeNode();27node.setId(null);28node.getId();29var node = new org.cerberus.dto.TreeNode();30node.setId("null");31node.getId();32var node = new org.cerberus.dto.TreeNode();33node.setId(undefined);34node.getId();
getId
Using AI Code Generation
1function getId() {2 return this.id;3}4function getChildren() {5 return this.children;6}7function setChildren(children) {8 this.children = children;9}10function getParent() {11 return this.parent;12}13function setParent(parent) {14 this.parent = parent;15}16function getText() {17 return this.text;18}19function setText(text) {20 this.text = text;21}22function getIcon() {23 return this.icon;24}25function setIcon(icon) {26 this.icon = icon;27}28function getTags() {29 return this.tags;30}31function setTags(tags) {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!