Skip to content

Commit

Permalink
CIRC-2141 Improvements after review
Browse files Browse the repository at this point in the history
  • Loading branch information
JanisSaldabols committed Oct 3, 2024
1 parent 4235837 commit 0db519b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
12 changes: 12 additions & 0 deletions src/main/java/org/folio/circulation/domain/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,4 +415,16 @@ public String getLendingLibraryCode() {
public String getDcbItemTitle() {
return getProperty(itemRepresentation, "instanceTitle");
}

public boolean isAtLocation(String locationCode) {
if (locationCode == null || locationCode.isEmpty()) {
return true;
} else {
return getLocation() != null && (
locationCode.equals(getLocation().getCode()) ||
locationCode.equals(getLocation().getLibrary().getCode()) ||
locationCode.equals(getLocation().getCampus().getCode()) ||
locationCode.equals(getLocation().getInstitution().getCode()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,21 @@ private Result<List<Item>> refusePageRequestWhenNoAvailablePageableItemsExist(Re
return failedValidation(message, INSTANCE_ID, request.getInstanceId());
}

List<Item> finalAvailablePageableItems;
if (request.geItemLocationCode() != null) {
finalAvailablePageableItems = availablePageableItems.stream()
.filter(item -> request.geItemLocationCode().equals(item.getLocation().getCode()) ||
request.geItemLocationCode().equals(item.getLocation().getLibrary().getCode()) ||
request.geItemLocationCode().equals(item.getLocation().getCampus().getCode()) ||
request.geItemLocationCode().equals(item.getLocation().getInstitution().getCode())
)
if (request.geItemLocationCode() == null) {
return of(() -> availablePageableItems);
} else {
List<Item> finalAvailablePageableItems = availablePageableItems.stream()
.filter(item -> item.isAtLocation(request.geItemLocationCode()))
.toList();
if (finalAvailablePageableItems.isEmpty()) {
String message = "Cannot create page TLR for this instance ID - no pageable available " +
"items found in forced location";
log.info("{}. Instance ID: {}, Forced location code {}",
"items found in requested location";
log.info("{}. Instance ID: {}, Requested location code {}",
message, request.getInstanceId(), request.geItemLocationCode());
return failedValidation(message, ITEM_LOCATION_CODE, request.geItemLocationCode());
}
} else {
finalAvailablePageableItems = availablePageableItems;
return of(() -> finalAvailablePageableItems);
}

return of(() -> finalAvailablePageableItems);
}

private static Item pickClosestItem(Collection<Location> requestedLocations, List<Item> availableItems) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/api/requests/RequestsAPICreationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ void createTitleLevelRequestWhenTlrEnabledSetLocationNoItems() {
assertThat(response.getStatusCode(), is(422));
assertThat(response.getJson(), hasErrorWith(
hasMessage("Cannot create page TLR for this instance ID - no pageable " +
"available items found in forced location")));
"available items found in requested location")));
}

@Test
Expand Down

0 comments on commit 0db519b

Please sign in to comment.