-
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' of https://github.com/folio-org/mod-circulation…
…-bff into MCBFF-17
- Loading branch information
Showing
11 changed files
with
338 additions
and
0 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
8 changes: 8 additions & 0 deletions
8
src/main/java/org/folio/circulationbff/service/EcsRequestExternalService.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.circulationbff.service; | ||
|
||
import org.folio.circulationbff.domain.dto.EcsRequestExternal; | ||
import org.folio.circulationbff.domain.dto.EcsTlr; | ||
|
||
public interface EcsRequestExternalService { | ||
EcsTlr createEcsRequestExternal(EcsRequestExternal ecsRequestExternal); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/org/folio/circulationbff/service/impl/EcsRequestExternalServiceImpl.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,32 @@ | ||
package org.folio.circulationbff.service.impl; | ||
|
||
import org.folio.circulationbff.client.feign.EcsTlrClient; | ||
import org.folio.circulationbff.domain.dto.EcsRequestExternal; | ||
import org.folio.circulationbff.domain.dto.EcsTlr; | ||
import org.folio.circulationbff.service.EcsRequestExternalService; | ||
import org.folio.circulationbff.service.UserTenantsService; | ||
import org.folio.spring.service.SystemUserScopedExecutionService; | ||
import org.springframework.stereotype.Service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Log4j2 | ||
public class EcsRequestExternalServiceImpl implements EcsRequestExternalService { | ||
|
||
private final SystemUserScopedExecutionService systemUserScopedExecutionService; | ||
private final EcsTlrClient ecsTlrClient; | ||
private final UserTenantsService userTenantsService; | ||
|
||
|
||
@Override | ||
public EcsTlr createEcsRequestExternal(EcsRequestExternal ecsRequestExternal) { | ||
String centralTenantId = userTenantsService.getCentralTenant(); | ||
log.info("createEcsRequestExternal:: centralTenantId={}", centralTenantId); | ||
|
||
return systemUserScopedExecutionService.executeSystemUserScoped(centralTenantId, | ||
() -> ecsTlrClient.createEcsExternalRequest(ecsRequestExternal)); | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
src/main/resources/swagger.api/paths/ecsRequestExternal/ecsRequestExternal.yaml
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,22 @@ | ||
post: | ||
description: Create ECS request external | ||
operationId: postEcsRequestExternal | ||
tags: | ||
- ecsRequestExternal | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '../../schemas/dto/ecsRequestExternal/ecsRequestExternal.yaml' | ||
required: true | ||
responses: | ||
'201': | ||
description: Ecs external request has been created | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '../../schemas/dto/ecs-tlr/EcsTlr.yaml#/EcsTlr' | ||
'400': | ||
$ref: '../../responses/badRequestResponse.yaml' | ||
'500': | ||
$ref: '../../responses/internalServerErrorResponse.yaml' |
65 changes: 65 additions & 0 deletions
65
src/main/resources/swagger.api/schemas/dto/ecsRequestExternal/ecsRequestExternal.yaml
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,65 @@ | ||
description: ECS Request External - title level requests in a multi-tenant environment with Сonsortia support enabled | ||
type: object | ||
properties: | ||
id: | ||
description: ID of the ECS TLR | ||
$ref: '../common/uuid.yaml' | ||
instanceId: | ||
description: ID of the instance being requested | ||
$ref: '../common/uuid.yaml' | ||
requesterId: | ||
description: ID of the requesting patron (user) | ||
$ref: '../common/uuid.yaml' | ||
requestLevel: | ||
description: Level of the request - Item or Title | ||
type: string | ||
enum: [ "Item", "Title" ] | ||
requestExpirationDate: | ||
description: Date when the request expires | ||
type: string | ||
format: date-time | ||
requestDate: | ||
description: Date when the request was placed | ||
type: string | ||
format: date-time | ||
patronComments: | ||
description: Comments made by the patron | ||
type: string | ||
fulfillmentPreference: | ||
description: How should the request be fulfilled (whether the item should be kept on the hold shelf for collection or delivered to the requester) | ||
type: string | ||
enum: ["Hold Shelf", "Delivery"] | ||
pickupServicePointId: | ||
description: The ID of the Service Point where this request can be picked up | ||
$ref: '../common/uuid.yaml' | ||
itemId: | ||
description: ID of the item being requested | ||
$ref: '../common/uuid.yaml' | ||
holdingsRecordId: | ||
description: ID of the holdings record being requested | ||
$ref: '../common/uuid.yaml' | ||
primaryRequestId: | ||
description: Primary request ID | ||
$ref: '../common/uuid.yaml' | ||
primaryRequestDcbTransactionId: | ||
description: ID of DCB transaction created for primary request | ||
$ref: '../common/uuid.yaml' | ||
primaryRequestTenantId: | ||
description: ID of the tenant primary request was created in | ||
type: string | ||
secondaryRequestId: | ||
description: "Secondary request ID" | ||
$ref: '../common/uuid.yaml' | ||
secondaryRequestDcbTransactionId: | ||
description: ID of DCB transaction created for secondary request | ||
$ref: '../common/uuid.yaml' | ||
secondaryRequestTenantId: | ||
description: ID of the tenant secondary request was created in | ||
type: string | ||
|
||
required: | ||
- instanceId | ||
- requesterId | ||
- requestLevel | ||
- fulfillmentPreference | ||
- requestDate |
82 changes: 82 additions & 0 deletions
82
src/test/java/org/folio/circulationbff/api/EcsExternalRequestApiTest.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,82 @@ | ||
package org.folio.circulationbff.api; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.jsonResponse; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.matching; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching; | ||
import static org.apache.http.HttpStatus.SC_CREATED; | ||
import static org.apache.http.HttpStatus.SC_OK; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import org.folio.circulationbff.domain.dto.EcsRequestExternal; | ||
import org.folio.circulationbff.domain.dto.EcsTlr; | ||
import org.folio.circulationbff.domain.dto.UserTenant; | ||
import org.folio.circulationbff.domain.dto.UserTenantCollection; | ||
import org.folio.spring.integration.XOkapiHeaders; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
|
||
import com.github.tomakehurst.wiremock.client.WireMock; | ||
|
||
import lombok.SneakyThrows; | ||
|
||
class EcsExternalRequestApiTest extends BaseIT { | ||
private static final String TLR_CREATE_ECS_EXTERNAL_REQUEST_URL = | ||
"/tlr/create-ecs-request-external"; | ||
private static final String CIRCULATION_BFF_CREATE_ECS_EXTERNAL_REQUEST_URL = | ||
"/circulation-bff/create-ecs-request-external"; | ||
private static final String TEST_CENTRAL_TENANT_ID = "testCentralTenantId"; | ||
|
||
@Test | ||
@SneakyThrows | ||
void postEcsRequestExternalTest() { | ||
EcsRequestExternal requestExternal = buildEcsRequestExternal(); | ||
mockEcsTlrExternalRequestCreating(requestExternal); | ||
mockUserTenants(); | ||
mockPerform(requestExternal); | ||
|
||
wireMockServer.verify(1, postRequestedFor(urlPathMatching(TLR_CREATE_ECS_EXTERNAL_REQUEST_URL)) | ||
.withHeader(XOkapiHeaders.TENANT, equalTo(TEST_CENTRAL_TENANT_ID))); | ||
} | ||
|
||
private static void mockUserTenants() { | ||
UserTenant userTenant = new UserTenant(); | ||
userTenant.setCentralTenantId(TEST_CENTRAL_TENANT_ID); | ||
UserTenantCollection userTenants = new UserTenantCollection(List.of(userTenant), 1); | ||
|
||
wireMockServer.stubFor(WireMock.get(urlPathEqualTo(USER_TENANTS_URL)) | ||
.withQueryParam("limit", matching("\\d*")) | ||
.withHeader(HEADER_TENANT, equalTo(TENANT_ID_CONSORTIUM)) | ||
.willReturn(jsonResponse(asJsonString(userTenants), SC_OK))); | ||
} | ||
|
||
private static EcsRequestExternal buildEcsRequestExternal() { | ||
return new EcsRequestExternal( | ||
UUID.randomUUID().toString(), | ||
UUID.randomUUID().toString(), | ||
EcsRequestExternal.RequestLevelEnum.ITEM, | ||
new Date(LocalDate.of(2000, 1, 1).toEpochDay()), | ||
EcsRequestExternal.FulfillmentPreferenceEnum.HOLD_SHELF | ||
); | ||
} | ||
|
||
private void mockPerform(EcsRequestExternal requestExternal) throws Exception { | ||
mockMvc.perform(buildRequest(MockMvcRequestBuilders.post( | ||
CIRCULATION_BFF_CREATE_ECS_EXTERNAL_REQUEST_URL), requestExternal) | ||
.header(XOkapiHeaders.TENANT, TENANT_ID_CONSORTIUM)); | ||
} | ||
|
||
private static void mockEcsTlrExternalRequestCreating(EcsRequestExternal requestExternal) { | ||
wireMockServer.stubFor(WireMock.post(urlMatching(TLR_CREATE_ECS_EXTERNAL_REQUEST_URL)) | ||
.withRequestBody(equalToJson(asJsonString(requestExternal))) | ||
.willReturn(jsonResponse(asJsonString(new EcsTlr()), SC_CREATED))); | ||
} | ||
} |
Oops, something went wrong.