Skip to content

Commit

Permalink
MCBFF-52 Change Allowed SP routing implementation (#51)
Browse files Browse the repository at this point in the history
* MCBFF-52 Initial implementation

* MCBFF-52 Fix a test

* MCBFF-52 Remove comments, clean up logs

* MCBFF-52 Fix logging
  • Loading branch information
alexanderkurash authored Jan 28, 2025
1 parent 11aa65c commit d0c55d7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,39 +52,50 @@ public SearchSlipCollection fetchSearchSlipsByServicePointId(String servicePoint
@Override
public AllowedServicePoints getAllowedServicePoints(AllowedServicePointParams params, String tenantId) {
log.info("getAllowedServicePoints:: params: {}", params);
if (settingsService.isEcsTlrFeatureEnabled()) {
if (userTenantsService.isCentralTenant()) {
log.info("getAllowedServicePoints:: Ecs TLR Feature is enabled and we are in the central " +
"tenant. Calling local mod-tlr.");
return ecsTlrClient.getAllowedServicePoints(params);
} else {
if (params.getRequestId() == null) {
log.info("getAllowedServicePoints:: Ecs TLR Feature is enabled, requestId param is " +
"missing. Calling local mod-circulation.");
return circulationClient.allowedServicePoints(params);
} else {
var request = circulationClient.getRequestById(params.getRequestId().toString());
if (request.getEcsRequestPhase() == null) {
log.info("getAllowedServicePoints:: Ecs TLR Feature is enabled, but request is not " +
"an ECS request. Calling local mod-circulation.");
return circulationClient.allowedServicePoints(params);
} else {
log.info("getAllowedServicePoints:: Ecs TLR Feature is enabled and request is " +
"an ECS request. Calling central mod-tlr.");
String patronGroupId = params.getRequesterId() == null ? null :
userService.find(params.getRequesterId().toString()).getPatronGroup();
params.setPatronGroupId(patronGroupId != null ? UUID.fromString(patronGroupId) : null);
params.setRequesterId(null);
return executionService.executeSystemUserScoped(userTenantsService.getCentralTenant(),
() -> ecsTlrClient.getAllowedServicePoints(params));
}
}
}
} else {

if (!settingsService.isEcsTlrFeatureEnabled()) {
log.info("getAllowedServicePoints:: Ecs TLR Feature is disabled. " +
"Calling local mod-circulation.");
return circulationClient.allowedServicePoints(params);
}

if (userTenantsService.isCentralTenant()) {
log.info("getAllowedServicePoints:: Ecs TLR Feature is enabled and we are in the central " +
"tenant. Calling local mod-tlr.");
return ecsTlrClient.getAllowedServicePoints(params);
}

log.info("getAllowedServicePoints:: Ecs TLR Feature is enabled and current tenant is not " +
"central.");

if (params.getRequestId() == null) {
log.info("getAllowedServicePoints:: Request ID is missing (creation). Calling central mod-tlr.");
// This should handle both mediated request and local data tenant request cases.
// In case of a local request, central mod-tlr should call mod-circulation of the current
// data tenant anyway.
return getAllowedSpFromCentralTlr(params);
}

log.info("getAllowedServicePoints:: Request ID is present (editing).");

var request = circulationClient.getRequestById(params.getRequestId().toString());
if (request.getEcsRequestPhase() == null) {
log.info("getAllowedServicePoints:: Request is not an ECS request. Calling local mod-circulation.");
return circulationClient.allowedServicePoints(params);
}

log.info("getAllowedServicePoints:: Ecs TLR Feature is enabled and request is " +
"an ECS request. Calling central mod-tlr.");
return getAllowedSpFromCentralTlr(params);
}

private AllowedServicePoints getAllowedSpFromCentralTlr(AllowedServicePointParams params) {
String patronGroupId = params.getRequesterId() == null ? null :
userService.find(params.getRequesterId().toString()).getPatronGroup();
params.setPatronGroupId(patronGroupId != null ? UUID.fromString(patronGroupId) : null);
params.setRequesterId(null);
return executionService.executeSystemUserScoped(userTenantsService.getCentralTenant(),
() -> ecsTlrClient.getAllowedServicePoints(params));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ public boolean isCentralTenant(String tenantId) {
private UserTenant getFirstUserTenant() {
log.info("getFirstUserTenant:: finding first userTenant");
UserTenantCollection userTenants = userTenantsClient.getUserTenants(1);
log.info("getFirstUserTenant:: userTenants: {}", () -> userTenants);
log.debug("getFirstUserTenant:: userTenants: {}", userTenants);
if (userTenants == null || CollectionUtils.isEmpty(userTenants.getUserTenants())) {
log.warn("getFirstUserTenant: failed to fetch user tenants");
return null;
}
var firstUserTenant = userTenants.getUserTenants().get(0);
log.info("getFirstUserTenant:: result: {}", firstUserTenant);
log.debug("getFirstUserTenant:: result: {}",
() -> firstUserTenant == null ? null : firstUserTenant.getId());
return firstUserTenant;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ void allowedSpCallsDataTenantCirculationWhenEcsTlrEnabledWithoutRequestId() {
allowedSpResponseConsortium.setHold(Set.of(
buildAllowedServicePoint("SP_consortium_1"),
buildAllowedServicePoint("SP_consortium_2")));
wireMockServer.stubFor(WireMock.get(urlPathEqualTo(CIRCULATION_ALLOWED_SERVICE_POINT_URL))
.withHeader(HEADER_TENANT, equalTo(TENANT_ID_COLLEGE))

wireMockServer.stubFor(WireMock.get(urlPathEqualTo(TLR_ALLOWED_SERVICE_POINT_URL))
.withHeader(HEADER_TENANT, equalTo(TENANT_ID_CONSORTIUM))
.willReturn(jsonResponse(asJsonString(allowedSpResponseConsortium), SC_OK)));

var operation = "create";
Expand All @@ -174,7 +175,8 @@ void allowedSpCallsDataTenantCirculationWhenEcsTlrEnabledWithoutRequestId() {
containsInAnyOrder("SP_consortium_1", "SP_consortium_2")));

wireMockServer.verify(getRequestedFor(urlPathEqualTo(
CIRCULATION_ALLOWED_SERVICE_POINT_URL))
TLR_ALLOWED_SERVICE_POINT_URL))
.withHeader(HEADER_TENANT, equalTo(TENANT_ID_CONSORTIUM))
.withQueryParam("instanceId", equalTo(instanceId.toString()))
.withQueryParam("operation", equalTo(operation))
);
Expand Down

0 comments on commit d0c55d7

Please sign in to comment.