diff --git a/src/main/java/org/folio/controller/AllowedServicePointsController.java b/src/main/java/org/folio/controller/AllowedServicePointsController.java index bcdb027c..1bc2bd50 100644 --- a/src/main/java/org/folio/controller/AllowedServicePointsController.java +++ b/src/main/java/org/folio/controller/AllowedServicePointsController.java @@ -28,13 +28,14 @@ public class AllowedServicePointsController implements AllowedServicePointsApi { @Override public ResponseEntity getAllowedServicePoints(String operation, - UUID requesterId, UUID instanceId, UUID requestId, UUID itemId) { + UUID patronGroupId, UUID requesterId, UUID instanceId, UUID requestId, UUID itemId) { - log.info("getAllowedServicePoints:: params: operation={}, requesterId={}, instanceId={}, " + - "requestId={}, itemId={}", operation, requesterId, instanceId, requestId, itemId); + log.info("getAllowedServicePoints:: params: operation={}, patronGroupId={}, requesterId={}, " + + "instanceId={}, requestId={}, itemId={}", + operation, patronGroupId, requesterId, instanceId, requestId, itemId); AllowedServicePointsRequest request = new AllowedServicePointsRequest( - operation, requesterId, instanceId, requestId, itemId); + operation, patronGroupId, requesterId, instanceId, requestId, itemId); if (!validateAllowedServicePointsRequest(request)) { return ResponseEntity.status(UNPROCESSABLE_ENTITY).build(); @@ -49,6 +50,7 @@ public ResponseEntity getAllowedServicePoints(Stri private static boolean validateAllowedServicePointsRequest(AllowedServicePointsRequest request) { final RequestOperation operation = request.getOperation(); + final String patronGroupId = request.getPatronGroupId(); final String requesterId = request.getRequesterId(); final String instanceId = request.getInstanceId(); final String requestId = request.getRequestId(); @@ -56,14 +58,15 @@ private static boolean validateAllowedServicePointsRequest(AllowedServicePointsR boolean allowedCombinationOfParametersDetected = false; - if (operation == CREATE && requesterId != null && instanceId != null && + boolean requesterOrPatronGroupSet = requesterId != null || patronGroupId != null; + if (operation == CREATE && requesterOrPatronGroupSet && instanceId != null && itemId == null && requestId == null) { log.info("validateAllowedServicePointsRequest:: TLR request creation case"); allowedCombinationOfParametersDetected = true; } - if (operation == CREATE && requesterId != null && instanceId == null && + if (operation == CREATE && requesterOrPatronGroupSet && instanceId == null && itemId != null && requestId == null) { log.info("validateAllowedServicePointsRequest:: ILR request creation case"); diff --git a/src/main/java/org/folio/domain/dto/AllowedServicePointsRequest.java b/src/main/java/org/folio/domain/dto/AllowedServicePointsRequest.java index 0887f0c1..0351305f 100644 --- a/src/main/java/org/folio/domain/dto/AllowedServicePointsRequest.java +++ b/src/main/java/org/folio/domain/dto/AllowedServicePointsRequest.java @@ -11,16 +11,18 @@ @ToString public class AllowedServicePointsRequest { private final RequestOperation operation; + private final String patronGroupId; private final String requesterId; @Setter private String instanceId; private final String requestId; private final String itemId; - public AllowedServicePointsRequest(String operation, UUID requesterId, UUID instanceId, - UUID requestId, UUID itemId) { + public AllowedServicePointsRequest(String operation, UUID patronGroupId, + UUID requesterId, UUID instanceId, UUID requestId, UUID itemId) { this.operation = RequestOperation.from(operation); + this.patronGroupId = asString(patronGroupId); this.requesterId = asString(requesterId); this.instanceId = asString(instanceId); this.requestId = asString(requestId); diff --git a/src/main/java/org/folio/service/impl/AllowedServicePointsServiceImpl.java b/src/main/java/org/folio/service/impl/AllowedServicePointsServiceImpl.java index 4c72ba21..8ff2866f 100644 --- a/src/main/java/org/folio/service/impl/AllowedServicePointsServiceImpl.java +++ b/src/main/java/org/folio/service/impl/AllowedServicePointsServiceImpl.java @@ -9,6 +9,7 @@ import java.util.Set; import java.util.UUID; +import org.apache.commons.lang3.StringUtils; import org.folio.client.feign.CirculationClient; import org.folio.client.feign.SearchItemClient; import org.folio.domain.dto.AllowedServicePointsInner; @@ -49,7 +50,11 @@ public AllowedServicePointsResponse getAllowedServicePoints(AllowedServicePoints } private AllowedServicePointsResponse getForCreate(AllowedServicePointsRequest request) { - String patronGroupId = userService.find(request.getRequesterId()).getPatronGroup(); + String patronGroupId = request.getPatronGroupId(); + String requesterId = request.getRequesterId(); + if (StringUtils.isBlank(patronGroupId)) { + patronGroupId = userService.find(requesterId).getPatronGroup(); + } log.info("getForCreate:: patronGroupId={}", patronGroupId); Map page = new HashMap<>(); @@ -89,7 +94,6 @@ protected abstract AllowedServicePointsResponse getAllowedServicePointsFromTenan private AllowedServicePointsResponse getForReplace(AllowedServicePointsRequest request) { EcsTlrEntity ecsTlr = findEcsTlr(request); - log.info("getForReplace:: fetching allowed service points from secondary request tenant"); var allowedServicePoints = executionService.executeSystemUserScoped( ecsTlr.getSecondaryRequestTenantId(), () -> circulationClient.allowedServicePoints( REPLACE.getValue(), ecsTlr.getSecondaryRequestId().toString())); diff --git a/src/main/resources/swagger.api/allowed-service-points.yaml b/src/main/resources/swagger.api/allowed-service-points.yaml index 5b268ac4..0924d34a 100644 --- a/src/main/resources/swagger.api/allowed-service-points.yaml +++ b/src/main/resources/swagger.api/allowed-service-points.yaml @@ -11,6 +11,7 @@ paths: operationId: getAllowedServicePoints parameters: - $ref: '#/components/parameters/operation' + - $ref: '#/components/parameters/patronGroupId' - $ref: '#/components/parameters/requesterId' - $ref: '#/components/parameters/instanceId' - $ref: '#/components/parameters/requestId' @@ -42,6 +43,13 @@ components: enum: - create - replace + patronGroupId: + name: patronGroupId + in: query + required: false + schema: + type: string + format: uuid requesterId: name: requesterId in: query