Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MCBFF-5] BFF for allowed service points functionality #6

Merged
merged 25 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8a23b9e
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 10, 2024
fe9a614
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 11, 2024
d6ba54b
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 13, 2024
805970e
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 13, 2024
7d16dbc
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 13, 2024
245ea9e
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 13, 2024
d4f11fb
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 13, 2024
9d5b03d
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 20, 2024
32aa157
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 23, 2024
2b1008a
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 23, 2024
b013d64
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 23, 2024
52da6e2
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 24, 2024
17c9e98
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 24, 2024
aee1bec
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 24, 2024
e7e9f16
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 24, 2024
7f82eae
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 24, 2024
174885b
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 24, 2024
2f0a2c1
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 25, 2024
5a179ee
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 26, 2024
d4d6c26
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 27, 2024
1631082
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 30, 2024
97859b3
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 30, 2024
5e3d372
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 30, 2024
0d070a6
MCBFF-5 BFF for allowed service points functionality
MagzhanArtykov Sep 30, 2024
853ab80
MCBFF-5 Fixes after merge
OleksandrVidinieiev Sep 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
],
"pathPattern": "/circulation-bff/requests/allowed-service-points",
"permissionsRequired": ["circulation-bff.requests.allowed-service-points.get"],
"modulePermissions": []
"modulePermissions": [
"tlr.ecs-tlr-allowed-service-points.get",
"circulation.requests.allowed-service-points.get",
"tlr.settings.get",
"circulation.settings.item.get",
"circulation.settings.collection.get",
"user-tenants.collection.get"
]
},
{
"methods": [
Expand Down Expand Up @@ -71,4 +78,4 @@
{ "name": "JAVA_OPTIONS", "value": "-XX:MaxRAMPercentage=66.0"}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.folio.circulationbff.client.feign;

import org.folio.circulationbff.domain.dto.AllowedServicePointParams;
import org.folio.circulationbff.domain.dto.AllowedServicePoints;
import org.folio.circulationbff.domain.dto.CirculationSettingsResponse;
import org.folio.spring.config.FeignClientConfiguration;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(name = "circulation", url = "circulation", configuration = FeignClientConfiguration.class)
public interface CirculationClient {

@GetMapping("/requests/allowed-service-points")
AllowedServicePoints allowedServicePoints (@SpringQueryMap AllowedServicePointParams params);

@GetMapping(value = "/settings")
CirculationSettingsResponse getCirculationSettingsByQuery(@RequestParam("query") String query);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.folio.circulationbff.client.feign;

import org.folio.circulationbff.domain.dto.AllowedServicePointParams;
import org.folio.circulationbff.domain.dto.AllowedServicePoints;
import org.folio.circulationbff.domain.dto.TlrSettings;
import org.folio.spring.config.FeignClientConfiguration;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.GetMapping;

@FeignClient(name = "ecs-tlr", url = "tlr", configuration = FeignClientConfiguration.class)
public interface EcsTlrClient {

@GetMapping("/allowed-service-points")
AllowedServicePoints getAllowedServicePoints(@SpringQueryMap AllowedServicePointParams params);

@GetMapping("/settings")
TlrSettings getTlrSettings();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.folio.circulationbff.client.feign;


import org.folio.circulationbff.domain.dto.UserTenantCollection;
import org.folio.spring.config.FeignClientConfiguration;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(name = "user-tenants", url = "user-tenants", configuration = FeignClientConfiguration.class)
public interface UserTenantsClient {

@GetMapping()
UserTenantCollection getUserTenants(@RequestParam(name = "limit", required = false) Integer limit);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.util.UUID;

import org.folio.circulationbff.domain.dto.AllowedServicePointParams;
import org.folio.circulationbff.domain.dto.AllowedServicePoints;
import org.folio.circulationbff.domain.dto.InstanceSearchResult;
import org.folio.circulationbff.rest.resource.CirculationBffApi;
import org.folio.circulationbff.service.CirculationBffService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -16,13 +18,32 @@
@Log4j2
@AllArgsConstructor
public class CirculationBffController implements CirculationBffApi {

private final CirculationBffService circulationBffService;

@Override
public ResponseEntity<AllowedServicePoints> circulationBffRequestsAllowedServicePointsGet(UUID patronGroupId, String operation, UUID instanceId, UUID requestId) {
return ResponseEntity.status(HttpStatus.OK).body(new AllowedServicePoints());
public ResponseEntity<AllowedServicePoints> circulationBffRequestsAllowedServicePointsGet(
String operation, String tenantId, UUID patronGroupId, UUID instanceId, UUID requestId,
UUID requesterId, UUID itemId) {

log.info("circulationBffRequestsAllowedServicePointsGet:: params: " +
"patronGroupId={}, operation={}, instanceId={}, requestId={}, requesterId={}, itemId={}",
patronGroupId, operation, instanceId, requestId, requesterId, itemId);

return ResponseEntity.status(HttpStatus.OK).body(circulationBffService.getAllowedServicePoints(
AllowedServicePointParams.builder()
.operation(operation)
.patronGroupId(patronGroupId)
.instanceId(instanceId)
.requestId(requestId)
.requesterId(requestId)
.itemId(itemId)
.build(),
tenantId));
}

@Override
public ResponseEntity<InstanceSearchResult> circulationBffRequestsSearchInstancesGet(String query) {
return ResponseEntity.status(HttpStatus.OK).body(new InstanceSearchResult());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.folio.circulationbff.domain.dto;

import java.util.UUID;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class AllowedServicePointParams {
private String operation;

private UUID patronGroupId;

private UUID instanceId;

private UUID requestId;

private UUID requesterId;

private UUID itemId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.folio.circulationbff.service;

import org.folio.circulationbff.domain.dto.AllowedServicePointParams;
import org.folio.circulationbff.domain.dto.AllowedServicePoints;

public interface CirculationBffService {
AllowedServicePoints getAllowedServicePoints(AllowedServicePointParams allowedServicePointParams, String tenantId);
MagzhanArtykov marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.folio.circulationbff.service;

public interface SettingsService {
boolean isEcsTlrFeatureEnabled(String tenantId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.folio.circulationbff.service;

public interface UserTenantsService {
boolean isCentralTenant(String tenantId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.folio.circulationbff.service.impl;

import org.folio.circulationbff.client.feign.CirculationClient;
import org.folio.circulationbff.client.feign.EcsTlrClient;
import org.folio.circulationbff.domain.dto.AllowedServicePointParams;
import org.folio.circulationbff.domain.dto.AllowedServicePoints;
import org.folio.circulationbff.service.CirculationBffService;
import org.folio.circulationbff.service.SettingsService;
import org.folio.circulationbff.service.UserTenantsService;
import org.springframework.stereotype.Service;

import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;

@Service
@RequiredArgsConstructor
@Log4j2
public class CirculationBffServiceImpl implements CirculationBffService {

private final CirculationClient circulationClient;
private final EcsTlrClient ecsTlrClient;
private final SettingsService settingsService;
private final UserTenantsService userTenantsService;

@Override
public AllowedServicePoints getAllowedServicePoints(AllowedServicePointParams params, String tenantId) {
log.info("getAllowedServicePoints:: params: {}", params);
if (settingsService.isEcsTlrFeatureEnabled(tenantId) && userTenantsService.isCentralTenant(tenantId)) {
log.info("getAllowedServicePoints:: Ecs TLR Feature is enabled. Getting allowed service " +
"points from mod-tlr module");
return ecsTlrClient.getAllowedServicePoints(params);
} else {
log.info("getAllowedServicePoints:: Ecs TLR Feature is disabled. Getting allowed service " +
"points from mod-circulation module");
return circulationClient.allowedServicePoints(params);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.folio.circulationbff.service.impl;

import org.folio.circulationbff.client.feign.CirculationClient;
import org.folio.circulationbff.client.feign.EcsTlrClient;
import org.folio.circulationbff.service.SettingsService;
import org.folio.circulationbff.service.UserTenantsService;
import org.springframework.stereotype.Service;

import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;

@Service
@RequiredArgsConstructor
@Log4j2
public class SettingsServiceImpl implements SettingsService {

public static final String ECS_TLR_FEATURE_SETTINGS = "name=ecsTlrFeature";
private final EcsTlrClient ecsTlrClient;
private final CirculationClient circulationClient;
private final UserTenantsService userTenantsService;

@Override
public boolean isEcsTlrFeatureEnabled(String tenantId) {
if (userTenantsService.isCentralTenant(tenantId)) {
return ecsTlrClient.getTlrSettings().getEcsTlrFeatureEnabled();
}
return isTlrEnabledInCirculationSettings();
}

private boolean isTlrEnabledInCirculationSettings() {
log.debug("getCirculationSettings:: Getting circulation settings");
var circulationSettingsResponse = circulationClient.getCirculationSettingsByQuery(ECS_TLR_FEATURE_SETTINGS);
if (circulationSettingsResponse.getTotalRecords() > 0) {
try {
var circulationSettings = circulationSettingsResponse.getCirculationSettings().get(0);
log.info("getCirculationSettings:: circulation settings: {}",
circulationSettings.getValue());
return circulationSettings.getValue().getEnabled();
} catch (Exception e) {
log.error("getCirculationSettings:: Failed to parse circulation settings", e);
}
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.folio.circulationbff.service.impl;

import java.util.List;

import org.folio.circulationbff.client.feign.UserTenantsClient;
import org.folio.circulationbff.domain.dto.UserTenant;
import org.folio.circulationbff.domain.dto.UserTenantCollection;
import org.folio.circulationbff.service.UserTenantsService;
import org.springframework.stereotype.Service;

import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;

@Service
@RequiredArgsConstructor
@Log4j2
public class UserTenantsServiceImpl implements UserTenantsService {

private final UserTenantsClient userTenantsClient;

@Override
public boolean isCentralTenant(String tenantId) {
UserTenant firstUserTenant = findFirstUserTenant();
if (firstUserTenant == null) {
log.info("processUserGroupEvent: Failed to get user-tenants info");
return false;
}
String centralTenantId = firstUserTenant.getCentralTenantId();
if (centralTenantId != null && centralTenantId.equals(tenantId)) {
log.info("isCentralTenant: tenantId={} is central tenant", tenantId);
return true;
}
return false;
}

private UserTenant findFirstUserTenant() {
log.info("findFirstUserTenant:: finding first userTenant");
UserTenant firstUserTenant = null;
UserTenantCollection userTenantCollection = userTenantsClient.getUserTenants(1);
log.info("findFirstUserTenant:: userTenantCollection: {}", () -> userTenantCollection);
if (userTenantCollection != null) {
log.info("findFirstUserTenant:: userTenantCollection: {}", () -> userTenantCollection);
List<UserTenant> userTenants = userTenantCollection.getUserTenants();
if (!userTenants.isEmpty()) {
firstUserTenant = userTenants.get(0);
log.info("findFirstUserTenant:: found userTenant: {}", firstUserTenant);
}
}
log.info("findFirstUserTenant:: result: {}", firstUserTenant);
return firstUserTenant;
}
}

8 changes: 8 additions & 0 deletions src/main/resources/swagger.api/circulation-bff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ paths:
$ref: 'paths/allowedServicePoints/allowedServicePoints.yaml'
/circulation-bff/requests/search-instances:
$ref: 'paths/searchInstances/searchInstances.yaml'
components:
schemas:
tlr-settings:
$ref: 'schemas/dto/TlrSettings.yaml#/TlrSettings'
circulationSettingsResponse:
$ref: 'schemas/response/circulationSettingsResponse.yaml'
userTenantCollection:
$ref: 'schemas/dto/UserTenantCollection.yaml#/UserTenantCollection'
6 changes: 6 additions & 0 deletions src/main/resources/swagger.api/parameters/itemId.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: itemId
in: query
required: false
schema:
type: string
format: uuid
4 changes: 2 additions & 2 deletions src/main/resources/swagger.api/parameters/operation.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: operation
in: query
required: false
required: true
schema:
type: string
enum:
- create
- replace
- replace
4 changes: 2 additions & 2 deletions src/main/resources/swagger.api/parameters/patronGroupId.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: patronGroupId
in: query
required: true
required: false
schema:
type: string
format: uuid
format: uuid
6 changes: 6 additions & 0 deletions src/main/resources/swagger.api/parameters/requesterId.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: requesterId
in: query
required: false
schema:
type: string
format: uuid
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ get:
- $ref: '../../parameters/patronGroupId.yaml'
- $ref: '../../parameters/instanceId.yaml'
- $ref: '../../parameters/requestId.yaml'
- $ref: '../../parameters/requesterId.yaml'
- $ref: '../../parameters/itemId.yaml'
- in: header
name: X-Okapi-Tenant
required: true
schema:
type: string
description: The tenant ID for the request
tags:
- getAllowedServicePoints
responses:
Expand All @@ -19,4 +27,4 @@ get:
'422':
$ref: '../../responses/unprocessableEntityResponse.yaml'
'500':
$ref: '../../responses/internalServerErrorResponse.yaml'
$ref: '../../responses/internalServerErrorResponse.yaml'
Loading