From 8ec73cee33ad0bd916c88ca6abbd6852ba349850 Mon Sep 17 00:00:00 2001 From: Marcos Lopez Gonzalez Date: Thu, 26 Oct 2023 12:13:06 +0200 Subject: [PATCH] #533 fixed grscicoll lookup case where there were multiple collection exact matches and some didn't match the identifier --- .../collections/service/LookupServiceIT.java | 76 +++++++++++-------- registry-service/README.md | 2 +- .../lookup/matchers/BaseMatcher.java | 7 +- .../lookup/matchers/MatchersTest.java | 4 +- 4 files changed, 55 insertions(+), 34 deletions(-) diff --git a/registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/service/LookupServiceIT.java b/registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/service/LookupServiceIT.java index 81cc5704b1..0b08ec55b7 100644 --- a/registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/service/LookupServiceIT.java +++ b/registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/service/LookupServiceIT.java @@ -14,51 +14,30 @@ package org.gbif.registry.ws.it.collections.service; import org.gbif.api.model.collections.Address; -import org.gbif.api.model.collections.AlternativeCode; -import org.gbif.api.model.collections.Collection; -import org.gbif.api.model.collections.Institution; -import org.gbif.api.model.collections.OccurrenceMapping; -import org.gbif.api.model.collections.lookup.CollectionMatched; -import org.gbif.api.model.collections.lookup.InstitutionMatched; -import org.gbif.api.model.collections.lookup.LookupParams; -import org.gbif.api.model.collections.lookup.LookupResult; -import org.gbif.api.model.collections.lookup.Match; -import org.gbif.api.model.registry.Dataset; -import org.gbif.api.model.registry.Identifier; -import org.gbif.api.model.registry.Installation; -import org.gbif.api.model.registry.Node; -import org.gbif.api.model.registry.Organization; +import org.gbif.api.model.collections.*; +import org.gbif.api.model.collections.lookup.*; +import org.gbif.api.model.registry.*; import org.gbif.api.service.collections.CollectionService; import org.gbif.api.service.collections.InstitutionService; import org.gbif.api.service.registry.DatasetService; import org.gbif.api.service.registry.InstallationService; import org.gbif.api.service.registry.NodeService; import org.gbif.api.service.registry.OrganizationService; -import org.gbif.api.vocabulary.Country; -import org.gbif.api.vocabulary.DatasetType; -import org.gbif.api.vocabulary.IdentifierType; -import org.gbif.api.vocabulary.InstallationType; -import org.gbif.api.vocabulary.Language; -import org.gbif.api.vocabulary.License; -import org.gbif.api.vocabulary.NodeType; -import org.gbif.api.vocabulary.ParticipationStatus; +import org.gbif.api.vocabulary.*; import org.gbif.registry.database.TestCaseDatabaseInitializer; import org.gbif.registry.service.collections.lookup.LookupService; import org.gbif.ws.client.filter.SimplePrincipalProvider; - -import java.util.Collections; -import java.util.List; -import java.util.UUID; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.beans.factory.annotation.Autowired; +import java.util.Collections; +import java.util.List; +import java.util.UUID; + import static org.junit.Assert.assertNull; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** Tests the {@link LookupService}. */ public class LookupServiceIT extends BaseServiceIT { @@ -822,6 +801,43 @@ public void exactCollectionMatchByInstitutionBelongingTest() { assertEquals(Match.Status.ACCEPTED, collectionMatch.getStatus()); } + @Test + public void exactCollectionMatchByInstitutionBelongingAndIdMatchTest() { + // State + LookupParams params = new LookupParams(); + params.setInstitutionCode(i5.getCode()); + params.setInstitutionId(i5.getKey().toString()); + params.setCollectionId(c6.getKey().toString()); + params.setCollectionCode(c6.getCode()); + params.setVerbose(true); + + // When + LookupResult result = lookupService.lookup(params); + + // Should + assertNotNull(result.getInstitutionMatch()); + Match institutionMatch = result.getInstitutionMatch(); + assertEquals(Match.MatchType.EXACT, institutionMatch.getMatchType()); + assertEquals(i5.getKey(), institutionMatch.getEntityMatched().getKey()); + assertEquals(2, institutionMatch.getReasons().size()); + assertEquals(Match.Status.ACCEPTED, institutionMatch.getStatus()); + + assertNotNull(result.getCollectionMatch()); + Match collectionMatch = result.getCollectionMatch(); + assertEquals(Match.MatchType.EXACT, collectionMatch.getMatchType()); + assertEquals(c6.getKey(), collectionMatch.getEntityMatched().getKey()); + assertEquals(3, collectionMatch.getReasons().size()); + assertTrue(collectionMatch.getReasons().contains(Match.Reason.BELONGS_TO_INSTITUTION_MATCHED)); + assertTrue(collectionMatch.getReasons().contains(Match.Reason.KEY_MATCH)); + assertTrue(collectionMatch.getReasons().contains(Match.Reason.CODE_MATCH)); + assertEquals(Match.Status.ACCEPTED, collectionMatch.getStatus()); + + assertEquals(1, result.getAlternativeMatches().getCollectionMatches().size()); + assertEquals( + c7.getKey(), + result.getAlternativeMatches().getCollectionMatches().get(0).getEntityMatched().getKey()); + } + @Test public void codeOverAlternativeCodeTest() { // State diff --git a/registry-service/README.md b/registry-service/README.md index 02c37bf770..039e05e98e 100644 --- a/registry-service/README.md +++ b/registry-service/README.md @@ -19,7 +19,7 @@ The overall matching process for each entity is as follows: If the code is not provided and the identifier matches it's considered a exact match. Also, when the institution match is exact or explicit, the collection match will be exact if it belongs to the institution matched and some field matches -like the code. +like the code (even if the identifier doesn't match). The identifier match also includes the matches by key (UUID) - e.g.: `institutionId=1a69e6fc-4a8d-44d5-90a6-a7dc7a1aa7c7`. diff --git a/registry-service/src/main/java/org/gbif/registry/service/collections/lookup/matchers/BaseMatcher.java b/registry-service/src/main/java/org/gbif/registry/service/collections/lookup/matchers/BaseMatcher.java index 978ec75199..03c1cfb560 100644 --- a/registry-service/src/main/java/org/gbif/registry/service/collections/lookup/matchers/BaseMatcher.java +++ b/registry-service/src/main/java/org/gbif/registry/service/collections/lookup/matchers/BaseMatcher.java @@ -71,8 +71,13 @@ protected Match chooseAccepted( } // if there is no unique match we try with the country if provided + // https://github.com/gbif/registry/issues/533 added the identifier match because in the case + // of collections there might be cases where an exact match haven't match the identifier because it belongs to the + // institution matched Optional> uniqueMatch = - findUniqueMatch(filteredMatched, Arrays.asList(isCountryMatch(), isActiveMatch())); + findUniqueMatch( + filteredMatched, + Arrays.asList(isIdentifierMatch(), isCountryMatch(), isActiveMatch())); if (uniqueMatch.isPresent()) { Match acceptedMatch = uniqueMatch.get(); acceptedMatch.setStatus(Match.Status.ACCEPTED); diff --git a/registry-service/src/test/java/org/gbif/registry/service/collections/lookup/matchers/MatchersTest.java b/registry-service/src/test/java/org/gbif/registry/service/collections/lookup/matchers/MatchersTest.java index 309b1a2be7..ed0ef317ca 100644 --- a/registry-service/src/test/java/org/gbif/registry/service/collections/lookup/matchers/MatchersTest.java +++ b/registry-service/src/test/java/org/gbif/registry/service/collections/lookup/matchers/MatchersTest.java @@ -13,10 +13,10 @@ */ package org.gbif.registry.service.collections.lookup.matchers; -import java.util.UUID; - import org.junit.jupiter.api.Test; +import java.util.UUID; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull;