Skip to content

Commit

Permalink
MODTLR-102: Allowed SP - accept patronGroupId parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
imerabishvili committed Nov 29, 2024
1 parent 43d5b57 commit 1a602d5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public class AllowedServicePointsController implements AllowedServicePointsApi {

@Override
public ResponseEntity<AllowedServicePointsResponse> 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);

AllowedServicePointsRequest request = new AllowedServicePointsRequest(
operation, requesterId, instanceId, requestId, itemId);
operation, patronGroupId, requesterId, instanceId, requestId, itemId);

if (!validateAllowedServicePointsRequest(request)) {
return ResponseEntity.status(UNPROCESSABLE_ENTITY).build();
Expand All @@ -49,21 +49,23 @@ public ResponseEntity<AllowedServicePointsResponse> 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();
final String itemId = request.getItemId();

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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,7 +50,12 @@ public AllowedServicePointsResponse getAllowedServicePoints(AllowedServicePoints
}

private AllowedServicePointsResponse getForCreate(AllowedServicePointsRequest request) {
String patronGroupId = userService.find(request.getRequesterId()).getPatronGroup();
String patronGroupId = request.getPatronGroupId();
String requesterId = request.getRequesterId();
log.info("getForCreate:: requester patron group and id: {}, {}", patronGroupId, requesterId);
if (StringUtils.isBlank(patronGroupId)) {
patronGroupId = userService.find(requesterId).getPatronGroup();
}
log.info("getForCreate:: patronGroupId={}", patronGroupId);

Map<String, AllowedServicePointsInner> page = new HashMap<>();
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/swagger.api/allowed-service-points.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1a602d5

Please sign in to comment.