-
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.
Merge branch 'master' into MODTLR-19
- Loading branch information
Showing
24 changed files
with
871 additions
and
129 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,13 @@ | ||
package org.folio.service; | ||
|
||
import java.util.Collection; | ||
|
||
import org.folio.domain.RequestWrapper; | ||
import org.folio.domain.dto.Request; | ||
|
||
public interface RequestService { | ||
RequestWrapper createPrimaryRequest(Request request, String borrowingTenantId); | ||
|
||
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
87 changes: 87 additions & 0 deletions
87
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,87 @@ | ||
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 createPrimaryRequest(Request request, String borrowingTenantId) { | ||
final String requestId = request.getId(); | ||
log.info("createPrimaryRequest:: creating primary request {} in borrowing tenant {}", | ||
requestId, borrowingTenantId); | ||
Request primaryRequest = tenantScopedExecutionService.execute(borrowingTenantId, | ||
() -> circulationClient.createRequest(request)); | ||
log.info("createPrimaryRequest:: primary request {} created in borrowing tenant {}", | ||
requestId, borrowingTenantId); | ||
log.debug("createPrimaryRequest:: primary request: {}", () -> primaryRequest); | ||
|
||
return new RequestWrapper(primaryRequest, borrowingTenantId); | ||
} | ||
|
||
@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.