Skip to content

Commit

Permalink
#626 replaced call for type specimen counts to use vocab
Browse files Browse the repository at this point in the history
  • Loading branch information
marcos-lg committed Jan 13, 2025
1 parent fb00ec4 commit e3ecb7d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<spring-cloud-sleuth.version>2.2.8.RELEASE</spring-cloud-sleuth.version>

<!-- GBIF -->
<gbif-api.version>2.0.0</gbif-api.version>
<gbif-api.version>2.0.1</gbif-api.version>
<gbif-common.version>0.59</gbif-common.version>
<gbif-common-mybatis.version>2.0.0</gbif-common-mybatis.version>
<gbif-common-ws.version>2.0.0</gbif-common-ws.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,24 @@ private static Set<String> findChildren(
return allChildren;
}

public static List<String> getVocabularyConcepts(String vocabulary, ConceptClient conceptClient) {
int limit = 100;
long offset = 0;
PagingResponse<ConceptView> response;
List<String> concepts = new ArrayList<>();
do {
ConceptListParams params = ConceptListParams.builder().limit(limit).offset(offset).build();
response =
Retry.decorateSupplier(
RETRY, () -> conceptClient.listConceptsLatestRelease(vocabulary, params))
.get();
response.getResults().forEach(r -> concepts.add(r.getConcept().getName()));
offset += limit;
} while (!response.isEndOfRecords());

return concepts;
}

public static ConceptView getConceptLatestRelease(
String vocabulary, String conceptName, ConceptClient conceptClient) {
return Retry.decorateSupplier(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.gbif.registry.persistence.mapper.collections.CollectionMapper;
import org.gbif.registry.persistence.mapper.collections.InstitutionMapper;
import org.gbif.registry.persistence.mapper.params.Count;
import org.gbif.registry.service.collections.utils.Vocabularies;
import org.gbif.vocabulary.client.ConceptClient;
import org.gbif.ws.client.ClientBuilder;
import org.gbif.ws.json.JacksonJsonObjectMapperProvider;

Expand All @@ -47,15 +49,18 @@ public class GRSciCollCountsUpdaterService {

private final InstitutionMapper institutionMapper;
private final CollectionMapper collectionMapper;
private final ConceptClient conceptClient;
private final OccurrenceWsSearchClient occurrenceWsSearchClient;

@Autowired
public GRSciCollCountsUpdaterService(
InstitutionMapper institutionMapper,
CollectionMapper collectionMapper,
ConceptClient conceptClient,
@Value("${api.root.url}") String apiRootUrl) {
this.institutionMapper = institutionMapper;
this.collectionMapper = collectionMapper;
this.conceptClient = conceptClient;
this.occurrenceWsSearchClient =
new ClientBuilder()
.withObjectMapper(JacksonJsonObjectMapperProvider.getObjectMapperWithBuilderSupport())
Expand Down Expand Up @@ -138,8 +143,11 @@ private void updateCounts() {
}

// add type specimens to the request and make the call
Arrays.stream(TypeStatus.values())
.filter(t -> t != TypeStatus.NOTATYPE)
List<String> typeStatusValues =
Vocabularies.getVocabularyConcepts(Vocabularies.TYPE_STATUS, conceptClient);

typeStatusValues.stream()
.filter(t -> !t.equalsIgnoreCase("NotAType"))
.forEach(request::addTypeStatusFilter);
SearchResponse<Occurrence, OccurrenceSearchParameter> typeSpecimenCountsResponse =
occurrenceWsSearchClient.search(request);
Expand Down

0 comments on commit e3ecb7d

Please sign in to comment.