Skip to content

Commit

Permalink
CIRC-2148: Reverted CIRC-2100 PR and Rework for PrintEventDetail Pagi…
Browse files Browse the repository at this point in the history
…nation, searching and sorting (#1492)

* CIRC-2148: Reverted CIRC-2100 PR

* CIRC-2148: [Impl] mapped UserDetails user data in Request

* CIRC-2148: [Impl] mapped UserDetails user data in Request

* CIRC-2148: code refactoring

* CIRC-2148: code refactoring

* CIRC-2148: added lastPrintRequester in removeRelatedRecordInformation for update request, reverted some permissions, added new printDetails fields in request.json

* CIRC-2148: test case added partial for debug

* CIRC-2148: fix test case

* CIRC-2148: Fixed PR comments

* CIRC-2148: Bump up interface version

* CIRC-2148: Bump up interface version

* CIRC-2148: reverted circulation version
  • Loading branch information
kapil-epam authored Sep 25, 2024
1 parent 7b49c91 commit 69d9888
Show file tree
Hide file tree
Showing 18 changed files with 193 additions and 478 deletions.
6 changes: 2 additions & 4 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@
},
{
"id": "request-storage",
"version": "6.0"
"version": "6.1"
},
{
"id": "request-storage-batch",
Expand Down Expand Up @@ -2065,9 +2065,7 @@
"users.collection.get",
"addresstypes.collection.get",
"usergroups.collection.get",
"usergroups.item.get",
"print-events-storage.print-events-status.item.post",
"circulation-storage.circulation-settings.collection.get"
"usergroups.item.get"
],
"visible": false
},
Expand Down
8 changes: 5 additions & 3 deletions ramls/examples/request.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@
"pickupServicePointName": "Circ Desk 1"
},
"printDetails": {
"count": 4,
"lastPrintedDate": "2024-07-29T11:54:07.000Z",
"printCount": 32,
"requesterId": "21457ab5-4635-4e56-906a-908f05e9233b",
"isPrinted": true,
"printEventDate": "2024-09-13T06:34:16.035+00:00",
"lastPrintRequester": {
"lastName": "lastName",
"firstName": "firstName",
"lastName": "lastName",
"middleName": "middleName"
}
}
Expand Down
14 changes: 12 additions & 2 deletions ramls/request.json
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,22 @@
"type": "object",
"readonly": true,
"properties": {
"count": {
"printCount": {
"description": "Total no of times the request is printed",
"type": "integer",
"readOnly": true
},
"lastPrintedDate": {
"requesterId": {
"description": "User uuid of last print requester",
"type": "string",
"readOnly": true
},
"isPrinted": {
"description": "Whether the request is ever printed",
"type": "boolean",
"readOnly": true
},
"printEventDate": {
"description": "Recent printed time of the request",
"type": "string",
"format": "date-time",
Expand Down
48 changes: 0 additions & 48 deletions src/main/java/org/folio/circulation/domain/PrintEventDetail.java

This file was deleted.

13 changes: 11 additions & 2 deletions src/main/java/org/folio/circulation/domain/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ public class Request implements ItemRelatedRecord, UserRelatedRecord {
private boolean changedPosition;
private Integer previousPosition;
private boolean changedStatus;

@With
private PrintEventDetail printEventDetail;
private final User printDetailsRequester;

public static Request from(JsonObject representation) {
// TODO: make sure that operation and TLR settings don't matter for all processes calling
Expand Down Expand Up @@ -225,7 +226,7 @@ public Request withItem(Item newItem) {
cancellationReasonRepresentation, instance, instanceItems, instanceItemsRequestPolicies,
newItem, requester, proxy, addressType,
loan == null ? null : loan.withItem(newItem), pickupServicePoint, changedPosition,
previousPosition, changedStatus, printEventDetail);
previousPosition, changedStatus, null);
}

@Override
Expand All @@ -243,6 +244,10 @@ public User getUser() {
return getRequester();
}

public User getPrintDetailsRequester() {
return printDetailsRequester;
}

public String getfulfillmentPreferenceName() {
return requestRepresentation.getString("fulfillmentPreference");
}
Expand Down Expand Up @@ -291,6 +296,10 @@ public JsonObject getRequesterFromRepresentation() {
return requestRepresentation.getJsonObject("requester");
}

public JsonObject getPrintDetails() {
return requestRepresentation.getJsonObject("printDetails");
}

public String getRequesterBarcode() {
return getRequesterFromRepresentation().getString("barcode", EMPTY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,33 @@ public JsonObject extendedRepresentation(Request request) {
addAdditionalProxyProperties(requestRepresentation, request.getProxy());
addAdditionalServicePointProperties(requestRepresentation, request.getPickupServicePoint());
addDeliveryAddress(requestRepresentation, request, request.getRequester());
addPrintEventProperties(requestRepresentation, request.getPrintEventDetail());
addPrintDetailsProperties(request, requestRepresentation);

removeSearchIndexFields(requestRepresentation);

return requestRepresentation;
}

private void addPrintDetailsProperties(Request request, JsonObject requestRepresentation) {
JsonObject printDetails = requestRepresentation.getJsonObject("printDetails");
if (printDetails == null) {
if (log.isInfoEnabled()) {
log.info("addPrintEventProperties:: printDetails property is null for" +
" requestId {}", requestRepresentation.getString("id"));
}
return;
}

User printDetailsUser = request.getPrintDetailsRequester();
if (printDetailsUser != null) {
JsonObject lastPrintRequester = new JsonObject();
lastPrintRequester.put("firstName", printDetailsUser.getFirstName());
lastPrintRequester.put("lastName", printDetailsUser.getLastName());
lastPrintRequester.put("middleName", printDetailsUser.getMiddleName());
printDetails.put("lastPrintRequester", lastPrintRequester);
}
}

private static void addAdditionalRequesterProperties(JsonObject request, User requester) {
if (requester == null) {
String msg = "Unable to add requester properties to the request: {}, requester is null.";
Expand Down Expand Up @@ -258,29 +279,5 @@ private static JsonObject userSummary(User user) {
private static void removeSearchIndexFields(JsonObject request) {
request.remove("searchIndex");
}

private static void addPrintEventProperties(JsonObject request, PrintEventDetail printEventDetail) {
if (printEventDetail == null) {
if (log.isInfoEnabled()) {
log.info("addPrintEventProperties:: printEvent property is null for requestId {}", request.getString("id"));
}
return;
}

var printEvent = new JsonObject();
write(printEvent, "count", printEventDetail.getCount());
write(printEvent, "lastPrintedDate", printEventDetail.getPrintEventDate());

var user = printEventDetail.getUser();
if (user != null) {
var userSummary = new JsonObject();
write(userSummary, "lastName", user.getLastName());
write(userSummary, "firstName", user.getFirstName());
write(userSummary, "middleName", user.getMiddleName());
write(printEvent, "lastPrintRequester", userSummary);
}
write(request, "printDetails", printEvent);
}

}

Original file line number Diff line number Diff line change
@@ -1,46 +1,26 @@
package org.folio.circulation.infrastructure.storage;

import io.vertx.core.json.JsonObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.folio.circulation.domain.MultipleRecords;
import org.folio.circulation.domain.PrintEventDetail;
import org.folio.circulation.domain.PrintEventRequest;
import org.folio.circulation.domain.Request;
import org.folio.circulation.support.Clients;
import org.folio.circulation.support.CollectionResourceClient;
import org.folio.circulation.support.http.client.ResponseInterpreter;
import org.folio.circulation.support.results.Result;

import java.lang.invoke.MethodHandles;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;

import static java.util.concurrent.CompletableFuture.completedFuture;
import static org.folio.circulation.resources.PrintEventsResource.PRINT_EVENT_FLAG_PROPERTY_NAME;
import static org.folio.circulation.resources.PrintEventsResource.PRINT_EVENT_FLAG_QUERY;
import static org.folio.circulation.support.http.ResponseMapping.forwardOnFailure;
import static org.folio.circulation.support.json.JsonPropertyFetcher.getProperty;
import static org.folio.circulation.support.results.Result.of;
import static org.folio.circulation.support.results.Result.succeeded;
import static org.folio.circulation.support.results.ResultBinding.flatMapResult;
import static org.folio.circulation.support.utils.LogUtil.multipleRecordsAsString;

public class PrintEventsRepository {
private static final Logger log = LogManager.getLogger(MethodHandles.lookup().lookupClass());
private static final String RECORDS_PROPERTY_NAME = "printEventsStatusResponses";
private static final String REQUEST_IDS = "requestIds";

private final CollectionResourceClient printEventsStorageClient;
private final CollectionResourceClient printEventsStorageStatusClient;
private final CirculationSettingsRepository circulationSettingsRepository;

public PrintEventsRepository(Clients clients) {
this.printEventsStorageClient = clients.printEventsStorageClient();
this.printEventsStorageStatusClient = clients.printEventsStorageStatusClient();
this.circulationSettingsRepository = new CirculationSettingsRepository(clients);
printEventsStorageClient = clients.printEventsStorageClient();
}

public CompletableFuture<Result<Void>> create(PrintEventRequest printEventRequest) {
Expand All @@ -52,54 +32,4 @@ public CompletableFuture<Result<Void>> create(PrintEventRequest printEventReques
return printEventsStorageClient.post(storagePrintEventRequest).thenApply(interpreter::flatMap);
}

public CompletableFuture<Result<MultipleRecords<Request>>> findPrintEventDetails(
MultipleRecords<Request> multipleRequests) {
log.debug("findPrintEventDetails:: parameters multipleRequests: {}",
() -> multipleRecordsAsString(multipleRequests));
var requestIds = multipleRequests.toKeys(Request::getId);
if (requestIds.isEmpty()) {
log.info("fetchAndMapPrintEventDetails:: No request id found");
return completedFuture(succeeded(multipleRequests));
}
return validatePrintEventFeatureFlag()
.thenCompose(isEnabled -> Boolean.TRUE.equals(isEnabled)
? fetchAndMapPrintEventDetails(multipleRequests, requestIds)
: completedFuture(succeeded(multipleRequests)));
}

private CompletableFuture<Result<MultipleRecords<Request>>> fetchAndMapPrintEventDetails(
MultipleRecords<Request> multipleRequests, Set<String> requestIds) {
log.debug("fetchAndMapPrintEventDetails:: parameters multipleRequests: {}, requestIds {}",
() -> multipleRecordsAsString(multipleRequests), () -> requestIds);
return fetchPrintDetailsByRequestIds(requestIds)
.thenApply(printEventRecordsResult -> printEventRecordsResult
.next(printEventRecords -> mapPrintEventDetailsToRequest(printEventRecords, multipleRequests)));
}

private CompletableFuture<Boolean> validatePrintEventFeatureFlag() {
log.debug("validatePrintEventFeatureFlag:: Fetching and validating enablePrintLog flag from settings");
return circulationSettingsRepository.findBy(PRINT_EVENT_FLAG_QUERY)
.thenApply(res -> Optional.ofNullable(res.value())
.flatMap(records -> records.getRecords().stream().findFirst())
.map(setting -> Boolean.valueOf(getProperty(setting.getValue(), PRINT_EVENT_FLAG_PROPERTY_NAME)))
.orElse(false));
}

private CompletableFuture<Result<MultipleRecords<PrintEventDetail>>> fetchPrintDetailsByRequestIds
(Collection<String> requestIds) {
log.debug("fetchPrintDetailsByRequestIds:: fetching print event details for requestIds {}", requestIds);
return printEventsStorageStatusClient.post(new JsonObject().put(REQUEST_IDS, requestIds))
.thenApply(flatMapResult(response ->
MultipleRecords.from(response, PrintEventDetail::from, RECORDS_PROPERTY_NAME)));
}

private Result<MultipleRecords<Request>> mapPrintEventDetailsToRequest(
MultipleRecords<PrintEventDetail> printEventDetails, MultipleRecords<Request> requests) {
log.debug("mapPrintEventDetailsToRequest:: Mapping print event details {} with requests {}",
() -> multipleRecordsAsString(printEventDetails), () -> multipleRecordsAsString(requests));
Map<String, PrintEventDetail> printEventDetailMap = printEventDetails.toMap(PrintEventDetail::getRequestId);
return of(() ->
requests.mapRecords(request -> request
.withPrintEventDetail(printEventDetailMap.getOrDefault(request.getId(), null))));
}
}
Loading

0 comments on commit 69d9888

Please sign in to comment.