Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIRCSTORE-541: added ItemRetrievalServicePointUpdateProcessorForRequest for retrival SP for request #505

Merged
merged 22 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7a5fd74
CIRCSTORE-540: ItemUpdateProcessorForRequest update item's location a…
kapil-epam Dec 13, 2024
78f28d0
CIRCSTORE-540: added log for debugging
kapil-epam Dec 13, 2024
a0341dd
CIRCSTORE-540: added log for debugging
kapil-epam Dec 13, 2024
d3653a5
CIRCSTORE-540: set additionalProperties true inside location.json
kapil-epam Dec 13, 2024
32c8464
CIRCSTORE-540: fix exception issue
kapil-epam Dec 13, 2024
73c1ad5
CIRCSTORE-540: fix exception issue
kapil-epam Dec 13, 2024
15344f5
CIRCSTORE-540: 1) added async mechanism in EventProcessor class to ex…
kapil-epam Dec 16, 2024
c70e263
CIRCSTORE-540: removed unnecessary log and code
kapil-epam Dec 16, 2024
b25ccac
CIRCSTORE-540: using location and SP constants
kapil-epam Dec 16, 2024
0d592b3
CIRCSTORE-540: fix NLP due to logging of null object
kapil-epam Dec 17, 2024
dcefa0e
Merge branch 'master' into CIRCSTORE-540
kapil-epam Dec 17, 2024
29b77fb
CIRCSTORE-540: fixed sonar issues
kapil-epam Dec 17, 2024
fc37788
Merge remote-tracking branch 'origin/CIRCSTORE-540' into CIRCSTORE-540
kapil-epam Dec 17, 2024
f00ec57
CIRCSTORE-541: added ItemRetrievalServicePointUpdateProcessorForReque…
kapil-epam Dec 19, 2024
e7da0d8
Merge branch 'master' into CIRCSTORE-541
kapil-epam Dec 19, 2024
35addbe
CIRCSTORE-541: fix duplicate code line sonar issue
kapil-epam Dec 19, 2024
e58ea5f
Merge remote-tracking branch 'origin/CIRCSTORE-541' into CIRCSTORE-541
kapil-epam Dec 19, 2024
1f3d619
CIRCSTORE-540: added interface dependency for location and service-po…
kapil-epam Dec 20, 2024
cd4cf78
Merge branch 'master' into CIRCSTORE-540
kapil-epam Dec 20, 2024
226eefb
Merge branch 'CIRCSTORE-540' into CIRCSTORE-541
kapil-epam Dec 20, 2024
c0f9087
Merge branch 'master' into CIRCSTORE-541
kapil-epam Dec 23, 2024
2ee8bff
CIRCSTORE-541: resolved merge conflict
kapil-epam Dec 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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