@Override public Answer updateSystemsByUser(User user, List<UserSystem> newGroups) { Answer a = new Answer(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK)); AnswerList an = this.readByUser(user.getLogin()); if (an.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) { List<UserSystem> oldGroups = an.getDataList(); // delete if don't exist in new for (UserSystem old : oldGroups) { if (!newGroups.contains(old)) { Answer del = userSystemDAO.remove(old); if (!del.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) { a = del; } } } // insert if don't exist in old for (UserSystem group : newGroups) { if (!oldGroups.contains(group)) { Answer add = userSystemDAO.create(group); if (!add.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) { a = add; } } } } return a; }
@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()); } }