Skip to content

Commit 59216dc

Browse files
NikitaKr1vonosovatarix83
authored andcommitted
[DSC-1350] - Add warning log
1 parent afb9f8f commit 59216dc

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

dspace-api/src/main/java/org/dspace/discovery/SolrServiceBestMatchIndexingPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected void addIndexValueForPersonItem(Item item, SolrInputDocument document)
6868
String lastName = getMetadataValue(item, LASTNAME_FIELD);
6969
List<String> fullNames = getMetadataValues(item, FULLNAME_FIELDS);
7070

71-
getAllNameVariants(firstName, lastName, fullNames)
71+
getAllNameVariants(firstName, lastName, fullNames, item.getID().toString())
7272
.forEach(variant -> addIndexValue(document, variant));
7373
}
7474

dspace-api/src/main/java/org/dspace/util/PersonNameUtil.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import org.apache.commons.collections4.iterators.PermutationIterator;
1818
import org.apache.commons.lang3.StringUtils;
19+
import org.apache.logging.log4j.Logger;
1920

2021
/**
2122
* Utility class that handle person names.
@@ -24,6 +25,7 @@
2425
*
2526
*/
2627
public final class PersonNameUtil {
28+
private static Logger log = org.apache.logging.log4j.LogManager.getLogger(PersonNameUtil.class);
2729

2830
private PersonNameUtil() {
2931

@@ -35,12 +37,14 @@ private PersonNameUtil() {
3537
* @param firstName the first name
3638
* @param lastName the last name
3739
* @param fullNames the full names
40+
* @param uuid the uuid
3841
* @return all the variants of the given names
3942
*/
40-
public static Set<String> getAllNameVariants(String firstName, String lastName, List<String> fullNames) {
43+
public static Set<String> getAllNameVariants(String firstName, String lastName, List<String> fullNames,
44+
String uuid) {
4145
Set<String> variants = new HashSet<String>();
4246
variants.addAll(getNameVariants(firstName, lastName));
43-
variants.addAll(getNameVariants(fullNames));
47+
variants.addAll(getNameVariants(fullNames, uuid));
4448
return variants;
4549
}
4650

@@ -95,17 +99,17 @@ private static List<String> getNameVariants(String[] firstNames, String lastName
9599
return variants;
96100
}
97101

98-
private static List<String> getNameVariants(List<String> fullNames) {
102+
private static List<String> getNameVariants(List<String> fullNames, String uuid) {
99103
return fullNames.stream()
100104
.filter(Objects::nonNull)
101105
.map(name -> removeComma(name))
102106
.distinct()
103-
.flatMap(name -> getAllNamePermutations(name).stream())
107+
.flatMap(name -> getAllNamePermutations(name, uuid).stream())
104108
.distinct()
105109
.collect(Collectors.toList());
106110
}
107111

108-
private static List<String> getAllNamePermutations(String name) {
112+
private static List<String> getAllNamePermutations(String name, String uuid) {
109113

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

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

121128
return namePermutations;

dspace-api/src/test/java/org/dspace/util/PersonNameUtilTest.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public class PersonNameUtilTest {
2727
@Test
2828
public void testWithAllNames() {
2929

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

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

3940
Set<String> variants = getAllNameVariants("Luca Paolo", "Giamminonni",
40-
List.of("Giamminonni, Luca", "Luke Giammo"));
41+
List.of("Giamminonni, Luca", "Luke Giammo"), "uuid");
4142

4243
assertThat(variants, containsInAnyOrder("Giamminonni Luca Paolo", "Luca Paolo Giamminonni",
4344
"Giamminonni Luca", "Luca Giamminonni", "Giamminonni Paolo", "Paolo Giamminonni",
@@ -51,7 +52,7 @@ public void testWithFirstNameComposedByTwoNames() {
5152
public void testWithFirstNameComposedByThreeNames() {
5253

5354
Set<String> variants = getAllNameVariants("Luca Paolo Claudio", "Giamminonni",
54-
List.of("Giamminonni, Luca", "Luke Giammo"));
55+
List.of("Giamminonni, Luca", "Luke Giammo"), "uuid");
5556

5657
assertThat(variants, containsInAnyOrder("Giamminonni Luca Paolo Claudio", "Luca Paolo Claudio Giamminonni",
5758
"Giamminonni Luca Claudio", "Luca Claudio Giamminonni", "Giamminonni Paolo Claudio",
@@ -69,7 +70,8 @@ public void testWithFirstNameComposedByThreeNames() {
6970
@Test
7071
public void testWithoutFirstAndLastName() {
7172

72-
Set<String> variants = getAllNameVariants(null, null, List.of("Giamminonni, Luca Fabio", "Luke Giammo"));
73+
Set<String> variants = getAllNameVariants(null, null, List.of("Giamminonni, Luca Fabio", "Luke Giammo"),
74+
"uuid");
7375

7476
assertThat(variants, containsInAnyOrder("Giamminonni Luca Fabio", "Fabio Luca Giamminonni",
7577
"Giamminonni Fabio Luca", "Luca Fabio Giamminonni", "Luca Giamminonni Fabio",
@@ -80,12 +82,13 @@ public void testWithoutFirstAndLastName() {
8082
@Test
8183
public void testWithAlreadyTruncatedName() {
8284

83-
Set<String> variants = getAllNameVariants("L.", "Giamminonni", List.of("Giamminonni, Luca"));
85+
Set<String> variants = getAllNameVariants("L.", "Giamminonni", List.of("Giamminonni, Luca"),
86+
"uuid");
8487

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

88-
variants = getAllNameVariants("L. P.", "Giamminonni", List.of("Giamminonni, Luca"));
91+
variants = getAllNameVariants("L. P.", "Giamminonni", List.of("Giamminonni, Luca"), "uuid");
8992

9093
assertThat(variants, containsInAnyOrder("Giamminonni Luca", "Luca Giamminonni", "L. Giamminonni",
9194
"Giamminonni L.", "P. Giamminonni", "Giamminonni P.", "Giamminonni L. P.", "L. P. Giamminonni",
@@ -97,7 +100,8 @@ public void testWithAlreadyTruncatedName() {
97100
@Test
98101
public void testWithAlreadyTruncatedNameOnFullName() {
99102

100-
Set<String> variants = getAllNameVariants("Luca", "Giamminonni", List.of("Giamminonni, L."));
103+
Set<String> variants = getAllNameVariants("Luca", "Giamminonni", List.of("Giamminonni, L."),
104+
"uuid");
101105

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

0 commit comments

Comments
 (0)