@Override protected void doGet( HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException { ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext()); ITestCaseService testService = appContext.getBean(ITestCaseService.class); PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS); String test = policy.sanitize(httpServletRequest.getParameter("test")); JSONArray array = new JSONArray(); JSONObject jsonObject = new JSONObject(); for (TCase testcase : testService.findTestCaseByTest(test)) { array.put(testcase.getTestCase()); } try { jsonObject.put("testcasesList", array); httpServletResponse.setContentType("application/json"); httpServletResponse.getWriter().print(jsonObject.toString()); } catch (JSONException exception) { MyLogger.log(GetTestCaseList.class.getName(), Level.WARN, exception.toString()); } }
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext()); ITestCaseService testService = appContext.getBean(ITestCaseService.class); IInvariantService invariantService = appContext.getBean(IInvariantService.class); ICampaignService campaignService = appContext.getBean(ICampaignService.class); ITestBatteryService testBatteryService = appContext.getBean(ITestBatteryService.class); IBuildRevisionInvariantService buildRevisionInvariantService = appContext.getBean(IBuildRevisionInvariantService.class); String system = req.getParameter("system"); JSONArray jsonResponse = new JSONArray(); String[] columns = { "test", "project", "ticket", "bugID", "origine", "creator", "application", "priority", "status", "group", "activePROD", "activeUAT", "activeQA", "tcActive" }; try { JSONObject data; for (String s : columns) { data = new JSONObject(); data.put("data", new JSONArray(testService.findUniqueDataOfColumn(s))); data.put("name", s); jsonResponse.put(data); } JSONArray build = new JSONArray(); for (BuildRevisionInvariant bri : buildRevisionInvariantService.convert( buildRevisionInvariantService.readBySystemLevel(system, 1))) { build.put(bri.getVersionName()); } data = new JSONObject(); data.put("data", build); data.put("name", "fromBuild"); jsonResponse.put(data); data = new JSONObject(); data.put("data", build); data.put("name", "toBuild"); jsonResponse.put(data); data = new JSONObject(); data.put("data", build); data.put("name", "targetBuild"); jsonResponse.put(data); JSONArray revision = new JSONArray(); for (BuildRevisionInvariant bri : buildRevisionInvariantService.convert( buildRevisionInvariantService.readBySystemLevel(system, 2))) { revision.put(bri.getVersionName()); } data = new JSONObject(); data.put("data", revision); data.put("name", "fromRev"); jsonResponse.put(data); data = new JSONObject(); data.put("data", revision); data.put("name", "toRev"); jsonResponse.put(data); data = new JSONObject(); data.put("data", revision); data.put("name", "targetRev"); jsonResponse.put(data); JSONArray env = new JSONArray(); AnswerList answer = invariantService.readByIdname( "ENVIRONMENT"); // TODO: handle if the response does not turn ok for (Invariant i : (List<Invariant>) answer.getDataList()) { env.put(i.getValue()); } data = new JSONObject(); data.put("data", env); data.put("name", "executionEnv"); jsonResponse.put(data); JSONArray country = new JSONArray(); answer = invariantService.readByIdname("COUNTRY"); // TODO: handle if the response does not turn ok for (Invariant i : (List<Invariant>) answer.getDataList()) { country.put(i.getValue()); } data = new JSONObject(); data.put("data", country); data.put("name", "executionCountry"); jsonResponse.put(data); JSONArray campaign = new JSONArray(); for (Campaign c : campaignService.findAll()) { campaign.put(c.getCampaign()); } data = new JSONObject(); data.put("data", campaign); data.put("name", "campaign"); jsonResponse.put(data); JSONArray battery = new JSONArray(); for (TestBattery c : testBatteryService.findAll()) { battery.put(c.getTestbattery()); } data = new JSONObject(); data.put("data", battery); data.put("name", "testBattery"); jsonResponse.put(data); resp.setContentType("application/json"); resp.getWriter().print(jsonResponse.toString()); } catch (JSONException e) { MyLogger.log(GetDataForTestCaseSearch.class.getName(), Level.FATAL, "" + e); resp.setContentType("text/html"); resp.getWriter().print(e.getMessage()); } catch (CerberusException e) { MyLogger.log(GetDataForTestCaseSearch.class.getName(), Level.FATAL, "" + e); resp.setContentType("text/html"); resp.getWriter().print(e.getMessage()); } }