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-44: Reimplement mod-patron's logic for placing external ECS TLR requests #50

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
MCBFF-44 Revert redundant changes
OleksandrVidinieiev committed Jan 29, 2025
commit dec5916016f375ad72aca2cb088a24c0f22eb150

This file was deleted.

Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
import java.util.Optional;

public interface TenantService {

String getCurrentTenantId();
Optional<String> getCentralTenantId();
Optional<String> getSecureTenantId();
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package org.folio.circulationbff.service;

import org.folio.circulationbff.domain.dto.UserTenant;

public interface UserTenantsService {
String getCurrentTenant();
String getCentralTenant();
boolean isCentralTenant();
UserTenant getFirstUserTenant();
boolean isCentralTenant(String tenantId);
boolean isCentralTenant(UserTenant userTenant);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.folio.circulationbff.service.impl;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

import org.folio.circulationbff.config.TenantConfig;
import org.folio.circulationbff.domain.dto.UserTenant;
@@ -19,7 +19,7 @@
@Log4j2
public class TenantServiceImpl implements TenantService {

private static final Map<String, String> CENTRAL_TENANT_ID_CACHE = new HashMap<>();
private static final Map<String, String> CENTRAL_TENANT_ID_CACHE = new ConcurrentHashMap<>();

private final UserTenantsService userTenantsService;
private final TenantConfig tenantConfig;
@@ -41,10 +41,7 @@ public Optional<String> getCentralTenantId() {
currentTenantId, centralTenantId);
} else {
log.info("getCentralTenantId:: cache miss: currentTenantId={}", currentTenantId);
centralTenantId = Optional.ofNullable(userTenantsService.getFirstUserTenant())
.map(UserTenant::getCentralTenantId)
.orElse(null);

centralTenantId = resolveCentralTenantId();
log.info("getCentralTenantId:: populating cache: tenantId={}, centralTenantId={}",
currentTenantId, centralTenantId);
CENTRAL_TENANT_ID_CACHE.put(currentTenantId, centralTenantId);
@@ -84,4 +81,13 @@ public static void clearCache() {
CENTRAL_TENANT_ID_CACHE.clear();
}

private String resolveCentralTenantId() {
String centralTenantId = Optional.ofNullable(userTenantsService.getFirstUserTenant())
.map(UserTenant::getCentralTenantId)
.orElse(null);

log.info("resolveCentralTenantId:: centralTenantId={}", centralTenantId);
return centralTenantId;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.folio.circulationbff.service.impl;

import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.folio.circulationbff.client.feign.UserTenantsClient;
import org.folio.circulationbff.domain.dto.UserTenant;
import org.folio.circulationbff.domain.dto.UserTenantCollection;
@@ -18,11 +17,21 @@ public class UserTenantsServiceImpl implements UserTenantsService {

private final UserTenantsClient userTenantsClient;

@Override
public String getCurrentTenant() {
UserTenant firstUserTenant = getFirstUserTenant();
if (firstUserTenant == null) {
return null;
}
String currentTenantId = firstUserTenant.getTenantId();
log.info("getCurrentTenant:: currentTenantId={}", currentTenantId);
return currentTenantId;
}

@Override
public String getCentralTenant() {
UserTenant firstUserTenant = getFirstUserTenant();
if (firstUserTenant == null) {
log.info("getCentralTenant:: failed to fetch user tenants");
return null;
}
String centralTenantId = firstUserTenant.getCentralTenantId();
@@ -32,16 +41,16 @@ public String getCentralTenant() {

@Override
public boolean isCentralTenant() {
return isCentralTenant(getFirstUserTenant());
}

@Override
public UserTenant getFirstUserTenant() {
UserTenant firstUserTenant = findFirstUserTenant();
UserTenant firstUserTenant = getFirstUserTenant();
if (firstUserTenant == null) {
log.info("processUserGroupEvent: Failed to get user-tenants info");
return false;
}
return firstUserTenant;
String centralTenantId = firstUserTenant.getCentralTenantId();
String tenantId = firstUserTenant.getTenantId();
log.info("isCentralTenant:: centralTenantId={}, tenantId={}", centralTenantId,
tenantId);

return centralTenantId.equals(tenantId);
}

@Override
@@ -58,35 +67,16 @@ public boolean isCentralTenant(String tenantId) {
return false;
}

@Override
public boolean isCentralTenant(UserTenant userTenant) {
if (userTenant == null) {
log.info("isCentralTenant:: failed to fetch user tenants");
return false;
}
String centralTenantId = userTenant.getCentralTenantId();
String tenantId = userTenant.getTenantId();
log.info("isCentralTenant:: centralTenantId={}, tenantId={}", centralTenantId,
tenantId);

return centralTenantId.equals(tenantId);
}

private UserTenant findFirstUserTenant() {
log.info("findFirstUserTenant:: finding first userTenant");
UserTenant firstUserTenant = null;
UserTenantCollection userTenantCollection = userTenantsClient.getUserTenants(1);
log.debug("findFirstUserTenant:: userTenantCollection: {}", () -> userTenantCollection);
if (userTenantCollection != null) {
log.debug("findFirstUserTenant:: userTenantCollection: {}", () -> userTenantCollection);
List<UserTenant> userTenants = userTenantCollection.getUserTenants();
if (!userTenants.isEmpty()) {
firstUserTenant = userTenants.get(0);
log.debug("findFirstUserTenant:: found userTenant: {}", firstUserTenant);
}
private UserTenant getFirstUserTenant() {
log.info("getFirstUserTenant:: finding first userTenant");
UserTenantCollection userTenants = userTenantsClient.getUserTenants(1);
log.debug("getFirstUserTenant:: userTenants: {}", () -> userTenants);
if (userTenants == null || CollectionUtils.isEmpty(userTenants.getUserTenants())) {
log.warn("getFirstUserTenant: failed to fetch user tenants");
return null;
}
log.debug("findFirstUserTenant:: result: {}", firstUserTenant);
var firstUserTenant = userTenants.getUserTenants().get(0);
log.debug("getFirstUserTenant:: result: {}", firstUserTenant);
return firstUserTenant;
}
}