Skip to content

Commit

Permalink
CIRC-1933 Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksandrVidinieiev committed Dec 1, 2023
1 parent ce45970 commit e83c30b
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public class TemplateContextUtil {
private static final String FEE_ACTION = "feeAction";
private static final String UNLIMITED = "unlimited";
public static final String CURRENT_DATE_TIME = "currentDateTime";
private static final String PICK_SLIPS_KEY = "pickSlips";
private static final String ADDITIONAL_INFO_KEY = "additionalInfo";

private TemplateContextUtil() {
Expand Down Expand Up @@ -120,25 +119,30 @@ public static JsonObject createStaffSlipContext(Request request) {
return createStaffSlipContext(request.getItem(), request);
}

public static JsonObject addPrimaryServicePointNameToStaffSlipContext(JsonObject entries, ServicePoint primaryServicePoint) {
log.debug("addPrimaryServicePointNameToStaffSlipContext:: parameters entries: {} primaryServicePoint: {}", entries, primaryServicePoint);
public static JsonObject addPrimaryServicePointNameToStaffSlipContext(JsonObject entries,
ServicePoint primaryServicePoint, String slipsCollectionName) {

log.debug("addPrimaryServicePointNameToStaffSlipContext:: parameters entries: {}, " +
"primaryServicePoint: {}, slipsCollectionName: {}", entries, primaryServicePoint, slipsCollectionName);
if (primaryServicePoint == null) {
log.info("addPrimaryServicePointNameToStaffSlipContext:: primaryServicePoint object is null");
return entries;
}

if (entries == null) {
log.info("addPrimaryServicePointNameToStaffSlipContext:: entries JsonObject is null, primaryServicePointName: {}", primaryServicePoint.getName());
log.info("addPrimaryServicePointNameToStaffSlipContext:: entries JsonObject is null, " +
"primaryServicePointName: {}", primaryServicePoint.getName());
return new JsonObject();
}

entries.getJsonArray(PICK_SLIPS_KEY)
entries.getJsonArray(slipsCollectionName)
.stream()
.map(JsonObject.class::cast)
.map(pickSlip -> pickSlip.getJsonObject(ITEM))
.forEach(item -> item.put("effectiveLocationPrimaryServicePointName", primaryServicePoint.getName()));

log.info("addPrimaryServicePointNameToStaffSlipContext:: Result entries: {}, primaryServicePointName: {}", entries, primaryServicePoint.getName());
log.debug("addPrimaryServicePointNameToStaffSlipContext:: Result entries: {}, " +
"primaryServicePointName: {}", () -> entries, primaryServicePoint::getName);

return entries;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
public class PickSlipsResource extends SlipsResource {

public PickSlipsResource(String rootPath, HttpClient client) {
super(rootPath, client, PAGE, PAGED, "pickSlips");
super(rootPath, client, "pickSlips", PAGE, PAGED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
public class SearchSlipsResource extends SlipsResource {

public SearchSlipsResource(String rootPath, HttpClient client) {
super(rootPath, client, HOLD, getItemStatusesAllowedForRequestType(HOLD), "searchSlips");
super(rootPath, client, "searchSlips", HOLD, getItemStatusesAllowedForRequestType(HOLD));
}
}
26 changes: 17 additions & 9 deletions src/main/java/org/folio/circulation/resources/SlipsResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.folio.circulation.domain.Request;
import org.folio.circulation.domain.RequestStatus;
import org.folio.circulation.domain.RequestType;
import org.folio.circulation.domain.ServicePoint;
import org.folio.circulation.domain.notice.TemplateContextUtil;
import org.folio.circulation.infrastructure.storage.ServicePointRepository;
import org.folio.circulation.infrastructure.storage.inventory.ItemRepository;
Expand Down Expand Up @@ -70,24 +71,24 @@ public abstract class SlipsResource extends Resource {
private static final String PRIMARY_SERVICE_POINT_KEY = "primaryServicePoint";

private final String rootPath;
private final String collectionName;
private final RequestType requestType;
private final Collection<ItemStatus> itemStatuses;
private final String jsonCollectionName;

public SlipsResource(String rootPath, HttpClient client, RequestType requestType,
ItemStatus itemStatus, String jsonCollectionName) {
public SlipsResource(String rootPath, HttpClient client, String collectionName,
RequestType requestType, ItemStatus itemStatus) {

this(rootPath, client, requestType, List.of(itemStatus), jsonCollectionName);
this(rootPath, client, collectionName, requestType, List.of(itemStatus));
}

public SlipsResource(String rootPath, HttpClient client, RequestType requestType,
Collection<ItemStatus> itemStatuses, String jsonCollectionName) {
public SlipsResource(String rootPath, HttpClient client, String collectionName,
RequestType requestType, Collection<ItemStatus> itemStatuses) {

super(client);
this.rootPath = rootPath;
this.requestType = requestType;
this.itemStatuses = itemStatuses;
this.jsonCollectionName = jsonCollectionName;
this.collectionName = collectionName;
}

@Override
Expand Down Expand Up @@ -120,7 +121,7 @@ private void getMany(RoutingContext routingContext) {
.thenComposeAsync(r -> r.after(servicePointRepository::findServicePointsForRequests))
.thenApply(flatMapResult(this::mapResultToJson))
.thenComposeAsync(r -> r.combineAfter(() -> servicePointRepository.getServicePointById(servicePointId),
TemplateContextUtil::addPrimaryServicePointNameToStaffSlipContext))
this::addPrimaryServicePointNameToStaffSlipContext))
.thenApply(r -> r.map(JsonHttpResponse::ok))
.thenAccept(context::writeResultToHttpResponse);
}
Expand Down Expand Up @@ -243,9 +244,16 @@ private Result<JsonObject> mapResultToJson(MultipleRecords<Request> requests) {
.map(TemplateContextUtil::createStaffSlipContext)
.toList();
JsonObject jsonRepresentations = new JsonObject()
.put(jsonCollectionName, representations)
.put(collectionName, representations)
.put(TOTAL_RECORDS_KEY, representations.size());

return succeeded(jsonRepresentations);
}

private JsonObject addPrimaryServicePointNameToStaffSlipContext(JsonObject context,
ServicePoint servicePoint) {

return TemplateContextUtil.addPrimaryServicePointNameToStaffSlipContext(
context, servicePoint, collectionName);
}
}
Loading

0 comments on commit e83c30b

Please sign in to comment.