Skip to content

Commit

Permalink
Merge branch 'master' into MSEARCH-617
Browse files Browse the repository at this point in the history
  • Loading branch information
GeloPakDev1 authored Nov 9, 2023
2 parents 7f3f788 + 1e478ef commit ee45bb6
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<folio-spring-support.version>7.3.0-SNAPSHOT</folio-spring-support.version>
<folio-service-tools.version>3.1.0</folio-service-tools.version>
<folio-isbn-utils.version>1.6.0</folio-isbn-utils.version>
<folio-cql2pgjson.version>35.1.0</folio-cql2pgjson.version>
<folio-cql2pgjson.version>35.1.1</folio-cql2pgjson.version>
<opensearch.version>2.9.0</opensearch.version>
<mapstruct.version>1.5.5.Final</mapstruct.version>
<!-- bump kafka.version to fix snappy-java vulnerabilities;
Expand Down
46 changes: 28 additions & 18 deletions src/main/java/org/folio/search/utils/CallNumberUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ public static Long getCallNumberAsLong(String callNumber, int firstPosition) {
* </ul>
* </p>
*
* @param context - call number browse context
* @param context - call number browse context
* @param callNumberTypeValue - call number type to check/compare result items' types
* @param browseItems - list of CallNumberBrowseItem objects
* @param browseItems - list of CallNumberBrowseItem objects
* @return filtered records
*/
public static List<CallNumberBrowseItem> excludeIrrelevantResultItems(BrowseContext context,
Expand All @@ -195,18 +195,9 @@ public static List<CallNumberBrowseItem> excludeIrrelevantResultItems(BrowseCont
getItemsFiltered(tenantFilter, locationFilter, callNumberType, folioCallNumberTypes, r));
}
});
return browseItems
.stream()
.filter(r -> {
Instance instance = r.getInstance();
if (instance != null) {
return instance.getItems()
.stream()
.anyMatch(i -> r.getFullCallNumber() == null
|| getFullCallNumber(i).equals(r.getFullCallNumber()));
}
return true;
}).toList();
return browseItems.stream()
.filter(CallNumberUtils::isItemRelevant)
.toList();
}

@NotNull
Expand All @@ -222,12 +213,30 @@ && locationMatch(locationFilter, i))
.toList();
}

private static boolean isItemRelevant(CallNumberBrowseItem r) {
Instance instance = r.getInstance();
if (instance != null) {
return instance.getItems()
.stream()
.anyMatch(i -> {
String fullCallNumber = getFullCallNumber(i);
return r.getFullCallNumber() == null
|| fullCallNumber != null && fullCallNumber.equals(r.getFullCallNumber());
});
}
return true;
}

private static boolean callNumberTypeMatch(Optional<String> callNumberType, Set<String> folioCallNumberTypes,
Item item) {
if (callNumberType.isEmpty()) {
return true;
}

if (item.getEffectiveCallNumberComponents() == null) {
return false;
}

var itemCallNumberTypeId = item.getEffectiveCallNumberComponents().getTypeId();
var itemCallNumberType = CallNumberType.fromId(itemCallNumberTypeId);
var requestCallNumberType = CallNumberType.fromName(callNumberType.get());
Expand All @@ -248,10 +257,11 @@ private static boolean locationMatch(List<Object> locationFilter, Item item) {
}

private static String getFullCallNumber(Item item) {
var iecnc = item.getEffectiveCallNumberComponents();
return Stream.of(iecnc.getPrefix(), iecnc.getCallNumber(), iecnc.getSuffix())
.filter(StringUtils::isNotBlank)
.collect(joining(StringUtils.SPACE));
return Optional.ofNullable(item.getEffectiveCallNumberComponents())
.map(iecnc -> Stream.of(iecnc.getPrefix(), iecnc.getCallNumber(), iecnc.getSuffix())
.filter(StringUtils::isNotBlank)
.collect(Collectors.joining(StringUtils.SPACE)))
.orElse(null);
}

private static long callNumberToLong(String callNumber, long startVal, int maxChars) {
Expand Down
45 changes: 44 additions & 1 deletion src/test/java/org/folio/search/utils/CallNumberUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ void excludeIrrelevantResultItems(String callNumberType, List<CallNumberBrowseIt
assertThat(unchangedItems).isEqualTo(given);
}

@Test
public void excludeIrrelevantResultItems_with_null_iecnc() {
var context = BrowseContext.builder().build();
var givenItems = createItemWithNullEffectiveCallNumberComponents();
var callNumberTypeValue = "dewey";

var resultItems = CallNumberUtils
.excludeIrrelevantResultItems(context, callNumberTypeValue, emptySet(), givenItems);

assertThat(resultItems).isEmpty();
}

@Test
void excludeIrrelevantResultItems_positive_tenantFilter() {
var tenantId = "tenant";
Expand Down Expand Up @@ -224,7 +236,7 @@ private static CallNumberBrowseItem browseItem(List<List<String>> data, String i
.effectiveShelvingOrder(getShelfKeyFromCallNumber(d.get(1))))
.toList();

var instance = new Instance()
var instance = new Instance()
.id(instanceId)
.title("instance #01")
.staffSuppress(false)
Expand All @@ -239,6 +251,37 @@ private static CallNumberBrowseItem browseItem(List<List<String>> data, String i
.instance(instance);
}

public static List<CallNumberBrowseItem> createItemWithNullEffectiveCallNumberComponents() {
var testId = randomId();
var data = List.of(newArrayList(DEWEY.getId(), "308 H977", "00000000-0000-0000-0000-000000000001"));

var items = data.stream().map(d -> new Item()
.id(d.get(2))
.tenantId("tenant")
.effectiveLocationId(testId)
.discoverySuppress(false)
.effectiveCallNumberComponents(null)
.effectiveShelvingOrder(getShelfKeyFromCallNumber(d.get(1))))
.toList();

var instance = new Instance()
.id(testId)
.title("instance #01")
.staffSuppress(false)
.discoverySuppress(false)
.isBoundWith(false)
.shared(false)
.tenantId(TENANT_ID)
.items(items)
.holdings(emptyList());

var callNumberBrowseItem = new CallNumberBrowseItem()
.fullCallNumber("cn")
.instance(instance);

return List.of(callNumberBrowseItem);
}

private static Stream<Arguments> eliminateIrrelevantItemsOnCallNumberBrowsingData() {
var id = randomId();
var mixedData = List.of(
Expand Down

0 comments on commit ee45bb6

Please sign in to comment.