Exemplo n.º 1
0
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    ApplicationContext appContext =
        WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    campaignService = appContext.getBean(ICampaignService.class);
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);

    String pk = policy.sanitize(request.getParameter("id"));
    String name = policy.sanitize(request.getParameter("columnName"));
    String value = policy.sanitize(request.getParameter("value"));

    response.setContentType("text/html");
    try {
      CampaignParameter campaignParameter =
          campaignService.findCampaignParameterByKey(Integer.parseInt(pk));
      if (name != null && "Value".equals(name.trim())) {
        campaignParameter.setValue(value);
      } else {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NOT_IMPLEMEMTED));
      }
      campaignService.updateCampaignParameter(campaignParameter);
      response.getWriter().print(value);
    } catch (CerberusException ex) {
      response.getWriter().print(ex.getMessageError().getDescription());
    }
  }
  @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());
    }
  }