public void deleteLLValue() {
   if (delRecordNo != null) {
     // System.out.println("delRecordNo = " + delRecordNo);
     boolean valueDeleted =
         dataBaseManagerInterface.removeLLRecord(delRecordNo, lineListGroup.getShortName());
     System.out.println("valueDeleted = " + valueDeleted);
   } else {
     System.out.println("delRecordNo is null");
   }
 }
  public String execute() {
    System.out.println("Reported Date " + reportedDate);

    // Map<String, String> llElementValuesMap = new HashMap<String,
    // String>();
    List<LineListElement> lineListElements;

    List<LineListDataValue> llDataValuesList = new ArrayList<LineListDataValue>();
    List<LineListDataValue> llDataValuesUpdatedList = new ArrayList<LineListDataValue>();

    OrganisationUnit organisationUnit = selectedStateManager.getSelectedOrganisationUnit();

    // period = periodService.getPeriod(period.getStartDate(),
    // period.getEndDate(), period.getPeriodType());
    lineListGroup = selectedStateManager.getSelectedLineListGroup();

    Period period;

    if (lineListGroup != null
        && lineListGroup.getPeriodType().getName().equalsIgnoreCase("OnChange")) {
      period = periodService.getPeriod(0);
    } else {
      period = selectedStateManager.getSelectedPeriod();

      period = reloadPeriodForceAdd(period);
    }

    // String parts[] = dataElementId.split( ":" );

    ActionContext ctx = ActionContext.getContext();
    HttpServletRequest req = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
    session = req.getSession();

    int totalRecords = Integer.parseInt(req.getParameter("totalRecords"));
    int recordsFromDb = Integer.parseInt(req.getParameter("recordsFromDb"));

    lineListElements = new ArrayList<LineListElement>(lineListGroup.getLineListElements());

    String recordNumbersList = req.getParameter("recordNumbersList");
    System.out.println(recordNumbersList);
    // this code is for edited value saving
    String[] recordNos = recordNumbersList.split(":");
    for (int j = 0; j < recordNos.length; j++) {
      String recordNo = recordNos[j];
      System.out.println("recordNo = " + recordNo);
      if (!(recordNo.equals(""))) {
        String valueChangedName = "changedValue:" + recordNo;
        String valueChanged = req.getParameter(valueChangedName);
        if (!(valueChanged.equalsIgnoreCase(""))) {
          System.out.println("valueChanged = " + valueChanged);
          String[] elementNames = valueChanged.split(" ");
          LineListDataValue llDataValue = new LineListDataValue();
          Map<String, String> llElementValuesMap = new HashMap<String, String>();
          for (int e = 0; e < elementNames.length; e++) {
            String name = elementNames[e] + ":" + recordNo;
            String dataValue = req.getParameter(name);
            // System.out.println("name = " + name + " value  = " +
            // dataValue);
            if (dataValue != null && dataValue.trim().equals("")) {
              dataValue = "";
            }
            // if(dataValue.equals( "" ))
            llElementValuesMap.put(elementNames[e], dataValue);
            // System.out.println("llElementValuesMap size = "+
            // llElementValuesMap.size() + " key = "+elementNames[e]
            // + " value = "+llElementValuesMap.get( elementNames[e]
            // ));

          }

          // add map in linelist data value
          llDataValue.setLineListValues(llElementValuesMap);

          // add recordNumber to pass to the update query
          llDataValue.setRecordNumber(Integer.parseInt(recordNo));

          // add stored by, timestamp in linelist data value
          storedBy = currentUserService.getCurrentUsername();

          if (storedBy == null) {
            storedBy = "[unknown]";
          }

          llDataValue.setStoredBy(storedBy);

          if (reportedDate != null) {
            Date reportDate = format.parseDate(reportedDate);
            llDataValue.setTimestamp(reportDate);
          } else {
            llDataValue.setTimestamp(new Date());
          }

          llDataValuesUpdatedList.add(llDataValue);
        }
      }
    }

    // this code is for newly added values save
    while (recordsFromDb < totalRecords) {
      System.out.println("recordsFromDb = " + recordsFromDb);
      System.out.println("totalRecords = " + totalRecords);
      recordsFromDb++;
      LineListDataValue llDataValue = new LineListDataValue();
      Map<String, String> llElementValuesMap = new HashMap<String, String>();
      for (LineListElement element : lineListElements) {

        String name = element.getShortName() + ":" + recordsFromDb;
        String dataValue = req.getParameter(name);
        System.out.println("name = " + name + " value  = " + req.getParameter(name));

        if (dataValue != null && dataValue.trim().equals("")) {
          dataValue = "";
        }
        if (!(dataValue.equals(""))) llElementValuesMap.put(element.getShortName(), dataValue);
      }

      // add map in linelist data value
      llDataValue.setLineListValues(llElementValuesMap);

      // add period source, stored by, timestamp in linelist data value
      llDataValue.setPeriod(period);
      llDataValue.setSource(organisationUnit);

      storedBy = currentUserService.getCurrentUsername();

      if (storedBy == null) {
        storedBy = "[unknown]";
      }

      llDataValue.setStoredBy(storedBy);

      if (reportedDate != null && !reportedDate.trim().equalsIgnoreCase("")) {
        Date reportDate = format.parseDate(reportedDate);
        llDataValue.setTimestamp(reportDate);
      } else {
        llDataValue.setTimestamp(new Date());
      }

      llDataValuesList.add(llDataValue);
    }

    if (llDataValuesList.isEmpty() || llDataValuesList == null) {

      // deleteLLValue();

    } else {

      boolean valueInserted =
          dataBaseManagerInterface.insertLLValueIntoDb(
              llDataValuesList, lineListGroup.getShortName());
      System.out.println("valueInserted = " + valueInserted);
    }

    if (llDataValuesUpdatedList.isEmpty() || llDataValuesUpdatedList == null) {

    } else {
      boolean updateLLValue =
          dataBaseManagerInterface.updateLLValue(
              llDataValuesUpdatedList, lineListGroup.getShortName());
      System.out.println("updateLLValue = " + updateLLValue);
    }
    if (delRecordNo != null) {
      deleteLLValue();
    }
    return SUCCESS;
  }