protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException, CerberusException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    ApplicationContext appContext =
        WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    DatabaseSpring database = appContext.getBean(DatabaseSpring.class);
    ITestCaseCountryPropertiesService propertiesService =
        appContext.getBean(ITestCaseCountryPropertiesService.class);
    IFactoryTestCaseCountryProperties propertiesFactory =
        appContext.getBean(IFactoryTestCaseCountryProperties.class);

    Connection connection = database.connect();
    try {
      Statement stmt4 = connection.createStatement();
      try {

        /*
         * PROPERTIES
         */
        /*
         * Get Test, TestCase and Country to update
         */
        String test_testcase_no_format_prop = this.getStringParameter("testcase_hidden", request);
        this.getStringParameter("Test", request);
        this.getStringParameter("TestCase", request);
        String country_list_no_format = this.getStringParameter("CountryList", request);

        /*
         * Properties Insert/Update
         */
        String[] testcase_properties_delete = request.getParameterValues("properties_delete");
        // this.getStringTable("old_property_hidden", request);
        // String[] testcase_properties_countr_list = this.getStringTable(
        // "old_property_hidden", request);
        String[] testcase_properties_countr_list =
            request.getParameterValues("old_property_hidden");
        if (testcase_properties_countr_list == null) {
          testcase_properties_countr_list = new String[0];
        }
        String[] testcase_properties_propertyrow = request.getParameterValues("property_hidden");
        String[] testcase_properties_property = this.getStringTable("properties_property", request);
        String[] testcase_properties_description =
            this.getStringTable("properties_description", request);
        String[] testcase_properties_country = this.getStringTable("properties_country", request);
        String[] testcase_properties_type = this.getStringTable("properties_type", request);
        String[] testcase_properties_value = this.getStringTable("properties_value", request);
        String[] testcase_properties_value2 = this.getStringTable("properties_value2", request);
        // String[] testcase_properties_value =
        //         request.getParameterValues("properties_type");

        String[] testcase_properties_length = this.getStringTable("properties_length", request);
        String[] testcase_properties_rowlimit = this.getStringTable("properties_rowlimit", request);
        String[] testcase_properties_retrynb = this.getStringTable("properties_retrynb", request);
        String[] testcase_properties_retryperiod =
            this.getStringTable("properties_retryperiod", request);
        String[] testcase_properties_nature = this.getStringTable("properties_nature", request);
        String[] testcase_properties_database = this.getStringTable("properties_dtb", request);

        /*
         * 0 : Test 1 : TestCase
         */
        String[] test_testcase_format_prop = new String[] {"", ""};
        test_testcase_format_prop = test_testcase_no_format_prop.split(" - ");
        String[] country_list = country_list_no_format.split(" - ");

        /*
         * Properties
         */
        List<String[]> testcase_properties_propertycountry = new ArrayList<String[]>();
        testcase_properties_propertycountry.add(testcase_properties_country);

        List<String[]> testcase_properties_info = new ArrayList<String[]>();
        testcase_properties_info.add(testcase_properties_propertyrow);
        testcase_properties_info.add(testcase_properties_property);
        testcase_properties_info.add(testcase_properties_type);
        testcase_properties_info.add(testcase_properties_value);
        testcase_properties_info.add(testcase_properties_value2);
        testcase_properties_info.add(testcase_properties_length);
        testcase_properties_info.add(testcase_properties_rowlimit);
        testcase_properties_info.add(testcase_properties_retrynb);
        testcase_properties_info.add(testcase_properties_retryperiod);
        testcase_properties_info.add(testcase_properties_nature);
        testcase_properties_info.add(testcase_properties_database);

        List<String[]> countr_list = new ArrayList<String[]>();
        countr_list.add(testcase_properties_countr_list);

        // To Delete the country unselected
        Collection<String> listOne = new ArrayList<String>();
        Collection<String> listTwo = new ArrayList<String>();
        Collection<String> similar = new ArrayList<String>();
        Collection<String> different = new ArrayList<String>();

        listOne.addAll(Arrays.asList(testcase_properties_countr_list));
        listTwo.addAll(Arrays.asList(testcase_properties_country));

        similar.addAll(listOne);
        similar.retainAll(listTwo);
        different.addAll(listOne);
        different.removeAll(similar);
        List<String> differentlist = new ArrayList<String>(different);
        //

        ResultSet rs_Properties =
            stmt4.executeQuery(
                "SELECT * "
                    + " FROM testcasecountryproperties "
                    + " WHERE Test = '"
                    + test_testcase_format_prop[0]
                    + "'"
                    + " AND TestCase = '"
                    + test_testcase_format_prop[1]
                    + "'");
        try {
          // the country property already exists????
          if (rs_Properties.first()) {

            for (int i = 0; i < testcase_properties_property.length; i++) {
              for (int j = 0; j < differentlist.size(); j++) {
                String[] tc_country = new String[] {"", ""};
                tc_country = differentlist.get(j).split(" - ");

                if (testcase_properties_propertyrow[i].equals(tc_country[0])) {
                  // if the number of the line is the same for the
                  // country and the property:
                  Statement stmt3 = connection.createStatement();
                  try {
                    stmt3.execute(
                        "DELETE FROM testcasecountryproperties "
                            + " WHERE Test = '"
                            + test_testcase_format_prop[0]
                            + "' "
                            + " AND TestCase = '"
                            + test_testcase_format_prop[1]
                            + "' "
                            + " AND Country = '"
                            + tc_country[1]
                            + "' "
                            + " AND Property = '"
                            + testcase_properties_property[i]
                            + "'");
                  } finally {
                    stmt3.close();
                  }
                  // Is the country exist in the database??
                } // end of the if loop
              } // end of the loop for differnet list
            } // end of the property loop >>>>>The country unselected have
            // been removed

            // Delete the property which have been renamed
            for (int i = 0; i < testcase_properties_property.length; i++) {
              for (int p = 0; p < testcase_properties_countr_list.length; p++) {
                String[] tc_prop = new String[] {"", "", ""};
                tc_prop = testcase_properties_countr_list[p].split(" - ");
                if (testcase_properties_propertyrow[i].equals(tc_prop[0])
                    && !testcase_properties_property[i].equals(tc_prop[2])) {
                  Statement stmt3 = connection.createStatement();
                  try {
                    stmt3.execute(
                        "DELETE FROM testcasecountryproperties "
                            + " WHERE Test = '"
                            + test_testcase_format_prop[0]
                            + "' "
                            + " AND TestCase = '"
                            + test_testcase_format_prop[1]
                            + "' "
                            + " AND Country = '"
                            + tc_prop[1]
                            + "' "
                            + " AND Property = '"
                            + tc_prop[2]
                            + "'");
                  } finally {
                    stmt3.close();
                  }
                }
              }
            }
            // for each line, insert the property when not exist and update
            // when exist.
            for (int i = 0; i < testcase_properties_property.length; i++) {
              // for each country flagged in the page
              for (int j = 0; j < testcase_properties_country.length; j++) {
                // separate the number of the line to the country:
                // example: 1 - AT
                String[] testcase_country = new String[] {"", ""};
                testcase_country = testcase_properties_country[j].split(" - ");
                // if the number of the line is the same for the country
                // and the property:
                if (testcase_properties_propertyrow[i].equals(testcase_country[0])) {
                  Statement stmt3 = connection.createStatement();
                  try {
                    ResultSet rs_numberOfTestCasesCountryProperties =
                        stmt3.executeQuery(
                            "SELECT Test, TestCase, Country, Property "
                                + " FROM testcasecountryproperties "
                                + " WHERE Test = '"
                                + test_testcase_format_prop[0]
                                + "'"
                                + " AND TestCase = '"
                                + test_testcase_format_prop[1]
                                + "'"
                                + " AND Country = '"
                                + testcase_country[1]
                                + "'"
                                + " AND Property = '"
                                + testcase_properties_property[i]
                                + "'");
                    try {
                      // Is the country exist in the database??
                      // the country property already exists, make an
                      // update
                      if (rs_numberOfTestCasesCountryProperties.first()) {

                        String test = test_testcase_format_prop[0];
                        String testcase = test_testcase_format_prop[1];
                        String country = testcase_country[1];
                        String property = testcase_properties_property[i];
                        String description = testcase_properties_description[i];
                        String nature = testcase_properties_nature[i];
                        int rowlimit = Integer.parseInt(testcase_properties_rowlimit[i]);
                        int length = Integer.parseInt(testcase_properties_length[i]);
                        int retryNb = Integer.parseInt(testcase_properties_retrynb[i]);
                        int retryPeriod = Integer.parseInt(testcase_properties_retryperiod[i]);
                        String value1 = testcase_properties_value[i];
                        String value2 = testcase_properties_value2[i];
                        String type = testcase_properties_type[i];
                        String dtb = testcase_properties_database[i];

                        TestCaseCountryProperties tccp =
                            propertiesFactory.create(
                                test,
                                testcase,
                                country,
                                property,
                                description,
                                type,
                                dtb,
                                value1,
                                value2,
                                length,
                                rowlimit,
                                nature,
                                retryNb,
                                retryPeriod);

                        propertiesService.updateTestCaseCountryProperties(tccp);

                      } else // the country property does'nt extist, make an
                      // insert :
                      {
                        /*
                         * Insert new rows
                         */

                        String test = test_testcase_format_prop[0];
                        String testcase = test_testcase_format_prop[1];
                        String country = testcase_country[1];
                        String property = testcase_properties_property[i];
                        String description = testcase_properties_description[i];
                        String nature = testcase_properties_nature[i];
                        int rowlimit = Integer.parseInt(testcase_properties_rowlimit[i]);
                        int length = Integer.parseInt(testcase_properties_length[i]);
                        int retryNb = Integer.parseInt(testcase_properties_retrynb[i]);
                        int retryPeriod = Integer.parseInt(testcase_properties_retryperiod[i]);
                        String value1 = testcase_properties_value[i];
                        String value2 = testcase_properties_value2[i];
                        String type = testcase_properties_type[i];
                        String dtb = testcase_properties_database[i];

                        TestCaseCountryProperties tccp =
                            propertiesFactory.create(
                                test,
                                testcase,
                                country,
                                property,
                                description,
                                type,
                                dtb,
                                value1,
                                value2,
                                length,
                                rowlimit,
                                nature,
                                retryNb,
                                retryPeriod);

                        propertiesService.insertTestCaseCountryProperties(tccp);
                      } // end of the else loop
                    } finally {
                      rs_numberOfTestCasesCountryProperties.close();
                    }
                  } finally {
                    stmt3.close();
                  }
                } // end of the if loop
              } // Close the loop for country
            } // Close the loop for (property)
          } // end of the if loop (property already exists??
          else // The property is a first one
          {
            for (int i = 0; i < testcase_properties_property.length; i++) {
              // for each country flagged in the page
              for (int j = 0; j < testcase_properties_country.length; j++) {
                // separate the number of the line to the country:
                // example: 1 - AT
                String[] testcase_country = new String[] {"", ""};
                testcase_country = testcase_properties_country[j].split(" - ");
                // if the number of the line is the same for the country
                // and the property:
                if (testcase_properties_propertyrow[i].equals(testcase_country[0])) {
                  String test = test_testcase_format_prop[0];
                  String testcase = test_testcase_format_prop[1];
                  String country = testcase_country[1];
                  String property = testcase_properties_property[i];
                  String description = testcase_properties_description[i];
                  String nature = testcase_properties_nature[i];
                  int rowlimit = Integer.parseInt(testcase_properties_rowlimit[i]);
                  int length = Integer.parseInt(testcase_properties_length[i]);
                  int retryNb = Integer.parseInt(testcase_properties_retrynb[i]);
                  int retryPeriod = Integer.parseInt(testcase_properties_retryperiod[i]);
                  String value1 = testcase_properties_value[i];
                  String value2 = testcase_properties_value2[i];
                  String type = testcase_properties_type[i];
                  String dtb = testcase_properties_database[i];

                  TestCaseCountryProperties tccp =
                      propertiesFactory.create(
                          test,
                          testcase,
                          country,
                          property,
                          description,
                          type,
                          dtb,
                          value1,
                          value2,
                          length,
                          rowlimit,
                          nature,
                          retryNb,
                          retryPeriod);

                  propertiesService.insertTestCaseCountryProperties(tccp);
                } // Close the condition on the row number
              } // Close the loop for (country)
            } // Close the else condition
          }
        } finally {
          rs_Properties.close();
        }

        /*
         * Delete Properties
         */
        if (testcase_properties_delete != null) { // If some properties
          // check for delete
          Statement stmt3 = connection.createStatement();
          try {
            for (String element : testcase_properties_delete) {
              String property_and_country[] = element.split(" - ");
              for (int i = 1; i < property_and_country.length; i++) {
                stmt3.execute(
                    "DELETE FROM testcasecountryproperties "
                        + " WHERE Test = '"
                        + test_testcase_format_prop[0]
                        + "' "
                        + " AND TestCase = '"
                        + test_testcase_format_prop[1]
                        + "' "
                        + " AND Country = '"
                        + property_and_country[i]
                        + "' "
                        + " AND Property = '"
                        + property_and_country[0]
                        + "'");
              }
            }
          } finally {
            stmt3.close();
          }
        }

        String sqlupd =
            "UPDATE testcase "
                + "SET LastModifier = '"
                + request.getUserPrincipal().getName()
                + "' WHERE Test = '"
                + test_testcase_format_prop[0]
                + "' AND TestCase = '"
                + test_testcase_format_prop[1]
                + "' ";
        stmt4.execute(sqlupd);

        /*
         * END OF PROPERTIES
         */
        /*
         * Get Test, TestCase and Country to update
         */
        String test_testcase_no_format = this.getStringParameter("testcase_hidden", request);
        this.getStringParameter("Test", request);
        this.getStringParameter("TestCase", request);

        /*
         * Get TestCase Step Informations
         */
        /*
         * Step Number & Description
         */
        String step_delete[] = request.getParameterValues("testcasestep_delete");
        String step_id[] = this.getStringTable("testcasestep_hidden", request);
        String step_desc[] = this.getStringTable("step_description", request, true);
        String step_number_toadd[] = this.getStringTable("step_number_add", request);
        String step_desc_toadd[] = this.getStringTable("step_description_add", request, true);

        /*
         * Step actions
         */
        String step_action_delete[] = request.getParameterValues("actions_delete");
        String step_number_hide[] = this.getStringTable("stepnumber_hidden", request);
        String step_sequence[] = this.getStringTable("actions_sequence", request);
        String step_action[] = this.getStringTable("actions_action", request);
        String step_conditionOper[] = this.getStringTable("actions_conditionOper", request);
        String step_conditionVal1[] = this.getStringTable("actions_conditionVal1", request);
        String step_conditionVal2[] = this.getStringTable("actions_conditionVal2", request);
        String step_value1[] = this.getStringTable("actions_value1", request);
        String step_value2[] = this.getStringTable("actions_value2", request);
        String step_description[] = this.getStringTable("actions_description", request, true);
        /*
         * Get TestCase Step Controls Informations
         */
        String controls_delete[] = request.getParameterValues("controls_delete");
        String controls_step[] = this.getStringTable("controls_step", request);
        String controls_sequence[] = this.getStringTable("controls_sequence", request);
        String controls_controlsequence[] =
            this.getStringTable("controls_controlsequence", request);
        String controls_conditionoper[] =
            this.getStringTable("controls_conditionoper", request, true);
        String controls_conditionval1[] =
            this.getStringTable("controls_conditionval1", request, true);
        String controls_conditionval2[] =
            this.getStringTable("controls_conditionval2", request, true);
        String controls_control[] = this.getStringTable("controls_control", request);
        String controls_value1[] = this.getStringTable("controls_value1", request);
        String controls_value2[] = this.getStringTable("controls_value2", request);
        String controls_description[] = this.getStringTable("controls_description", request, true);
        String controls_fatal[] = this.getStringTable("controls_fatal", request);

        /*
         * Properties Insert/Update
         */
        String[] test_testcase_format = test_testcase_no_format.split(" - ");

        /*
         * Properties
         */
        /*
         * Actions
         */
        List<String[]> testcase_actions_info = new ArrayList<String[]>();
        testcase_actions_info.add(step_number_hide);
        testcase_actions_info.add(step_sequence);
        testcase_actions_info.add(step_conditionOper);
        testcase_actions_info.add(step_conditionVal1);
        testcase_actions_info.add(step_conditionVal2);
        testcase_actions_info.add(step_action);
        testcase_actions_info.add(step_value1);
        testcase_actions_info.add(step_value2);
        testcase_actions_info.add(step_description);

        /*
         * Controls
         */
        List<String[]> testcase_controls_info = new ArrayList<String[]>();
        testcase_controls_info.add(controls_step);
        testcase_controls_info.add(controls_sequence);
        testcase_controls_info.add(controls_controlsequence);
        testcase_controls_info.add(controls_description);
        testcase_controls_info.add(controls_conditionoper);
        testcase_controls_info.add(controls_conditionval1);
        testcase_controls_info.add(controls_conditionval2);
        testcase_controls_info.add(controls_control);
        testcase_controls_info.add(controls_value1);
        testcase_controls_info.add(controls_value2);
        testcase_controls_info.add(controls_fatal);

        /*
         * Test Case Step Description
         */
        /*
         * Update Test Case Step
         */
        int numberOfSteps = 0;
        Integer steps = 0;
        ResultSet rs_step =
            stmt4.executeQuery(
                "SELECT COUNT(*) "
                    + " FROM testcasestep "
                    + " WHERE Test = '"
                    + test_testcase_format[0]
                    + "'"
                    + " AND TestCase = '"
                    + test_testcase_format[1]
                    + "'");
        try {

          if (rs_step.next()) {
            numberOfSteps = rs_step.getInt(1);
          }
          if (request.getParameter("step_number_add") != null) {
            steps = Integer.parseInt(request.getParameter("step_number_add"));
          }
          if (steps == null || steps == 0) {
            steps = step_id.length;
          }
        } finally {
          rs_step.close();
        }

        for (int i = 0; i < steps; i++) {
          int i2 = i + 1;
          String step_batch[] = request.getParameterValues("batch-" + i2);

          if (i < numberOfSteps) {
            stmt4.executeUpdate(
                "UPDATE testcasestep "
                    + " SET Description = '"
                    + step_desc[i]
                    + "' "
                    + " WHERE Test = '"
                    + test_testcase_format[0]
                    + "'"
                    + " AND TestCase = '"
                    + test_testcase_format[1]
                    + "' "
                    + " AND Step = "
                    + step_id[i]
                    + "");

            stmt4.executeUpdate(
                "DELETE FROM testcasestepbatch WHERE  "
                    + " test = '"
                    + test_testcase_format[0]
                    + "' "
                    + " AND TestCase = '"
                    + test_testcase_format[1]
                    + "' AND STEP = '"
                    + step_id[i]
                    + "' ");

            if (step_batch != null) {
              for (int j = 0; j < step_batch.length; j++) {
                try {
                  stmt4.executeUpdate(
                      "INSERT INTO testcasestepbatch (`Test`, `TestCase`, `Step`, `Batch`) VALUES ( "
                          + "'"
                          + test_testcase_format[0]
                          + "', "
                          + "'"
                          + test_testcase_format[1]
                          + "', "
                          + "'"
                          + step_id[i]
                          + "', "
                          + "'"
                          + step_batch[j]
                          + "' )");

                } catch (Exception e) {
                  MyLogger.log(
                      UpdateTestCaseDetail.class.getName(),
                      Level.FATAL,
                      "Error on insert into TestCaseStepBatch: " + e.toString());
                }
              }
            }
          }
        }

        /*
         * Insert Test Case Step
         */
        for (int i = 0; i < step_number_toadd.length; i++) {
          if (this.formIsFill(step_number_toadd[i]) && this.formIsFill(step_desc_toadd[i])) {
            String sql =
                ("INSERT INTO testcasestep (`Test`,`Testcase`,`Step`,`Description`) "
                    + " VALUES('"
                    + test_testcase_format[0]
                    + "', "
                    + "'"
                    + test_testcase_format[1]
                    + "', "
                    + step_number_toadd[i]
                    + ", "
                    + "'"
                    + step_desc_toadd[i]
                    + "')");
            stmt4.execute(sql);
          }

          stmt4.executeUpdate(
              "DELETE FROM testcasestepbatch WHERE  "
                  + " test = '"
                  + test_testcase_format[0]
                  + "' "
                  + " AND TestCase = '"
                  + test_testcase_format[1]
                  + "' AND STEP = '"
                  + request.getParameter("step_number_add")
                  + "' ");

          String step_batch[] = request.getParameterValues("batch-" + step_number_toadd[i]);

          if (step_batch != null) {
            for (int j = 0; j < step_batch.length; j++) {
              try {

                String sql =
                    "INSERT INTO testcasestepbatch (`Test`, `TestCase`, `Step`, `Batch`) VALUES ( "
                        + "'"
                        + test_testcase_format[0]
                        + "', "
                        + "'"
                        + test_testcase_format[1]
                        + "', "
                        + "'"
                        + step_number_toadd[i]
                        + "', "
                        + "'"
                        + step_batch[j]
                        + "' )";
                stmt4.executeUpdate(sql);

              } catch (Exception e) {
                MyLogger.log(
                    UpdateTestCaseDetail.class.getName(),
                    Level.FATAL,
                    "Error on insert into TestCaseStepBatch: " + e.toString());
              }
            }
          }
        }

        /*
         * Test Case Step Actions
         */
        for (int i = 0; i < step_number_hide.length; i++) {

          /*
           * Select to know if need to update or insert
           */
          if (this.formIsFill(step_sequence[i]) && (step_sequence[i].length() > 0)) {
            String sql =
                ("SELECT * "
                    + " FROM testcasestepaction"
                    + " WHERE Test = '"
                    + test_testcase_format[0]
                    + "'"
                    + " AND TestCase = '"
                    + test_testcase_format[1]
                    + "' "
                    + " AND Step = "
                    + step_number_hide[i]
                    + " "
                    + " AND Sequence = "
                    + step_sequence[i]);
            ResultSet rs_stepaction = stmt4.executeQuery(sql);
            try {
              IFactoryTestCaseStepAction actionFactory =
                  appContext.getBean(IFactoryTestCaseStepAction.class);
              ITestCaseStepActionService actionService =
                  appContext.getBean(ITestCaseStepActionService.class);
              TestCaseStepAction tcsa =
                  actionFactory.create(
                      test_testcase_format[0],
                      test_testcase_format[1],
                      Integer.parseInt(step_number_hide[i]),
                      Integer.parseInt(step_sequence[i]),
                      Integer.parseInt(step_sequence[i]),
                      step_conditionOper[i],
                      step_conditionVal1[i],
                      step_conditionVal2[i],
                      step_action[i],
                      step_value1[i],
                      step_value2[i],
                      "",
                      step_description[i],
                      "");

              if (rs_stepaction.next()) {
                actionService.updateTestCaseStepAction(tcsa);

              } else if (this.formIsFullFill(testcase_actions_info, i)) {
                actionService.insertTestCaseStepAction(tcsa);
              }
            } finally {
              rs_stepaction.close();
            }
          }
        }

        /*
         * TestCase Step Controls
         */
        /*
         * Get Number of actual testcase controls
         */
        for (int i = 0; i < controls_controlsequence.length; i++) {

          /*
           * Select to know if need to update or insert
           */
          if (this.formIsFill(controls_sequence[i]) && (controls_sequence[i].length() > 0)) {
            String sql =
                ("SELECT * "
                    + " FROM testcasestepactioncontrol"
                    + " WHERE Test = '"
                    + test_testcase_format[0]
                    + "'"
                    + " AND TestCase = '"
                    + test_testcase_format[1]
                    + "' "
                    + " AND Step = "
                    + controls_step[i]
                    + " "
                    + " AND Sequence = "
                    + controls_sequence[i]
                    + " "
                    + " AND controlSequence = "
                    + controls_controlsequence[i]);
            ResultSet rs_stepactioncontrol = stmt4.executeQuery(sql);
            try {
              IFactoryTestCaseStepActionControl controlFactory =
                  appContext.getBean(IFactoryTestCaseStepActionControl.class);
              ITestCaseStepActionControlService controlService =
                  appContext.getBean(ITestCaseStepActionControlService.class);
              TestCaseStepActionControl control =
                  controlFactory.create(
                      test_testcase_format[0],
                      test_testcase_format[1],
                      Integer.parseInt(controls_step[i]),
                      Integer.parseInt(controls_sequence[i]),
                      Integer.parseInt(controls_controlsequence[i]),
                      0,
                      controls_conditionoper[i],
                      controls_conditionval1[i],
                      controls_conditionval2[i],
                      controls_control[i],
                      (controls_value1[i]),
                      controls_value2[i],
                      controls_fatal[i],
                      controls_description[i],
                      "");

              if (rs_stepactioncontrol.next()) {

                controlService.updateTestCaseStepActionControl(control);

              } else {
                //                        if (this.formIsFullFill(testcase_controls_info, i)) {

                controlService.insertTestCaseStepActionControl(control);

                //                        }
              }

            } finally {
              rs_stepactioncontrol.close();
            }
          }
        }

        /*
         * DELETE
         */
        if (step_delete != null) {
          for (String step_to_delete : step_delete) {
            stmt4.execute(
                "DELETE FROM testcasestep "
                    + " WHERE Test = '"
                    + test_testcase_format[0]
                    + "' "
                    + " AND TestCase = '"
                    + test_testcase_format[1]
                    + "' "
                    + " AND Step = "
                    + step_to_delete
                    + "");
          }
        }

        /*
         * Delete Actions
         */
        if (step_action_delete != null) { // If some actions to delete
          for (String action_to_delete : step_action_delete) { // Delete
            // with
            // key

            String[] step_action_split = action_to_delete.split("-");

            stmt4.execute(
                "DELETE FROM testcasestepaction "
                    + " WHERE Test = '"
                    + test_testcase_format[0]
                    + "' "
                    + " AND TestCase = '"
                    + test_testcase_format[1]
                    + "' "
                    + " AND Step = "
                    + step_action_split[0]
                    + " "
                    + " AND Sequence = "
                    + step_action_split[1]
                    + "");
          }
        }

        /*
         * Delete Controls
         */
        if (controls_delete != null) { // If controls to delete
          for (String keys_to_delete : controls_delete) {

            String[] key_delete = keys_to_delete.split("-"); // Get
            // Step,
            // Sequence
            // and
            // Control

            stmt4.execute(
                "DELETE FROM testcasestepactioncontrol "
                    + " WHERE Test = '"
                    + test_testcase_format[0]
                    + "' "
                    + " AND TestCase = '"
                    + test_testcase_format[1]
                    + "' "
                    + " AND Step = "
                    + key_delete[0]
                    + " "
                    + " AND Sequence = "
                    + key_delete[1]
                    + " "
                    + " AND ControlSequence = "
                    + key_delete[2]
                    + "");
          }
        }

        stmt4.execute(
            "UPDATE testcase "
                + "SET LastModifier = '"
                + request.getUserPrincipal().getName()
                + "' "
                + "WHERE Test = '"
                + test_testcase_format[0]
                + "' "
                + " AND TestCase = '"
                + test_testcase_format[1]
                + "' ");

        /** Adding Log entry. */
        ILogEventService logEventService = appContext.getBean(LogEventService.class);
        logEventService.createPrivateCalls(
            "/UpdateTestCaseDetail",
            "UPDATE",
            "Update testcase detail : ['"
                + test_testcase_format_prop[0]
                + "'|'"
                + test_testcase_format_prop[1]
                + "']",
            request);

        /*
         * Redirect
         */
        response.sendRedirect(
            "TestCase.jsp?Load=Load&Test="
                + test_testcase_format[0]
                + "&TestCase="
                + test_testcase_format[1]);
        return;
      } finally {
        stmt4.close();
      }
    } catch (SQLException ex) {
      MyLogger.log(UpdateTestCaseDetail.class.getName(), Level.FATAL, "" + ex);
      // out.println ( UpdateTestCase.class.getName ( ) + ex ) ;
    } catch (NullPointerException ex) {
      MyLogger.log(UpdateTestCaseDetail.class.getName(), Level.FATAL, "" + ex);
    } catch (ArrayIndexOutOfBoundsException ex) {
      MyLogger.log(UpdateTestCaseDetail.class.getName(), Level.FATAL, "" + ex);
    } finally {
      try {
        if (connection != null) {
          connection.close();
        }
      } catch (SQLException e) {
        MyLogger.log(UpdateTestCaseDetail.class.getName(), Level.WARN, e.toString());
      }
    }

    response.sendRedirect(
        "TestCase.jsp?Load=Load&Test="
            + request.getParameter("Test")
            + "&TestCase="
            + request.getParameter("TestCase"));
    out.close();
  }
