How to use TreeNode class of org.cerberus.dto package

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

Source:ReadTestCaseExecutionByTag.java Github

copy

Full Screen

...50import org.cerberus.crud.service.impl.InvariantService;51import org.cerberus.crud.service.impl.LabelService;52import org.cerberus.dto.SummaryStatisticsBugTrackerDTO;53import org.cerberus.dto.SummaryStatisticsDTO;54import org.cerberus.dto.TreeNode;55import org.cerberus.engine.entity.MessageEvent;56import org.cerberus.enums.MessageEventEnum;57import org.cerberus.exception.CerberusException;58import org.cerberus.util.ParameterParserUtil;59import org.cerberus.util.StringUtil;60import org.cerberus.util.answer.AnswerItem;61import org.cerberus.util.answer.AnswerList;62import org.cerberus.util.servlet.ServletUtil;63import org.json.JSONArray;64import org.json.JSONException;65import org.json.JSONObject;66import org.springframework.context.ApplicationContext;67import org.springframework.web.context.support.WebApplicationContextUtils;68import org.springframework.web.util.JavaScriptUtils;69/**70 *71 * @author bcivel72 */73@WebServlet(name = "ReadTestCaseExecutionByTag", urlPatterns = {"/ReadTestCaseExecutionByTag"})74public class ReadTestCaseExecutionByTag extends HttpServlet {75 private ITestCaseExecutionService testCaseExecutionService;76 private ITagService tagService;77 private ITestCaseExecutionQueueService testCaseExecutionInQueueService;78 private ITestCaseLabelService testCaseLabelService;79 private ILabelService labelService;80 private IFactoryTestCase factoryTestCase;81 private static final Logger LOG = LogManager.getLogger("ReadTestCaseExecutionByTag");82 /**83 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>84 * methods.85 *86 * @param request servlet request87 * @param response servlet response88 * @throws ServletException if a servlet-specific error occurs89 * @throws IOException if an I/O error occurs90 */91 protected void processRequest(HttpServletRequest request, HttpServletResponse response)92 throws ServletException, IOException {93 // Calling Servlet Transversal Util.94 ServletUtil.servletStart(request);95 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());96 response.setContentType("application/json");97 response.setCharacterEncoding("utf8");98 String echo = request.getParameter("sEcho");99 AnswerItem<JSONObject> answer = new AnswerItem<>(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));100 testCaseExecutionService = appContext.getBean(ITestCaseExecutionService.class);101 tagService = appContext.getBean(ITagService.class);102 factoryTestCase = appContext.getBean(IFactoryTestCase.class);103 testCaseExecutionInQueueService = appContext.getBean(ITestCaseExecutionQueueService.class);104 try {105 // Data/Filter Parameters.106 String Tag = ParameterParserUtil.parseStringParam(request.getParameter("Tag"), "");107 List<String> outputReport = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("outputReport"), new ArrayList<>(), "UTF-8");108 boolean fullList = ParameterParserUtil.parseBooleanParam(request.getParameter("fullList"), false);109 JSONObject jsonResponse = new JSONObject();110 JSONObject statusFilter = getStatusList(request);111 JSONObject countryFilter = getCountryList(request, appContext);112 //Get Data from database113 List<TestCaseExecution> testCaseExecutions = testCaseExecutionService.readLastExecutionAndExecutionInQueueByTag(Tag);114 List<TestCaseLabel> testCaseLabelScopeList = null;115 if (outputReport.isEmpty() || outputReport.contains("labelStat") || outputReport.contains("table")) {116 String testCaseKey = "";117 HashMap<String, TestCase> ttc = new HashMap<>();118 List<TestCase> tcList = new ArrayList<>();119 for (TestCaseExecution testCaseExecution : testCaseExecutions) {120 testCaseKey = testCaseExecution.getTest() + "__" + testCaseExecution.getTestCase();121 if (ttc.get(testCaseKey) == null) {122 ttc.put(testCaseKey, factoryTestCase.create(testCaseExecution.getTest(), testCaseExecution.getTestCase()));123 tcList.add(factoryTestCase.create(testCaseExecution.getTest(), testCaseExecution.getTestCase()));124 }125 }126 testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);127 AnswerList<TestCaseLabel> testCaseLabelList = testCaseLabelService.readByTestTestCase(null, null, tcList);128 testCaseLabelScopeList = testCaseLabelList.getDataList();129 }130 // Table that contain the list of testcases and corresponding executions131 if (outputReport.isEmpty() || outputReport.contains("table")) {132 jsonResponse.put("table", generateTestCaseExecutionTable(appContext, testCaseExecutions, statusFilter, countryFilter, testCaseLabelScopeList, fullList));133 }134 // Table that contain the list of testcases and corresponding executions135 if (outputReport.isEmpty() || outputReport.contains("table")) {136 jsonResponse.put("manualExecutionList", generateManualExecutionTable(appContext, testCaseExecutions, statusFilter, countryFilter));137 }138 // Executions per Function (or Test).139 if (outputReport.isEmpty() || outputReport.contains("functionChart")) {140 jsonResponse.put("functionChart", generateFunctionChart(testCaseExecutions, Tag, statusFilter, countryFilter));141 }142 // Global executions stats per Status143 if (outputReport.isEmpty() || outputReport.contains("statsChart")) {144 jsonResponse.put("statsChart", generateStats(request, testCaseExecutions, statusFilter, countryFilter, true));145 }146 // BugTracker Recap147 if (outputReport.isEmpty() || outputReport.contains("bugTrackerStat")) {148 jsonResponse.put("bugTrackerStat", generateBugStats(request, testCaseExecutions, statusFilter, countryFilter));149 }150 // Labels Stats151 if (outputReport.isEmpty() || outputReport.contains("labelStat")) {152 jsonResponse.put("labelStat", generateLabelStats(appContext, request, testCaseExecutions, statusFilter, countryFilter, testCaseLabelScopeList));153 }154 if (!outputReport.isEmpty()) {155 //currently used to optimize the homePage156 if (outputReport.contains("totalStatsCharts") && !outputReport.contains("statsChart")) {157 jsonResponse.put("statsChart", generateStats(request, testCaseExecutions, statusFilter, countryFilter, false));158 }159 //currently used to optimize the homePage160 if (outputReport.contains("resendTag")) {161 jsonResponse.put("tag", Tag);162 }163 }164 Tag mytag = tagService.convert(tagService.readByKey(Tag));165 if (mytag != null) {166 JSONObject tagJSON = convertTagToJSONObject(mytag);167 jsonResponse.put("tagObject", tagJSON);168 jsonResponse.put("tagDuration", (mytag.getDateEndQueue().getTime() - mytag.getDateCreated().getTime()) / 60000);169 }170 answer.setItem(jsonResponse);171 answer.setResultMessage(answer.getResultMessage().resolveDescription("ITEM", "Tag Statistics").resolveDescription("OPERATION", "Read"));172 jsonResponse.put("messageType", answer.getResultMessage().getMessage().getCodeString());173 jsonResponse.put("message", answer.getResultMessage().getDescription());174 jsonResponse.put("sEcho", echo);175 response.getWriter().print(jsonResponse.toString());176 } catch (ParseException ex) {177 LOG.error("Error on main call : " + ex, ex);178 } catch (CerberusException ex) {179 LOG.error("Error on main call : " + ex, ex);180 } catch (JSONException ex) {181 LOG.error("Error on main call : " + ex, ex);182 } catch (Exception ex) {183 LOG.error("Error on main call : " + ex, ex);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// if (testCaseExecution.getApplicationObj() != null && testCaseExecution.getApplicationObj().getBugTrackerUrl() != null213// && !"".equals(testCaseExecution.getApplicationObj().getBugTrackerUrl()) && testCaseExecution.getTestCaseObj().getBugID() != null) {214// result.put("AppBugURL", testCaseExecution.getApplicationObj().getBugTrackerUrl());215// bugId = testCaseExecution.getApplicationObj().getBugTrackerUrl().replace("%BUGID%", testCaseExecution.getTestCaseObj().getBugID());216// bugId = new StringBuffer("<a href='")217// .append(bugId)218// .append("' target='reportBugID'>")219// .append(testCaseExecution.getTestCaseObj().getBugID())220// .append("</a>")221// .toString();222// }223// String comment;224// String function;225// String shortDesc;226// JSONArray bugId = new JSONArray();227// if ((testCaseExecution.getTestCaseObj() != null) && (testCaseExecution.getTestCaseObj().getTest() != null)) {228// bugId = testCaseExecution.getTestCaseObj().getBugID();229// comment = JavaScriptUtils.javaScriptEscape(testCaseExecution.getTestCaseObj().getComment());230// function = JavaScriptUtils.javaScriptEscape(testCaseExecution.getTestCaseObj().getFunction());231// shortDesc = testCaseExecution.getTestCaseObj().getDescription();232// } else {233// comment = "";234// function = "";235// shortDesc = "";236// }237// result.put("BugID", bugId);238// result.put("Priority", JavaScriptUtils.javaScriptEscape(String.valueOf(testCaseExecution.getTestCaseObj().getPriority())));239// result.put("Comment", comment);240// result.put("Function", function);241// result.put("ShortDescription", shortDesc);242// result.put("Application", JavaScriptUtils.javaScriptEscape(testCaseExecution.getApplication()));243 List<JSONObject> testCaseDep = new ArrayList<>();244 if (testCaseExecution.getTestCaseExecutionQueueDepList() != null) {245 for (TestCaseExecutionQueueDep tce : testCaseExecution.getTestCaseExecutionQueueDepList()) {246 JSONObject obj = new JSONObject();247 obj.put("test", tce.getDepTest());248 obj.put("testcase", tce.getDepTestCase());249 testCaseDep.add(obj);250 }251 }252 result.put("TestCaseDep", testCaseDep);253 return result;254 }255 private JSONObject getStatusList(HttpServletRequest request) {256 JSONObject statusList = new JSONObject();257 try {258 statusList.put("OK", ParameterParserUtil.parseStringParam(request.getParameter("OK"), "off"));259 statusList.put("KO", ParameterParserUtil.parseStringParam(request.getParameter("KO"), "off"));260 statusList.put("NA", ParameterParserUtil.parseStringParam(request.getParameter("NA"), "off"));261 statusList.put("NE", ParameterParserUtil.parseStringParam(request.getParameter("NE"), "off"));262 statusList.put("WE", ParameterParserUtil.parseStringParam(request.getParameter("WE"), "off"));263 statusList.put("PE", ParameterParserUtil.parseStringParam(request.getParameter("PE"), "off"));264 statusList.put("FA", ParameterParserUtil.parseStringParam(request.getParameter("FA"), "off"));265 statusList.put("CA", ParameterParserUtil.parseStringParam(request.getParameter("CA"), "off"));266 statusList.put("QU", ParameterParserUtil.parseStringParam(request.getParameter("QU"), "off"));267 statusList.put("QE", ParameterParserUtil.parseStringParam(request.getParameter("QE"), "off"));268 } catch (JSONException ex) {269 LOG.error("Error on getStatusList : " + ex, ex);270 }271 return statusList;272 }273 private JSONObject getCountryList(HttpServletRequest request, ApplicationContext appContext) {274 JSONObject countryList = new JSONObject();275 try {276 IInvariantService invariantService = appContext.getBean(InvariantService.class);277 for (Invariant country : (List<Invariant>) invariantService.readByIdName("COUNTRY")) {278 countryList.put(country.getValue(), ParameterParserUtil.parseStringParam(request.getParameter(country.getValue()), "off"));279 }280 } catch (JSONException | CerberusException ex) {281 LOG.error("Error on getCountryList : " + ex, ex);282 }283 return countryList;284 }285 private JSONObject generateTestCaseExecutionTable(ApplicationContext appContext, List<TestCaseExecution> testCaseExecutions, JSONObject statusFilter, JSONObject countryFilter, List<TestCaseLabel> testCaseLabelList, boolean fullList) {286 JSONObject testCaseExecutionTable = new JSONObject();287 LinkedHashMap<String, JSONObject> ttc = new LinkedHashMap<>();288 LinkedHashMap<String, JSONObject> columnMap = new LinkedHashMap<>();289 for (TestCaseExecution testCaseExecution : testCaseExecutions) {290 try {291 String controlStatus = testCaseExecution.getControlStatus();292 // We check is Country and status is inside the fitered values.293 if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {294 JSONObject executionJSON = testCaseExecutionToJSONObject(testCaseExecution);295 String execKey = testCaseExecution.getEnvironment() + " " + testCaseExecution.getCountry() + " " + testCaseExecution.getRobotDecli();296 String testCaseKey = testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase();297 JSONObject execTab = new JSONObject();298 JSONObject ttcObject = new JSONObject();299 if (ttc.containsKey(testCaseKey)) {300 // We add an execution entry into the testcase line.301 ttcObject = ttc.get(testCaseKey);302 execTab = ttcObject.getJSONObject("execTab");303 execTab.put(execKey, executionJSON);304 ttcObject.put("execTab", execTab);305 // Nb Total Executions306 Integer nbExeTot = (Integer) ttcObject.get("NbExe");307 nbExeTot += testCaseExecution.getNbExecutions();308 ttcObject.put("NbExe", nbExeTot);309 // Nb Total Executions310 Integer nbRetryTot = (Integer) ttcObject.get("NbRetry");311 nbRetryTot += testCaseExecution.getNbExecutions() - 1;312 ttcObject.put("NbRetry", nbRetryTot);313 // Nb Total Usefull Executions314 Integer nbExeUsefullTot = (Integer) ttcObject.get("NbExeUsefull");315 nbExeUsefullTot++;316 ttcObject.put("NbExeUsefull", nbExeUsefullTot);317 // Nb Total Usefull Executions in QU or OK status318 Integer nbExeTmp;319 if (isToHide(controlStatus)) {320 nbExeTmp = (Integer) ttcObject.get("NbExeUsefullToHide");321 ttcObject.put("NbExeUsefullToHide", ++nbExeTmp);322 }323 if (isNotBug(controlStatus)) {324 nbExeTmp = (Integer) ttcObject.get("NbExeUsefullOK");325 ttcObject.put("NbExeUsefullOK", ++nbExeTmp);326 }327 if (isBug(controlStatus)) {328 nbExeTmp = (Integer) ttcObject.get("NbExeUsefullHasBug");329 ttcObject.put("NbExeUsefullHasBug", ++nbExeTmp);330 }331 if (isPending(controlStatus)) {332 nbExeTmp = (Integer) ttcObject.get("NbExeUsefullIsPending");333 ttcObject.put("NbExeUsefullIsPending", ++nbExeTmp);334 }335 } else {336 // We add a new testcase entry (with The current execution).337 ttcObject.put("test", testCaseExecution.getTest());338 ttcObject.put("testCase", testCaseExecution.getTestCase());339 ttcObject.put("shortDesc", testCaseExecution.getDescription());340 ttcObject.put("status", testCaseExecution.getStatus());341 ttcObject.put("application", testCaseExecution.getApplication());342 boolean testExist = ((testCaseExecution.getTestCaseObj() != null) && (testCaseExecution.getTestCaseObj().getTest() != null));343 if (testExist) {344 ttcObject.put("function", testCaseExecution.getTestCaseObj().getFunction());345 ttcObject.put("priority", testCaseExecution.getTestCaseObj().getPriority());346 ttcObject.put("comment", testCaseExecution.getTestCaseObj().getComment());347 ttcObject.put("bugId", testCaseExecution.getTestCaseObj().getBugID());348 } else {349 ttcObject.put("function", "");350 ttcObject.put("priority", 0);351 ttcObject.put("comment", "");352 ttcObject.put("bugId", new JSONArray());353 }354 // Flag that report if test case still exist.355 ttcObject.put("testExist", testExist);356 // Adding nb of execution on retry.357 ttcObject.put("NbRetry", (testCaseExecution.getNbExecutions() - 1));358 // Adding nb of execution on retry.359 ttcObject.put("NbExe", (testCaseExecution.getNbExecutions()));360 // Nb Total Usefull Executions361 ttcObject.put("NbExeUsefull", 1);362 // Nb Total Usefull Executions in QU or OK status363 if (isToHide(controlStatus)) {364 ttcObject.put("NbExeUsefullToHide", 1);365 } else {366 ttcObject.put("NbExeUsefullToHide", 0);367 }368 // Nb Total Usefull Executions in QU or OK status369 if (isNotBug(controlStatus)) {370 ttcObject.put("NbExeUsefullOK", 1);371 } else {372 ttcObject.put("NbExeUsefullOK", 0);373 }374 // Nb Total Usefull Executions in QU or OK status375 if (isBug(controlStatus)) {376 ttcObject.put("NbExeUsefullHasBug", 1);377 } else {378 ttcObject.put("NbExeUsefullHasBug", 0);379 }380 // Nb Total Usefull Executions in QU or OK status381 if (isPending(controlStatus)) {382 ttcObject.put("NbExeUsefullIsPending", 1);383 } else {384 ttcObject.put("NbExeUsefullIsPending", 0);385 }386 execTab.put(execKey, executionJSON);387 ttcObject.put("execTab", execTab);388 /**389 * Iterate on the label retrieved and generate HashMap390 * based on the key Test_TestCase391 */392 LinkedHashMap<String, JSONArray> testCaseWithLabel = new LinkedHashMap<>();393 for (TestCaseLabel label : (List<TestCaseLabel>) testCaseLabelList) {394 if (Label.TYPE_STICKER.equals(label.getLabel().getType())) { // We only display STICKER Type Label in Reporting By Tag Page..395 String key = label.getTest() + "_" + label.getTestcase();396 JSONObject jo = new JSONObject().put("name", label.getLabel().getLabel()).put("color", label.getLabel().getColor()).put("description", label.getLabel().getDescription());397 if (testCaseWithLabel.containsKey(key)) {398 testCaseWithLabel.get(key).put(jo);399 } else {400 testCaseWithLabel.put(key, new JSONArray().put(jo));401 }402 }403 }404 ttcObject.put("labels", testCaseWithLabel.get(testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase()));405 }406 ttc.put(testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase(), ttcObject);407 JSONObject column = new JSONObject();408 column.put("country", testCaseExecution.getCountry());409 column.put("environment", testCaseExecution.getEnvironment());410 column.put("robotDecli", testCaseExecution.getRobotDecli());411 columnMap.put(testCaseExecution.getRobotDecli() + "_" + testCaseExecution.getCountry() + "_" + testCaseExecution.getEnvironment(), column);412 }413 TreeMap<String, JSONObject> bugMap = new TreeMap<>();414 HashMap<String, Boolean> bugMapUniq = new HashMap<>();415 int nbTOCLEAN = 0;416 int nbPENDING = 0;417 int nbTOREPORT = 0;418 // building Bug Status.419 for (Map.Entry<String, JSONObject> entry : ttc.entrySet()) {420 JSONObject val = entry.getValue();421 JSONArray bugA = new JSONArray(val.getString("bugId"));422 int nbBug = bugA.length();423 if (nbBug > 0) {424 for (int i = 0; i < nbBug; i++) {425 bugMapUniq.put(bugA.getJSONObject(i).getString("id"), true);426 String key = bugA.getJSONObject(i).getString("id") + "#" + val.getString("test") + "#" + val.getString("testCase");427 if (bugMap.containsKey(key)) {428 JSONObject bugO = bugMap.get(key);429 } else {430 JSONObject bugO = new JSONObject();431 bugO.put("test", val.getString("test"));432 bugO.put("testCase", val.getString("testCase"));433 bugO.put("bug", bugA.getJSONObject(i).getString("id"));434 bugO.put("NbExeUsefullHasBug", val.getInt("NbExeUsefullHasBug"));435 bugO.put("testExist", val.getBoolean("testExist"));436 bugO.put("NbExeUsefull", val.getInt("NbExeUsefull"));437 bugO.put("NbExeUsefullIsPending", val.getInt("NbExeUsefullIsPending"));438 if (val.getInt("NbExeUsefullIsPending") > 0) {439 bugO.put("status", "STILL RUNNING...");440 nbPENDING++;441 } else {442 if (val.getInt("NbExeUsefull") == val.getInt("NbExeUsefullOK")) {443 bugO.put("status", "TO CLEAN");444 nbTOCLEAN++;445 }446 }447 bugMap.put(key, bugO);448 }449 }450 } else {451 if (val.getInt("NbExeUsefullHasBug") > 0) {452 String key = val.getString("test") + "#" + val.getString("testCase");453 JSONObject bugO = new JSONObject();454 bugO.put("test", val.getString("test"));455 bugO.put("testCase", val.getString("testCase"));456 bugO.put("bug", "");457 bugO.put("NbExeUsefullHasBug", val.getInt("NbExeUsefullHasBug"));458 bugO.put("testExist", val.getBoolean("testExist"));459 bugO.put("NbExeUsefull", val.getInt("NbExeUsefull"));460 bugO.put("NbExeUsefullIsPending", val.getInt("NbExeUsefullIsPending"));461 bugO.put("status", "TO REPORT...");462 nbTOREPORT++;463 bugMap.put(key, bugO);464 }465 }466 }467 JSONObject bugRes = new JSONObject();468 bugRes.put("bugSummary", bugMap.values());469 bugRes.put("nbTOREPORT", nbTOREPORT);470 bugRes.put("nbPENDING", nbPENDING);471 bugRes.put("nbTOCLEAN", nbTOCLEAN);472 bugRes.put("nbBugs", bugMapUniq.size());473 testCaseExecutionTable.put("bugContent", bugRes);474 // Now loading only necessary records to final structure (filtering testcase that have all usefull executions OK of QU).475 if (fullList) {476 testCaseExecutionTable.put("tableContent", ttc.values());477 testCaseExecutionTable.put("iTotalRecords", ttc.size());478 testCaseExecutionTable.put("iTotalDisplayRecords", ttc.size());479 } else {480 LinkedHashMap<String, JSONObject> newttc = new LinkedHashMap<>();481 for (Map.Entry<String, JSONObject> entry : ttc.entrySet()) {482 String key = entry.getKey();483 JSONObject val = entry.getValue();484 if ((val.getInt("NbExeUsefullToHide") != val.getInt("NbExeUsefull")) // One of the execution of the test case has a status <> QU and OK485 || (val.getJSONArray("bugId").length() > 0) // At least 1 bug has been assigned to the testcase.486 ) {487 newttc.put(key, val);488 }489 }490 testCaseExecutionTable.put("tableContent", newttc.values());491 testCaseExecutionTable.put("iTotalRecords", newttc.size());492 testCaseExecutionTable.put("iTotalDisplayRecords", newttc.size());493 }494 Map<String, JSONObject> treeMap = new TreeMap<>(columnMap);495 testCaseExecutionTable.put("tableColumns", treeMap.values());496 } catch (JSONException ex) {497 LOG.error("Error on generateTestCaseExecutionTable : " + ex, ex);498 } catch (Exception ex) {499 LOG.error("Error on generateTestCaseExecutionTable : " + ex, ex);500 }501 }502 return testCaseExecutionTable;503 }504 private boolean isToHide(String controlStatus) {505 return (controlStatus.equals(TestCaseExecution.CONTROLSTATUS_QU) || controlStatus.equals(TestCaseExecution.CONTROLSTATUS_OK));506 }507 private boolean isPending(String controlStatus) {508 return (controlStatus.equals(TestCaseExecution.CONTROLSTATUS_QU) || controlStatus.equals(TestCaseExecution.CONTROLSTATUS_WE) || controlStatus.equals(TestCaseExecution.CONTROLSTATUS_PE));509 }510 private boolean isBug(String controlStatus) {511 return (controlStatus.equals(TestCaseExecution.CONTROLSTATUS_FA) || controlStatus.equals(TestCaseExecution.CONTROLSTATUS_KO));512 }513 private boolean isNotBug(String controlStatus) {514 return (controlStatus.equals(TestCaseExecution.CONTROLSTATUS_OK) || controlStatus.equals(TestCaseExecution.CONTROLSTATUS_QE));515 }516 private JSONObject generateManualExecutionTable(ApplicationContext appContext, List<TestCaseExecution> testCaseExecutions, JSONObject statusFilter, JSONObject countryFilter) {517 JSONObject manualExecutionTable = new JSONObject();518 HashMap<String, JSONObject> manualExecutions = new HashMap<>();519 int totalManualExecution = 0;520 int totalManualWEExecution = 0;521 for (TestCaseExecution testCaseExecution : testCaseExecutions) {522 try {523 String controlStatus = testCaseExecution.getControlStatus();524 boolean isManual = StringUtil.parseBoolean(testCaseExecution.getManualExecution());525 // We check is Country and status is inside the fitered values.526 if (countryFilter.get(testCaseExecution.getCountry()).equals("on")) {527 if (isManual) {528 totalManualExecution++;529 String executor = "NoExecutorDefined";530 if (!StringUtil.isNullOrEmpty(testCaseExecution.getExecutor())) {531 executor = testCaseExecution.getExecutor();532 }533 if (manualExecutions.containsKey(executor)) {534 JSONObject executorObj = manualExecutions.get(executor);535 JSONArray array = (JSONArray) executorObj.get("executionList");536 array.put(testCaseExecution.getId());537 JSONArray arrayWE = (JSONArray) executorObj.get("executionWEList");538 if (controlStatus.equals(TestCaseExecution.CONTROLSTATUS_WE)) {539 arrayWE.put(testCaseExecution.getId());540 }541 executorObj.put("executionList", array);542 executorObj.put("executionWEList", arrayWE);543 executorObj.put("executor", executor);544 manualExecutions.put(executor, executorObj);545 } else {546 JSONObject executorObj = new JSONObject();547 JSONArray array = new JSONArray();548 array.put(testCaseExecution.getId());549 JSONArray arrayWE = new JSONArray();550 if (controlStatus.equals(TestCaseExecution.CONTROLSTATUS_WE)) {551 arrayWE.put(testCaseExecution.getId());552 }553 executorObj.put("executionList", array);554 executorObj.put("executionWEList", arrayWE);555 executorObj.put("executor", executor);556 manualExecutions.put(executor, executorObj);557 }558 if (controlStatus.equals(TestCaseExecution.CONTROLSTATUS_WE)) {559 totalManualWEExecution++;560 }561 }562 }563 JSONArray array = new JSONArray();564 for (Map.Entry<String, JSONObject> entry : manualExecutions.entrySet()) {565 Object key = entry.getKey();566 JSONObject val = entry.getValue();567 array.put(val);568 }569 manualExecutionTable.put("perExecutor", array);570 manualExecutionTable.put("totalExecution", totalManualExecution);571 manualExecutionTable.put("totalWEExecution", totalManualWEExecution);572 } catch (JSONException ex) {573 LOG.error("Error on generateManualExecutionTable : " + ex, ex);574 } catch (Exception ex) {575 LOG.error("Error on generateManualExecutionTable : " + ex, ex);576 }577 }578 return manualExecutionTable;579 }580 private JSONObject generateFunctionChart(List<TestCaseExecution> testCaseExecutions, String tag, JSONObject statusFilter, JSONObject countryFilter) throws JSONException {581 JSONObject jsonResult = new JSONObject();582 Map<String, JSONObject> axisMap = new HashMap<String, JSONObject>();583 String globalStart = "";584 String globalEnd = "";585 long globalStartL = 0;586 long globalEndL = 0;587 String globalStatus = "Finished";588 for (TestCaseExecution testCaseExecution : testCaseExecutions) {589 String key;590 JSONObject control = new JSONObject();591 JSONObject function = new JSONObject();592 String controlStatus = testCaseExecution.getControlStatus();593 if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {594 if (testCaseExecution.getTestCaseObj() != null && testCaseExecution.getTestCaseObj().getFunction() != null && !"".equals(testCaseExecution.getTestCaseObj().getFunction())) {595 key = testCaseExecution.getTestCaseObj().getFunction();596 } else {597 key = testCaseExecution.getTest();598 }599 controlStatus = testCaseExecution.getControlStatus();600 control.put("value", 1);601 control.put("color", getColor(controlStatus));602 control.put("label", controlStatus);603 function.put("name", key);604 if (axisMap.containsKey(key)) {605 function = axisMap.get(key);606 if (function.has(controlStatus)) {607 int prec = function.getJSONObject(controlStatus).getInt("value");608 control.put("value", prec + 1);609 }610 }611 function.put(controlStatus, control);612 axisMap.put(key, function);613 }614 if (testCaseExecution.getStart() != 0) {615 if ((globalStartL == 0) || (globalStartL > testCaseExecution.getStart())) {616 globalStartL = testCaseExecution.getStart();617 globalStart = String.valueOf(new Date(testCaseExecution.getStart()));618 }619 }620 if (!testCaseExecution.getControlStatus().equalsIgnoreCase("PE") && testCaseExecution.getEnd() != 0) {621 if ((globalEndL == 0) || (globalEndL < testCaseExecution.getEnd())) {622 globalEndL = testCaseExecution.getEnd();623 globalEnd = String.valueOf(new Date(testCaseExecution.getEnd()));624 }625 }626 if (testCaseExecution.getControlStatus().equalsIgnoreCase("PE")) {627 globalStatus = "Pending...";628 }629 }630 Gson gson = new Gson();631 List<JSONObject> axisList = new ArrayList<>();632 for (Map.Entry<String, JSONObject> entry : axisMap.entrySet()) {633 String key = entry.getKey();634 JSONObject value = entry.getValue();635 axisList.add(value);636 }637 Collections.sort(axisList, new SortExecution());638 jsonResult.put("axis", axisList);639 jsonResult.put("tag", tag);640 jsonResult.put("globalEnd", gson.toJson(new Timestamp(globalEndL)).replace("\"", ""));641 jsonResult.put("globalStart", globalStart);642 jsonResult.put("globalStatus", globalStatus);643 return jsonResult;644 }645 class SortExecution implements Comparator<JSONObject> {646 // Used for sorting in ascending order of 647 // name value. 648 @Override649 public int compare(JSONObject a, JSONObject b) {650 if (a != null && b != null) {651 try {652 String aS = (String) a.get("name");653 String bS = (String) b.get("name");654 return aS.compareToIgnoreCase(bS);655 } catch (JSONException ex) {656 LOG.error("JSON Error Exception", ex);657 return 1;658 }659 } else {660 return 1;661 }662 }663 }664 private JSONObject generateStats(HttpServletRequest request, List<TestCaseExecution> testCaseExecutions, JSONObject statusFilter, JSONObject countryFilter, boolean splitStats) throws JSONException {665 JSONObject jsonResult = new JSONObject();666 boolean env = request.getParameter("env") != null || !splitStats;667 boolean country = request.getParameter("country") != null || !splitStats;668 boolean robotDecli = request.getParameter("robotDecli") != null || !splitStats;669 boolean app = request.getParameter("app") != null || !splitStats;670 HashMap<String, SummaryStatisticsDTO> statMap = new HashMap<String, SummaryStatisticsDTO>();671 for (TestCaseExecution testCaseExecution : testCaseExecutions) {672 String controlStatus = testCaseExecution.getControlStatus();673 if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {674 StringBuilder key = new StringBuilder();675 key.append((env) ? testCaseExecution.getEnvironment() : "");676 key.append("_");677 key.append((country) ? testCaseExecution.getCountry() : "");678 key.append("_");679 key.append((robotDecli) ? testCaseExecution.getRobotDecli() : "");680 key.append("_");681 key.append((app) ? testCaseExecution.getApplication() : "");682 SummaryStatisticsDTO stat = new SummaryStatisticsDTO();683 stat.setEnvironment(testCaseExecution.getEnvironment());684 stat.setCountry(testCaseExecution.getCountry());685 stat.setRobotDecli(testCaseExecution.getRobotDecli());686 stat.setApplication(testCaseExecution.getApplication());687 statMap.put(key.toString(), stat);688 }689 }690 jsonResult.put("contentTable", getStatByEnvCountryRobotDecli(testCaseExecutions, statMap, env, country, robotDecli, app, statusFilter, countryFilter, splitStats));691 return jsonResult;692 }693 private JSONObject generateBugStats(HttpServletRequest request, List<TestCaseExecution> testCaseExecutions, JSONObject statusFilter, JSONObject countryFilter) throws JSONException {694 JSONObject jsonResult = new JSONObject();695 SummaryStatisticsBugTrackerDTO stat = new SummaryStatisticsBugTrackerDTO();696 String bugsToReport = "KO,FA";697 stat.setNbExe(1);698 int totalBugReported = 0;699 int totalBugToReport = 0;700 int totalBugToReportReported = 0;701 int totalBugToClean = 0;702 HashMap<String, SummaryStatisticsBugTrackerDTO> statMap = new HashMap<>();703 for (TestCaseExecution testCaseExecution : testCaseExecutions) {704 String controlStatus = testCaseExecution.getControlStatus();705 if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {706 String key = "";707 if (bugsToReport.contains(testCaseExecution.getControlStatus())) {708 totalBugToReport++;709 }710 if ((testCaseExecution.getTestCaseObj() != null) && (testCaseExecution.getTestCaseObj().getBugID().length() > 0)) {711 JSONArray arr = testCaseExecution.getTestCaseObj().getBugID();712 for (int i = 0; i < arr.length(); i++) {713 JSONObject bug = (JSONObject) arr.get(i);714 key = bug.getString("id");715 stat = statMap.get(key);716 totalBugReported++;717 if (stat == null) {718 stat = new SummaryStatisticsBugTrackerDTO();719 stat.setNbExe(1);720 stat.setBugId(key);721 stat.setBugIdURL(testCaseExecution.getApplicationObj().getBugTrackerUrl().replace("%BUGID%", key));722 stat.setExeIdLastStatus(testCaseExecution.getControlStatus());723 stat.setExeIdFirst(testCaseExecution.getId());724 stat.setExeIdLast(testCaseExecution.getId());725 stat.setTestFirst(testCaseExecution.getTest());726 stat.setTestLast(testCaseExecution.getTest());727 stat.setTestCaseFirst(testCaseExecution.getTestCase());728 stat.setTestCaseLast(testCaseExecution.getTestCase());729 } else {730 stat.setNbExe(stat.getNbExe() + 1);731 stat.setExeIdLastStatus(testCaseExecution.getControlStatus());732 stat.setExeIdLast(testCaseExecution.getId());733 stat.setTestLast(testCaseExecution.getTest());734 stat.setTestCaseLast(testCaseExecution.getTestCase());735 }736 if (!(bugsToReport.contains(testCaseExecution.getControlStatus()))) {737 totalBugToClean++;738 stat.setToClean(true);739 } else {740 totalBugToReportReported++;741 }742 statMap.put(key, stat);743 }744 }745 }746 }747 Gson gson = new Gson();748 JSONArray dataArray = new JSONArray();749 for (String key : statMap.keySet()) {750 SummaryStatisticsBugTrackerDTO sumStats = statMap.get(key);751 dataArray.put(new JSONObject(gson.toJson(sumStats)));752 }753 jsonResult.put("BugTrackerStat", dataArray);754 jsonResult.put("totalBugToReport", totalBugToReport);755 jsonResult.put("totalBugToReportReported", totalBugToReportReported);756 jsonResult.put("totalBugReported", totalBugReported);757 jsonResult.put("totalBugToClean", totalBugToClean);758 return jsonResult;759 }760 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 {761 SummaryStatisticsDTO total = new SummaryStatisticsDTO();762 total.setEnvironment("Total");763 for (TestCaseExecution testCaseExecution : testCaseExecutions) {764 String controlStatus = testCaseExecution.getControlStatus();765 if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on") || !splitStats) {766 StringBuilder key = new StringBuilder();767 key.append((env) ? testCaseExecution.getEnvironment() : "");768 key.append("_");769 key.append((country) ? testCaseExecution.getCountry() : "");770 key.append("_");771 key.append((robotDecli) ? testCaseExecution.getRobotDecli() : "");772 key.append("_");773 key.append((app) ? testCaseExecution.getApplication() : "");774 if (statMap.containsKey(key.toString())) {775 statMap.get(key.toString()).updateStatisticByStatus(testCaseExecution.getControlStatus());776 }777 total.updateStatisticByStatus(testCaseExecution.getControlStatus());778 }779 }780 return extractSummaryData(statMap, total, splitStats);781 }782 private JSONObject extractSummaryData(HashMap<String, SummaryStatisticsDTO> summaryMap, SummaryStatisticsDTO total, boolean splitStats) throws JSONException {783 JSONObject extract = new JSONObject();784 Gson gson = new Gson();785 if (splitStats) {786 JSONArray dataArray = new JSONArray();787 //sort keys788 TreeMap<String, SummaryStatisticsDTO> sortedKeys = new TreeMap<String, SummaryStatisticsDTO>(summaryMap);789 for (String key : sortedKeys.keySet()) {790 SummaryStatisticsDTO sumStats = summaryMap.get(key);791 //percentage values792 sumStats.updatePercentageStatistics();793 dataArray.put(new JSONObject(gson.toJson(sumStats)));794 }795 extract.put("split", dataArray);796 }797 total.updatePercentageStatistics();798 extract.put("total", new JSONObject(gson.toJson(total)));799 return extract;800 }801 private String getColor(String controlStatus) {802 String color = null;803 if ("OK".equals(controlStatus)) {804 color = TestCaseExecution.CONTROLSTATUS_OK_COL;805 } else if ("KO".equals(controlStatus)) {806 color = TestCaseExecution.CONTROLSTATUS_KO_COL;807 } else if ("FA".equals(controlStatus)) {808 color = TestCaseExecution.CONTROLSTATUS_FA_COL;809 } else if ("CA".equals(controlStatus)) {810 color = TestCaseExecution.CONTROLSTATUS_CA_COL;811 } else if ("NA".equals(controlStatus)) {812 color = TestCaseExecution.CONTROLSTATUS_NA_COL;813 } else if ("NE".equals(controlStatus)) {814 color = TestCaseExecution.CONTROLSTATUS_NE_COL;815 } else if ("WE".equals(controlStatus)) {816 color = TestCaseExecution.CONTROLSTATUS_WE_COL;817 } else if ("PE".equals(controlStatus)) {818 color = TestCaseExecution.CONTROLSTATUS_PE_COL;819 } else if ("QU".equals(controlStatus)) {820 color = TestCaseExecution.CONTROLSTATUS_QU_COL;821 } else if ("QE".equals(controlStatus)) {822 color = TestCaseExecution.CONTROLSTATUS_QE_COL;823 } else {824 color = "#000000";825 }826 return color;827 }828 private JSONObject convertTagToJSONObject(Tag tag) throws JSONException {829 Gson gson = new Gson();830 JSONObject result = new JSONObject(gson.toJson(tag));831 return result;832 }833 private JSONObject generateLabelStats(ApplicationContext appContext, HttpServletRequest request, List<TestCaseExecution> testCaseExecutions, JSONObject statusFilter, JSONObject countryFilter, List<TestCaseLabel> testCaseLabelList) throws JSONException {834 JSONObject jsonResult = new JSONObject();835 labelService = appContext.getBean(LabelService.class);836 TreeNode node;837 JSONArray jsonArraySTICKER = new JSONArray();838 JSONArray jsonArrayREQUIREMENT = new JSONArray();839 AnswerList<Label> resp = labelService.readByVarious(new ArrayList<>(), new ArrayList<>(asList(Label.TYPE_STICKER, Label.TYPE_REQUIREMENT)));840 // Building Label inputlist with target layout841 if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {842 HashMap<Integer, TreeNode> inputList = new HashMap<>();843 for (Label label : (List<Label>) resp.getDataList()) {844 String text = "";845 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>";846 text += "<span style='margin-left: 5px; margin-right: 5px;' class=''>" + label.getDescription() + "</span>";847 text += "%STATUSBAR%";848 text += "%COUNTER1TEXT%";849 text += "%COUNTER1WITHCHILDTEXT%";850 text += "%NBNODESWITHCHILDTEXT%";851 // Specific pills852 //text += "<span class='badge badge-pill badge-secondary'>666</span>";853 // Standard pills854 List<String> attributList = new ArrayList<>();855 if (Label.TYPE_REQUIREMENT.equals(label.getType())) {856 if (!StringUtil.isNullOrEmpty(label.getReqType()) && !"unknown".equalsIgnoreCase(label.getReqType())) {857 attributList.add("<span class='badge badge-pill badge-secondary'>" + label.getReqType() + "</span>");858 }859 if (!StringUtil.isNullOrEmpty(label.getReqStatus()) && !"unknown".equalsIgnoreCase(label.getReqStatus())) {860 attributList.add("<span class='badge badge-pill badge-secondary'>" + label.getReqStatus() + "</span>");861 }862 if (!StringUtil.isNullOrEmpty(label.getReqCriticity()) && !"unknown".equalsIgnoreCase(label.getReqCriticity())) {863 attributList.add("<span class='badge badge-pill badge-secondary'>" + label.getReqCriticity() + "</span>");864 }865 }866 // Create Node.867 node = new TreeNode(label.getId() + "-" + label.getSystem() + "-" + label.getLabel(), label.getSystem(), label.getLabel(), label.getId(), label.getParentLabelID(), text, null, null, false);868 node.setCounter1(0);869 node.setCounter1WithChild(0);870 node.setTags(attributList);871 node.setType(label.getType());872 node.setCounter1Text("<span style='background-color:#000000' class='cnt1 badge badge-pill badge-secondary'>%COUNTER1%</span>");873 node.setCounter1WithChildText("<span class='cnt1WC badge badge-pill badge-secondary'>%COUNTER1WITHCHILD%</span>");874 node.setNbNodesText("<span style='background-color:#337ab7' class='nbNodes badge badge-pill badge-primary'>%NBNODESWITHCHILD%</span>");875 node.setLabelObj(label);876 inputList.put(node.getId(), node);877// LOG.debug("Label : " + node.getId() + " T : " + node);878 }879 HashMap<String, List<Integer>> testCaseWithLabel1 = new HashMap<>();880 for (TestCaseLabel label : (List<TestCaseLabel>) testCaseLabelList) {881// LOG.debug("TCLabel : " + label.getLabel() + " T : " + label.getTest() + " C : " + label.getTestcase() + " Type : " + label.getLabel().getType());882 if ((Label.TYPE_STICKER.equals(label.getLabel().getType()))883 || (Label.TYPE_REQUIREMENT.equals(label.getLabel().getType()))) {884 String key = label.getTest() + "_" + label.getTestcase();885 List<Integer> curLabelIdList = new ArrayList<>();886 if (testCaseWithLabel1.get(key) != null) {887 curLabelIdList = testCaseWithLabel1.get(key);888 curLabelIdList.add(label.getLabelId());889 testCaseWithLabel1.put(key, curLabelIdList);890// LOG.debug(" ADDED");891 } else {892 curLabelIdList.add(label.getLabelId());893 testCaseWithLabel1.put(key, curLabelIdList);894// LOG.debug(" ADDED");895 }896 }897 }898 /**899 * For All execution, get all labels from the test case and add if900 * those labels were in the list add the stats of executions into901 * the counters.902 */903 for (TestCaseExecution testCaseExecution : testCaseExecutions) {904// LOG.debug("Exe : " + testCaseExecution.getId() + " T : " + testCaseExecution.getTest() + " C : " + testCaseExecution.getTestCase());905 String controlStatus = testCaseExecution.getControlStatus();906 if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {907 //Get label for current test_testcase908 List<Integer> labelsForTestCase = testCaseWithLabel1.get(testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase());909 if (labelsForTestCase != null) {910 for (Integer integer : labelsForTestCase) {911// LOG.debug(" T : " + testCaseExecution.getTest() + " C : " + testCaseExecution.getTestCase() + " T : " + integer);912 TreeNode curTreenode = inputList.get(integer);913 if (curTreenode != null) {914// LOG.debug(" K : " + titi.getKey() + " C : " + titi.getCounter1());915 curTreenode.setCounter1(curTreenode.getCounter1() + 1);916 curTreenode.setCounter1WithChild(curTreenode.getCounter1WithChild() + 1);917 switch (testCaseExecution.getControlStatus()) {918 case TestCaseExecution.CONTROLSTATUS_OK:919 curTreenode.setNbOK(curTreenode.getNbOK() + 1);920 break;921 case TestCaseExecution.CONTROLSTATUS_KO:922 curTreenode.setNbKO(curTreenode.getNbKO() + 1);923 break;924 case TestCaseExecution.CONTROLSTATUS_FA:925 curTreenode.setNbFA(curTreenode.getNbFA() + 1);926 break;927 case TestCaseExecution.CONTROLSTATUS_NA:928 curTreenode.setNbNA(curTreenode.getNbNA() + 1);929 break;930 case TestCaseExecution.CONTROLSTATUS_NE:931 curTreenode.setNbNE(curTreenode.getNbNE() + 1);932 break;933 case TestCaseExecution.CONTROLSTATUS_WE:934 curTreenode.setNbWE(curTreenode.getNbWE() + 1);935 break;936 case TestCaseExecution.CONTROLSTATUS_PE:937 curTreenode.setNbPE(curTreenode.getNbPE() + 1);938 break;939 case TestCaseExecution.CONTROLSTATUS_QE:940 curTreenode.setNbQE(curTreenode.getNbQE() + 1);941 break;942 case TestCaseExecution.CONTROLSTATUS_QU:943 curTreenode.setNbQU(curTreenode.getNbQU() + 1);944 break;945 case TestCaseExecution.CONTROLSTATUS_CA:946 curTreenode.setNbCA(curTreenode.getNbCA() + 1);947 break;948 }949 inputList.put(curTreenode.getId(), curTreenode);950 }951 }952 }953 }954 }955 // Build Tres.956 List<TreeNode> finalList;957 jsonArraySTICKER = new JSONArray();958 jsonArrayREQUIREMENT = new JSONArray();959 finalList = labelService.hierarchyConstructor(inputList);960 for (TreeNode treeNode : finalList) {961 if (treeNode.getCounter1WithChild() > 0) {962 if (Label.TYPE_STICKER.equals(treeNode.getType())) {963 jsonArraySTICKER.put(treeNode.toJson());964 } else {965 jsonArrayREQUIREMENT.put(treeNode.toJson());966 }967 }968 }969 }970 if ((jsonArraySTICKER.length() <= 0) && (jsonArrayREQUIREMENT.length() <= 0)) {971 return null;972 }973 jsonResult.put("labelTreeSTICKER", jsonArraySTICKER);974 jsonResult.put("labelTreeREQUIREMENT", jsonArrayREQUIREMENT);...

Full Screen

Full Screen

Source:ILabelService.java Github

copy

Full Screen

...21import java.util.HashMap;22import java.util.List;23import java.util.Map;24import org.cerberus.crud.entity.Label;25import org.cerberus.dto.TreeNode;26import org.cerberus.exception.CerberusException;27import org.cerberus.util.answer.Answer;28import org.cerberus.util.answer.AnswerItem;29import org.cerberus.util.answer.AnswerList;30/**31 *32 * @author bcivel33 */34public interface ILabelService {35 /**36 *37 * @param id38 * @return39 */40 AnswerItem<Label> readByKey(Integer id);41 /**42 *43 * @return44 */45 AnswerList<Label> readAll();46 /**47 * Reading from database all lines of Parent / Child Labels.48 *49 * @return50 */51 AnswerList<Label> readAllLinks();52 /**53 * Add child element into list of Label Id.54 *55 * @param labelIdList56 * @return57 */58 List<Integer> enrichWithChild(List<Integer> labelIdList);59 /**60 *61 * @param system62 * @return63 */64 AnswerList<Label> readBySystem(List<String> system);65 /**66 *67 * @param system68 * @param type69 * @return70 */71 AnswerList<Label> readByVarious(List<String> system, List<String> type);72 /**73 *74 * @param startPosition75 * @param length76 * @param columnName77 * @param sort78 * @param searchParameter79 * @param individualSearch80 * @return81 */82 AnswerList<Label> readByCriteria(int startPosition, int length, String columnName, String sort, String searchParameter, Map<String, List<String>> individualSearch);83 /**84 *85 * @param system86 * @param strictSystemFilter87 * @param type88 * @param startPosition89 * @param length90 * @param columnName91 * @param sort92 * @param searchParameter93 * @param individualSearch94 * @return95 */96 AnswerList<Label> readByVariousByCriteria(List<String> system, boolean strictSystemFilter, List<String> type, int startPosition, int length, String columnName, String sort, String searchParameter, Map<String, List<String>> individualSearch);97 /**98 *99 * @param id100 * @return true is label exist or false is label does not exist in database.101 */102 boolean exist(Integer id);103 /**104 *105 * @param object106 * @return107 */108 Answer create(Label object);109 /**110 *111 * @param object112 * @return113 */114 Answer delete(Label object);115 /**116 *117 * @param object118 * @return119 */120 Answer update(Label object);121 /**122 *123 * @param answerItem124 * @return125 * @throws CerberusException126 */127 Label convert(AnswerItem<Label> answerItem) throws CerberusException;128 /**129 *130 * @param answerList131 * @return132 * @throws CerberusException133 */134 List<Label> convert(AnswerList<Label> answerList) throws CerberusException;135 /**136 *137 * @param answer138 * @throws CerberusException139 */140 void convert(Answer answer) throws CerberusException;141 /**142 *143 * @param system144 * @param searchParameter145 * @param individualSearch146 * @param columnName147 * @return148 */149 public AnswerList<String> readDistinctValuesByCriteria(String system, String searchParameter, Map<String, List<String>> individualSearch, String columnName);150 /**151 *152 * @param inputList153 * @return154 */155 public List<TreeNode> hierarchyConstructor(HashMap<Integer, TreeNode> inputList);156}...

Full Screen

Full Screen

TreeNode

Using AI Code Generation

copy

Full Screen

1import org.cerberus.dto.TreeNode;2public class 3 {3 public static void main(String[] args) {4 TreeNode root = new TreeNode(1);5 root.left = new TreeNode(2);6 root.right = new TreeNode(3);7 root.left.left = new TreeNode(4);8 root.left.right = new TreeNode(5);9 root.right.left = new TreeNode(6);10 root.right.right = new TreeNode(7);11 System.out.println("Height of tree is : " + height(root));12 }13 static int height(TreeNode root) {14 if (root == null) {15 return 0;16 } else {17 int lheight = height(root.left);18 int rheight = height(root.right);19 if (lheight > rheight) {20 return (lheight + 1);21 } else {22 return (rheight + 1);23 }24 }25 }26}27Java Program to Find Height of a Tree Using BFS (Iterative Method)28Java Program to Find Height of a Tree Using BFS (Recursive Method)29Java Program to Find Height of a Tree Using DFS (Iterative Method)30Java Program to Find Height of a Tree Using DFS (Recursive Method)31Java Program to Find Height of a Tree Using Postorder Traversal (Iterative Method)32Java Program to Find Height of a Tree Using Postorder Traversal (Recursive Method)33Java Program to Find Height of a Tree Using Preorder Traversal (Iterative Method)34Java Program to Find Height of a Tree Using Preorder Traversal (Recursive Method)35Java Program to Find Height of a Tree Using Inorder Traversal (Iterative Method)36Java Program to Find Height of a Tree Using Inorder Traversal (Recursive Method)

Full Screen

Full Screen

TreeNode

Using AI Code Generation

copy

Full Screen

1import org.cerberus.dto.TreeNode;2public class 3 {3 public static void main(String[] args) {4 TreeNode root = new TreeNode(1);5 root.left = new TreeNode(2);6 root.right = new TreeNode(3);7 root.left.left = new TreeNode(4);8 root.left.right = new TreeNode(5);9 root.right.left = new TreeNode(6);10 root.right.right = new TreeNode(7);11 root.left.left.left = new TreeNode(8);12 root.left.left.right = new TreeNode(9);13 root.right.right.left = new TreeNode(10);14 root.right.right.right = new TreeNode(11);15 System.out.println("PreOrder Traversal");16 preOrder(root);17 System.out.println("18InOrder Traversal");19 inOrder(root);20 System.out.println("21PostOrder Traversal");22 postOrder(root);23 }24 public static void preOrder(TreeNode root){25 if(root == null)26 return;27 System.out.print(root.val+" ");28 preOrder(root.left);29 preOrder(root.right);30 }31 public static void inOrder(TreeNode root){32 if(root == null)33 return;34 inOrder(root.left);35 System.out.print(root.val+" ");36 inOrder(root.right);37 }38 public static void postOrder(TreeNode root){39 if(root == null)40 return;41 postOrder(root.left);42 postOrder(root.right);43 System.out.print(root.val+" ");44 }45}

Full Screen

Full Screen

TreeNode

Using AI Code Generation

copy

Full Screen

1import org.cerberus.dto.TreeNode;2import org.cerberus.dto.TreeNodeFactory;3import org.cerberus.dto.TreeNodeType;4public class Main {5 public static void main(String[] args) {6 TreeNodeFactory factory = new TreeNodeFactory();7 TreeNode root = factory.createTreeNode(TreeNodeType.ROOT);8 TreeNode node1 = factory.createTreeNode(TreeNodeType.NODE);9 TreeNode node2 = factory.createTreeNode(TreeNodeType.NODE);10 TreeNode node3 = factory.createTreeNode(TreeNodeType.NODE);11 TreeNode node4 = factory.createTreeNode(TreeNodeType.NODE);12 TreeNode node5 = factory.createTreeNode(TreeNodeType.NODE);13 TreeNode node6 = factory.createTreeNode(TreeNodeType.NODE);14 TreeNode node7 = factory.createTreeNode(TreeNodeType.NODE);15 TreeNode node8 = factory.createTreeNode(TreeNodeType.NODE);16 TreeNode node9 = factory.createTreeNode(TreeNodeType.NODE);17 TreeNode node10 = factory.createTreeNode(TreeNodeType.NODE);18 TreeNode node11 = factory.createTreeNode(TreeNodeType.NODE);19 TreeNode node12 = factory.createTreeNode(TreeNodeType.NODE);20 TreeNode node13 = factory.createTreeNode(TreeNodeType.NODE);21 TreeNode node14 = factory.createTreeNode(TreeNodeType.NODE);22 TreeNode node15 = factory.createTreeNode(TreeNodeType.NODE);23 TreeNode node16 = factory.createTreeNode(TreeNodeType.NODE);24 TreeNode node17 = factory.createTreeNode(TreeNodeType.NODE);25 TreeNode node18 = factory.createTreeNode(TreeNodeType.NODE);

Full Screen

Full Screen

TreeNode

Using AI Code Generation

copy

Full Screen

1import org.cerberus.dto.*;2import java.util.*;3public class 3 {4 public static void main(String[] args) {5 TreeNode<String> root = new TreeNode<>("root");6 TreeNode<String> child1 = new TreeNode<>("child1");7 TreeNode<String> child2 = new TreeNode<>("child2");8 TreeNode<String> child3 = new TreeNode<>("child3");9 TreeNode<String> child4 = new TreeNode<>("child4");10 TreeNode<String> child5 = new TreeNode<>("child5");11 TreeNode<String> child6 = new TreeNode<>("child6");12 root.addChild(child1);13 root.addChild(child2);14 root.addChild(child3);15 child3.addChild(child4);16 child3.addChild(child5);17 child3.addChild(child6);18 System.out.println("Tree:");19 System.out.println(root);20 System.out.println("Depth: " + root.getDepth());21 System.out.println("Children of root:");22 for (TreeNode<String> child : root.getChildren()) {23 System.out.println(child);24 }25 System.out.println("Children of child3:");26 for (TreeNode<String> child : child3.getChildren()) {27 System.out.println(child);28 }29 System.out.println("Children of child4:");30 for (TreeNode<String> child : child4.getChildren()) {31 System.out.println(child);32 }33 }34}

Full Screen

Full Screen

TreeNode

Using AI Code Generation

copy

Full Screen

1import org.cerberus.dto.TreeNode;2public class 3 {3public static void main(String[] args) {4TreeNode root = new TreeNode(1, "root");5TreeNode child1 = new TreeNode(2, "child1");6TreeNode child2 = new TreeNode(3, "child2");7TreeNode child3 = new TreeNode(4, "child3");8root.addChild(child1);9root.addChild(child2);10root.addChild(child3);11TreeNode child11 = new TreeNode(5, "child11");12TreeNode child12 = new TreeNode(6, "child12");13child1.addChild(child11);14child1.addChild(child12);15TreeNode child21 = new TreeNode(7, "child21");16TreeNode child22 = new TreeNode(8, "child22");17child2.addChild(child21);18child2.addChild(child22);19TreeNode child31 = new TreeNode(9, "child31");20TreeNode child32 = new TreeNode(10, "child32");21child3.addChild(child31);22child3.addChild(child32);23TreeNode child111 = new TreeNode(11, "child111");24TreeNode child112 = new TreeNode(12, "child112");25child11.addChild(child111);26child11.addChild(child112);27TreeNode child121 = new TreeNode(13, "child121");28TreeNode child122 = new TreeNode(14, "child122");29child12.addChild(child121);30child12.addChild(child122);31TreeNode child211 = new TreeNode(15, "child211");32TreeNode child212 = new TreeNode(16, "child212");33child21.addChild(child211);34child21.addChild(child212);35TreeNode child221 = new TreeNode(17, "child221");36TreeNode child222 = new TreeNode(18, "child222");37child22.addChild(child221);38child22.addChild(child222);39TreeNode child311 = new TreeNode(19, "child311");40TreeNode child312 = new TreeNode(20, "child312");41child31.addChild(child311);42child31.addChild(child312);43TreeNode child321 = new TreeNode(21, "child321");44TreeNode child322 = new TreeNode(22, "child322");45child32.addChild(child321);46child32.addChild(child322);47System.out.println(root);48}49}

Full Screen

Full Screen

TreeNode

Using AI Code Generation

copy

Full Screen

1import org.cerberus.dto.TreeNode;2{3 public static void main(String[] args)4 {5 TreeNode root = new TreeNode("A");6 TreeNode leaf1 = new TreeNode("B");7 TreeNode leaf2 = new TreeNode("C");8 TreeNode leaf3 = new TreeNode("D");9 TreeNode leaf4 = new TreeNode("E");10 TreeNode leaf5 = new TreeNode("F");11 TreeNode leaf6 = new TreeNode("G");12 TreeNode leaf7 = new TreeNode("H");13 TreeNode leaf8 = new TreeNode("I");14 TreeNode leaf9 = new TreeNode("J");15 TreeNode leaf10 = new TreeNode("K");16 TreeNode leaf11 = new TreeNode("L");17 TreeNode leaf12 = new TreeNode("M");18 TreeNode leaf13 = new TreeNode("N");19 TreeNode leaf14 = new TreeNode("O");20 TreeNode leaf15 = new TreeNode("P");21 TreeNode leaf16 = new TreeNode("Q");22 TreeNode leaf17 = new TreeNode("R");23 TreeNode leaf18 = new TreeNode("S");24 TreeNode leaf19 = new TreeNode("T");25 TreeNode leaf20 = new TreeNode("U");26 TreeNode leaf21 = new TreeNode("V");27 TreeNode leaf22 = new TreeNode("W");28 TreeNode leaf23 = new TreeNode("X");29 TreeNode leaf24 = new TreeNode("Y");30 TreeNode leaf25 = new TreeNode("Z");31 root.addChild(leaf1);32 root.addChild(leaf2);33 root.addChild(leaf3);34 root.addChild(leaf4);35 root.addChild(leaf5);36 root.addChild(leaf6);37 root.addChild(leaf7);38 root.addChild(leaf8);39 root.addChild(leaf9);40 root.addChild(leaf10);41 root.addChild(leaf11);42 root.addChild(leaf12);43 root.addChild(leaf13);44 root.addChild(leaf14);45 root.addChild(leaf15);46 root.addChild(leaf16);47 root.addChild(leaf17);48 root.addChild(leaf18);49 root.addChild(leaf19);50 root.addChild(leaf20);51 root.addChild(leaf21);52 root.addChild(leaf22);53 root.addChild(leaf23);54 root.addChild(leaf24);55 root.addChild(leaf25);56 leaf1.addChild(new TreeNode("1"));57 leaf1.addChild(new TreeNode("2"));58 leaf1.addChild(new TreeNode("3"));59 leaf1.addChild(new TreeNode("4"));

Full Screen

Full Screen

TreeNode

Using AI Code Generation

copy

Full Screen

1package com.cerberus.test;2import org.cerberus.dto.TreeNode;3public class Test {4public static void main(String[] args) {5TreeNode node = new TreeNode();6node.setId(1);7node.setName("root");8node.setParentId(0);9System.out.println(node);10}11}

Full Screen

Full Screen

TreeNode

Using AI Code Generation

copy

Full Screen

1package org.cerberus.dto;2import java.util.*;3public class TreeNode{4 private String name = null;5 private String value = null;6 private List<TreeNode> children = null;7 public TreeNode(String name, String value){8 this.name = name;9 this.value = value;10 children = new ArrayList<TreeNode>();11 }12 public TreeNode(String name){13 this(name, null);14 }15 public String getName(){16 return name;17 }18 public String getValue(){19 return value;20 }21 public void setValue(String value){22 this.value = value;23 }24 public void addChild(TreeNode child){25 children.add(child);26 }27 public void removeChild(TreeNode child){28 children.remove(child);29 }30 public List<TreeNode> getChildren(){31 return children;32 }33}34package org.cerberus.dto;35public class Main{36 public static void main(String[] args){37 TreeNode root = new TreeNode("root", "root");38 TreeNode child1 = new TreeNode("child1", "child1");39 TreeNode child2 = new TreeNode("child2", "child2");40 TreeNode child1_1 = new TreeNode("child1_1", "child1_1");41 TreeNode child1_2 = new TreeNode("child1_2", "child1_2");42 TreeNode child2_1 = new TreeNode("child2_1", "child2_1");43 child1.addChild(child1_1);44 child1.addChild(child1_2);45 child2.addChild(child2_1);46 root.addChild(child1);47 root.addChild(child2);48 for(TreeNode child :

Full Screen

Full Screen

TreeNode

Using AI Code Generation

copy

Full Screen

1package org.cerberus.dto;2public class TreeNode {3 public String data;4 public TreeNode left;5 public TreeNode right;6 public TreeNode(String data){7 this.data = data;8 left = null;9 right = null;10 }11 public void insert(String value){12 if(value.compareTo(data) <= 0){13 if(left == null){14 left = new TreeNode(value);15 }else{16 left.insert(value);17 }18 }else{19 if(right == null){20 right = new TreeNode(value);21 }else{22 right.insert(value);23 }24 }25 }26 public boolean contains(String value){27 if(value.equals(data)){28 return true;29 }else if(value.compareTo(data) < 0){30 if(left == null){31 return false;32 }else{33 return left.contains(value);34 }35 }else{36 if(right == null){37 return false;38 }else{39 return right.contains(value);40 }41 }42 }43 public void printInOrder(){44 if(left != null){45 left.printInOrder();46 }47 System.out.println(data);48 if(right != null){49 right.printInOrder();50 }51 }52}53package org.cerberus.dto;54public class Tree {55 public TreeNode root;56 public void insert(String value){57 if(root == null){58 root = new TreeNode(value);59 }else{60 root.insert(value);61 }62 }63 public boolean contains(String value){64 if(root == null){65 return false;66 }else{67 return root.contains(value);68 }69 }70 public void printInOrder(){71 if(root != null){72 root.printInOrder();73 }74 }75}76package org.cerberus.dto;77public class TreeApp {78 public static void main(String[] args){79 Tree t = new Tree();80 t.insert("mohamed");81 t.insert("ahmed");82 t.insert("

Full Screen

Full Screen

TreeNode

Using AI Code Generation

copy

Full Screen

1import org.cerberus.dto.TreeNode;2{3 public static void main(String[] args)4 {5 TreeNode root = new TreeNode("root");6 TreeNode left = new TreeNode("left");7 TreeNode right = new TreeNode("right");8 root.setLeft(left);9 root.setRight(right);10 System.out.println(root);11 }12}13package org.cerberus.dto;14{15 private String label;16 private TreeNode left;17 private TreeNode right;18 public TreeNode(String label)19 {20 this.label = label;21 }22 public void setLeft(TreeNode left)23 {24 this.left = left;25 }26 public void setRight(TreeNode right)27 {28 this.right = right;29 }30 public String toString()31 {32 return "Tree: " + label;33 }34}

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