diff --git a/src/main/java/org/folio/ncip/FolioRemoteServiceManager.java b/src/main/java/org/folio/ncip/FolioRemoteServiceManager.java index 46e55c5..9625031 100644 --- a/src/main/java/org/folio/ncip/FolioRemoteServiceManager.java +++ b/src/main/java/org/folio/ncip/FolioRemoteServiceManager.java @@ -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(); @@ -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(); @@ -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) @@ -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); @@ -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); diff --git a/src/main/java/org/folio/ncip/services/FolioRequestItemService.java b/src/main/java/org/folio/ncip/services/FolioRequestItemService.java index 0dc3f0c..24e0dcb 100644 --- a/src/main/java/org/folio/ncip/services/FolioRequestItemService.java +++ b/src/main/java/org/folio/ncip/services/FolioRequestItemService.java @@ -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; @@ -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"); @@ -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; diff --git a/src/test/java/org/folio/ncip/MockServer.java b/src/test/java/org/folio/ncip/MockServer.java index b729135..7806b2e 100644 --- a/src/test/java/org/folio/ncip/MockServer.java +++ b/src/test/java/org/folio/ncip/MockServer.java @@ -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); diff --git a/src/test/resources/mockdata/ncip-requestitem-title.xml b/src/test/resources/mockdata/ncip-requestitem-title.xml index 32b71c7..7677a17 100644 --- a/src/test/resources/mockdata/ncip-requestitem-title.xml +++ b/src/test/resources/mockdata/ncip-requestitem-title.xml @@ -24,5 +24,14 @@ instanceHrid1 + + + + + FAIRCHILD + + + +