Skip to content

Commit

Permalink
Revert "CIRC-2050 Add useStubItem parameter to allowed-service-points…
Browse files Browse the repository at this point in the history
… endpoint (#1447)"

This reverts commit e11290c.
  • Loading branch information
roman-barannyk committed Apr 15, 2024
1 parent 948a2c5 commit 393cb0d
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 128 deletions.
2 changes: 1 addition & 1 deletion descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@
},
{
"id": "allowed-service-points",
"version": "1.1",
"version": "1.0",
"handlers": [
{
"methods": [
Expand Down
6 changes: 1 addition & 5 deletions ramls/circulation.raml
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,6 @@ resourceTypes:
description: "Instance ID"
pattern: "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[1-5][a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$"
required: false
useStubItem:
description: "When true, allows to apply circulation rules based on patron group only"
type: boolean
required: false
responses:
200:
description: "List of allowed service points was retrieved successfully"
Expand All @@ -368,4 +364,4 @@ resourceTypes:
description: "Internal server error"
body:
text/plain:
example: "Internal server error"
example: "Internal server error"
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public class AllowedServicePointsRequest {
private String requesterId;
private String instanceId;
private String itemId;
private String requestId;
private boolean useStubItem;

public boolean isForTitleLevelRequest() {
return instanceId != null;
Expand All @@ -29,6 +27,7 @@ public boolean isForTitleLevelRequest() {
public boolean isForItemLevelRequest() {
return itemId != null;
}
private String requestId;

public AllowedServicePointsRequest updateWithRequestInformation(Request request) {
log.debug("updateWithRequestInformation:: parameters request: {}", request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.function.BinaryOperator;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -96,15 +95,6 @@ public CompletableFuture<Result<Map<RequestPolicy, Set<Item>>>> lookupRequestPol
.thenCompose(r -> r.after(this::lookupRequestPolicies));
}

public CompletableFuture<Result<RequestPolicy>> lookupRequestPolicy(User user) {
// Circulation rules need to be executed with the patron group parameter only.
// All the item-related parameters should be random UUIDs.
return lookupRequestPolicyId(UUID.randomUUID().toString(), user.getPatronGroupId(),
UUID.randomUUID().toString(), UUID.randomUUID().toString())
.thenCompose(r -> r.after(this::lookupRequestPolicy))
.thenApply(result -> result.map(RequestPolicy::from));
}

private BinaryOperator<Set<Item>> itemsMergeOperator() {
return (items1, items2) -> Stream.concat(items1.stream(), items2.stream())
.collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,39 +67,52 @@ private static Result<AllowedServicePointsRequest> buildRequest(RoutingContext r
.map(String::toUpperCase)
.map(Request.Operation::valueOf)
.orElse(null);
String requesterId = queryParams.get("requesterId");
String instanceId = queryParams.get("instanceId");
String itemId = queryParams.get("itemId");
String requestId = queryParams.get("requestId");
String useStubItem = queryParams.get("useStubItem");

AllowedServicePointsRequest request = new AllowedServicePointsRequest(operation,
queryParams.get("requesterId"), queryParams.get("instanceId"), queryParams.get("itemId"),
queryParams.get("requestId"));

return validateAllowedServicePointsRequest(request);
}

private static Result<AllowedServicePointsRequest> validateAllowedServicePointsRequest(
AllowedServicePointsRequest allowedServicePointsRequest) {

log.debug("validateAllowedServicePointsRequest:: parameters allowedServicePointsRequest: {}",
allowedServicePointsRequest);

Request.Operation operation = allowedServicePointsRequest.getOperation();
String requesterId = allowedServicePointsRequest.getRequesterId();
String instanceId = allowedServicePointsRequest.getInstanceId();
String itemId = allowedServicePointsRequest.getItemId();
String requestId = allowedServicePointsRequest.getRequestId();

List<String> errors = new ArrayList<>();

// Checking UUID validity

if (requesterId != null && !isUuid(requesterId)) {
log.warn("validateAllowedServicePointsRequest:: requester ID is not a valid UUID: {}", requesterId);
log.warn("Requester ID is not a valid UUID: {}", requesterId);
errors.add(String.format("Requester ID is not a valid UUID: %s.", requesterId));
}

if (instanceId != null && !isUuid(instanceId)) {
log.warn("validateAllowedServicePointsRequest:: instance ID is not a valid UUID: {}",
requesterId);
log.warn("Instance ID is not a valid UUID: {}", requesterId);
errors.add(String.format("Instance ID is not a valid UUID: %s.", instanceId));
}

if (itemId != null && !isUuid(itemId)) {
log.warn("validateAllowedServicePointsRequest:: item ID is not a valid UUID: {}", itemId);
log.warn("Item ID is not a valid UUID: {}", itemId);
errors.add(String.format("Item ID is not a valid UUID: %s.", itemId));
}

if (requestId != null && !isUuid(requestId)) {
log.warn("validateAllowedServicePointsRequest:: request ID is not a valid UUID: {}",
requestId);
log.warn("Request ID is not a valid UUID: {}", requestId);
errors.add(String.format("Request ID is not a valid UUID: %s.", requestId));
}
if (useStubItem != null && !"true".equals(useStubItem) && !"false".equals(useStubItem)) {
log.warn("validateAllowedServicePointsRequest:: useStubItem is not a valid boolean: {}",
useStubItem);
errors.add(String.format("useStubItem is not a valid boolean: %s.", useStubItem));
}

// Checking parameter combinations

boolean allowedCombinationOfParametersDetected = false;

if (operation == Request.Operation.CREATE && requesterId != null && instanceId != null &&
Expand All @@ -108,36 +121,40 @@ private static Result<AllowedServicePointsRequest> buildRequest(RoutingContext r
log.info("validateAllowedServicePointsRequest:: TLR request creation case");
allowedCombinationOfParametersDetected = true;
}

if (operation == Request.Operation.CREATE && requesterId != null && instanceId == null &&
itemId != null && requestId == null) {

log.info("validateAllowedServicePointsRequest:: ILR request creation case");
allowedCombinationOfParametersDetected = true;
}

if (operation == Request.Operation.REPLACE && requesterId == null && instanceId == null &&
itemId == null && requestId != null) {

log.info("validateAllowedServicePointsRequest:: request replacement case");
allowedCombinationOfParametersDetected = true;
}

if (operation == Request.Operation.MOVE && requesterId == null && instanceId == null &&
itemId != null && requestId != null) {

log.info("validateAllowedServicePointsRequest:: request movement case");
allowedCombinationOfParametersDetected = true;
}

if (!allowedCombinationOfParametersDetected) {
String errorMessage = "Invalid combination of query parameters";
errors.add(errorMessage);
}

if (!errors.isEmpty()) {
String errorMessage = String.join(" ", errors);
log.error("validateRequest:: allowed service points request failed: {}", errorMessage);
return failed(new BadRequestFailure(errorMessage));
}

return succeeded(new AllowedServicePointsRequest(operation, requesterId, instanceId, itemId,
requestId, Boolean.parseBoolean(useStubItem)));
return succeeded(allowedServicePointsRequest);
}

private static JsonObject toJson(Map<RequestType, Set<AllowedServicePoint>> allowedServicePoints) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -155,12 +154,6 @@ private CompletableFuture<Result<User>> fetchUser(AllowedServicePointsRequest re
? this::extractAllowedServicePointsIgnoringItemStatus
: this::extractAllowedServicePointsConsideringItemStatus;

if (request.isUseStubItem()) {
return requestPolicyRepository.lookupRequestPolicy(user)
.thenCompose(r -> r.after(policy -> extractAllowedServicePointsIgnoringItemStatus(
policy, new HashSet<>())));
}

return requestPolicyRepository.lookupRequestPolicies(items, user)
.thenCompose(r -> r.after(policies -> allOf(policies, mappingFunction)))
.thenApply(r -> r.map(this::combineAllowedServicePoints));
Expand Down
Loading

0 comments on commit 393cb0d

Please sign in to comment.