Skip to content

Commit

Permalink
CIRCSTORE-541: added ItemRetrievalServicePointUpdateProcessorForReque…
Browse files Browse the repository at this point in the history
…st for retrival SP for request (#505)

* CIRCSTORE-540: ItemUpdateProcessorForRequest update item's location and SP

* CIRCSTORE-540: added log for debugging

* CIRCSTORE-540: added log for debugging

* CIRCSTORE-540: set additionalProperties true inside location.json

* CIRCSTORE-540: fix exception issue

* CIRCSTORE-540: fix exception issue

* CIRCSTORE-540: 1) added async mechanism in EventProcessor class to execute and support non-blocking api calls. 2) Added test case.

* CIRCSTORE-540: removed unnecessary log and code

* CIRCSTORE-540: using location and SP constants

* CIRCSTORE-540: fix NLP due to logging of null object

* CIRCSTORE-540: fixed sonar issues

* CIRCSTORE-541: added ItemRetrievalServicePointUpdateProcessorForRequest for retrival SP for request

* CIRCSTORE-541: fix duplicate code line sonar issue

* CIRCSTORE-540: added interface dependency for location and service-point api

* CIRCSTORE-541: resolved merge conflict
  • Loading branch information
kapil-epam authored Dec 23, 2024
1 parent 6d3700b commit b46a339
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.folio.kafka.AsyncRecordHandler;
import org.folio.persist.RequestPolicyRepository;
import org.folio.persist.RequestRepository;
import org.folio.service.event.handler.processor.ItemRetrievalServicePointUpdateProcessorForRequest;
import org.folio.service.event.handler.processor.ServicePointUpdateProcessorForRequest;
import org.folio.service.event.handler.processor.ServicePointUpdateProcessorForRequestPolicy;

Expand All @@ -31,6 +32,8 @@ public Future<String> handle(KafkaConsumerRecord<String, String> kafkaConsumerRe
return new ServicePointUpdateProcessorForRequest(requestRepository)
.run(kafkaConsumerRecord.key(), payload)
.compose(notUsed -> new ServicePointUpdateProcessorForRequestPolicy(requestPolicyRepository)
.run(kafkaConsumerRecord.key(), payload));
.run(kafkaConsumerRecord.key(), payload))
.compose(notUsed -> new ItemRetrievalServicePointUpdateProcessorForRequest(requestRepository)
.run(kafkaConsumerRecord.key(), payload));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.folio.service.event.handler.processor;

import io.vertx.core.Future;
import io.vertx.core.json.JsonObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.folio.persist.RequestRepository;
import org.folio.rest.jaxrs.model.Request;
import org.folio.rest.persist.Criteria.Criteria;
import org.folio.rest.persist.Criteria.Criterion;

import java.util.ArrayList;
import java.util.List;

import static org.apache.commons.lang3.ObjectUtils.notEqual;
import static org.folio.service.event.InventoryEventType.INVENTORY_SERVICE_POINT_UPDATED;
import static org.folio.service.event.handler.processor.ItemUpdateProcessorForRequest.RETRIEVAL_SERVICE_POINT_ID;

public class ItemRetrievalServicePointUpdateProcessorForRequest extends UpdateEventProcessor<Request> {
private static final Logger log = LogManager.getLogger(ItemRetrievalServicePointUpdateProcessorForRequest.class);
private static final String SERVICE_POINT_NAME_KEY = "name";

public ItemRetrievalServicePointUpdateProcessorForRequest(RequestRepository requestRepository) {
super(INVENTORY_SERVICE_POINT_UPDATED, requestRepository);
}

@Override
protected Future<List<Change<Request>>> collectRelevantChanges(JsonObject payload) {
JsonObject newObject = payload.getJsonObject("new");
JsonObject oldObject = payload.getJsonObject("old");
List<Change<Request>> changes = new ArrayList<>();

// compare service point names
String newServicePointName = newObject.getString(SERVICE_POINT_NAME_KEY);
String oldServicePointName = oldObject.getString(SERVICE_POINT_NAME_KEY);
if (notEqual(oldServicePointName, newServicePointName)) {
log.info("ItemRetrievalServicePointUpdateProcessorForRequest :: collectRelevantChanges:: changing item.retrievalServicePointName from {} to {}",
oldServicePointName, newServicePointName);
changes.add(new Change<>(request -> request.getItem().setRetrievalServicePointName(newServicePointName)));
}
return Future.succeededFuture(changes);
}

@Override
protected Criterion criterionForObjectsToBeUpdated(String oldObjectId) {
log.info("ItemRetrievalServicePointUpdateProcessorForRequest :: criterionForObjectsToBeUpdated:: oldObjectId: {}",
oldObjectId);
return new Criterion(
new Criteria()
.addField("'item'")
.addField(String.format("'%s'", RETRIEVAL_SERVICE_POINT_ID))
.setOperation("=")
.setVal(oldObjectId));
}
}
49 changes: 48 additions & 1 deletion src/test/java/org/folio/rest/api/EventConsumerVerticleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import static org.hamcrest.MatcherAssert.assertThat;

