/**
   * Returns an email address for a given username as defined in Harvest.
   *
   * @param username a username
   * @return the email address corresponding to the username
   */
  private String getEmailAddress(String username) {

    try {
      String emailAddress = (String) userEmailMapping.get(username);

      // If we couldn't find the email address, it's probably the first
      // time we're trying
      // or it's a new one, so just reload the list.
      if (emailAddress == null) {

        if (!login()) {
          return null;
        }

        userEmailMapping.clear();
        JCaContainer userList = harvest.getUserList();
        int iNumUsers = userList.getKeyElementCount(JCaAttrKey.CA_ATTRKEY_NAME);
        for (int i = 0; i < iNumUsers; i++) {
          userEmailMapping.put(
              userList.getString(JCaAttrKey.CA_ATTRKEY_NAME, i),
              userList.getString(JCaAttrKey.CA_ATTRKEY_EMAIL, i));
        }

        emailAddress = (String) userEmailMapping.get(username);
      }

      return emailAddress;
    } catch (JCaHarvestException e) {
      LOG.error(e.getMessage());
    }

    return null;
  }
 /** Internal method which disconnects from Harvest. */
 protected void logout() {
   try {
     harvest.logout();
     loggedIn = false;
   } catch (JCaHarvestException e) {
     LOG.error(e.getMessage());
   }
 }
  /**
   * Returns a List of Modifications detailing all the changes between the last build and the latest
   * revision at the repository
   *
   * @param lastBuild last build time
   * @return maybe empty, never null.
   */
  public List getModifications(Date lastBuild, Date now) {

    LOG.debug("getModifications( " + lastBuild + ", " + now + " )");

    if (!login()) {
      return new ArrayList();
    }

    List list = new ArrayList();
    JCaContainer versionList = null;
    JCaContainer demotedVersionList = null;

    try {
      if (checkMode == CHECK_VERSION_CHOOSER) {
        versionList = getVersionsInRange(lastBuild, now);
      } else {
        versionList = getPromotedAndDemotedVersions(lastBuild, true);
        if (prevState != null) {
          demotedVersionList = getPromotedAndDemotedVersions(lastBuild, false);
        }
      }

      // This test is critical, as sometimes the count throws an exception
      int numVers =
          (versionList == null) || versionList.isEmpty()
              ? 0
              : versionList.getKeyElementCount(JCaAttrKey.CA_ATTRKEY_NAME);

      for (int n = 0; n < numVers; n++) {
        String status = versionList.getString(JCaAttrKey.CA_ATTRKEY_VERSION_STATUS, n);

        // Don't add reserved tagged files - the file hasn't actually changed
        if (!status.equals("R")) {
          list.add(transformJCaVersionContainerToModification(versionList, n, true));
        }
      }

      // This test is critical, as sometimes the count throws an exception
      numVers =
          (demotedVersionList == null) || demotedVersionList.isEmpty()
              ? 0
              : demotedVersionList.getKeyElementCount(JCaAttrKey.CA_ATTRKEY_NAME);

      for (int n = 0; n < numVers; n++) {
        String status = demotedVersionList.getString(JCaAttrKey.CA_ATTRKEY_VERSION_STATUS, n);

        // Don't add reserved tagged files - the file hasn't actually
        // changed
        if (!status.equals("R")) {
          list.add(transformJCaVersionContainerToModification(demotedVersionList, n, false));
        }
      }
    } catch (JCaHarvestException e) {
      LOG.error(e.getMessage());
    }

    return list;
  }