Skip to content

Commit

Permalink
Fixed GRSciCollCountsUpdaterService to set counts to zero when an ent…
Browse files Browse the repository at this point in the history
…ity used to have records before
  • Loading branch information
marcos-lg committed Sep 6, 2023
1 parent 4a6de31 commit ea6e11f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,6 @@ public interface CollectionMapper
*/
List<MasterSourceOrganizationDto> findByDatasetOrganizationAsMasterSource(
@Param("organizationKey") UUID organizationKey);

List<UUID> getAllKeys();
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ void convertToCollection(
@Param("institutionKey") UUID institutionKey, @Param("collectionKey") UUID collectionKey);

List<InstitutionGeoJsonDto> listGeoJson(@Param("params") InstitutionSearchParams searchParams);

List<UUID> getAllKeys();
}
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@
WHERE key = aux.entity_key::uuid
</update>

<select id="getAllKeys" resultType="java.util.UUID">
SELECT key FROM collection WHERE deleted IS NULL
</select>

<!-- new model contacts -->
<select id="listContactPersons" resultMap="org.gbif.registry.persistence.mapper.collections.CollectionContactMapper.CONTACT_MAP">
SELECT <include refid="org.gbif.registry.persistence.mapper.collections.CollectionContactMapper.CONTACT_READ_FIELDS"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@
WHERE key = aux.entity_key::uuid
</update>

<select id="getAllKeys" resultType="java.util.UUID">
SELECT key FROM institution WHERE deleted IS NULL
</select>

<!-- LOOKUP -->
<sql id="LOOKUP_MATCH_FIELDS">
i.key, i.name, i.code, i.address_key, i.mailing_address_key, akeys(i.alternative_codes) AS alternative_codes, i.active
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@
import org.gbif.ws.client.ClientBuilder;
import org.gbif.ws.json.JacksonJsonObjectMapperProvider;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -81,9 +79,9 @@ public void scheduleUpdateCounts() {
private void updateCounts() {
log.info("Updating GRSciColl counts");

long institutionsCount = institutionMapper.count(InstitutionSearchParams.builder().build());
long collectionsCount = collectionMapper.count(CollectionSearchParams.builder().build());
long facetCount = Math.max(institutionsCount, collectionsCount);
List<UUID> institutionKeys = institutionMapper.getAllKeys();
List<UUID> collectionKeys = collectionMapper.getAllKeys();
long facetCount = Math.max(institutionKeys.size(), collectionKeys.size());

OccurrenceSearchRequest request = new OccurrenceSearchRequest();
request.setLimit(0);
Expand All @@ -93,8 +91,32 @@ private void updateCounts() {
SearchResponse<Occurrence, OccurrenceSearchParameter> occurrenceCountsResponse =
occurrenceWsSearchClient.search(request);

Map<UUID, Count> institutionsCounts = new HashMap<>();
Map<UUID, Count> collectionsCounts = new HashMap<>();
// all entities are initialised to zero because the occurrence response doesn't return values
// with count zero and if they used to have records we need to update them to zero
Map<UUID, Count> institutionsCounts =
institutionKeys.stream()
.collect(
Collectors.toMap(
k -> k,
k -> {
Count c = new Count();
c.setKey(k);
c.setOccurrenceCount(0);
c.setTypeSpecimenCount(0);
return c;
}));
Map<UUID, Count> collectionsCounts =
collectionKeys.stream()
.collect(
Collectors.toMap(
k -> k,
k -> {
Count c = new Count();
c.setKey(k);
c.setOccurrenceCount(0);
c.setTypeSpecimenCount(0);
return c;
}));

Function<OccurrenceSearchParameter, Map<UUID, Count>> mapCountsSupplier =
p -> {
Expand Down

0 comments on commit ea6e11f

Please sign in to comment.