/**
   * @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#getDataResourcesForProvider(java.lang.String)
  */
 @SuppressWarnings("unchecked")
 public List<DataResourceDTO> getDataResourcesForProvider(String dataProviderKey)
     throws ServiceException {
   Long dataProviderId = parseKey(dataProviderKey);
   List<DataResource> dataResources = dataResourceDAO.getDataResourcesForProvider(dataProviderId);
   return (List<DataResourceDTO>) dataResourceDTOFactory.createDTOList(dataResources);
 }
 /**
  * @see org.gbif.portal.service.DataResourceManager#findDatasets(java.lang.String, boolean,
  *     org.gbif.portal.dto.util.SearchConstraints)
  */
 @SuppressWarnings("unchecked")
 public SearchResultsDTO findDatasetsFromPlots(
     String nameStub,
     boolean fuzzy,
     boolean anyOccurrence,
     boolean includeCountrySearch,
     SearchConstraints searchConstraints) {
   List resources =
       dataResourceDAO.findDataResourcesAndProvidersAndNetworksFromPlots(
           nameStub,
           fuzzy,
           anyOccurrence,
           includeCountrySearch,
           searchConstraints.getStartIndex(),
           searchConstraints.getMaxResults() + 1);
   List resourceDTOList = new ArrayList();
   for (Object resource : resources) {
     if (resource instanceof DataResource)
       resourceDTOList.add(dataResourceDTOFactory.createDTO(resource));
     else if (resource instanceof DataProvider)
       resourceDTOList.add(dataProviderDTOFactory.createDTO(resource));
     else if (resource instanceof ResourceNetwork)
       resourceDTOList.add(resourceNetworkDTOFactory.createDTO(resource));
   }
   SearchResultsDTO searchResultsDTO = new SearchResultsDTO();
   searchResultsDTO.setResults(resourceDTOList, searchConstraints.getMaxResults());
   return searchResultsDTO;
 }
  /**
   * @see
   *     org.gbif.portal.service.DataResourceManager#getDataResourceWithOccurrencesFor(java.lang.String,
   *     java.lang.String, boolean)
   */
  public List<CountDTO> getDataResourceWithOccurrencesFor(
      String taxonConceptKey, String rank, boolean georeferenced) throws ServiceException {

    List<Object[]> results =
        dataResourceDAO.getDataResourceWithOccurrencesFor(
            parseKey(taxonConceptKey), rank, georeferenced);
    return (new CountDTOFactory()).createDTOList(results);
  }
 /**
  * @see
  *     org.gbif.portal.service.DataResourceManager#getDataResourcesForResourceNetwork(java.lang.String)
  */
 @SuppressWarnings("unchecked")
 public List<DataResourceDTO> getDataResourcesForResourceNetwork(String resourceNetworkKey)
     throws ServiceException {
   Long resourceNetworkId = parseKey(resourceNetworkKey);
   List<DataResource> dataResources =
       dataResourceDAO.getDataResourcesForResourceNetwork(resourceNetworkId);
   return (List<DataResourceDTO>) dataResourceDTOFactory.createDTOList(dataResources);
 }
 /** @see org.gbif.portal.service.DataResourceManager#getDataResourceList(java.lang.String) */
 @SuppressWarnings({"unchecked", "unchecked"})
 public List<KeyValueDTO> getDataResourceList(String resourceNetworkKey, String dataProviderKey) {
   Long resourceNetworkId = parseKey(resourceNetworkKey);
   Long dataProviderId = parseKey(dataProviderKey);
   List dataResourceKVs = null;
   if (resourceNetworkId != null) {
     List<DataResource> dataResources =
         dataResourceDAO.getDataResourcesForResourceNetwork(resourceNetworkId);
     List<KeyValueDTO> kvps = new ArrayList<KeyValueDTO>();
     for (DataResource dr : dataResources) {
       StringBuffer sb = new StringBuffer(dr.getName());
       if (dr.getDataProvider() != null) {
         sb.append(" - ");
         sb.append(dr.getDataProvider().getName());
       }
       kvps.add(new KeyValueDTO(dr.getId().toString(), sb.toString()));
     }
     return kvps;
   } else {
     dataResourceKVs = dataResourceDAO.getDataResourceList(dataProviderId);
     return keyValueDTOFactory.createDTOList(dataResourceKVs);
   }
 }
  /**
   * @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#getDatasetAlphabet() */
 public List<Character> getDatasetAlphabet() {
   return dataResourceDAO.getDatasetAlphabet();
 }
 /** @see org.gbif.portal.service.DataResourceManager#getTotalDataResourceCount() */
 public int getTotalDataResourceCount() throws ServiceException {
   return dataResourceDAO.getTotalDataResourceCount();
 }
 /** @see org.gbif.portal.service.DataResourceManager#getDataResourcesWithInferredTaxonomies() */
 @SuppressWarnings("unchecked")
 public List<DataResourceDTO> getDataResourcesWithInferredTaxonomies() throws ServiceException {
   logger.debug("Retrieving Data Resource offering taxonomies");
   List<DataResource> dataResources = dataResourceDAO.getDataResourcesWithNonSharedTaxonomies();
   return (List<DataResourceDTO>) dataResourceDTOFactory.createDTOList(dataResources);
 }
 /** @see org.gbif.portal.service.DataResourceManager#getNewestDataResource() */
 public DataResourceDTO getNewestDataResource() throws ServiceException {
   DataResource dataResource = dataResourceDAO.getLastDataResourceAdded();
   return (DataResourceDTO) dataResourceDTOFactory.createDTO(dataResource);
 }
 /** @see org.gbif.portal.service.DataResourceManager#getNubDataResource() */
 public DataResourceDTO getNubDataResource() throws ServiceException {
   DataResource dataResource = dataResourceDAO.getDataResourceFor(nubDataResourceId);
   return (DataResourceDTO) dataResourceDTOFactory.createDTO(dataResource);
 }
 /** @see org.gbif.portal.service.DataResourceManager#getDataResourceFor(java.lang.String) */
 public DataResourceDTO getDataResourceFor(String dataResourceKey) throws ServiceException {
   Long dataResourceId = parseKey(dataResourceKey);
   DataResource dataResource = dataResourceDAO.getDataResourceFor(dataResourceId);
   return (DataResourceDTO) dataResourceDTOFactory.createDTO(dataResource);
 }
 /** @see org.gbif.portal.service.DataResourceManager#getAllDataResources() */
 public List<DataResourceDTO> getAllDataResources() throws ServiceException {
   List<DataResource> drs = dataResourceDAO.getAllDataResources();
   return dataResourceDTOFactory.createDTOList(drs);
 }