/**
   * @see org.gbif.portal.service.DataResourceManager#findDataResources(java.lang.String, boolean,
   *     org.gbif.portal.dto.util.SearchConstraints)
   */
  public Long countDataResources(
      String resourceName,
      boolean fuzzy,
      String providerKey,
      String basisOfRecordCode,
      Date modifiedSince)
      throws ServiceException {
    BasisOfRecord basisOfRecord = null;
    if (basisOfRecordCode != null) {
      basisOfRecord = BasisOfRecord.getBasisOfRecord(basisOfRecordCode);

      if (basisOfRecord == null) {
        throw new ServiceException("No basis of record found for code " + basisOfRecordCode);
      }
    }

    DataProvider dataProvider = null;
    if (providerKey != null) {
      Long dataProviderId = parseKey(providerKey);
      dataProvider = dataProviderDAO.getDataProviderFor(dataProviderId);

      if (dataProvider == null) {
        throw new ServiceException("No DataProvider found for key " + providerKey);
      }
    }

    Long recordCount =
        dataResourceDAO.countDataResources(
            resourceName, fuzzy, dataProvider, basisOfRecord, modifiedSince);
    return recordCount;
  }
  /** @see org.gbif.portal.service.DataResourceManager#findDataProvidersForUser(java.lang.String) */
  public List<DataProviderDTO> findDataProvidersForUser(String email) throws ServiceException {

    int indexOfAt = email.indexOf('@');
    if (indexOfAt < 0) {
      return new ArrayList<DataProviderDTO>();
    }

    // this could be dodgy - eg. [email protected] and [email protected]
    String username = email.substring(0, indexOfAt) + '%';
    String domain = '%' + email.substring(indexOfAt + 1);

    List<DataProvider> dps = dataProviderDAO.getDataProviderAssociatedWithUser(username, domain);
    return dataProviderDTOFactory.createDTOList(dps);
  }
 /**
  * @see org.gbif.portal.service.DataResourceManager#findDataProviders(java.lang.String, boolean,
  *     java.lang.String, java.util.Date, org.gbif.portal.dto.util.SearchConstraints)
  */
 public SearchResultsDTO findDataProviders(
     String providerName,
     boolean fuzzy,
     String isoCountryCode,
     Date modifiedSince,
     SearchConstraints searchConstraints) {
   List<DataProvider> providers =
       dataProviderDAO.findDataProviders(
           providerName,
           fuzzy,
           isoCountryCode,
           modifiedSince,
           searchConstraints.getStartIndex(),
           searchConstraints.getMaxResults() + 1);
   return dataProviderDTOFactory.createResultsDTO(providers, searchConstraints.getMaxResults());
 }
  /**
   * @see org.gbif.portal.service.DataResourceManager#findDataResources(java.lang.String, boolean,
   *     org.gbif.portal.dto.util.SearchConstraints)
   */
  public SearchResultsDTO findDataResources(
      String resourceName,
      boolean fuzzy,
      String providerKey,
      String basisOfRecordCode,
      Date modifiedSince,
      SearchConstraints searchConstraints)
      throws ServiceException {
    BasisOfRecord basisOfRecord = null;
    if (basisOfRecordCode != null) {
      basisOfRecord = BasisOfRecord.getBasisOfRecord(basisOfRecordCode);

      if (basisOfRecord == null) {
        throw new ServiceException("No basis of record found for code " + basisOfRecordCode);
      }
    }

    DataProvider dataProvider = null;
    if (providerKey != null) {
      Long dataProviderId = parseKey(providerKey);
      dataProvider = dataProviderDAO.getDataProviderFor(dataProviderId);

      if (dataProvider == null) {
        throw new ServiceException("No DataProvider found for key " + providerKey);
      }
    }

    List<DataResource> resources =
        dataResourceDAO.findDataResources(
            resourceName,
            fuzzy,
            dataProvider,
            basisOfRecord,
            modifiedSince,
            searchConstraints.getStartIndex(),
            searchConstraints.getMaxResults() + 1);
    return dataResourceDTOFactory.createResultsDTO(resources, searchConstraints.getMaxResults());
  }
 /** @see org.gbif.portal.service.DataResourceManager#getOcurrencePerMonth() */
 public List<String> getOcurrencePerMonth() {
   return dataProviderDAO.getOcurrencesPerMonth();
 }
 /** @see org.gbif.portal.service.DataResourceManager#getInternationalDataProviders() */
 public List<DataProviderDTO> getInternationalDataProviders() {
   return dataProviderDTOFactory.createDTOList(
       dataProviderDAO.getInternationalDataProviders(true));
 }
 /**
  * @see org.gbif.portal.service.DataResourceManager#getTotalCountHostedby(java.lang.String,
  *     boolean)
  */
 public int getTotalCountHostedby(String isoCountryCode, boolean georeferenced)
     throws ServiceException {
   return dataProviderDAO.getDataProviderCountsForHostCountry(isoCountryCode, georeferenced);
 }
 /** @see org.gbif.portal.service.DataResourceManager#getDataProviderFor(java.lang.String) */
 public DataProviderDTO getDataProviderFor(String dataProviderKey) throws ServiceException {
   Long dataProviderId = parseKey(dataProviderKey);
   DataProvider dataProvider = dataProviderDAO.getDataProviderFor(dataProviderId);
   return (DataProviderDTO) dataProviderDTOFactory.createDTO(dataProvider);
 }
 /** @see org.gbif.portal.service.DataResourceManager#getOcurrencePerMonthAccumulativeCounts() */
 public List<String> getOcurrencePerMonthAccumulativeCounts() {
   return dataProviderDAO.getOcurrencePerMonthAccumulativeCounts();
 };
 /**
  * @see org.gbif.portal.service.DataResourceManager#countDataProviders(java.lang.String, boolean,
  *     java.lang.String, java.util.Date)
  */
 public Long countDataProviders(
     String providerName, boolean fuzzy, String isoCountryCode, Date modifiedSince) {
   Long recordCount =
       dataProviderDAO.countDataProviders(providerName, fuzzy, isoCountryCode, modifiedSince);
   return recordCount;
 }
 /** @see org.gbif.portal.service.DataResourceManager#getTotalDataResourceCount() */
 public int getTotalOcurrenceCoordinateCount() throws ServiceException {
   return dataProviderDAO.getTotalOcurrenceCoordinateCount();
 }
 /** @see org.gbif.portal.service.DataResourceManager#getTotalDataProviderCount() */
 public int getTotalDataProviderCount() throws ServiceException {
   return dataProviderDAO.getTotalDataProviderCount();
 }
 /** @see org.gbif.portal.service.DataResourceManager#getDataProvidersOfferingTaxonomies() */
 @SuppressWarnings("unchecked")
 public List<DataProviderDTO> getDataProvidersOfferingTaxonomies() throws ServiceException {
   logger.debug("Retrieving Data Providers offering taxonomies");
   List<DataProvider> dataProviders = dataProviderDAO.getDataProvidersOfferingTaxonomies();
   return (List<DataProviderDTO>) dataProviderDTOFactory.createDTOList(dataProviders);
 }
 /** @see org.gbif.portal.service.DataResourceManager#getNewestDataProvider() */
 public DataProviderDTO getNewestDataProvider() throws ServiceException {
   DataProvider dataProvider = dataProviderDAO.getLastDataProviderAdded();
   return (DataProviderDTO) dataProviderDTOFactory.createDTO(dataProvider);
 }
 /** @see org.gbif.portal.service.DataResourceManager#getNubDataProvider() */
 public DataProviderDTO getNubDataProvider() throws ServiceException {
   DataProvider dataProvider = dataProviderDAO.getDataProviderFor(nubDataProviderId);
   return (DataProviderDTO) dataProviderDTOFactory.createDTO(dataProvider);
 }
 /** @see org.gbif.portal.service.DataResourceManager#getTotalDataResourceCountPerProvider() */
 public int getTotalDataResourceCountPerProvider(String dataProviderKey) {
   return dataProviderDAO.getTotalDataResourceCountPerProvider(dataProviderKey);
 }
 /** @see org.gbif.portal.service.DataResourceManager#getProviderTypeCounts() */
 public List<String> getProviderTypeCounts() {
   return dataProviderDAO.getProviderTypeCounts();
 };
 /** @see org.gbif.portal.service.DataResourceManager#getDataProviderList() */
 @SuppressWarnings("unchecked")
 public List<KeyValueDTO> getDataProviderList() {
   List dataProviderKVs = dataProviderDAO.getDataProviderList();
   return keyValueDTOFactory.createDTOList(dataProviderKVs);
 }
 /** @see org.gbif.portal.service.DataResourceManager#getOcurrencePerMonthTriCounts() */
 public List<String> getOcurrencePerMonthTriCounts() {
   return dataProviderDAO.getOcurrencePerMonthTriCounts();
 };
 /** @see org.gbif.portal.service.DataResourceManager#getAllDataProviders() */
 public List<DataProviderDTO> getAllDataProviders() throws ServiceException {
   List<DataProvider> dps = dataProviderDAO.getAllDataProviders();
   return dataProviderDTOFactory.createDTOList(dps);
 }