/**
   * This method gets the list of update candidates, validates it, removes any failed candidates
   * from the update list, then updates the database with the [validated] update candidate list.
   *
   * @return The number of records updated
   */
  public int validateAndUpdateCandidates() {
    int updateCount = 0;
    List<BibliosDAO> bibliosList =
        bibliosManager.getUpdateCandidateBiblios(); // Get update candidates.
    Map<Integer, BibliosDAO> errorMap = validator.validate(bibliosList); // Validate the list.

    if (!bibliosList.isEmpty()) { // If there are update candidates ...
      if (!errorMap.isEmpty()) { //     If there were validation errors ...
        Iterator<BibliosDAO> iterator = bibliosList.iterator();
        while (iterator.hasNext()) { //     ... remove the failed candidates from the update list.
          BibliosDAO biblio = iterator.next();
          int pk = biblio.getId_biblio();
          if (errorMap.containsKey(pk)) {
            Object[] parms = new Object[] {biblio.getId_biblio()};
            String logMsg = messages.getMessage("Biblios.RemoveFailedCandidate", parms, Locale.UK);
            logger.warn(logMsg);
            iterator.remove();
          }
        }
      }

      bibliosList =
          updateBibliosFromWebService(
              bibliosList); // Update any biblios with valid pubmed_ids from web service.
      updateCount = save(bibliosList); // Save the changes.
    }

    return updateCount;
  }
  /**
   * Validates update candidate biblios (biblios whose <code>update</code> database field is either
   * null or is not equal to 'Y')
   *
   * @return 0 if there are no validation errors; 1 otherwise.
   */
  public int validateUpdateCandidates() {
    String logMsg = messages.getMessage("Biblios.ValidateUpdateCandidates", BEGIN, Locale.UK);
    logger.info(logMsg);

    List<BibliosDAO> bibliosList = bibliosManager.getUpdateCandidateBiblios();
    Map<Integer, BibliosDAO> errorMap = validator.validate(bibliosList);

    logMsg = messages.getMessage("Biblios.ValidateUpdateCandidates", END, Locale.UK);
    logger.info(logMsg);

    return (errorMap.isEmpty() ? 0 : 1);
  }
  /**
   * Updates the database with the given biblios. Since each biblio is not related to its sibling,
   * we commit after each update.
   *
   * @param biblioList The biblios to be udpated
   * @return the number of biblio records updated
   */
  public int save(final List<BibliosDAO> biblioList) {
    int count = 0;
    for (BibliosDAO biblio : biblioList) {
      DefaultTransactionDefinition paramTransactionDefinition = new DefaultTransactionDefinition();
      TransactionStatus status = jdbcTran.getTransaction(paramTransactionDefinition);
      bibliosManager.save(biblio);
      jdbcTran.commit(status);
      count++;
    }

    return count;
  }
 public EmmaBiblioJOB() {
   ac =
       new ClassPathXmlApplicationContext(
           "/jobApplicationContext.xml"); // Get job application context.
   messages =
       (ReloadableResourceBundleMessageSource)
           ac.getBean("messageSource"); // Get message resource file.
   jdbcTemplate = (JdbcTemplate) ac.getBean("jdbcTemplate"); // Get JdbcTemplate.
   jdbcTran =
       (PlatformTransactionManager)
           ac.getBean("transactionManager"); // Get JdbcTransactionManager.
   bibliosManager = new BibliosManager();
   validator = new EmmaBiblioValidator();
   logger.info(bibliosManager.getDbInfo());
 }
 public String getDbInfo() {
   return bibliosManager.getDbInfo();
 }