Skip to content

Commit

Permalink
#533 fixed grscicoll lookup case where there were multiple collection…
Browse files Browse the repository at this point in the history
… exact matches and some didn't match the identifier
  • Loading branch information
marcos-lg committed Oct 26, 2023
1 parent 8b804f1 commit 8ec73ce
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<InstitutionMatched> 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<CollectionMatched> 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
Expand Down
2 changes: 1 addition & 1 deletion registry-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ protected Match<R> 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<Match<R>> uniqueMatch =
findUniqueMatch(filteredMatched, Arrays.asList(isCountryMatch(), isActiveMatch()));
findUniqueMatch(
filteredMatched,
Arrays.asList(isIdentifierMatch(), isCountryMatch(), isActiveMatch()));
if (uniqueMatch.isPresent()) {
Match<R> acceptedMatch = uniqueMatch.get();
acceptedMatch.setStatus(Match.Status.ACCEPTED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 8ec73ce

Please sign in to comment.