Skip to content

Commit

Permalink
MODTLR-118 Get central tenant ID from consortia configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksandrVidinieiev committed Dec 26, 2024
1 parent 7bdb068 commit f179623
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.folio.client.feign;

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

@FeignClient(name = "consortia-configuration", url = "consortia-configuration", configuration = FeignClientConfiguration.class)
public interface ConsortiaConfigurationClient {

@GetMapping
ConsortiaConfiguration getConfiguration();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.folio.domain.dto.User;
import org.folio.domain.dto.UserGroup;
import org.folio.exception.KafkaEventDeserializationException;
import org.folio.service.ConsortiaService;
import org.folio.service.KafkaEventHandler;
import org.folio.service.UserTenantsService;
import org.folio.service.impl.LoanEventHandler;
Expand Down Expand Up @@ -46,7 +47,7 @@ public class KafkaEventListener {
private final UserEventHandler userEventHandler;
private final SystemUserScopedExecutionService systemUserScopedExecutionService;
private final RequestBatchUpdateEventHandler requestBatchEventHandler;
private final UserTenantsService userTenantsService;
private final ConsortiaService consortiaService;
private final FolioModuleMetadata folioModuleMetadata;

@KafkaListener(
Expand Down Expand Up @@ -100,7 +101,7 @@ private <T> void handleEvent(String eventString, KafkaEventHandler<T> handler,
folioModuleMetadata, messageHeaders);

try (FolioExecutionContextSetter contextSetter = new FolioExecutionContextSetter(context)) {
String centralTenantId = userTenantsService.getCentralTenantId();
String centralTenantId = consortiaService.getCentralTenantId();
systemUserScopedExecutionService.executeAsyncSystemUserScoped(centralTenantId,
() -> handler.handle(event));
} catch (Exception e) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/folio/service/ConsortiaService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
public interface ConsortiaService {
TenantCollection getAllConsortiumTenants(String consortiumId);
Collection<Tenant> getAllConsortiumTenants();
String getCentralTenantId();
}
13 changes: 13 additions & 0 deletions src/main/java/org/folio/service/impl/ConsortiaServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.Optional;

import org.folio.client.feign.ConsortiaClient;
import org.folio.client.feign.ConsortiaConfigurationClient;
import org.folio.domain.dto.ConsortiaConfiguration;
import org.folio.domain.dto.Tenant;
import org.folio.domain.dto.TenantCollection;
import org.folio.domain.dto.UserTenant;
Expand All @@ -21,6 +23,7 @@
@RequiredArgsConstructor
public class ConsortiaServiceImpl implements ConsortiaService {
private final ConsortiaClient consortiaClient;
private final ConsortiaConfigurationClient consortiaConfigurationClient;
private final UserTenantsService userTenantsService;

@Override
Expand All @@ -40,4 +43,14 @@ public Collection<Tenant> getAllConsortiumTenants() {
log.info("getAllConsortiumTenants:: found {} consortium tenants", tenants::size);
return tenants;
}

@Override
public String getCentralTenantId() {
log.info("getCentralTenantId:: resolving central tenant ID");
String centralTenantId = Optional.ofNullable(consortiaConfigurationClient.getConfiguration())
.map(ConsortiaConfiguration::getCentralTenantId)
.orElseThrow();
log.info("getCentralTenantId: central tenant ID: {}", centralTenantId);
return centralTenantId;
}
}
6 changes: 4 additions & 2 deletions src/main/resources/swagger.api/ecs-tlr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ components:
transactionStatusResponse:
$ref: 'schemas/transactionStatusResponse.yaml#/TransactionStatusResponse'
tenant:
$ref: 'schemas/tenant.yaml#/Tenant'
$ref: 'schemas/consortia/tenant.yaml#/Tenant'
tenants:
$ref: 'schemas/tenant.yaml#/TenantCollection'
$ref: 'schemas/consortia/tenant.yaml#/TenantCollection'
consortiaConfiguration:
$ref: 'schemas/consortia/consortiaConfiguration.yaml#/ConsortiaConfiguration'
publicationRequest:
$ref: 'schemas/publication.yaml#/PublicationRequest'
publicationResponse:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ConsortiaConfiguration:
type: "object"
description: "Consortia Configuration"
properties:
id:
type: "string"
format: "uuid"
centralTenantId:
type: "string"
3 changes: 2 additions & 1 deletion src/test/java/org/folio/listener/KafkaEventListenerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Map;

import org.folio.listener.kafka.KafkaEventListener;
import org.folio.service.ConsortiaService;
import org.folio.service.UserTenantsService;
import org.folio.service.impl.LoanEventHandler;
import org.folio.service.impl.RequestBatchUpdateEventHandler;
Expand Down Expand Up @@ -37,7 +38,7 @@ class KafkaEventListenerTest {
@Mock
UserEventHandler userEventHandler;
@Mock
UserTenantsService userTenantsService;
ConsortiaService consortiaService;
@InjectMocks
KafkaEventListener kafkaEventListener;

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/folio/service/UserEventHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void handleUserUpdatingEventShouldUpdateUserForAllDataTenants() {
when(userTenantsService.findFirstUserTenant()).thenReturn(mockUserTenant());
when(consortiaService.getAllConsortiumTenants(anyString())).thenReturn(mockTenantCollection());
when(userService.update(any(User.class))).thenReturn(new User());
when(userTenantsService.getCentralTenantId()).thenReturn(CENTRAL_TENANT_ID);
when(consortiaService.getCentralTenantId()).thenReturn(CENTRAL_TENANT_ID);

doAnswer(invocation -> {
((Runnable) invocation.getArguments()[1]).run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void handleUserGroupCreatingEventShouldCreateUserGroupForAllDataTenants() {
when(userTenantsService.findFirstUserTenant()).thenReturn(mockUserTenant());
when(consortiaService.getAllConsortiumTenants(anyString())).thenReturn(mockTenantCollection());
when(userGroupService.create(any(UserGroup.class))).thenReturn(new UserGroup());
when(userTenantsService.getCentralTenantId()).thenReturn(CENTRAL_TENANT_ID);
when(consortiaService.getCentralTenantId()).thenReturn(CENTRAL_TENANT_ID);

doAnswer(invocation -> {
((Runnable) invocation.getArguments()[1]).run();
Expand All @@ -51,7 +51,7 @@ void handleUserGroupUpdatingEventShouldUpdateUserGroupForAllDataTenants() {
when(userTenantsService.findFirstUserTenant()).thenReturn(mockUserTenant());
when(consortiaService.getAllConsortiumTenants(anyString())).thenReturn(mockTenantCollection());
when(userGroupService.update(any(UserGroup.class))).thenReturn(new UserGroup());
when(userTenantsService.getCentralTenantId()).thenReturn(CENTRAL_TENANT_ID);
when(consortiaService.getCentralTenantId()).thenReturn(CENTRAL_TENANT_ID);

doAnswer(invocation -> {
((Runnable) invocation.getArguments()[1]).run();
Expand Down
20 changes: 20 additions & 0 deletions src/test/resources/mappings/consortiaConfiguration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"mappings": [
{
"request": {
"method": "GET",
"url": "/consortia-configuration"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"jsonBody": {
"id": "0bc8835b-1233-48ba-bc75-979cb04dc06e",
"centralTenantId": "consortium"
}
}
}
]
}

0 comments on commit f179623

Please sign in to comment.