@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());
    }
  }
Exemplo n.º 2
0
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  final void processRequest(final HttpServletRequest request, final HttpServletResponse response)
      throws ServletException, IOException, CerberusException, JSONException {
    JSONObject jsonResponse = new JSONObject();
    ApplicationContext appContext =
        WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    Answer ans = new Answer();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    ans.setResultMessage(msg);

    response.setContentType("text/html;charset=UTF-8");
    String charset = request.getCharacterEncoding();

    // Parameter that are already controled by GUI (no need to decode) --> We SECURE them
    // Parameter that needs to be secured --> We SECURE+DECODE them
    String testbattery =
        ParameterParserUtil.parseStringParamAndDecodeAndSanitize(
            URLDecoder.decode(request.getParameter("testBattery"), "UTF-8"), null, charset);
    String description =
        ParameterParserUtil.parseStringParamAndDecodeAndSanitize(
            URLDecoder.decode(request.getParameter("description"), "UTF-8"), null, charset);
    // Parameter that we cannot secure as we need the html --> We DECODE them
    String batteryContent =
        ParameterParserUtil.parseStringParam(request.getParameter("batteryContent"), null);
    Answer finalAnswer = new Answer();
    if (StringUtil.isNullOrEmpty(testbattery)) {
      msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
      msg.setDescription(
          msg.getDescription()
              .replace("%ITEM%", "Battery")
              .replace("%OPERATION%", "Create")
              .replace("%REASON%", "Battery name is missing!"));
      finalAnswer.setResultMessage(msg);
    } else {
      ITestBatteryService testBatteryService = appContext.getBean(ITestBatteryService.class);
      IFactoryTestBattery factoryTestBattery = appContext.getBean(IFactoryTestBattery.class);

      TestBattery te = factoryTestBattery.create(0, testbattery, description);
      finalAnswer = testBatteryService.create(te);

      if (finalAnswer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {

        /** Adding Log entry. */
        ILogEventService logEventService = appContext.getBean(LogEventService.class);
        logEventService.createPrivateCalls(
            "/CreateTestBattery", "CREATE", "Create Test Battery : " + testbattery, request);

        if (batteryContent != null) {

          JSONArray batteriesContent = new JSONArray(batteryContent);
          ITestBatteryContentService testBatteryContentService =
              appContext.getBean(ITestBatteryContentService.class);
          IFactoryTestBatteryContent factoryTestBatteryContent =
              appContext.getBean(IFactoryTestBatteryContent.class);
          ArrayList<TestBatteryContent> arr = new ArrayList<>();
          for (int i = 0; i < batteriesContent.length(); i++) {
            JSONObject bat = batteriesContent.getJSONObject(i);
            TestBatteryContent co =
                factoryTestBatteryContent.create(
                    0, bat.getString("test"), bat.getString("testCase"), testbattery);
            arr.add(co);
          }

          finalAnswer =
              testBatteryContentService.compareListAndUpdateInsertDeleteElements(
                  te.getTestbattery(), arr);
          if (finalAnswer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
            /** Adding Log entry. */
            logEventService.createPrivateCalls(
                "/CreateTestBattery",
                "Create",
                "Create Test battery : " + te.getTestbattery(),
                request);
          }
        }
      }
    }

    /** Formating and returning the json result. */
    jsonResponse.put("messageType", finalAnswer.getResultMessage().getMessage().getCodeString());
    jsonResponse.put("message", finalAnswer.getResultMessage().getDescription());

    response.getWriter().print(jsonResponse);
    response.getWriter().flush();
  }
Exemplo n.º 3
0
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    ApplicationContext appContext =
        WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    testBatteryService = appContext.getBean(ITestBatteryService.class);
    factoryTestBatteryContent = appContext.getBean(IFactoryTestBatteryContent.class);
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);

    String jsonResponse = "-1";
    String testbattery = policy.sanitize(request.getParameter("TestBattery"));
    String testBatteryName;

    String[] testcasesselected = request.getParameterValues("testcaseselected");

    if (testcasesselected == null) {
      response.setStatus(404);
      jsonResponse = "Please select at least one testcase !";
    } else {
      try {
        testBatteryName =
            testBatteryService.findTestBatteryByKey(Integer.parseInt(testbattery)).getTestbattery();
      } catch (CerberusException ex) {
        MyLogger.log(AddTestBatteryContent.class.getName(), Level.DEBUG, ex.getMessage());
        testBatteryName = null;
      }

      if (testBatteryName != null) {
        String test;
        String testcase;

        // response.setContentType("text/html");
        for (String testcaseselect : testcasesselected) {
          test =
              policy.sanitize(
                  URLDecoder.decode(
                      testcaseselect.split("Test=")[1].split("&TestCase=")[0], "UTF-8"));
          testcase =
              policy.sanitize(URLDecoder.decode(testcaseselect.split("&TestCase=")[1], "UTF-8"));
          try {

            testBatteryService.createTestBatteryContent(
                factoryTestBatteryContent.create(null, test, testcase, testBatteryName));
            List<TestBatteryContent> batteryContent =
                testBatteryService.findTestBatteryContentsByCriteria(
                    null, testBatteryName, test, testcase);

            if (batteryContent != null && batteryContent.size() == 1) {
              String newTestBatteryContentId =
                  String.valueOf(
                      testBatteryService
                          .findTestBatteryContentsByCriteria(null, testBatteryName, test, testcase)
                          .get(0)
                          .getTestbatterycontentID());
              jsonResponse = newTestBatteryContentId;
            }
          } catch (CerberusException ex) {
            MyLogger.log(AddTestBatteryContent.class.getName(), Level.DEBUG, ex.getMessage());
            jsonResponse = "-1";
          }
        }
      }
    }
    response.getWriter().append(jsonResponse).close();
  }