How to use getLabel method of org.cerberus.dto.TreeNode class

Best Cerberus-source code snippet using org.cerberus.dto.TreeNode.getLabel

Source:ReadTestCaseExecutionByTag.java Github

copy

Full Screen

...363 * 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")) {...

Full Screen

Full Screen

Source:LabelService.java Github

copy

Full Screen

...100 HashMap<Integer, Label> labelsMap = this.readAllToHash();101 HashMap<String, List<Label>> labelsToReturn = new HashMap<>();102 testCaseLabels.forEach((key, value) -> {103 if (labelsToReturn.containsKey(value.getTestcase())) {104 labelsToReturn.get(value.getTestcase()).add(labelsMap.get(value.getLabelId()));105 } else {106 labelsToReturn.put(value.getTestcase(), new ArrayList<Label>());107 labelsToReturn.get(value.getTestcase()).add(labelsMap.get(value.getLabelId()));108 }109 });110 return labelsToReturn;111 }112 @Override113 public boolean exist(Integer id) {114 AnswerItem objectAnswer = readByKey(id);115 return (objectAnswer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) && (objectAnswer.getItem() != null); // Call was successfull and object was found.116 }117 @Override118 public Answer create(Label object) {119 Answer answerChecks = checkLabelParentconsistency(object);120 if (answerChecks == null) {121 return labelDAO.create(object);122 } else {123 return answerChecks;124 }125 }126 @Override127 public Answer delete(Label object) {128 return labelDAO.delete(object);129 }130 @Override131 public Answer update(Label object) {132 Answer answerChecks = checkLabelParentconsistency(object);133 if (answerChecks == null) {134 return labelDAO.update(object);135 } else {136 return answerChecks;137 }138 }139 private Answer checkLabelParentconsistency(Label object) {140 // If parent label exist we check that it is consistent.141 if (object.getParentLabelID() != 0) {142 Answer response = new Answer();143 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_LABEL);144 // Getting parent label.145 AnswerItem<Label> answerLabelParent = readByKey(object.getParentLabelID());146 if ((answerLabelParent.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) && (answerLabelParent.getItem() != null)) {147 Label parentLabel = (Label) answerLabelParent.getItem();148 if ((!parentLabel.getSystem().equals(object.getSystem())) && (!StringUtil.isNullOrEmpty(parentLabel.getSystem()))) {149 // Parent Label system is not empty and different from child label system.150 msg.setDescription(msg.getDescription()151 .replace("%LABEL%", object.getLabel())152 .replace("%LABELPARENT%", parentLabel.getLabel())153 .replace("%DESCRIPTION%", "Parent label does not belong to the same system as child"));154 response.setResultMessage(msg);155 return response;156 }157 if (!parentLabel.getType().equals(object.getType())) {158 // Parent & Child have different types.159 msg.setDescription(msg.getDescription()160 .replace("%LABEL%", object.getLabel())161 .replace("%LABELPARENT%", parentLabel.getLabel())162 .replace("%DESCRIPTION%", "Cannot attach " + object.getType() + " Parent label to " + parentLabel.getType() + " child label. Types must be consistent"));163 response.setResultMessage(msg);164 return response;165 }166 if ((parentLabel.getId().equals(object.getParentLabelID())) && (object.getId().equals(parentLabel.getParentLabelID())) && (object.getId() > 0)) {167 // Parent & Child have different types. and current > 0 (means that we are not creating a new record.)168 msg.setDescription(msg.getDescription()169 .replace("%LABEL%", object.getLabel())170 .replace("%LABELPARENT%", parentLabel.getLabel())171 .replace("%DESCRIPTION%", "'" + parentLabel.getLabel() + "' is already attached to '" + object.getLabel() + "' and recursive links are not allowed"));172 response.setResultMessage(msg);173 return response;174 }175 if (object.getId() == object.getParentLabelID()) {176 // Parent & Child have different types.177 msg.setDescription(msg.getDescription()178 .replace("%LABEL%", object.getLabel())179 .replace("%LABELPARENT%", parentLabel.getLabel())180 .replace("%DESCRIPTION%", "Label cannot be attached to itself"));181 response.setResultMessage(msg);182 return response;183 }184 } else {185 // Parent label does not exist.186 msg.setDescription(msg.getDescription()187 .replace("%LABEL%", object.getLabel())188 .replace("%LABELPARENT%", object.getParentLabelID().toString())189 .replace("%DESCRIPTION%", "Parent label does not exist"));190 response.setResultMessage(msg);191 return response;192 }193 }194 return null;195 }196 @Override197 public List<Integer> enrichWithChild(List<Integer> labelIdList) {198 try {199 // Loading list of labelId into a map in order to dedup it.200 HashMap<Integer, Integer> finalMap = new HashMap<>();201 HashMap<Integer, Integer> initMap = new HashMap<>();202 // Dedup list on a MAP203 for (Integer labelId : labelIdList) {204 finalMap.put(labelId, 0);205 initMap.put(labelId, 0);206 }207 // Loading from database the list of links from parent to childs.208 List<Label> labelLinkList = labelService.convert(labelService.readAllLinks());209 // Looping of each campaign label and add the childs.210 Integer initSize = initMap.size();211 Integer finalSize = initSize;212 Integer i = 0;213 do {214 for (Map.Entry<Integer, Integer> entry : finalMap.entrySet()) {215 Integer key = entry.getKey();216 initMap.put(key, 0);217 }218 initSize = initMap.size();219 for (Map.Entry<Integer, Integer> entry : initMap.entrySet()) {220 Integer key = entry.getKey();221 Integer value = entry.getValue();222 for (Label label : labelLinkList) {223 if (Objects.equals(key, label.getParentLabelID())) {224 finalMap.put(label.getId(), 0);225 }226 }227 }228 finalSize = finalMap.size();229 i++;230 } while (!Objects.equals(finalSize, initSize) && i < 50);231 List<Integer> finalList = new ArrayList<>();232 for (Map.Entry<Integer, Integer> entry : finalMap.entrySet()) {233 Integer key = entry.getKey();234 finalList.add(key);235 }236 return finalList;237 } catch (CerberusException ex) {238 LOG.error("Exception when enriching Labels with Child.", ex);239 }240 return new ArrayList<>();241 }242 @Override243 public Label convert(AnswerItem<Label> answerItem) throws CerberusException {244 if (answerItem.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {245 //if the service returns an OK message then we can get the item246 return (Label) answerItem.getItem();247 }248 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));249 }250 @Override251 public List<Label> convert(AnswerList<Label> answerList) throws CerberusException {252 if (answerList.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {253 //if the service returns an OK message then we can get the item254 return (List<Label>) answerList.getDataList();255 }256 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));257 }258 @Override259 public void convert(Answer answer) throws CerberusException {260 if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {261 //if the service returns an OK message then we can get the item262 return;263 }264 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));265 }266 @Override267 public AnswerList<String> readDistinctValuesByCriteria(String system, String searchParameter, Map<String, List<String>> individualSearch, String columnName) {268 return labelDAO.readDistinctValuesByCriteria(system, searchParameter, individualSearch, columnName);269 }270 @Override271 public List<TreeNode> hierarchyConstructor(HashMap<Integer, TreeNode> inputList) {272 // Preparing data structure.273 // Looping against inputList to build nodeList.274 // Also saving all entry that have a parent in treeParent.275 Map<Integer, TreeNode> nodeList = new HashMap<>();276 List<TreeNode> treeParent = new ArrayList<>();277 for (Map.Entry<Integer, TreeNode> entry : inputList.entrySet()) {278 Integer key = entry.getKey();279 TreeNode localNode = entry.getValue();280 nodeList.put(localNode.getId(), localNode);281 if (localNode.getParentId() > 0) {282 treeParent.add(localNode);283 }284 }285 // Building final list286 List<TreeNode> finalList = new ArrayList<>();287 try {288 // Loop on maximum hierarchy levels.289 int i = 0;290 while (i < 50 && !nodeList.isEmpty()) {291// LOG.debug(i + ".start : " + nodeList);292 List<TreeNode> listToRemove = new ArrayList<>();293 // Looping against nodeList.294 for (Map.Entry<Integer, TreeNode> entry : nodeList.entrySet()) {295 Integer key = entry.getKey();296 TreeNode value = entry.getValue();297// LOG.debug(value.getId() + " " + value.getParentId() + " " + value.getNodes().size());298 // Does current entry has at least a child ?299 boolean hasChild = false;300 for (TreeNode treeNode : treeParent) {301 if (treeNode.getParentId() == value.getId()) {302 hasChild = true;303 }304 }305 if (!hasChild) {306 // If entry has no more child, we can add it to finalList.307 if ((i == 0) && (value.getNodes().isEmpty())) {308 value.setNodes(null);309 }310// LOG.debug("Pas de fils.");311 if (value.getParentId() <= 0) {312// LOG.debug("Adding to final result and remove from list." + i);313 if (value.getNodes() != null && !value.getNodes().isEmpty()) {314 Collections.sort(value.getNodes(), new SortbyLabel());315 }316 finalList.add(value);317 listToRemove.add(value);318 } else {319// LOG.debug("Moving to parent and remove from list." + i + " Parent " + value.getParentId());320 // Mettre sur le fils sur son pere.321 TreeNode father = nodeList.get(value.getParentId());322 if (father != null) {323 List<TreeNode> sons = father.getNodes();324 if (sons == null) {325 sons = new ArrayList<>();326 }327 if (value.getNodes() != null && !value.getNodes().isEmpty()) {328 Collections.sort(value.getNodes(), new SortbyLabel());329 }330 sons.add(value);331 father.setNodes(sons);332 father.setCounter1WithChild(father.getCounter1WithChild() + value.getCounter1WithChild());333 father.setNbNodesWithChild(father.getNbNodesWithChild() + 1);334 father.setNbOK(father.getNbOK() + value.getNbOK());335 father.setNbKO(father.getNbKO() + value.getNbKO());336 father.setNbFA(father.getNbFA() + value.getNbFA());337 father.setNbNA(father.getNbNA() + value.getNbNA());338 father.setNbNE(father.getNbNE() + value.getNbNE());339 father.setNbWE(father.getNbWE() + value.getNbWE());340 father.setNbPE(father.getNbPE() + value.getNbPE());341 father.setNbQE(father.getNbQE() + value.getNbQE());342 father.setNbQU(father.getNbQU() + value.getNbQU());343 father.setNbCA(father.getNbCA() + value.getNbCA());344 nodeList.put(father.getId(), father);345 } else {346 if (value.getNodes() != null && !value.getNodes().isEmpty()) {347// List<TreeNode> newTree = next.getNodes();348 Collections.sort(value.getNodes(), new SortbyLabel());349// next.setNodes(newTree);350 }351 // Father does not exist so we attach it to root.352 finalList.add(value);353 listToRemove.add(value);354 }355 listToRemove.add(value);356 treeParent.remove(value);357 }358 }359 }360 // Removing all entries that has been clasified to finalList.361// LOG.debug("To remove : " + listToRemove);362 for (TreeNode label : listToRemove) {363 nodeList.remove(label.getId());364 }365 i++;366 }367 // We now sort the root level (other levels were already sorted).368 Collections.sort(finalList, new SortbyLabel());369 } catch (Exception e) {370 LOG.error("Exception in hierarchyConstructor.", e);371 }372 return finalList;373 }374 class SortbyLabel implements Comparator<TreeNode> {375 // Used for sorting in ascending order of376 // Label name.377 @Override378 public int compare(TreeNode a, TreeNode b) {379 if (a != null && b != null & a.getLabel() != null) {380 return a.getLabel().compareToIgnoreCase(b.getLabel());381 } else {382 return 1;383 }384 }385 }386}...

Full Screen

Full Screen

getLabel

Using AI Code Generation

copy

Full Screen

1package org.cerberus.test;2import org.cerberus.dto.TreeNode;3public class 3 {4 public static void main(String[] args) {5 TreeNode node = new TreeNode();6 node.setLabel("test");7 System.out.println(node.getLabel());8 }9}10package org.cerberus.test;11import org.cerberus.dto.TreeNode;12public class 4 {13 public static void main(String[] args) {14 TreeNode node = new TreeNode();15 node.setLabel("test");16 System.out.println(node.getLabel());17 }18}19package org.cerberus.test;20import org.cerberus.dto.TreeNode;21public class 5 {22 public static void main(String[] args) {23 TreeNode node = new TreeNode();24 node.setLabel("test");25 System.out.println(node.getLabel());26 }27}28package org.cerberus.test;29import org.cerberus.dto.TreeNode;30public class 6 {31 public static void main(String[] args) {32 TreeNode node = new TreeNode();33 node.setLabel("test");34 System.out.println(node.getLabel());35 }36}37package org.cerberus.test;38import org.cerberus.dto.TreeNode;39public class 7 {40 public static void main(String[] args) {41 TreeNode node = new TreeNode();42 node.setLabel("test");43 System.out.println(node.getLabel());44 }45}46package org.cerberus.test;47import org.cerberus.dto.TreeNode;48public class 8 {49 public static void main(String[] args) {50 TreeNode node = new TreeNode();51 node.setLabel("test");52 System.out.println(node.getLabel());53 }54}

Full Screen

Full Screen

getLabel

Using AI Code Generation

copy

Full Screen

1package org.cerberus;2import org.cerberus.dto.TreeNode;3{4public static void main(String[] args) {5TreeNode node = new TreeNode();6node.setLabel("Cerberus");7System.out.println("Label of the node is: "+node.getLabel());8}9}

Full Screen

Full Screen

getLabel

Using AI Code Generation

copy

Full Screen

1package org.cerberus.dto;2import org.cerberus.dto.TreeNode;3import org.testng.annotations.Test;4import org.testng.Assert;5public class TreeNodeTest {6 public void testGetLabel() {7 TreeNode node = new TreeNode();8 node.setLabel("Label");9 Assert.assertEquals(node.getLabel(), "Label");10 }11}12package org.cerberus.dto;13import org.cerberus.dto.TreeNode;14import org.testng.annotations.Test;15import org.testng.Assert;16public class TreeNodeTest {17 public void testGetLabel() {18 TreeNode node = new TreeNode();19 node.setLabel("Label");20 Assert.assertEquals(node.getLabel(), "Label");21 }22}23package org.cerberus.dto;24import org.cerberus.dto.TreeNode;25import org.testng.annotations.Test;26import org.testng.Assert;27public class TreeNodeTest {28 public void testGetLabel() {29 TreeNode node = new TreeNode();30 node.setLabel("Label");31 Assert.assertEquals(node.getLabel(), "Label");32 }33}34package org.cerberus.dto;35import org.cerberus.dto.TreeNode;36import org.testng.annotations.Test;37import org.testng.Assert;38public class TreeNodeTest {39 public void testGetLabel() {40 TreeNode node = new TreeNode();41 node.setLabel("Label");42 Assert.assertEquals(node.getLabel(), "Label");43 }44}45package org.cerberus.dto;46import org.cerberus.dto.TreeNode;47import org.testng.annotations.Test;48import org.testng.Assert;49public class TreeNodeTest {50 public void testGetLabel() {51 TreeNode node = new TreeNode();52 node.setLabel("Label");53 Assert.assertEquals(node.getLabel(), "Label");54 }55}56package org.cerberus.dto;57import org.cerber

Full Screen

Full Screen

getLabel

Using AI Code Generation

copy

Full Screen

1package org.cerberus;2import org.cerberus.dto.TreeNode;3public class Main{4 public static void main(String[] args){5 TreeNode treeNode = new TreeNode();6 treeNode.setLabel("Hello World");7 System.out.println(treeNode.getLabel());8 }9}

Full Screen

Full Screen

getLabel

Using AI Code Generation

copy

Full Screen

1import java.util.*;2import org.cerberus.dto.*;3class Test{4public static void main(String args[]){5TreeNode node1 = new TreeNode();6node1.setLabel("Node1");7TreeNode node2 = new TreeNode();8node2.setLabel("Node2");9TreeNode node3 = new TreeNode();10node3.setLabel("Node3");11TreeNode node4 = new TreeNode();12node4.setLabel("Node4");13node1.addChild(node2);14node1.addChild(node3);15node1.addChild(node4);16System.out.println(node1.getLabel());17System.out.println(node1.getChild(1).getLabel());18System.out.println(node1.getChild(2).getLabel());19System.out.println(node1.getChild(3).getLabel());20}21}

Full Screen

Full Screen

getLabel

Using AI Code Generation

copy

Full Screen

1import org.cerberus.dto.TreeNode;2import java.util.*;3public class 3{4public static void main(String args[]){5TreeNode node = new TreeNode();6node.setLabel("hello");7System.out.println(node.getLabel());8}9}10import org.cerberus.dto.TreeNode;11import java.util.*;12public class 4{13public static void main(String args[]){14TreeNode node = new TreeNode();15node.setLabel("hello");16System.out.println(node.getLabel());17}18}19import org.cerberus.dto.TreeNode;20import java.util.*;21public class 5{22public static void main(String args[]){23TreeNode node = new TreeNode();24node.setLabel("hello");25System.out.println(node.getLabel());26}27}28import org.cerberus.dto.TreeNode;29import java.util.*;30public class 6{31public static void main(String args[]){32TreeNode node = new TreeNode();33node.setLabel("hello");34System.out.println(node.getLabel());35}36}37import org.cerberus.dto.TreeNode;38import java.util.*;39public class 7{40public static void main(String args[]){41TreeNode node = new TreeNode();42node.setLabel("hello");43System.out.println(node.getLabel());44}45}46import org.cerberus.dto.TreeNode;47import java.util.*;48public class 8{49public static void main(String args[]){50TreeNode node = new TreeNode();51node.setLabel("hello");52System.out.println(node.getLabel());53}54}55import org.cerberus.dto.TreeNode;56import java.util.*;57public class 9{58public static void main(String args[]){59TreeNode node = new TreeNode();60node.setLabel("hello");61System.out.println(node.getLabel());62}63}64import

Full Screen

Full Screen

getLabel

Using AI Code Generation

copy

Full Screen

1package com.cerberus;2import org.cerberus.dto.TreeNode;3public class Three {4 public static void main(String args[]) {5 TreeNode node = new TreeNode("root");6 System.out.println(node.getLabel());7 }8}

Full Screen

Full Screen

getLabel

Using AI Code Generation

copy

Full Screen

1import org.cerberus.dto.TreeNode;2import org.cerberus.dto.TreeNodeFactory;3public class 3{4public static void main(String[] args) {5TreeNodeFactory factory = new TreeNodeFactory();6TreeNode root = factory.createTreeNode("root");7TreeNode child1 = factory.createTreeNode("child1");8TreeNode child2 = factory.createTreeNode("child2");9TreeNode child3 = factory.createTreeNode("child3");10root.addChild(child1);11root.addChild(child2);12child2.addChild(child3);13System.out.println("Label of the root is " + root.getLabel());14System.out.println("Label of the child1 is " + child1.getLabel());15System.out.println("Label of the child2 is " + child2.getLabel());16System.out.println("Label of the child3 is " + child3.getLabel());17}18}

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful