-
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-16: Create shadow requester in lending tenant (#19)
* MODTLR-16 Implementation and tests * MODTLR-16 Fix formatting * MODTLR-16 Fix formatting * MODTLR-22 Implementation and tests * MODTLR-22 Rename central tenant to match our setup on Rancher * MODTLR-22 Refactoring * MODTLR-22 Major refactoring after merging changes from MODTLR-18 * MODTLR-22 Logging adjustments * MODTLR-22 Remove unused exception * MODTLR-22 Minor fixes * MODTLR-22 Remove fully qualified class name * MODTLR-22 Add pickupServicePointId to primary request * MODTLR-22 Remove primary request creation
- Loading branch information
1 parent
180d8d8
commit f773328
Showing
23 changed files
with
817 additions
and
130 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
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,20 @@ | ||
package org.folio.client.feign; | ||
|
||
import org.folio.domain.dto.User; | ||
import org.folio.spring.config.FeignClientConfiguration; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
|
||
@FeignClient(name = "users", url = "users", configuration = FeignClientConfiguration.class) | ||
public interface UsersClient { | ||
|
||
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) | ||
User postUser(@RequestBody User user); | ||
|
||
@GetMapping("/{userId}") | ||
User getUser(@PathVariable String userId); | ||
} |
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,6 @@ | ||
package org.folio.domain; | ||
|
||
import org.folio.domain.dto.Request; | ||
|
||
public record RequestWrapper(Request request, String 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.folio.domain.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public enum UserType { | ||
SHADOW("shadow"); | ||
|
||
private final String value; | ||
} |
7 changes: 0 additions & 7 deletions
7
src/main/java/org/folio/domain/strategy/TenantPickingStrategy.java
This file was deleted.
Oops, something went wrong.
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,12 @@ | ||
package org.folio.service; | ||
|
||
import java.util.Collection; | ||
|
||
import org.folio.domain.RequestWrapper; | ||
import org.folio.domain.dto.Request; | ||
|
||
public interface RequestService { | ||
|
||
RequestWrapper createSecondaryRequest(Request request, String borrowingTenantId, | ||
Collection<String> lendingTenantIds); | ||
} |
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,12 @@ | ||
package org.folio.service; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.folio.domain.dto.EcsTlr; | ||
|
||
public interface TenantService { | ||
Optional<String> getBorrowingTenant(EcsTlr ecsTlr); | ||
|
||
List<String> getLendingTenants(EcsTlr ecsTlr); | ||
} |
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,9 @@ | ||
package org.folio.service; | ||
|
||
import org.folio.domain.dto.User; | ||
|
||
public interface UserService { | ||
User createShadowUser(User realUser, String tenantId); | ||
|
||
User findUser(String userId, String 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
73 changes: 73 additions & 0 deletions
73
src/main/java/org/folio/service/impl/RequestServiceImpl.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,73 @@ | ||
package org.folio.service.impl; | ||
|
||
import static java.lang.String.format; | ||
|
||
import java.util.Collection; | ||
|
||
import org.folio.client.feign.CirculationClient; | ||
import org.folio.domain.RequestWrapper; | ||
import org.folio.domain.dto.Request; | ||
import org.folio.domain.dto.User; | ||
import org.folio.exception.RequestCreatingException; | ||
import org.folio.service.RequestService; | ||
import org.folio.service.TenantScopedExecutionService; | ||
import org.folio.service.UserService; | ||
import org.springframework.stereotype.Service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Log4j2 | ||
public class RequestServiceImpl implements RequestService { | ||
private final TenantScopedExecutionService tenantScopedExecutionService; | ||
private final CirculationClient circulationClient; | ||
private final UserService userService; | ||
|
||
@Override | ||
public RequestWrapper createSecondaryRequest(Request request, String borrowingTenantId, | ||
Collection<String> lendingTenantIds) { | ||
|
||
log.info("createSecondaryRequest:: attempting to create secondary request in one of potential " + | ||
"lending tenants: {}", lendingTenantIds); | ||
final String requesterId = request.getRequesterId(); | ||
|
||
log.info("createSecondaryRequest:: looking for requester {} in borrowing tenant ({})", | ||
requesterId, borrowingTenantId); | ||
User realRequester = userService.findUser(requesterId, borrowingTenantId); | ||
|
||
for (String lendingTenantId : lendingTenantIds) { | ||
try { | ||
log.info("createSecondaryRequest:: attempting to create shadow requester {} in lending tenant {}", | ||
requesterId, lendingTenantId); | ||
userService.createShadowUser(realRequester, lendingTenantId); | ||
return createSecondaryRequest(request, lendingTenantId); | ||
} catch (Exception e) { | ||
log.error("createSecondaryRequest:: failed to create secondary request in lending tenant {}: {}", | ||
lendingTenantId, e.getMessage()); | ||
log.debug("createSecondaryRequest:: ", e); | ||
} | ||
} | ||
|
||
String errorMessage = format( | ||
"Failed to create secondary request for instance %s in all potential lending tenants: %s", | ||
request.getInstanceId(), lendingTenantIds); | ||
log.error("createSecondaryRequest:: {}", errorMessage); | ||
throw new RequestCreatingException(errorMessage); | ||
} | ||
|
||
private RequestWrapper createSecondaryRequest(Request request, String lendingTenantId) { | ||
final String requestId = request.getId(); | ||
log.info("createSecondaryRequest:: creating secondary request {} in lending tenant {}", | ||
requestId, lendingTenantId); | ||
Request secondaryRequest = tenantScopedExecutionService.execute(lendingTenantId, | ||
() -> circulationClient.createInstanceRequest(request)); | ||
log.info("createSecondaryRequest:: secondary request {} created in lending tenant {}", | ||
requestId, lendingTenantId); | ||
log.debug("createSecondaryRequest:: secondary request: {}", () -> secondaryRequest); | ||
|
||
return new RequestWrapper(secondaryRequest, lendingTenantId); | ||
} | ||
|
||
} |
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
Oops, something went wrong.