From 63ffa5ef595b375d9f58e119ce4d9bf741e9ddcc Mon Sep 17 00:00:00 2001 From: Alexander Kurash Date: Fri, 1 Mar 2024 19:40:26 +0200 Subject: [PATCH] MODTLR-12 Create a client for DCB transaction creation (#15) * MODTLR-12 Initial implementation * MODTLR-12 Rename endpoint to be consistent * MODTLR-12 Rename copied schemas * MODTLR-12 Rename component in yaml * MODTLR-12 Fix code smells in unit tests * MODTLR-12 Change schema, response type * MODTLR-12 Add transaction ID --- .../org/folio/client/feign/DcbClient.java | 18 ++++++++ src/main/resources/swagger.api/ecs-tlr.yaml | 6 +++ .../swagger.api/schemas/dcbItem.yaml | 19 ++++++++ .../swagger.api/schemas/dcbPatron.yaml | 13 ++++++ .../swagger.api/schemas/dcbPickup.yaml | 13 ++++++ .../swagger.api/schemas/dcbTransaction.yaml | 15 +++++++ .../schemas/transactionStatus.yaml | 16 +++++++ .../schemas/transactionStatusResponse.yaml | 4 ++ .../java/org/folio/client/DcbClientTest.java | 43 +++++++++++++++++++ 9 files changed, 147 insertions(+) create mode 100644 src/main/java/org/folio/client/feign/DcbClient.java create mode 100644 src/main/resources/swagger.api/schemas/dcbItem.yaml create mode 100644 src/main/resources/swagger.api/schemas/dcbPatron.yaml create mode 100644 src/main/resources/swagger.api/schemas/dcbPickup.yaml create mode 100644 src/main/resources/swagger.api/schemas/dcbTransaction.yaml create mode 100644 src/main/resources/swagger.api/schemas/transactionStatus.yaml create mode 100644 src/main/resources/swagger.api/schemas/transactionStatusResponse.yaml create mode 100644 src/test/java/org/folio/client/DcbClientTest.java diff --git a/src/main/java/org/folio/client/feign/DcbClient.java b/src/main/java/org/folio/client/feign/DcbClient.java new file mode 100644 index 00000000..9d5d52e1 --- /dev/null +++ b/src/main/java/org/folio/client/feign/DcbClient.java @@ -0,0 +1,18 @@ +package org.folio.client.feign; + +import org.folio.domain.dto.DcbTransaction; +import org.folio.domain.dto.TransactionStatusResponse; +import org.folio.spring.config.FeignClientConfiguration; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +@FeignClient(name = "dcb", url = "${folio.okapi-url}", configuration = FeignClientConfiguration.class) +public interface DcbClient { + + @PostMapping("/ecs-tlr-transactions/{dcbTransactionId}") + TransactionStatusResponse createDcbTransaction(@PathVariable String dcbTransactionId, + @RequestBody DcbTransaction dcbTransaction); + +} diff --git a/src/main/resources/swagger.api/ecs-tlr.yaml b/src/main/resources/swagger.api/ecs-tlr.yaml index e751d5b8..05a63f00 100644 --- a/src/main/resources/swagger.api/ecs-tlr.yaml +++ b/src/main/resources/swagger.api/ecs-tlr.yaml @@ -73,6 +73,12 @@ components: schemas: ecs-tlr: $ref: 'schemas/EcsTlr.yaml#/EcsTlr' + dcbTransaction: + $ref: 'schemas/dcbTransaction.yaml#/DcbTransaction' + transactionStatus: + $ref: 'schemas/transactionStatus.yaml#/TransactionStatus' + transactionStatusResponse: + $ref: 'schemas/transactionStatusResponse.yaml#/TransactionStatusResponse' errorResponse: $ref: 'schemas/errors.json' request: diff --git a/src/main/resources/swagger.api/schemas/dcbItem.yaml b/src/main/resources/swagger.api/schemas/dcbItem.yaml new file mode 100644 index 00000000..6a4f0e87 --- /dev/null +++ b/src/main/resources/swagger.api/schemas/dcbItem.yaml @@ -0,0 +1,19 @@ +DcbItem: + description: Item metadata required for the transaction + type: object + properties: + id: + description: The unique item identifier + $ref: "uuid.yaml" + title: + description: The title of the item that has been requested + type: string + barcode: + description: The barcode of the item as specified in the lending library + type: string + materialType: + description: The “hub-normalized” form of the item item type, used in the circulation rules for determining the correct loan policy. + type: string + lendingLibraryCode: + description: The code which identifies the lending library + type: string diff --git a/src/main/resources/swagger.api/schemas/dcbPatron.yaml b/src/main/resources/swagger.api/schemas/dcbPatron.yaml new file mode 100644 index 00000000..64e9bbbf --- /dev/null +++ b/src/main/resources/swagger.api/schemas/dcbPatron.yaml @@ -0,0 +1,13 @@ +DcbPatron: + description: Patron metadata required for the transaction + type: object + properties: + id: + description: The unique identifier for the patron making the request as known in the requesting library + $ref: "uuid.yaml" + group: + description: The patron group associated with the requesting patron + type: string + barcode: + description: The barcode of the patron + type: string diff --git a/src/main/resources/swagger.api/schemas/dcbPickup.yaml b/src/main/resources/swagger.api/schemas/dcbPickup.yaml new file mode 100644 index 00000000..13fa3d2f --- /dev/null +++ b/src/main/resources/swagger.api/schemas/dcbPickup.yaml @@ -0,0 +1,13 @@ +DcbPickup: + description: Pickup Location metadata required for the pickup service point + type: object + properties: + libraryCode: + description: The code which identifies the pickup library + type: string + servicePointId: + description: UUID of the pickup service point + type: string + servicePointName: + description: The name of the pickup service point + type: string diff --git a/src/main/resources/swagger.api/schemas/dcbTransaction.yaml b/src/main/resources/swagger.api/schemas/dcbTransaction.yaml new file mode 100644 index 00000000..a026aea4 --- /dev/null +++ b/src/main/resources/swagger.api/schemas/dcbTransaction.yaml @@ -0,0 +1,15 @@ +DcbTransaction: + type: object + properties: + item: + $ref: 'dcbItem.yaml#/DcbItem' + role: + type: string + enum: + - LENDER + - BORROWER + - PICKUP + - BORROWING-PICKUP + requestId: + description: ID of the existing request + $ref: "uuid.yaml" diff --git a/src/main/resources/swagger.api/schemas/transactionStatus.yaml b/src/main/resources/swagger.api/schemas/transactionStatus.yaml new file mode 100644 index 00000000..e999b7c2 --- /dev/null +++ b/src/main/resources/swagger.api/schemas/transactionStatus.yaml @@ -0,0 +1,16 @@ +TransactionStatus: + type: object + properties: + status: + type: string + enum: + - CREATED #Created by DCB + - OPEN #Item checked in at lending library + - AWAITING_PICKUP #Item checked in at borrowing/Pickup library + - ITEM_CHECKED_OUT #Item checkout by patron. Request is fulfilled and loan is created + - ITEM_CHECKED_IN #Item returned to borrowing/Pickup library + - CLOSED #Item returned to lending library + - CANCELLED #Request was cancelled + - ERROR #Error occurred + message: + type: string diff --git a/src/main/resources/swagger.api/schemas/transactionStatusResponse.yaml b/src/main/resources/swagger.api/schemas/transactionStatusResponse.yaml new file mode 100644 index 00000000..84941250 --- /dev/null +++ b/src/main/resources/swagger.api/schemas/transactionStatusResponse.yaml @@ -0,0 +1,4 @@ +TransactionStatusResponse: + allOf: + - $ref: 'transactionStatus.yaml#/TransactionStatus' + - $ref: 'dcbTransaction.yaml#/DcbTransaction' diff --git a/src/test/java/org/folio/client/DcbClientTest.java b/src/test/java/org/folio/client/DcbClientTest.java new file mode 100644 index 00000000..a362fcb2 --- /dev/null +++ b/src/test/java/org/folio/client/DcbClientTest.java @@ -0,0 +1,43 @@ +package org.folio.client; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.Mockito.when; + +import java.util.UUID; + +import org.folio.client.feign.DcbClient; +import org.folio.domain.dto.DcbTransaction; +import org.folio.domain.dto.TransactionStatusResponse; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class DcbClientTest { + @Mock + private DcbClient dcbClient; + + @Test + void canCreateDcbTransaction() { + String requestId = UUID.randomUUID().toString(); + String dcbTransactionId = UUID.randomUUID().toString(); + DcbTransaction dcbTransaction = new DcbTransaction() + .role(DcbTransaction.RoleEnum.BORROWER) + .requestId(requestId); + TransactionStatusResponse transactionStatusResponse = new TransactionStatusResponse() + .status(TransactionStatusResponse.StatusEnum.CANCELLED) + .message("test message") + .item(dcbTransaction.getItem()) + .role(TransactionStatusResponse.RoleEnum.BORROWER) + .requestId(requestId); + when(dcbClient.createDcbTransaction(dcbTransactionId, dcbTransaction)) + .thenReturn(transactionStatusResponse); + var response = dcbClient.createDcbTransaction(dcbTransactionId, + dcbTransaction); + assertNotNull(response); + assertEquals(TransactionStatusResponse.RoleEnum.BORROWER, response.getRole()); + assertEquals(requestId, response.getRequestId()); + } +}