Skip to content

Commit

Permalink
Merge branch 'PR-2026' into PR-2026-D
Browse files Browse the repository at this point in the history
  • Loading branch information
JanisSaldabols committed Nov 12, 2024
2 parents c759a42 + 0381e2c commit 9b5a065
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
55 changes: 30 additions & 25 deletions src/main/java/org/folio/ncip/FolioRemoteServiceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public JsonObject checkIn(CheckInItemInitiationData initData, String agencyId) t

initProperties(agencyId, baseUrl);

String servicePoint = ncipProperties.getProperty(agencyId + ".checkin.service.point.id");
String servicePoint = getProperty(agencyId,"checkin.service.point.id");

JsonObject jsonObject = new JsonObject();
jsonObject.put("servicePointId", servicePoint);
Expand Down Expand Up @@ -409,7 +409,7 @@ public JsonObject checkOut(CheckOutItemInitiationData initData, String agencyId)

initProperties(agencyId, baseUrl);

String servicePoint = ncipProperties.getProperty(agencyId + ".checkout.service.point.id");
String servicePoint = getProperty(agencyId, "checkout.service.point.id");
JsonObject jsonObject = new JsonObject();
jsonObject.put("itemBarcode", itemBarcode);
jsonObject.put("userBarcode", user.getString("barcode"));
Expand Down Expand Up @@ -447,11 +447,11 @@ public JsonObject checkOut(CheckOutItemInitiationData initData, String agencyId)
}

