Skip to content

Commit

Permalink
PR-1758 Set service point by code
Browse files Browse the repository at this point in the history
  • Loading branch information
JanisSaldabols committed May 27, 2024
1 parent 1d4c6fd commit 29566ca
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
26 changes: 18 additions & 8 deletions src/main/java/org/folio/ncip/FolioRemoteServiceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,7 @@ public JsonObject acceptItem(AcceptItemInitiationData initData, UserId userId, S

// VALIDATE PICKUP LOCATION
String pickUpLocationCode = initData.getPickupLocation().getValue();
String query = "code==" + StringUtil.cqlEncode(pickUpLocationCode) + " AND pickupLocation==true";
String pickupLocationUrl = baseUrl + "/service-points?query=" + PercentCodec.encode(query);
String servicePointResponse = callApiGet(pickupLocationUrl);
JsonObject servicePoints = new JsonObject(servicePointResponse);
if (servicePoints.getJsonArray("servicepoints").size() == 0)
throw new FolioNcipException("pickup location code note found: " + pickUpLocationCode);
String sPointId = getServicePointId(pickUpLocationCode, baseUrl);

// GENERATE UUIDS FOR OBJECTS
UUID instanceUuid = UUID.randomUUID();
Expand Down Expand Up @@ -508,7 +503,6 @@ public JsonObject acceptItem(AcceptItemInitiationData initData, UserId userId, S
request.put("instanceId", holdings.getString("instanceId"));
request.put("requestLevel", "Item");
request.put("holdingsRecordId", holdingsUuid.toString());
String sPointId = servicePoints.getJsonArray("servicepoints").getJsonObject(0).getString("id");
request.put("pickupServicePointId", sPointId);
DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
ZonedDateTime now = ZonedDateTime.now();
Expand Down Expand Up @@ -552,7 +546,18 @@ public JsonObject acceptItem(AcceptItemInitiationData initData, UserId userId, S
return returnValues;
}

public JsonObject requestItem(String hrid, UserId userId, boolean titleRequest, String requestType) throws Exception {
private String getServicePointId(String pickUpLocationCode, String baseUrl) throws Exception {
String query = "code==" + StringUtil.cqlEncode(pickUpLocationCode) + " AND pickupLocation==true";
String pickupLocationUrl = baseUrl + "/service-points?query=" + PercentCodec.encode(query);
String servicePointResponse = callApiGet(pickupLocationUrl);
JsonObject servicePoints = new JsonObject(servicePointResponse);
if (servicePoints.getJsonArray("servicepoints").size() == 0)
throw new FolioNcipException("pickup location code note found: " + pickUpLocationCode);
return servicePoints.getJsonArray("servicepoints").getJsonObject(0).getString("id");
}

public JsonObject requestItem(String hrid, UserId userId, boolean titleRequest, String requestType,
String pickUpLocationCode) throws Exception {
JsonObject returnValues = new JsonObject();
JsonObject user = lookupPatronRecord(userId);
if (user == null)
Expand All @@ -566,6 +571,7 @@ public JsonObject requestItem(String hrid, UserId userId, boolean titleRequest,

Integer totalRecords = response.getInteger("totalRecords");
if (totalRecords == 1) {

JsonObject request = new JsonObject();
if (titleRequest) {
JsonObject instanceObject = response.getJsonArray("instances").getJsonObject(0);
Expand All @@ -585,6 +591,10 @@ public JsonObject requestItem(String hrid, UserId userId, boolean titleRequest,
request.put("fulfillmentPreference", "Delivery");
request.put("requesterId", user.getString("id"));
request.put("requestDate", DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now()));
if (pickUpLocationCode != null) {
String servicePointId = getServicePointId(pickUpLocationCode, baseUrl);
request.put("pickupServicePointId", servicePointId);
}

String requestUrl = baseUrl + Constants.REQUEST_URL;
String requestResponse = callApiPost(requestUrl, request);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.folio.ncip.services;

import io.vertx.core.json.JsonObject;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.extensiblecatalog.ncip.v2.service.BibliographicId;
import org.extensiblecatalog.ncip.v2.service.ItemDescription;
Expand Down Expand Up @@ -60,6 +61,16 @@ public RequestItemResponseData performService(RequestItemInitiationData initData
exception.getMessage(),exception.getMessage()));
}

String pickUpLocationCode = null;
if (initData.getItemOptionalFields() != null && initData.getItemOptionalFields().getLocations() != null &&
!initData.getItemOptionalFields().getLocations().isEmpty() && initData.getItemOptionalFields().getLocation(0) != null &&
initData.getItemOptionalFields().getLocation(0).getLocationName() != null &&
initData.getItemOptionalFields().getLocation(0).getLocationName().getLocationNameInstances() != null &&
!initData.getItemOptionalFields().getLocation(0).getLocationName().getLocationNameInstances().isEmpty() &&
StringUtils.isNotBlank(initData.getItemOptionalFields().getLocation(0).getLocationName().getLocationNameInstance(0).getLocationNameValue())) {
pickUpLocationCode = initData.getItemOptionalFields().getLocation(0).getLocationName().getLocationNameInstance(0).getLocationNameValue();

}

final boolean titleRequest = initData.getRequestScopeType() != null && initData.getRequestScopeType().getValue().toLowerCase().contains("title");
final String requestType = REQUEST_TYPE.getOrDefault(initData.getRequestType().getValue().toLowerCase(), "Page");
Expand All @@ -69,7 +80,7 @@ public RequestItemResponseData performService(RequestItemInitiationData initData
LocationNameInstance locationNameInstance = new LocationNameInstance();
try {
JsonObject requestItemResponseDetails = ((FolioRemoteServiceManager)serviceManager)
.requestItem(bibliographicId.getBibliographicRecordId().getBibliographicRecordIdentifier(), userId, titleRequest, requestType);
.requestItem(bibliographicId.getBibliographicRecordId().getBibliographicRecordIdentifier(), userId, titleRequest, requestType, pickUpLocationCode);
String assignedRequestId = requestItemResponseDetails.getString("id");
String barcode = null;
String callNumber = null;
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/folio/ncip/MockServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ private Router defineRoutes() {
router.get("/groups/:id").handler(this::groupLookup);
router.get("/users").handler(this::users);
router.get("/service-points-users").handler(this::servicePointUsers);
router.get("/service-points").handler(this::servicePointUsers);
router.get("/manualblocks").handler(this::manualBlocks);
router.get("/automated-patron-blocks/:id").handler(this::automatedBlocks);
//router.get("/configurations/entries/maxloancount").handler(this::getMaxLoanCount);
Expand Down
9 changes: 9 additions & 0 deletions src/test/resources/mockdata/ncip-requestitem-title.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,14 @@
<BibliographicRecordIdentifier>instanceHrid1</BibliographicRecordIdentifier>
</BibliographicRecordId>
</BibliographicId>
<ItemOptionalFields>
<Location>
<LocationName>
<LocationNameInstance>
<LocationNameValue>FAIRCHILD</LocationNameValue>
</LocationNameInstance>
</LocationName>
</Location>
</ItemOptionalFields>
</RequestItem>
</NCIPMessage>

0 comments on commit 29566ca

Please sign in to comment.