diff --git a/src/main/java/org/folio/circulation/domain/ServicePoint.java b/src/main/java/org/folio/circulation/domain/ServicePoint.java index b9710508fb..1f4ffb7dce 100644 --- a/src/main/java/org/folio/circulation/domain/ServicePoint.java +++ b/src/main/java/org/folio/circulation/domain/ServicePoint.java @@ -12,6 +12,10 @@ public static ServicePoint unknown(String id) { return new ServicePoint(id, null, null, false, null, null, null, null, null); } + public static ServicePoint unknown(String id, String name) { + return new ServicePoint(id, name, null, false, null, null, null, null, null); + } + String id; String name; String code; diff --git a/src/main/java/org/folio/circulation/domain/notice/TemplateContextUtil.java b/src/main/java/org/folio/circulation/domain/notice/TemplateContextUtil.java index 839cdd1123..499da205a0 100644 --- a/src/main/java/org/folio/circulation/domain/notice/TemplateContextUtil.java +++ b/src/main/java/org/folio/circulation/domain/notice/TemplateContextUtil.java @@ -44,6 +44,7 @@ public class TemplateContextUtil { private static final String FEE_CHARGE = "feeCharge"; private static final String FEE_ACTION = "feeAction"; private static final String UNLIMITED = "unlimited"; + private static final String PICK_SLIPS_KEY = "pickSlips"; private TemplateContextUtil() { } @@ -108,6 +109,19 @@ public static JsonObject createStaffSlipContext(Request request) { return createStaffSlipContext(request.getItem(), request); } + public static JsonObject addPrimaryServicePointNameToStaffSlipContext(JsonObject entries, ServicePoint primaryServicePoint) { + if (entries == null) { + return new JsonObject(); + } + if(primaryServicePoint == null) { + return entries; + } + entries.getJsonArray(PICK_SLIPS_KEY).stream().forEach(pickSlip -> { + ((JsonObject)pickSlip).getJsonObject(ITEM).put("effectiveLocationPrimaryServicePointName", primaryServicePoint.getName()); + }); + return entries; + } + public static JsonObject createStaffSlipContext( Item item, Request request) { @@ -184,6 +198,7 @@ private static JsonObject createItemContext(Item item) { if (location != null) { itemContext .put("effectiveLocationSpecific", location.getName()) + .put("effectiveLocationPrimaryServicePointName", location.getPrimaryServicePoint().getName()) .put("effectiveLocationLibrary", location.getLibraryName()) .put("effectiveLocationCampus", location.getCampusName()) .put("effectiveLocationInstitution", location.getInstitutionName()) @@ -231,6 +246,9 @@ private static JsonObject createRequestContext(Request request) { .map(Request::getPickupServicePoint) .map(ServicePoint::getName) .ifPresent(value -> requestContext.put("servicePointPickup", value)); + optionalRequest + .map(Request::getRequestDate) + .ifPresent(value -> write(requestContext, "requestDate", value)); optionalRequest .map(Request::getRequestExpirationDate) .ifPresent(value -> write(requestContext, "requestExpirationDate", value)); diff --git a/src/main/java/org/folio/circulation/resources/PickSlipsResource.java b/src/main/java/org/folio/circulation/resources/PickSlipsResource.java index 3d94bb3bdd..02fafca506 100644 --- a/src/main/java/org/folio/circulation/resources/PickSlipsResource.java +++ b/src/main/java/org/folio/circulation/resources/PickSlipsResource.java @@ -104,6 +104,8 @@ private void getMany(RoutingContext routingContext) { .thenComposeAsync(r -> r.after(addressTypeRepository::findAddressTypesForRequests)) .thenComposeAsync(r -> r.after(servicePointRepository::findServicePointsForRequests)) .thenApply(flatMapResult(this::mapResultToJson)) + .thenComposeAsync(a -> a.combineAfter(() -> servicePointRepository.getServicePointById(servicePointId), + TemplateContextUtil::addPrimaryServicePointNameToStaffSlipContext)) .thenApply(r -> r.map(JsonHttpResponse::ok)) .thenAccept(context::writeResultToHttpResponse); } diff --git a/src/main/java/org/folio/circulation/storage/mappers/LocationMapper.java b/src/main/java/org/folio/circulation/storage/mappers/LocationMapper.java index 897c30e26f..338534bf5e 100644 --- a/src/main/java/org/folio/circulation/storage/mappers/LocationMapper.java +++ b/src/main/java/org/folio/circulation/storage/mappers/LocationMapper.java @@ -27,7 +27,7 @@ public Location toDomain(JsonObject representation) { Institution.unknown(getProperty(representation, "institutionId")), Campus.unknown(getProperty(representation, "campusId")), Library.unknown(getProperty(representation, "libraryId")), - ServicePoint.unknown(getProperty(representation, "primaryServicePoint"))); + ServicePoint.unknown(getProperty(representation, "primaryServicePoint"), getProperty(representation, "primaryServicePointName"))); } private Collection getServicePointIds(JsonObject representation) { diff --git a/src/test/java/api/requests/PickSlipsTests.java b/src/test/java/api/requests/PickSlipsTests.java index f8a1af547b..6b90745dde 100644 --- a/src/test/java/api/requests/PickSlipsTests.java +++ b/src/test/java/api/requests/PickSlipsTests.java @@ -178,7 +178,7 @@ void responseContainsPickSlipWithAllAvailableTokens() { JsonObject itemContext = pickSlip.getJsonObject(ITEM_KEY); ZonedDateTime requestCheckinDateTime = getDateTimeProperty(itemContext, "lastCheckedInDateTime"); - + Item item = Item.from(itemResource.getJson()) .withInstance(new InstanceMapper().toDomain(itemResource.getInstance().getJson())); @@ -206,7 +206,7 @@ void responseContainsPickSlipWithAllAvailableTokens() { assertEquals(item.getDescriptionOfPieces(), itemContext.getString("descriptionOfPieces")); assertDatetimeEquivalent(actualCheckinDateTime, requestCheckinDateTime); assertEquals(location.getName(), itemContext.getString("effectiveLocationSpecific")); - + assertEquals(location.getPrimaryServicePoint().getName(), itemContext.getString("effectiveLocationPrimaryServicePointName")); CallNumberComponents callNumberComponents = item.getCallNumberComponents(); assertEquals(callNumberComponents.getCallNumber(), itemContext.getString("callNumber")); assertEquals(callNumberComponents.getPrefix(), itemContext.getString("callNumberPrefix")); diff --git a/src/test/java/api/support/builders/LocationBuilder.java b/src/test/java/api/support/builders/LocationBuilder.java index cec11f32e6..a53762c91f 100644 --- a/src/test/java/api/support/builders/LocationBuilder.java +++ b/src/test/java/api/support/builders/LocationBuilder.java @@ -10,6 +10,7 @@ import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; +import org.folio.circulation.domain.ServicePoint; public class LocationBuilder extends JsonBuilder implements Builder { @@ -21,9 +22,10 @@ public class LocationBuilder extends JsonBuilder implements Builder { private final UUID libraryId; private final UUID primaryServicePointId; private final Set otherServicePointIds; + private final String primaryServicePointName; public LocationBuilder() { - this(null, null, null, null, null, null, null, new HashSet<>()); + this(null, null, null, null, null, null, null, new HashSet<>(), null); } private LocationBuilder( @@ -34,7 +36,8 @@ private LocationBuilder( UUID campusId, UUID libraryId, UUID primaryServicePointId, - Set otherServicePointIds) { + Set otherServicePointIds, + String primaryServicePointName) { if (otherServicePointIds == null) { otherServicePointIds = new HashSet<>(); @@ -48,6 +51,7 @@ private LocationBuilder( this.libraryId = libraryId; this.primaryServicePointId = primaryServicePointId; this.otherServicePointIds = otherServicePointIds; + this.primaryServicePointName = primaryServicePointName; } @Override @@ -70,6 +74,7 @@ public JsonObject create() { .collect(Collectors.toList())); write(representation, "servicePointIds", mappedServicePointIds); + write(representation, "primaryServicePointName", primaryServicePointName); } return representation; @@ -84,7 +89,8 @@ public LocationBuilder withName(String name) { this.campusId, this.libraryId, this.primaryServicePointId, - this.otherServicePointIds); + this.otherServicePointIds, + this.primaryServicePointName); } public LocationBuilder withCode(String code) { @@ -96,7 +102,8 @@ public LocationBuilder withCode(String code) { this.campusId, this.libraryId, this.primaryServicePointId, - this.otherServicePointIds); + this.otherServicePointIds, + this.primaryServicePointName); } public LocationBuilder forInstitution(UUID institutionId) { @@ -108,7 +115,8 @@ public LocationBuilder forInstitution(UUID institutionId) { this.campusId, this.libraryId, this.primaryServicePointId, - this.otherServicePointIds); + this.otherServicePointIds, + this.primaryServicePointName); } public LocationBuilder forCampus(UUID campusId) { @@ -120,7 +128,8 @@ public LocationBuilder forCampus(UUID campusId) { campusId, this.libraryId, this.primaryServicePointId, - this.otherServicePointIds); + this.otherServicePointIds, + this.primaryServicePointName); } public LocationBuilder forLibrary(UUID libraryId) { @@ -132,7 +141,8 @@ public LocationBuilder forLibrary(UUID libraryId) { this.campusId, libraryId, this.primaryServicePointId, - this.otherServicePointIds); + this.otherServicePointIds, + this.primaryServicePointName); } public LocationBuilder withPrimaryServicePoint(UUID primaryServicePointId) { @@ -144,7 +154,22 @@ public LocationBuilder withPrimaryServicePoint(UUID primaryServicePointId) { this.campusId, this.libraryId, primaryServicePointId, - this.otherServicePointIds) + this.otherServicePointIds, + this.primaryServicePointName) + .servedBy(primaryServicePointId); + } + + public LocationBuilder withPrimaryServicePointName(String primaryServicePointName) { + return new LocationBuilder( + this.name, + this.code, + this.discoveryDisplayName, + this.institutionId, + this.campusId, + this.libraryId, + primaryServicePointId, + this.otherServicePointIds, + primaryServicePointName) .servedBy(primaryServicePointId); } @@ -157,7 +182,8 @@ public LocationBuilder withDiscoveryDisplayName(String discoveryDisplayName) { this.campusId, this.libraryId, this.primaryServicePointId, - this.otherServicePointIds); + this.otherServicePointIds, + this.primaryServicePointName); } public LocationBuilder servedBy(UUID servicePointId) { @@ -181,6 +207,7 @@ public LocationBuilder servedBy(Set servicePoints) { this.campusId, this.libraryId, this.primaryServicePointId, - newServicePointIds); + newServicePointIds, + this.primaryServicePointName); } } diff --git a/src/test/java/api/support/examples/LocationExamples.java b/src/test/java/api/support/examples/LocationExamples.java index c368585573..5e4ce2d1dd 100644 --- a/src/test/java/api/support/examples/LocationExamples.java +++ b/src/test/java/api/support/examples/LocationExamples.java @@ -70,6 +70,7 @@ public LocationBuilder thirdFloor() { .forCampus(jubileeCampusId) .forLibrary(djanoglyLibraryId) .withPrimaryServicePoint(primaryServicePointId) + .withPrimaryServicePointName("Circ Desk 1") .servedBy(otherServicePointIds); }