private void addStaffInfoIfNeeded(String agencyId, RequestId requestId, String loanUuid, String baseUrl){
String noteEnabled = ncipProperties.getProperty(agencyId + ".request.note.enabled");
String noteEnabled = getProperty(agencyId, "request.note.enabled");
if (Constants.BOOLEAN_TRUE.equalsIgnoreCase(noteEnabled) && requestId != null &&
requestId.getRequestIdentifierValue() != null) {
JsonObject staffInfo = new JsonObject();
staffInfo.put("action", ncipProperties.getProperty(agencyId + ".checkout.loan.info.type"));
staffInfo.put("action", getProperty(agencyId, "checkout.loan.info.type"));
staffInfo.put("actionComment", String.format(Constants.NOTE_TITLE_TEMPLATE, requestId.getRequestIdentifierValue()));
try {
callApiPost(baseUrl + String.format(Constants.ADD_STAFF_INFO_URL, loanUuid), staffInfo);
Expand Down Expand Up @@ -511,13 +511,13 @@ public JsonObject acceptItem(AcceptItemInitiationData initData, UserId userId, S
// BUILD INSTANCE
JsonObject instance = new JsonObject();
instance.put(Constants.TITLE, retreiveItemTitle(initData));
instance.put("instanceTypeId", ncipProperties.get(requesterAgencyId + ".instance.type.id"));
instance.put("instanceTypeId", getProperty(requesterAgencyId,"instance.type.id"));
instance.put(Constants.ID, instanceUuid.toString());
instance.put("source", ncipProperties.get(requesterAgencyId + ".instance.source"));
instance.put("source", getProperty(requesterAgencyId,"instance.source"));
instance.put("discoverySuppress", true);
JsonArray identifiersArray = new JsonArray();
JsonObject identifier = new JsonObject();
identifier.put("identifierTypeId", ncipProperties.get(requesterAgencyId + ".instance.custom.identifier.id"));
identifier.put("identifierTypeId", getProperty(requesterAgencyId, "instance.custom.identifier.id"));
identifier.put("value", initData.getRequestId().getRequestIdentifierValue());
identifiersArray.add(identifier);
instance.put("identifiers", identifiersArray);
Expand All @@ -529,9 +529,9 @@ public JsonObject acceptItem(AcceptItemInitiationData initData, UserId userId, S

// CALL HOLDINGS API:
JsonObject holdings = new JsonObject();
String holdingsPermLocation = ncipProperties.getProperty(requesterAgencyId + ".holdings.perm.location.id");
String holdingsPermLocation = getProperty(requesterAgencyId,"holdings.perm.location.id");
holdings.put(Constants.ID, holdingsUuid.toString());
holdings.put("sourceId", ncipProperties.get(requesterAgencyId + ".holdings.source.id"));
holdings.put("sourceId", getProperty(requesterAgencyId, "holdings.source.id"));
holdings.put("instanceId", instanceUuid.toString());
holdings.put("discoverySuppress", true);
// REQUIRED, ELSE IT WILL NOT SHOW UP IN INVENTORY SEARCH BY LOCA.
Expand All @@ -540,8 +540,8 @@ public JsonObject acceptItem(AcceptItemInitiationData initData, UserId userId, S
String holdingsResponse = callApiPost(url, holdings);

// CALL ITEMS API
String itemStatusName = ncipProperties.getProperty(requesterAgencyId + ".item.status.name");
String itemLocation = ncipProperties.getProperty(requesterAgencyId + ".item.perm.location.id");
String itemStatusName = getProperty(requesterAgencyId, "item.status.name");
String itemLocation = getProperty(requesterAgencyId, "item.perm.location.id");
ItemId itemId = initData.getItemId();
JsonObject item = new JsonObject();
item.put(Constants.ID, itemUuid.toString());
Expand All @@ -552,11 +552,11 @@ public JsonObject acceptItem(AcceptItemInitiationData initData, UserId userId, S
JsonObject permLocation = new JsonObject();
permLocation.put(Constants.ID, itemLocation);
JsonObject materialType = new JsonObject();
materialType.put(Constants.ID, ncipProperties.getProperty(requesterAgencyId + ".item.material.type.id"));
materialType.put(Constants.ID, getProperty(requesterAgencyId, "item.material.type.id"));
JsonObject status = new JsonObject();
status.put("name", itemStatusName);
JsonObject permLoanType = new JsonObject();
permLoanType.put(Constants.ID, ncipProperties.getProperty(requesterAgencyId + ".item.perm.loan.type.id"));
permLoanType.put(Constants.ID, getProperty(requesterAgencyId, "item.perm.loan.type.id"));

item.put(Constants.STATUS, status);
item.put("materialType", materialType);
Expand All @@ -572,7 +572,7 @@ public JsonObject acceptItem(AcceptItemInitiationData initData, UserId userId, S
request.put("requestType", "Page");
// FOR EXPLAINATION ABOUT HARDCODE FULFILLMENT
// SEE NOTES.TXT
request.put("fulfillmentPreference", ncipProperties.getProperty(requesterAgencyId + ".request.accept.fulfillment_preference"));
request.put("fulfillmentPreference", getProperty(requesterAgencyId, "request.accept.fulfillment_preference"));
String uid = user.getString(Constants.ID);
request.put("requesterId", uid);
request.put("itemId", itemUuid.toString());
Expand Down Expand Up @@ -740,14 +740,14 @@ public JsonObject requestItem(RequestItemInitiationData initData) throws Excepti
request.put(Constants.REQUEST_LEVEL, "Item");
}
request.put("requestType", requestType);
request.put("fulfillmentPreference", ncipProperties.getProperty(agencyId + ".request.fulfillment_preference"));
request.put("fulfillmentPreference", getProperty(agencyId, "request.fulfillment_preference"));
request.put("requesterId", user.getString(Constants.ID));
request.put("requestDate", DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now()));
String servicePointId;
if (pickUpLocationCode != null) {
servicePointId = getServicePointId(pickUpLocationCode, baseUrl);
} else {
servicePointId = ncipProperties.getProperty(agencyId + ".checkout.service.point.id");
servicePointId = getProperty(agencyId, "checkout.service.point.id");
}
request.put("pickupServicePointId", servicePointId);
request.put("itemLocationCode", locationCode);
Expand All @@ -772,11 +772,11 @@ public JsonObject requestItem(RequestItemInitiationData initData) throws Excepti

private void addNoteIfNeeded(String agencyId, String requestUuid, String illRequestId, String baseUrl) {
try {
String noteEnabled = ncipProperties.getProperty(agencyId + ".request.note.enabled");
String noteEnabled = getProperty(agencyId, "request.note.enabled");
if (Constants.BOOLEAN_TRUE.equalsIgnoreCase(noteEnabled)) {
JsonObject note = new JsonObject();
note.put("domain", Constants.NOTE_DOMAIN_REQUESTS);
note.put("typeId", ncipProperties.getProperty(agencyId + ".request.note.id"));
note.put("typeId", getProperty(agencyId, "request.note.id"));
note.put(Constants.TITLE, String.format(Constants.NOTE_TITLE_TEMPLATE, illRequestId));
JsonArray links = new JsonArray();
JsonObject link = new JsonObject();
Expand Down Expand Up @@ -916,10 +916,7 @@ private void initProperties(String requesterAgencyId, String baseUrl) throws Exc
String returnArray = (String) setting.get("returnArray");
String identifier = (String) setting.get("identifier");

String lookupValue = ncipProperties.getProperty(requesterAgencyId + "." + lookup);

//IF THERE IS A DEFAULT VALUE FOR THE TENANT USE IT
if (lookupValue == null) lookupValue = ncipProperties.getProperty(lookup);
String lookupValue = getProperty(requesterAgencyId, lookup);

if (lookupValue == null) throw new Exception("configuration value missing for " + requesterAgencyId + "." + lookup);

Expand Down Expand Up @@ -1088,7 +1085,7 @@ public JsonObject cancelRequestItem(String requestId, UserId userId, String agen

initProperties(agencyId, baseUrl);

String reasonId = ncipProperties.getProperty(agencyId + ".cancel.request.reason.id");
String reasonId = getProperty(agencyId,"cancel.request.reason.id");

String url = baseUrl + Constants.REQUEST_URL + "/" + requestId;
try {
Expand Down Expand Up @@ -1137,7 +1134,7 @@ public void deleteItem(String itemId, String agencyId) throws Exception {
JsonObject requestResponse = new JsonObject(requestResponseString);
if (requestResponse.getInteger(Constants.TOTAL_RECORDS) > 0) {
// Need to close open requests
String reasonId = ncipProperties.getProperty(agencyId + ".cancel.request.reason.patron.id");
String reasonId = getProperty(agencyId, "cancel.request.reason.patron.id");

JsonArray requests = requestResponse.getJsonArray("requests");
requests.forEach(r -> {
Expand All @@ -1155,7 +1152,7 @@ public void deleteItem(String itemId, String agencyId) throws Exception {
});
}

String softDeleteEnabled = ncipProperties.getProperty(agencyId + ".item.soft.delete");
String softDeleteEnabled = getProperty(agencyId, "item.soft.delete");
if (Constants.BOOLEAN_TRUE.equalsIgnoreCase(softDeleteEnabled)) {
// Update item to Unavailable
itemObject.getJsonObject(Constants.STATUS).put("name", Constants.ITEM_STATUS_UNAVAILABLE);
Expand All @@ -1174,6 +1171,14 @@ public void deleteItem(String itemId, String agencyId) throws Exception {
}
}

private String getProperty(String agencyId, String key){
String value = ncipProperties.getProperty(agencyId + "." + key);
if (value == null) {
value = ncipProperties.getProperty(key);
}
return value;
}

public JsonObject createUserFiscalTransaction(UserId userId, FiscalTransactionInformation fiscalTransactionInformation) throws Exception {
try {
String baseUrl = okapiHeaders.get(Constants.X_OKAPI_URL);
Expand Down
13 changes: 9 additions & 4 deletions src/test/java/org/folio/ncip/MockServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,15 @@ private void getNcipConfigs(RoutingContext ctx) {
ctx.reroute("/configurations/entries/toolkit");
}


String mockFileName = TestConstants.PATH_TO_MOCK_FILES + "ncip-configs.json";
String body = readLineByLine(mockFileName);
serverResponse(ctx, 200, APPLICATION_JSON, body);
if (param.contains("code==\"request.fulfillment_preference\"") ||
param.contains("code==\"request.accept.fulfillment_preference\"") ||
param.contains("code==\"checkout.loan.info.type\"")) {
serverResponse(ctx, 200, APPLICATION_JSON, "{\"configs\": []}");
} else {
String mockFileName = TestConstants.PATH_TO_MOCK_FILES + "ncip-configs.json";
String body = readLineByLine(mockFileName);
serverResponse(ctx, 200, APPLICATION_JSON, body);
}
}

private void getToolkitCofigs(RoutingContext ctx) {
Expand Down

0 comments on commit 9b5a065

Please sign in to comment.