Skip to content

Commit

Permalink
[DSC-1350] - Add warning log
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaKr1vonosov authored and atarix83 committed Dec 27, 2023
1 parent afb9f8f commit 59216dc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected void addIndexValueForPersonItem(Item item, SolrInputDocument document)
String lastName = getMetadataValue(item, LASTNAME_FIELD);
List<String> fullNames = getMetadataValues(item, FULLNAME_FIELDS);

getAllNameVariants(firstName, lastName, fullNames)
getAllNameVariants(firstName, lastName, fullNames, item.getID().toString())
.forEach(variant -> addIndexValue(document, variant));
}

Expand Down
17 changes: 12 additions & 5 deletions dspace-api/src/main/java/org/dspace/util/PersonNameUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.apache.commons.collections4.iterators.PermutationIterator;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;

/**
* Utility class that handle person names.
Expand All @@ -24,6 +25,7 @@
*
*/
public final class PersonNameUtil {
private static Logger log = org.apache.logging.log4j.LogManager.getLogger(PersonNameUtil.class);

private PersonNameUtil() {

Expand All @@ -35,12 +37,14 @@ private PersonNameUtil() {
* @param firstName the first name
* @param lastName the last name
* @param fullNames the full names
* @param uuid the uuid
* @return all the variants of the given names
*/
public static Set<String> getAllNameVariants(String firstName, String lastName, List<String> fullNames) {
public static Set<String> getAllNameVariants(String firstName, String lastName, List<String> fullNames,
String uuid) {
Set<String> variants = new HashSet<String>();
variants.addAll(getNameVariants(firstName, lastName));
variants.addAll(getNameVariants(fullNames));
variants.addAll(getNameVariants(fullNames, uuid));
return variants;
}

Expand Down Expand Up @@ -95,17 +99,17 @@ private static List<String> getNameVariants(String[] firstNames, String lastName
return variants;
}

private static List<String> getNameVariants(List<String> fullNames) {
private static List<String> getNameVariants(List<String> fullNames, String uuid) {
return fullNames.stream()
.filter(Objects::nonNull)
.map(name -> removeComma(name))
.distinct()
.flatMap(name -> getAllNamePermutations(name).stream())
.flatMap(name -> getAllNamePermutations(name, uuid).stream())
.distinct()
.collect(Collectors.toList());
}

private static List<String> getAllNamePermutations(String name) {
private static List<String> getAllNamePermutations(String name, String uuid) {

List<String> namePermutations = new ArrayList<String>();

Expand All @@ -116,6 +120,9 @@ private static List<String> getAllNamePermutations(String name) {
while (permutationIterator.hasNext()) {
namePermutations.add(String.join(" ", permutationIterator.next()));
}
} else {
log.warn(String.format("Cannot retrieve variants on the Person with UUID %s because the name is too long",
uuid));
}

return namePermutations;
Expand Down
18 changes: 11 additions & 7 deletions dspace-api/src/test/java/org/dspace/util/PersonNameUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class PersonNameUtilTest {
@Test
public void testWithAllNames() {

Set<String> variants = getAllNameVariants("Luca", "Giamminonni", List.of("Giamminonni, Luca", "Luke Giammo"));
Set<String> variants = getAllNameVariants("Luca", "Giamminonni", List.of("Giamminonni, Luca",
"Luke Giammo"), "uuid");

assertThat(variants, containsInAnyOrder("Giamminonni Luca", "Luca Giamminonni",
"Giamminonni L.", "L. Giamminonni", "Giamminonni L", "L Giamminonni", "Luke Giammo", "Giammo Luke"));
Expand All @@ -37,7 +38,7 @@ public void testWithAllNames() {
public void testWithFirstNameComposedByTwoNames() {

Set<String> variants = getAllNameVariants("Luca Paolo", "Giamminonni",
List.of("Giamminonni, Luca", "Luke Giammo"));
List.of("Giamminonni, Luca", "Luke Giammo"), "uuid");

assertThat(variants, containsInAnyOrder("Giamminonni Luca Paolo", "Luca Paolo Giamminonni",
"Giamminonni Luca", "Luca Giamminonni", "Giamminonni Paolo", "Paolo Giamminonni",
Expand All @@ -51,7 +52,7 @@ public void testWithFirstNameComposedByTwoNames() {
public void testWithFirstNameComposedByThreeNames() {

Set<String> variants = getAllNameVariants("Luca Paolo Claudio", "Giamminonni",
List.of("Giamminonni, Luca", "Luke Giammo"));
List.of("Giamminonni, Luca", "Luke Giammo"), "uuid");

assertThat(variants, containsInAnyOrder("Giamminonni Luca Paolo Claudio", "Luca Paolo Claudio Giamminonni",
"Giamminonni Luca Claudio", "Luca Claudio Giamminonni", "Giamminonni Paolo Claudio",
Expand All @@ -69,7 +70,8 @@ public void testWithFirstNameComposedByThreeNames() {
@Test
public void testWithoutFirstAndLastName() {

Set<String> variants = getAllNameVariants(null, null, List.of("Giamminonni, Luca Fabio", "Luke Giammo"));
Set<String> variants = getAllNameVariants(null, null, List.of("Giamminonni, Luca Fabio", "Luke Giammo"),
"uuid");

assertThat(variants, containsInAnyOrder("Giamminonni Luca Fabio", "Fabio Luca Giamminonni",
"Giamminonni Fabio Luca", "Luca Fabio Giamminonni", "Luca Giamminonni Fabio",
Expand All @@ -80,12 +82,13 @@ public void testWithoutFirstAndLastName() {
@Test
public void testWithAlreadyTruncatedName() {

Set<String> variants = getAllNameVariants("L.", "Giamminonni", List.of("Giamminonni, Luca"));
Set<String> variants = getAllNameVariants("L.", "Giamminonni", List.of("Giamminonni, Luca"),
"uuid");

assertThat(variants, containsInAnyOrder("Giamminonni Luca", "Luca Giamminonni",
"Giamminonni L.", "L. Giamminonni", "Giamminonni L", "L Giamminonni"));

variants = getAllNameVariants("L. P.", "Giamminonni", List.of("Giamminonni, Luca"));
variants = getAllNameVariants("L. P.", "Giamminonni", List.of("Giamminonni, Luca"), "uuid");

assertThat(variants, containsInAnyOrder("Giamminonni Luca", "Luca Giamminonni", "L. Giamminonni",
"Giamminonni L.", "P. Giamminonni", "Giamminonni P.", "Giamminonni L. P.", "L. P. Giamminonni",
Expand All @@ -97,7 +100,8 @@ public void testWithAlreadyTruncatedName() {
@Test
public void testWithAlreadyTruncatedNameOnFullName() {

Set<String> variants = getAllNameVariants("Luca", "Giamminonni", List.of("Giamminonni, L."));
Set<String> variants = getAllNameVariants("Luca", "Giamminonni", List.of("Giamminonni, L."),
"uuid");

assertThat(variants, containsInAnyOrder("Giamminonni Luca", "Luca Giamminonni",
"Giamminonni L.", "L. Giamminonni", "Giamminonni L", "L Giamminonni"));
Expand Down

0 comments on commit 59216dc

Please sign in to comment.