private void loadBasicDetails(
     final WaterConnectionDetails addConnection,
     final Model model,
     final WaterConnectionDetails parentConnectionDetails) {
   addConnection.setConnectionStatus(ConnectionStatus.INPROGRESS);
   model.addAttribute("parentConnection", parentConnectionDetails.getConnection());
   model.addAttribute("waterConnectionDetails", parentConnectionDetails);
   model.addAttribute(
       "connectionType",
       waterConnectionDetailsService
           .getConnectionTypesMap()
           .get(parentConnectionDetails.getConnectionType().name()));
   model.addAttribute("addConnection", addConnection);
   model.addAttribute("stateType", parentConnectionDetails.getClass().getSimpleName());
   model.addAttribute(
       "currentUser", waterTaxUtils.getCurrentUserRole(securityUtils.getCurrentUser()));
   model.addAttribute("additionalRule", addConnection.getApplicationType().getCode());
   model.addAttribute("mode", "addconnection");
   model.addAttribute(
       "validationMessage",
       additionalConnectionService.validateAdditionalConnection(parentConnectionDetails));
   BigDecimal waterTaxDueforParent =
       waterConnectionDetailsService.getTotalAmount(parentConnectionDetails);
   model.addAttribute("waterTaxDueforParent", waterTaxDueforParent);
   model.addAttribute("typeOfConnection", WaterTaxConstants.ADDNLCONNECTION);
 }
  @RequestMapping(value = "/addconnection/addConnection-create", method = RequestMethod.POST)
  public String create(
      @Valid @ModelAttribute final WaterConnectionDetails addConnection,
      final BindingResult resultBinder,
      final RedirectAttributes redirectAttributes,
      final Model model,
      @RequestParam String workFlowAction,
      final HttpServletRequest request,
      final BindingResult errors) {

    final WaterConnectionDetails parent =
        waterConnectionDetailsService.findByConnection(
            addConnection.getConnection().getParentConnection());
    final String message = additionalConnectionService.validateAdditionalConnection(parent);
    if (!message.isEmpty() && !"".equals(message))
      return "redirect:/application/addconnection/"
          + addConnection.getConnection().getParentConnection().getConsumerCode();

    final List<ApplicationDocuments> applicationDocs = new ArrayList<ApplicationDocuments>();
    int i = 0;
    if (!addConnection.getApplicationDocs().isEmpty())
      for (final ApplicationDocuments applicationDocument : addConnection.getApplicationDocs()) {
        if (applicationDocument.getDocumentNumber() == null
            && applicationDocument.getDocumentDate() != null) {
          final String fieldError = "applicationDocs[" + i + "].documentNumber";
          resultBinder.rejectValue(fieldError, "documentNumber.required");
        }
        if (applicationDocument.getDocumentNumber() != null
            && applicationDocument.getDocumentDate() == null) {
          final String fieldError = "applicationDocs[" + i + "].documentDate";
          resultBinder.rejectValue(fieldError, "documentDate.required");
        } else if (validApplicationDocument(applicationDocument))
          applicationDocs.add(applicationDocument);
        i++;
      }

    if (addConnection.getState() == null)
      addConnection.setStatus(
          waterTaxUtils.getStatusByCodeAndModuleType(
              WaterTaxConstants.APPLICATION_STATUS_CREATED, WaterTaxConstants.MODULETYPE));

    if (resultBinder.hasErrors()) {
      final WaterConnectionDetails parentConnectionDetails =
          waterConnectionDetailsService.getActiveConnectionDetailsByConnection(
              addConnection.getConnection());
      loadBasicDetails(addConnection, model, parentConnectionDetails);
      prepareWorkflow(model, addConnection, new WorkflowContainer());
      model.addAttribute("additionalRule", addConnection.getApplicationType().getCode());
      model.addAttribute("stateType", addConnection.getClass().getSimpleName());
      model.addAttribute(
          "currentUser", waterTaxUtils.getCurrentUserRole(securityUtils.getCurrentUser()));
      return "addconnection-form";
    }
    addConnection.setApplicationDate(new Date());
    addConnection.getApplicationDocs().clear();
    addConnection.setApplicationDocs(applicationDocs);

    processAndStoreApplicationDocuments(addConnection);

    Long approvalPosition = 0l;
    String approvalComent = "";

    if (request.getParameter("approvalComent") != null)
      approvalComent = request.getParameter("approvalComent");

    if (request.getParameter("workFlowAction") != null)
      workFlowAction = request.getParameter("workFlowAction");

    if (request.getParameter("approvalPosition") != null
        && !request.getParameter("approvalPosition").isEmpty())
      approvalPosition = Long.valueOf(request.getParameter("approvalPosition"));

    final Boolean applicationByOthers =
        waterTaxUtils.getCurrentUserRole(securityUtils.getCurrentUser());

    if (applicationByOthers != null && applicationByOthers.equals(true)) {
      final Position userPosition =
          waterTaxUtils.getZonalLevelClerkForLoggedInUser(
              addConnection.getConnection().getPropertyIdentifier());
      if (userPosition == null) {
        final WaterConnectionDetails parentConnectionDetails =
            waterConnectionDetailsService.getActiveConnectionDetailsByConnection(
                addConnection.getConnection());
        loadBasicDetails(addConnection, model, parentConnectionDetails);
        prepareWorkflow(model, addConnection, new WorkflowContainer());
        model.addAttribute("additionalRule", addConnection.getApplicationType().getCode());
        model.addAttribute("stateType", addConnection.getClass().getSimpleName());
        model.addAttribute(
            "currentUser", waterTaxUtils.getCurrentUserRole(securityUtils.getCurrentUser()));
        errors.rejectValue(
            "connection.propertyIdentifier",
            "err.validate.connection.user.mapping",
            "err.validate.connection.user.mapping");
        return "addconnection-form";
      } else {
        approvalPosition = userPosition.getId();
      }
    }

    waterConnectionDetailsService.createNewWaterConnection(
        addConnection,
        approvalPosition,
        approvalComent,
        addConnection.getApplicationType().getCode(),
        workFlowAction);
    final String pathVars =
        addConnection.getApplicationNumber()
            + ","
            + waterTaxUtils.getApproverUserName(approvalPosition);
    return "redirect:/application/application-success?pathVars=" + pathVars;
  }