-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MODTLR-10: Support for cross-tenant requests (#10)
* MODTLR-10 Basic implementation and tests * MODTLR-10 Add logging configuration file * MODTLR-10 Add requestDate to ECS TLR schema, fix test * MODTLR-10 Replace dummy tenantId with "university" * MODTLR-10 Revert cosmetic changes * MODTLR-10 Attempt to fix Kafka listener test: increase timeout * MODTLR-10 Fix code smells * MODTLR-10 Test for TenantScopedExecutionService * MODTLR-10 Remove unused imports * MODTLR-10 Add Kafka environment variables * MODTLR-10 Add env variable OKAPI_URL * MODTLR-10 Extend EcsTlrApiTest * MODTLR-10 Minor adjustments * MODTLR-10 Rename method * MODTLR-10 Replace "=" with ":" in logs * MODTLR-10 Make requestDate required
- Loading branch information
1 parent
d0cb1c0
commit 6b4093b
Showing
25 changed files
with
849 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.folio.client; | ||
|
||
import org.folio.domain.dto.Request; | ||
import org.folio.spring.config.FeignClientConfiguration; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
|
||
@FeignClient(name = "circulation", url = "${folio.okapi-url}", configuration = FeignClientConfiguration.class) | ||
public interface CirculationClient { | ||
|
||
@PostMapping("/circulation/requests") | ||
Request createRequest(Request request); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/org/folio/exception/TenantScopedExecutionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.folio.exception; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class TenantScopedExecutionException extends RuntimeException { | ||
private final String tenantId; | ||
|
||
public TenantScopedExecutionException(Exception cause, String tenantId) { | ||
super(cause); | ||
this.tenantId = tenantId; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/org/folio/service/TenantScopedExecutionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.folio.service; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
public interface TenantScopedExecutionService { | ||
|
||
<T> T execute(String tenantId, Callable<T> action); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/org/folio/service/impl/TenantScopedExecutionServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.folio.service.impl; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.Callable; | ||
|
||
import org.folio.exception.TenantScopedExecutionException; | ||
import org.folio.service.TenantScopedExecutionService; | ||
import org.folio.spring.FolioExecutionContext; | ||
import org.folio.spring.FolioModuleMetadata; | ||
import org.folio.spring.integration.XOkapiHeaders; | ||
import org.folio.spring.scope.FolioExecutionContextSetter; | ||
import org.springframework.stereotype.Service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Log4j2 | ||
public class TenantScopedExecutionServiceImpl implements TenantScopedExecutionService { | ||
|
||
private final FolioModuleMetadata moduleMetadata; | ||
private final FolioExecutionContext executionContext; | ||
|
||
@Override | ||
public <T> T execute(String tenantId, Callable<T> action) { | ||
log.info("execute:: tenantId: {}", tenantId); | ||
Map<String, Collection<String>> headers = executionContext.getAllHeaders(); | ||
headers.put(XOkapiHeaders.TENANT, List.of(tenantId)); | ||
|
||
try (var x = new FolioExecutionContextSetter(moduleMetadata, headers)) { | ||
return action.call(); | ||
} catch (Exception e) { | ||
log.error("execute:: tenantId: {}", tenantId, e); | ||
throw new TenantScopedExecutionException(e, tenantId); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
status = error | ||
name = PropertiesConfig | ||
packages = org.folio.spring.logging | ||
|
||
appenders = console | ||
|
||
appender.console.type = Console | ||
appender.console.name = STDOUT | ||
|
||
appender.console.layout.type = PatternLayout | ||
appender.console.layout.pattern = %d{HH:mm:ss} [$${folio:requestid:-}] [$${folio:tenantid:-}] [$${folio:userid:-}] [$${folio:moduleid:-}] %-5p %-20.20C{1} %m%n | ||
|
||
rootLogger.level = debug | ||
rootLogger.appenderRefs = debug | ||
rootLogger.appenderRef.stdout.ref = STDOUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/resources/swagger.api/schemas/override-blocks.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "object", | ||
"description": "Blocks to override (e.g. during checkout or renewal)", | ||
"properties": { | ||
"itemNotLoanableBlock": { | ||
"description": "'Item not loanable' block", | ||
"type": "object", | ||
"properties": { | ||
"dueDate": { | ||
"description": "Due date for a new loan", | ||
"type": "string", | ||
"format": "date-time" | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"required": [ | ||
"dueDate" | ||
] | ||
}, | ||
"patronBlock": { | ||
"description": "Automated patron block", | ||
"type": "object", | ||
"additionalProperties": false | ||
}, | ||
"itemLimitBlock": { | ||
"description": "Item limit block", | ||
"type": "object", | ||
"additionalProperties": false | ||
}, | ||
"renewalBlock": { | ||
"description": "Renewal block", | ||
"type": "object", | ||
"additionalProperties": false | ||
}, | ||
"renewalDueDateRequiredBlock": { | ||
"description": "Override renewal block which requires due date field", | ||
"type": "object", | ||
"properties": { | ||
"dueDate": { | ||
"description": "Due date for a new loan", | ||
"type": "string", | ||
"format": "date-time" | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"required": [ | ||
"dueDate" | ||
] | ||
}, | ||
"comment": { | ||
"description": "Reason for override", | ||
"type": "string" | ||
} | ||
}, | ||
"additionalProperties": false | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/resources/swagger.api/schemas/request-search-index.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"description": "Request fields used for search", | ||
"type": "object", | ||
"properties": { | ||
"callNumberComponents": { | ||
"type": "object", | ||
"description": "Effective call number components", | ||
"properties": { | ||
"callNumber": { | ||
"type": "string", | ||
"description": "Effective Call Number is an identifier assigned to an item or its holding and associated with the item." | ||
}, | ||
"prefix": { | ||
"type": "string", | ||
"description": "Effective Call Number Prefix is the prefix of the identifier assigned to an item or its holding and associated with the item." | ||
}, | ||
"suffix": { | ||
"type": "string", | ||
"description": "Effective Call Number Suffix is the suffix of the identifier assigned to an item or its holding and associated with the item." | ||
} | ||
}, | ||
"additionalProperties": false | ||
}, | ||
"shelvingOrder": { | ||
"type": "string", | ||
"description": "A system generated normalization of the call number that allows for call number sorting in reports and search results" | ||
}, | ||
"pickupServicePointName": { | ||
"description": "The name of the request pickup service point", | ||
"type": "string" | ||
} | ||
}, | ||
"additionalProperties": false | ||
} |
Oops, something went wrong.