/**
   * Tags the application as complete and becomes ready for Data Entry. @RequestMapping(value =
   * "upload",params = {"pending"})
   *
   * @param ra
   * @param completeUpload
   * @param errors
   * @return view
   */
  @RequestMapping(
      value = "detail/{appNo}",
      method = RequestMethod.POST,
      params = {"complete"})
  public String completeSubmission(
      RedirectAttributes ra,
      @PathVariable String appNo,
      @ModelAttribute @Validated(TaggedAsCompleteInformationData.class)
          ApplicationDetailDTO completeUpload,
      BindingResult errors,
      @AuthenticationPrincipal OsaUser osaUser) {

    if (errors.hasErrors()) {
      // This is to preserve the validation results in case of redirection.
      ra.addFlashAttribute(APPDETAIL_MODEL_ATTRIB_KEY, completeUpload);
      ra.addFlashAttribute(BINDING_RESULT_KEY + APPDETAIL_MODEL_ATTRIB_KEY, errors);
      return "redirect:/detail/" + appNo;
    }

    if (completeUpload.getAdditionalImages().size() > 1) {
      if (!uploadService.uploadMoreImages(completeUpload, osaUser)) {
        // put error if it fails.
        MessageHelper.addErrorAttribute(ra, "upload.error");
      }
    }

    if (uploadService.updateApplicationStatusAsComplete(appNo)) {
      MessageHelper.addSuccessAttribute(ra, "upload.success", appNo);
    } else {
      MessageHelper.addErrorAttribute(ra, "upload.status.error");
    }

    return "redirect:/detail/" + appNo;
  }
  /**
   * Submits the application with newly added images.
   *
   * @param appNo
   * @param ra
   * @param appDetailsForm
   * @param errors
   * @return application detail screen.
   */
  @RequestMapping(value = "detail/{appNo}", method = RequestMethod.POST)
  public String uploadMore(
      @PathVariable String appNo,
      RedirectAttributes ra,
      @ModelAttribute @Validated(UploadInformationData.class) ApplicationDetailDTO appDetailsForm,
      BindingResult errors,
      @AuthenticationPrincipal OsaUser osaUser) {

    if (errors.hasErrors()) {
      // This is to preserve the validation results in case of redirection.
      ra.addFlashAttribute(APPDETAIL_MODEL_ATTRIB_KEY, appDetailsForm);
      ra.addFlashAttribute(BINDING_RESULT_KEY + APPDETAIL_MODEL_ATTRIB_KEY, errors);
      return "redirect:/detail/" + appNo;
    }

    if (uploadService.uploadMoreImages(appDetailsForm, osaUser)) {
      MessageHelper.addSuccessAttribute(ra, "upload.success", appDetailsForm.getAppNo());
    } else {
      MessageHelper.addErrorAttribute(ra, "upload.error");
    }

    return "redirect:/detail/" + appNo;
  }