/**
   * 'Edit/New Biblio' icon implementation
   *
   * @param biblio_key the biblio key being edited (a value of 0 indicates a new biblio is to be
   *     added).
   * @param filterBiblio_key the biblio key search criterion (may be empty)
   * @param filterStrain_key the strain key search criterion (may be empty)
   * @param filterPubmedId the pubmed id search criterion (may be empty)
   * @param filterBiblioAuthor1 the biblio author1 search criterion (may be empty)
   * @param filterBiblioJournal the biblio journal search criterion (may be empty)
   * @param filterBiblioTitle the biblio title search criterion (may be empty)
   * @param filterBiblioYear the biblio year search criterion (may be empty)
   * @param model the model
   * @return the view to show
   */
  @RequestMapping(value = "/edit", method = RequestMethod.GET)
  public String edit(
      @RequestParam(value = "biblio_key") Integer biblio_key,
      @RequestParam(value = "filterBiblioKey", required = true) String filterBiblio_key,
      @RequestParam(value = "filterStrainKey", required = true) String filterStrain_key,
      @RequestParam(value = "filterPubmedId", required = true) String filterPubmedId,
      @RequestParam(value = "filterBiblioAuthor1", required = true) String filterBiblioAuthor1,
      @RequestParam(value = "filterBiblioJournal", required = true) String filterBiblioJournal,
      @RequestParam(value = "filterBiblioTitle", required = true) String filterBiblioTitle,
      @RequestParam(value = "filterBiblioYear", required = true) String filterBiblioYear,
      Model model) {
    // Save the filter info and add to model.
    Filter filter =
        buildFilter(
            filterBiblio_key,
            filterStrain_key,
            filterPubmedId,
            filterBiblioAuthor1,
            filterBiblioJournal,
            filterBiblioTitle,
            filterBiblioYear);
    model.addAttribute(filter);

    String loggedInUser = SecurityContextHolder.getContext().getAuthentication().getName();
    model.addAttribute("loggedInUser", loggedInUser);

    Biblio biblio = bibliosManager.getBiblio(biblio_key);
    if (biblio == null) {
      biblio = new Biblio();
    }

    model.addAttribute("biblio", biblio);

    return "biblioManagementDetail";
  }
  /**
   * Save the form data.
   *
   * @param biblio the biblio instance
   * @param errors the Errors binding result object
   * @param biblio_key the biblio primary key
   * @param strain_keys the collection of strain keys (may be empty or null)
   * @param filterBiblio_key the biblio key search criterion (may be empty)
   * @param filterStrain_key the strain key search criterion (may be empty)
   * @param filterPubmedId the pubmed id search criterion (may be empty)
   * @param filterBiblioAuthor1 the biblio author1 search criterion (may be empty)
   * @param filterBiblioJournal the biblio journal search criterion (may be empty)
   * @param filterBiblioTitle the biblio title search criterion (may be empty)
   * @param filterBiblioYear the biblio year search criterion (may be empty)
   * @param model the filter data, saved above in edit().
   * @return redirected view to same gene detail data.
   */
  @RequestMapping(value = "/save", method = RequestMethod.POST)
  public String save(
      @Valid Biblio biblio,
      Errors errors,
      @RequestParam(value = "biblio_key", required = true) Integer biblio_key,
      @RequestParam(value = "strain_keys", required = false) String[] strain_keys,
      @RequestParam(value = "filterBiblioKey", required = true) String filterBiblio_key,
      @RequestParam(value = "filterStrainKey", required = true) String filterStrain_key,
      @RequestParam(value = "filterPubmedId", required = true) String filterPubmedId,
      @RequestParam(value = "filterBiblioAuthor1", required = true) String filterBiblioAuthor1,
      @RequestParam(value = "filterBiblioJournal", required = true) String filterBiblioJournal,
      @RequestParam(value = "filterBiblioTitle", required = true) String filterBiblioTitle,
      @RequestParam(value = "filterBiblioYear", required = true) String filterBiblioYear,
      Model model) {
    // Load the primary key, the foreign keys, and the strain key collection.
    biblio.setBiblio_key(biblio_key);
    biblio.setStrains(new LinkedHashSet());
    if (strain_keys != null) {
      for (String sStrain_key : strain_keys) {
        int strain_key = Integer.parseInt(sStrain_key);
        Strain strain = strainsManager.getStrain(strain_key);
        biblio.getStrains().add(strain);
      }
    }

    // Load up the model in case we have to redisplay the detail form.
    // Save the filter info and add to model.
    Filter filter =
        buildFilter(
            filterBiblio_key,
            filterStrain_key,
            filterPubmedId,
            filterBiblioAuthor1,
            filterBiblioJournal,
            filterBiblioTitle,
            filterBiblioYear);
    model.addAttribute(filter);
    String loggedInUser = SecurityContextHolder.getContext().getAuthentication().getName();
    model.addAttribute("loggedInUser", loggedInUser);

    // Validate.
    validator.validate(biblio, errors);
    if (errors.hasErrors()) {
      return "biblioManagementDetail";
    }

    try {
      bibliosManager.save(biblio);
    } catch (PersistFailedException pfe) {
      errors.reject(null, pfe.getLocalizedMessage());
      return "biblioManagementDetail";
    }

    return "redirect:/curation/biblioManagementDetail/edit"
        + "?biblio_key="
        + biblio.getBiblio_key()
        + "&filterBiblioKey="
        + filterBiblio_key
        + "&filterStrainKey="
        + filterStrain_key
        + "&filterPubmedId="
        + filterPubmedId
        + "&filterBiblioAuthor1="
        + filterBiblioAuthor1
        + "&filterBiblioJournal="
        + filterBiblioJournal
        + "&filterBiblioTitle="
        + filterBiblioTitle
        + "&filterBiblioYear="
        + filterBiblioYear;
  }