Esempio n. 2
0
  @Override
  public AnswerList readDistinctValuesByCriteria(
      String searchTerm, Map<String, List<String>> individualSearch, String columnName) {
    AnswerList answer = new AnswerList();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    List<String> distinctValues = new ArrayList<>();
    StringBuilder searchSQL = new StringBuilder();
    List<String> individalColumnSearchValues = new ArrayList<String>();

    StringBuilder query = new StringBuilder();

    query.append("SELECT distinct sol.");
    query.append(columnName);
    query.append(" as distinctValues FROM soaplibrary sol");
    query.append(" where 1=1");

    if (!StringUtil.isNullOrEmpty(searchTerm)) {
      searchSQL.append(" and (sol.Name like ?");
      searchSQL.append(" or sol.Type like ?");
      searchSQL.append(" or sol.ServicePath like ?");
      searchSQL.append(" or sol.Method like ?");
      searchSQL.append(" or sol.ParsingAnswer like ?");
      searchSQL.append(" or sol.Description like ?");
      searchSQL.append(" or sol.Envelope like ?)");
    }
    if (individualSearch != null && !individualSearch.isEmpty()) {
      searchSQL.append(" and ( 1=1 ");
      for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {
        searchSQL.append(" and sol.");
        searchSQL.append(
            SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));
        individalColumnSearchValues.addAll(entry.getValue());
      }
      searchSQL.append(" )");
    }
    query.append(searchSQL);
    query.append(" group by ifnull(sol.").append(columnName).append(",'')");
    query.append(" order by sol.").append(columnName).append(" asc");

    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
      LOG.debug("SQL : " + query.toString());
    }
    try (Connection connection = databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query.toString())) {

      int i = 1;
      if (!StringUtil.isNullOrEmpty(searchTerm)) {
        preStat.setString(i++, "%" + searchTerm + "%");
        preStat.setString(i++, "%" + searchTerm + "%");
        preStat.setString(i++, "%" + searchTerm + "%");
        preStat.setString(i++, "%" + searchTerm + "%");
        preStat.setString(i++, "%" + searchTerm + "%");
        preStat.setString(i++, "%" + searchTerm + "%");
        preStat.setString(i++, "%" + searchTerm + "%");
      }
      for (String individualColumnSearchValue : individalColumnSearchValues) {
        preStat.setString(i++, individualColumnSearchValue);
      }

      ResultSet resultSet = preStat.executeQuery();

      // gets the data
      while (resultSet.next()) {
        distinctValues.add(
            resultSet.getString("distinctValues") == null
                ? ""
                : resultSet.getString("distinctValues"));
      }

      // get the total number of rows
      resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");
      int nrTotalRows = 0;

      if (resultSet != null && resultSet.next()) {
        nrTotalRows = resultSet.getInt(1);
      }

      if (distinctValues.size()
          >= MAX_ROW_SELECTED) { // Result of SQl was limited by MAX_ROW_SELECTED constrain. That
                                 // means that we may miss some lines in the resultList.
        LOG.error("Partial Result in the query.");
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);
        msg.setDescription(
            msg.getDescription()
                .replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));
        answer = new AnswerList(distinctValues, nrTotalRows);
      } else if (distinctValues.size() <= 0) {
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
        answer = new AnswerList(distinctValues, nrTotalRows);
      } else {
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
        msg.setDescription(
            msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
        answer = new AnswerList(distinctValues, nrTotalRows);
      }
    } catch (Exception e) {
      LOG.warn("Unable to execute query : " + e.toString());
      msg =
          new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED)
              .resolveDescription("DESCRIPTION", e.toString());
    } finally {
      // We always set the result message
      answer.setResultMessage(msg);
    }

    answer.setResultMessage(msg);
    answer.setDataList(distinctValues);
    return answer;
  }