import java.net.URL;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -211,6 +210,43 @@ public void requestItemLocationAndSpIsSetWhenItemEffectiveLocationChange() {
verifyRequestItem(REQUEST_ID, expectedItem);
}

@Test
public void requestItemSpIsSetWhenItemEffectiveLocationPrimarySpChange() {
//Creating and mocking ServicePoint
String servicePointId = UUID.randomUUID().toString();
JsonObject servicePoint = buildServicePoint(servicePointId, "ServicePoint-1");
createStubForServicePoints(List.of(servicePoint));

//Creating and mocking Location
String locationId = UUID.randomUUID().toString();
JsonObject location = buildLocation(locationId, "Location-1", servicePointId);
createStubForLocations(List.of(location));

//Creating request with retrieval service-point in item object
JsonObject item = buildItem();
JsonObject request = buildRequest(REQUEST_ID, item);
JsonObject requestItem = request.getJsonObject("item");
requestItem.put(RETRIEVAL_SERVICE_POINT_ID, servicePointId);
requestItem.put(RETRIEVAL_SERVICE_POINT_NAME, servicePoint.getString("name"));
createRequest(request);

int initialOffset = getOffsetForServicePointUpdateEvents();

//Change ServicePoint Name in stub and publish SP update event
JsonObject servicePointNew = servicePoint.copy();
servicePointNew.put("name", "ServicePoint-2-Changed");
createStubForServicePoints(List.of(servicePoint));
publishServicePointUpdateEvent(servicePoint, servicePointNew);

// Expected RETRIEVAL_SERVICE_POINT in item
JsonObject expectedItemRetrivalServicePoint = new JsonObject();
expectedItemRetrivalServicePoint.put(RETRIEVAL_SERVICE_POINT_ID, servicePointId);
expectedItemRetrivalServicePoint.put(RETRIEVAL_SERVICE_POINT_NAME, servicePointNew.getString("name"));

waitUntilValueIsIncreased(initialOffset, EventConsumerVerticleTest::getOffsetForServicePointUpdateEvents);
verifyRequestItemRetrievalServicePoint(REQUEST_ID, expectedItemRetrivalServicePoint);
}

@Test
public void requestSearchIndexIsNotUpdatedWhenRequestAndEventAreForDifferentItems() {
JsonObject oldItem = buildItem(DEFAULT_CALL_NUMBER_PREFIX, DEFAULT_CALL_NUMBER,
Expand Down Expand Up @@ -707,6 +743,17 @@ private JsonObject verifyRequestItem(String requestId, JsonObject itemObject) {
}, equalTo(itemObject));
}

private JsonObject verifyRequestItemRetrievalServicePoint(String requestId, JsonObject itemObject) {
return waitAtMost(60, SECONDS)
.until(() -> {
JsonObject requestItem = getRequestItem(requestId);
JsonObject actualItem = new JsonObject();
actualItem.put(RETRIEVAL_SERVICE_POINT_ID, requestItem.getString(RETRIEVAL_SERVICE_POINT_ID));
actualItem.put(RETRIEVAL_SERVICE_POINT_NAME, requestItem.getString(RETRIEVAL_SERVICE_POINT_NAME));
return actualItem;
}, equalTo(itemObject));
}

private JsonObject verifyPickupServicePointName(String requestId, SearchIndex searchIndex) {
return waitAtMost(60, SECONDS)
.until(() -> getRequestSearchIndex(requestId), equalTo(mapFrom(searchIndex)));
Expand Down

0 comments on commit b46a339

Please sign in to comment.