Skip to content

Commit

Permalink
EDGOAIPMH-107 - Update edge-common version (#105)
Browse files Browse the repository at this point in the history
(cherry picked from commit 91c2db7)
  • Loading branch information
siarhei-charniak committed Dec 5, 2023
1 parent 87704eb commit eff83bf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 30 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<jaxb-impl.version>2.3.6</jaxb-impl.version>
<jaxb-core.version>4.0.0</jaxb-core.version>
<mod-configuration-client.version>5.9.1</mod-configuration-client.version>
<edge.common.version>4.4.3</edge.common.version>
<edge.common.version>4.5.2</edge.common.version>
<vertx-stack-depchain.version>4.3.8</vertx-stack-depchain.version>
<log4j-bom.version>2.17.2</log4j-bom.version>
<mockito-core.version>4.6.1</mockito-core.version>
Expand Down
33 changes: 4 additions & 29 deletions src/main/java/org/folio/edge/oaipmh/OaiPmhHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public class OaiPmhHandler extends Handler {
private static final String ERROR_FROM_REPOSITORY = "Error in the response from repository: status code - %s, response status message - %s %s";

private Cache<List<String>> tenantsCache;
private Cache<OkapiClient> clientCache;

public OaiPmhHandler(SecureStore secureStore, OkapiClientFactory ocf) {
super(secureStore, ocf);
Expand All @@ -76,11 +75,6 @@ public OaiPmhHandler(SecureStore secureStore, OkapiClientFactory ocf) {
.withNullValueTTL(0)
.withCapacity(100)
.build();
clientCache = new Cache.Builder<OkapiClient>()
.withTTL(TimeUnit.MINUTES.toMillis(10))
.withNullValueTTL(0)
.withCapacity(100)
.build();
}

protected void handle(RoutingContext ctx) {
Expand Down Expand Up @@ -174,22 +168,6 @@ private void callToTenant(RoutingContext ctx, String tenant) {
throwable -> oaiPmhFailureHandler(ctx, throwable)));
}

private CompletableFuture<OkapiClient> getClient(RoutingContext ctx, String tenant) {
var client = clientCache.get(tenant);
if (isNull(client)) {
log.info("Okapi client for tenant {} is not present in cache, creating new one", tenant);
var newClient = ocf.getOkapiClient(tenant);
return getToken(ctx, tenant, newClient)
.thenApply(token -> {
newClient.setToken(token);
clientCache.put(tenant, newClient);
return newClient;
});
}
log.info("Using cached okapi client for tenant {}", tenant);
return CompletableFuture.completedFuture(client);
}

private Optional<String> getNextTenant(List<String> list, String currentTenantId) {
log.info("Tenants list: {}", list);
var nextTenantIndex = list.indexOf(currentTenantId) + 1;
Expand Down Expand Up @@ -387,11 +365,6 @@ private boolean isFirstRequest(HttpServerRequest request) {
return isNull(request.params().get(RESUMPTION_TOKEN));
}

private CompletableFuture<String> getToken(RoutingContext ctx, String tenant, OkapiClient client) {
return getClientInfo(ctx)
.thenCompose(clientInfo -> iuHelper.getToken(client, clientInfo.salt, tenant, clientInfo.username));
}

private boolean isLastResponse(OAIPMH oaipmh) {
return (nonNull(oaipmh.getListRecords()) && (isNull(oaipmh.getListRecords().getResumptionToken()) || oaipmh.getListRecords().getResumptionToken().getValue().isEmpty()))
|| (nonNull(oaipmh.getListIdentifiers()) && (isNull(oaipmh.getListIdentifiers().getResumptionToken()) || oaipmh.getListIdentifiers().getResumptionToken().getValue().isEmpty()));
Expand All @@ -401,14 +374,16 @@ private boolean isErrorResponse(OAIPMH oaipmh) {
return isNotEmpty(oaipmh.getErrors());
}

private CompletableFuture<ClientInfo> getClientInfo(RoutingContext ctx) {
private CompletableFuture<OkapiClient> getClient(RoutingContext ctx, String tenantId) {
var key = keyHelper.getApiKey(ctx);
ClientInfo clientInfo;
try {
clientInfo = ApiKeyUtils.parseApiKey(key);
} catch (ApiKeyUtils.MalformedApiKeyException e) {
return CompletableFuture.failedFuture(e);
}
return CompletableFuture.completedFuture(clientInfo);
final OkapiClient client = ocf.getOkapiClient(tenantId);
return iuHelper.fetchToken(client, clientInfo.salt, tenantId, clientInfo.username)
.map(token -> client).toCompletionStage().toCompletableFuture();
}
}
3 changes: 3 additions & 0 deletions src/test/java/org/folio/edge/oaipmh/OaiPmhTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ static void setUpOnce(Vertx vertx, VertxTestContext context) throws Exception {
List<String> knownTenants = new ArrayList<>();
knownTenants.add(ApiKeyUtils.parseApiKey(API_KEY).tenantId);
knownTenants.add("central");
knownTenants.add("central2");
knownTenants.add("tenant1");
knownTenants.add("tenant2");
knownTenants.add("tenant3");
knownTenants.add("tenant4");
knownTenants.add("tenant5");
knownTenants.add("tenant6");

System.setProperty(SYS_PORT, String.valueOf(serverPort));
System.setProperty(SYS_OKAPI_URL, "http://localhost:" + okapiPort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ void setUp(Vertx vertx, VertxTestContext context) {

List<String> knownTenants = new ArrayList<>();
knownTenants.add(TENANT_DIKU);
knownTenants.add(TENANT_CENTRAL);
knownTenants.add(TENANT_CONSORTIA);
knownTenants.add(TENANT_EMPTY_CONSORTIA);

factory = new OaiPmhOkapiClientFactory(vertx, "http://localhost:" + okapiPort, REQUEST_TIMEOUT);

Expand Down

0 comments on commit eff83bf

Please sign in to comment.