Skip to content

Commit

Permalink
Filter repatriated datasets against country datasets (do not use repa…
Browse files Browse the repository at this point in the history
…tried flag in query)
  • Loading branch information
matsbov committed Jul 11, 2024
1 parent c51d983 commit 3cec4d6
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,24 @@ class GbifRepatDataSourceAdapter extends GbifDataSourceAdapter {
static final SOURCE = "GBIF_REPATRIATION"
GbifService gbifService

static final String OCCURRENCE_REPAT_SEARCH = "occurrence/search?repatriated=true&country={0}&type={1}&offset=0&limit=0&facet=datasetKey&facetLimit=10000"
static final String OCCURRENCE_REPAT_SEARCH = "occurrence/search?country={0}&type={1}&offset=0&limit=0&facet=datasetKey&facetLimit=10000"
static final String COUNTRY_DATASETS = "dataset?country={0}&limit=10000"

GbifRepatDataSourceAdapter(DataSourceConfiguration configuration) {
super(configuration)
}

List<String> fetchCountryDatasetKeys() {
String url = MessageFormat.format(COUNTRY_DATASETS, configuration.country)
JSONObject json = getJSONWS(url, false)
json.results.collect{ it -> it.key }
}

@Override
List<Map> datasets() throws ExternalResourceException {
def keys = []
def datasets = []
def countryDatasetKeys = fetchCountryDatasetKeys()

LOGGER.info("Requesting dataset lists configuration.country: ${configuration.country}")
String url = MessageFormat.format(OCCURRENCE_REPAT_SEARCH, configuration.country, configuration.recordType)
Expand All @@ -35,7 +43,10 @@ class GbifRepatDataSourceAdapter extends GbifDataSourceAdapter {
json.facets[0].counts.each {
keys << it.name

if (it.count >= configuration.minRecordCount && it.count <= configuration.maxRecordCount && datasets.size() < configuration.maxNoOfDatasets) {
if (!countryDatasetKeys.contains(it.name) &&
it.count >= configuration.minRecordCount &&
it.count <= configuration.maxRecordCount &&
datasets.size() < configuration.maxNoOfDatasets) {
LOGGER.info("Getting metadata for ${it.name} = ${it.count}")
def dataset = getDataset(it.name, it.count)
if (dataset.name) {
Expand Down

0 comments on commit 3cec4d6

Please sign in to comment.