Skip to content

Commit

Permalink
CIRC-1980: Fix intervalId absence in hold shelf expiry period
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksat-Galymzhan committed Jul 4, 2024
1 parent a1841c5 commit 3d25182
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.folio.circulation.domain.policy.ExpirationDateManagement;
Expand Down Expand Up @@ -184,8 +185,12 @@ private RequestQueue setHoldShelfExpirationDateWithExpirationDateManagement(

ExpirationDateManagement expirationDateManagement = calculatedRequest.getPickupServicePoint()
.getHoldShelfClosedLibraryDateManagement();
String intervalId = calculatedRequest.getPickupServicePoint().getHoldShelfExpiryPeriod()
.getIntervalId().toUpperCase();

String intervalId = "0";
if (StringUtils.isNotBlank(calculatedRequest.getPickupServicePoint().getHoldShelfExpiryPeriod().getIntervalId())) {
intervalId = calculatedRequest.getPickupServicePoint().getHoldShelfExpiryPeriod().getIntervalId().toUpperCase();
}

log.info("setHoldShelfExpirationDateWithExpirationDateManagement expDate before:{}",
calculatedRequest.getHoldShelfExpirationDate());
// Old data where strategy is not set so default value but TimePeriod has MINUTES / HOURS
Expand Down
47 changes: 47 additions & 0 deletions src/test/java/api/loans/CheckInByBarcodeTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import java.util.Map;
import java.util.UUID;

import api.support.builders.ServicePointBuilder;
import org.folio.circulation.domain.ItemStatus;
import org.folio.circulation.domain.Request;
import org.folio.circulation.domain.RequestStatus;
Expand All @@ -84,6 +85,7 @@
import org.folio.circulation.support.http.client.Response;
import org.folio.circulation.support.utils.ClockUtil;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import api.support.APITests;
Expand Down Expand Up @@ -1662,6 +1664,51 @@ void linkItemToHoldTLRWithHoldShelfWhenCheckedInItemThenFulfilledWithSuccess(){
assertThat(itemRepresentation.getJsonObject("status").getString("name"), is("Awaiting pickup"));
}

@Test
void checkInItemWhenServiceHasChangedToNoPickupLocation(){
int intervalDuration = 0;
String intervalId = null;
reconfigureTlrFeature(TlrFeatureStatus.NOT_CONFIGURED);
configurationsFixture.enableTlrFeature();
UUID instanceId = instancesFixture.basedUponDunkirk().getId();
IndividualResource defaultWithHoldings = holdingsFixture.defaultWithHoldings(instanceId);
IndividualResource checkedOutItem = itemsClient.create(buildCheckedOutItemWithHoldingRecordsId(defaultWithHoldings.getId()));
IndividualResource holdRequestBeforeFulfilled = requestsClient.create(buildHoldTLRWithHoldShelffulfillmentPreference(instanceId));

String servicePointCode = servicePointsFixture.cd1().getJson().getString("code");
ServicePointBuilder changedServicePoint = ServicePointBuilder.from(servicePointsFixture.cd1())
.withPickupLocation(Boolean.FALSE)
.withHoldShelfExpriyPeriod(intervalDuration, intervalId)
.withName("custom service point");

// Update existing service point
servicePointsFixture.update(servicePointCode, changedServicePoint);

checkInFixture.checkInByBarcode(checkedOutItem, servicePointsFixture.cd1().getId());

//validating request before fulfilled
IndividualResource holdRequestAfterFulfilled = requestsClient.get(holdRequestBeforeFulfilled.getId());
JsonObject representationBefore = holdRequestBeforeFulfilled.getJson();
assertThat(representationBefore.getString("itemId"), nullValue());
validateTLRequestByFields(representationBefore,
HOLD_SHELF, instanceId, OPEN_NOT_YET_FILLED);

//validating request after fulfilled
JsonObject representation = holdRequestAfterFulfilled.getJson();
assertThat(representation.getString("itemId"), is(checkedOutItem.getId().toString()));
assertThat(representation.getString("holdingsRecordId"), is(defaultWithHoldings.getId()));

validateTLRequestByFields(representation, HOLD_SHELF, instanceId, OPEN_AWAITING_PICKUP);

IndividualResource itemAfter = itemsClient.get(checkedOutItem.getId());
JsonObject itemRepresentation = itemAfter.getJson();
assertThat(itemRepresentation.getJsonObject("status").getString("name"), is("Awaiting pickup"));

JsonObject servicePointRepresentation = representation.getJsonObject("pickupServicePoint");
Assertions.assertFalse(Boolean.parseBoolean(servicePointRepresentation.getString("pickupLocation")));
assertThat(servicePointRepresentation.getString("shelvingLagTime"), nullValue());
}

@Test
void linkItemToHoldTLRWithDeliveryWhenCheckedInThenFulfilledWithSuccess(){
reconfigureTlrFeature(TlrFeatureStatus.NOT_CONFIGURED);
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/api/support/fixtures/RecordCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ IndividualResource createIfAbsent(JsonObject record) {
return createIfAbsent(identityMapKey.apply(record), record);
}

void update(String servicePointCode, JsonObject updateRecord) {
identityMap.put(servicePointCode, client.create(updateRecord));
}

private IndividualResource createIfAbsent(String key, JsonObject record) {
return needsCreating(key) ? create(record) : getExistingRecord(key);
}
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/api/support/fixtures/ServicePointsFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,8 @@ public IndividualResource create(ServicePointBuilder builder) {
public Collection<IndividualResource> getAllServicePoints() {
return servicePointRecordCreator.getIdentityMap().values();
}

public void update(String servicePointCode, ServicePointBuilder builder) {
servicePointRecordCreator.update(servicePointCode, builder.create());
}
}

0 comments on commit 3d25182

Please sign in to comment.