From 455374fc941f578042d2ec00de9d989a5fdb47b0 Mon Sep 17 00:00:00 2001 From: Roman_Barannyk Date: Tue, 16 Jan 2024 15:53:12 +0200 Subject: [PATCH 01/11] MODTLR-5 add new endpoints to descriptor and schema --- descriptors/ModuleDescriptor-template.json | 30 ++++++++--- src/main/resources/swagger.api/ecs-tlr.yaml | 56 +++++++++++++++++---- 2 files changed, 69 insertions(+), 17 deletions(-) diff --git a/descriptors/ModuleDescriptor-template.json b/descriptors/ModuleDescriptor-template.json index 99e729d8..b37b6254 100644 --- a/descriptors/ModuleDescriptor-template.json +++ b/descriptors/ModuleDescriptor-template.json @@ -7,20 +7,28 @@ "version": "1.0", "handlers": [ { - "methods": [ - "GET" - ], + "methods": ["GET"], "pathPattern": "/tlr/ecs-tlr/{requestId}", "permissionsRequired": ["tlr.ecs-tlr.item.get"], "modulePermissions": [] }, { - "methods": [ - "POST" - ], + "methods": ["POST"], "pathPattern": "/tlr/ecs-tlr", "permissionsRequired": ["tlr.ecs-tlr.post"], "modulePermissions": [] + }, + { + "methods": ["PUT"], + "pathPattern": "/tlr/ecs-tlr/{requestId}", + "permissionsRequired": ["tlr.ecs-tlr.item.put"], + "modulePermissions": [] + }, + { + "methods": ["DELETE"], + "pathPattern": "/tlr/ecs-tlr/{requestId}", + "permissionsRequired": ["tlr.ecs-tlr.item.delete"], + "modulePermissions": [] } ] }, @@ -62,6 +70,16 @@ "permissionName": "tlr.ecs-tlr.post", "displayName": "ecs-tlr - create request", "description": "create ecs-tlr request" + }, + { + "permissionName": "tlr.ecs-tlr.put", + "displayName": "ecs-tlr - update request", + "description": "update ecs-tlr request" + }, + { + "permissionName": "tlr.ecs-tlr.delete", + "displayName": "ecs-tlr - remove request", + "description": "remove ecs-tlr request" } ], "requires": [], diff --git a/src/main/resources/swagger.api/ecs-tlr.yaml b/src/main/resources/swagger.api/ecs-tlr.yaml index 8ab23021..15900946 100644 --- a/src/main/resources/swagger.api/ecs-tlr.yaml +++ b/src/main/resources/swagger.api/ecs-tlr.yaml @@ -32,12 +32,35 @@ paths: '400': $ref: '#/components/responses/badRequestResponse' '404': - description: Not found - content: - text/plain: - schema: - type: string - example: Not found + $ref: '#/components/responses/notFoundResponse' + '500': + $ref: '#/components/responses/internalServerErrorResponse' + put: + description: Update ECS TLR by id + operationId: putEcsTlrById + parameters: + - $ref: '#/components/parameters/requestId' + responses: + '204': + description: Request successfully updated + '400': + $ref: '#/components/responses/badRequestResponse' + '404': + $ref: '#/components/responses/notFoundResponse' + '500': + $ref: '#/components/responses/internalServerErrorResponse' + delete: + description: Remove ECS TLR by id + operationId: deleteEcsTlrById + parameters: + - $ref: '#/components/parameters/requestId' + responses: + '204': + description: Request successfully removed + '400': + $ref: '#/components/responses/badRequestResponse' + '404': + $ref: '#/components/responses/notFoundResponse' '500': $ref: '#/components/responses/internalServerErrorResponse' components: @@ -56,13 +79,24 @@ components: format: uuid responses: ecs-tlr: - description: ECS TLR object - content: - application/json: - schema: - $ref: 'schemas/EcsTlr.yaml#/EcsTlr' + description: ECS TLR object + content: + application/json: + schema: + $ref: 'schemas/EcsTlr.yaml#/EcsTlr' badRequestResponse: description: Validation errors + content: + application/json: + example: + errors: + - message: Request is invalid + code: notfound.request + total_records: 1 + schema: + $ref: "#/components/schemas/errorResponse" + notFoundResponse: + description: Not found content: application/json: example: From 9b3cc13a663c39328770bdf0b405ac30110b6640 Mon Sep 17 00:00:00 2001 From: Roman_Barannyk Date: Fri, 19 Jan 2024 15:45:38 +0200 Subject: [PATCH 02/11] MODTLR-9 add put and delete endpoints --- README.md | 4 ++-- .../folio/controller/EcsTlrController.java | 20 ++++++++++++++++++- .../java/org/folio/service/EcsTlrService.java | 2 ++ .../folio/service/impl/EcsTlrServiceImpl.java | 15 ++++++++++++++ src/main/resources/swagger.api/ecs-tlr.yaml | 6 ++++++ .../swagger.api/examples/EcsTlr.sample | 11 ++++++++++ .../resources/swagger.api/schemas/EcsTlr.yaml | 2 +- 7 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/swagger.api/examples/EcsTlr.sample diff --git a/README.md b/README.md index a401d212..d1ad3c90 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,10 @@ Version 2.0. See the file "[LICENSE](LICENSE)" for more information. ## Goal -FOLIO compatible title-level requests functionality. +FOLIO compatible title level requests functionality. ## Further information ### Issue tracker -Project [MODTLR](https://issues.folio.org/browse/MODTLR). \ No newline at end of file +Project [MODTLR](https://issues.folio.org/browse/MODTLR). diff --git a/src/main/java/org/folio/controller/EcsTlrController.java b/src/main/java/org/folio/controller/EcsTlrController.java index 9fe5e947..a0cb929d 100644 --- a/src/main/java/org/folio/controller/EcsTlrController.java +++ b/src/main/java/org/folio/controller/EcsTlrController.java @@ -1,6 +1,7 @@ package org.folio.controller; import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.HttpStatus.OK; import java.util.UUID; @@ -23,7 +24,7 @@ public class EcsTlrController implements TlrApi { @Override public ResponseEntity getEcsTlrById(UUID requestId) { - log.debug("getEcsTlrById:: parameters id: {}", requestId); + log.debug("getEcsTlrById:: parameters requestId: {}", requestId); return ecsTlrService.get(requestId) .map(ResponseEntity.status(OK)::body) @@ -36,4 +37,21 @@ public ResponseEntity postEcsTlr(EcsTlr ecsTlr) { return ResponseEntity.status(CREATED).body(ecsTlrService.post(ecsTlr)); } + + @Override + public ResponseEntity putEcsTlrById(UUID requestId, EcsTlr ecsTlr) { + log.debug("putEcsTlrById:: parameters requestId: {}", requestId); + ecsTlrService.put(requestId, ecsTlr); + + return ResponseEntity.status(NO_CONTENT).build(); + } + + @Override + public ResponseEntity deleteEcsTlrById(UUID requestId) { + log.debug("deleteEcsTlrById:: parameters requestId: {}", requestId); + + ecsTlrService.delete(requestId); + + return ResponseEntity.status(NO_CONTENT).build(); + } } diff --git a/src/main/java/org/folio/service/EcsTlrService.java b/src/main/java/org/folio/service/EcsTlrService.java index 4d7da52a..5298e09e 100644 --- a/src/main/java/org/folio/service/EcsTlrService.java +++ b/src/main/java/org/folio/service/EcsTlrService.java @@ -8,4 +8,6 @@ public interface EcsTlrService { Optional get(UUID requestId); EcsTlr post(EcsTlr ecsTlr); + boolean put(UUID requestId, EcsTlr ecsTlr); + void delete(UUID requestId); } diff --git a/src/main/java/org/folio/service/impl/EcsTlrServiceImpl.java b/src/main/java/org/folio/service/impl/EcsTlrServiceImpl.java index 43d20595..85fac58e 100644 --- a/src/main/java/org/folio/service/impl/EcsTlrServiceImpl.java +++ b/src/main/java/org/folio/service/impl/EcsTlrServiceImpl.java @@ -35,4 +35,19 @@ public EcsTlr post(EcsTlr ecsTlr) { return requestsMapper.mapEntityToDto(ecsTlrRepository.save( requestsMapper.mapDtoToEntity(ecsTlr))); } + + @Override + public boolean put(UUID requestId, EcsTlr ecsTlr) { + log.debug("put:: requestId: {}, ecsTlr: {}", requestId, ecsTlr); + + return ecsTlrRepository.findById(requestId) + .map(ecsTlrEntity -> requestsMapper.mapDtoToEntity(ecsTlr)) + .map(ecsTlrRepository::save) + .isPresent(); + } + + @Override + public void delete(UUID requestId) { + ecsTlrRepository.deleteById(requestId); + } } diff --git a/src/main/resources/swagger.api/ecs-tlr.yaml b/src/main/resources/swagger.api/ecs-tlr.yaml index 1c5d88a3..7b04ca1f 100644 --- a/src/main/resources/swagger.api/ecs-tlr.yaml +++ b/src/main/resources/swagger.api/ecs-tlr.yaml @@ -38,6 +38,12 @@ paths: put: description: Update ECS TLR by id operationId: putEcsTlrById + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/ecs-tlr" + required: true parameters: - $ref: '#/components/parameters/requestId' responses: diff --git a/src/main/resources/swagger.api/examples/EcsTlr.sample b/src/main/resources/swagger.api/examples/EcsTlr.sample new file mode 100644 index 00000000..1da9f5c2 --- /dev/null +++ b/src/main/resources/swagger.api/examples/EcsTlr.sample @@ -0,0 +1,11 @@ +{ + "id": "58e3b64b-c634-4afc-aba7-4d2a3ddef63d", + "instanceId": "2835ba05-fc4b-4ff2-972b-6ff7faaedd6e", + "requesterId": "4565999e-1994-4aab-9282-185731b4ce66", + "requestType": "Hold", + "requestLevel": "Title", + "requestExpirationDate": "2024-01-01T23:11:00-01:00", + "patronComments": "test comment", + "fulfillmentPreference": "Hold Shelf", + "pickupServicePointId": "71ff4b72-70a0-40f6-9f73-6db29ced80a3" +} diff --git a/src/main/resources/swagger.api/schemas/EcsTlr.yaml b/src/main/resources/swagger.api/schemas/EcsTlr.yaml index ca60b510..f5c633dd 100644 --- a/src/main/resources/swagger.api/schemas/EcsTlr.yaml +++ b/src/main/resources/swagger.api/schemas/EcsTlr.yaml @@ -1,5 +1,5 @@ EcsTlr: - description: ECS TLR - title-level requests in a multi-tenant environment with Сonsortia support enabled + description: ECS TLR - title level requests in a multi-tenant environment with Сonsortia support enabled type: "object" properties: id: From 9b2578c700a4c9238d6a7e3bd414ab77f0bb2876 Mon Sep 17 00:00:00 2001 From: Roman_Barannyk Date: Mon, 22 Jan 2024 17:50:17 +0200 Subject: [PATCH 03/11] MODTLR-9 add tests --- .../folio/controller/EcsTlrController.java | 12 ++++---- .../java/org/folio/service/EcsTlrService.java | 2 +- .../folio/service/impl/EcsTlrServiceImpl.java | 9 ++++-- .../controller/EcsTlrControllerTest.java | 30 ++++++++++++++++++- .../org/folio/service/EcsTlrServiceTest.java | 13 +++++++- 5 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/folio/controller/EcsTlrController.java b/src/main/java/org/folio/controller/EcsTlrController.java index a0cb929d..db79d8fe 100644 --- a/src/main/java/org/folio/controller/EcsTlrController.java +++ b/src/main/java/org/folio/controller/EcsTlrController.java @@ -1,6 +1,7 @@ package org.folio.controller; import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.NOT_FOUND; import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.HttpStatus.OK; @@ -41,17 +42,18 @@ public ResponseEntity postEcsTlr(EcsTlr ecsTlr) { @Override public ResponseEntity putEcsTlrById(UUID requestId, EcsTlr ecsTlr) { log.debug("putEcsTlrById:: parameters requestId: {}", requestId); - ecsTlrService.put(requestId, ecsTlr); - return ResponseEntity.status(NO_CONTENT).build(); + return ecsTlrService.put(requestId, ecsTlr) + ? ResponseEntity.status(NO_CONTENT).build() + : ResponseEntity.status(NOT_FOUND).build(); } @Override public ResponseEntity deleteEcsTlrById(UUID requestId) { log.debug("deleteEcsTlrById:: parameters requestId: {}", requestId); - ecsTlrService.delete(requestId); - - return ResponseEntity.status(NO_CONTENT).build(); + return ecsTlrService.delete(requestId) + ? ResponseEntity.status(NO_CONTENT).build() + : ResponseEntity.status(NOT_FOUND).build(); } } diff --git a/src/main/java/org/folio/service/EcsTlrService.java b/src/main/java/org/folio/service/EcsTlrService.java index 5298e09e..80b4614c 100644 --- a/src/main/java/org/folio/service/EcsTlrService.java +++ b/src/main/java/org/folio/service/EcsTlrService.java @@ -9,5 +9,5 @@ public interface EcsTlrService { Optional get(UUID requestId); EcsTlr post(EcsTlr ecsTlr); boolean put(UUID requestId, EcsTlr ecsTlr); - void delete(UUID requestId); + boolean delete(UUID requestId); } diff --git a/src/main/java/org/folio/service/impl/EcsTlrServiceImpl.java b/src/main/java/org/folio/service/impl/EcsTlrServiceImpl.java index 85fac58e..289a960f 100644 --- a/src/main/java/org/folio/service/impl/EcsTlrServiceImpl.java +++ b/src/main/java/org/folio/service/impl/EcsTlrServiceImpl.java @@ -47,7 +47,12 @@ public boolean put(UUID requestId, EcsTlr ecsTlr) { } @Override - public void delete(UUID requestId) { - ecsTlrRepository.deleteById(requestId); + public boolean delete(UUID requestId) { + return ecsTlrRepository.findById(requestId) + .map(ecsTlrEntity -> { + ecsTlrRepository.deleteById(ecsTlrEntity.getId()); + return ecsTlrEntity; + }) + .isPresent(); } } diff --git a/src/test/java/org/folio/controller/EcsTlrControllerTest.java b/src/test/java/org/folio/controller/EcsTlrControllerTest.java index f7f5021b..0b2b9596 100644 --- a/src/test/java/org/folio/controller/EcsTlrControllerTest.java +++ b/src/test/java/org/folio/controller/EcsTlrControllerTest.java @@ -5,9 +5,11 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.springframework.http.HttpStatus.CREATED; -import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; +import static org.springframework.http.HttpStatus.NOT_FOUND; +import static org.springframework.http.HttpStatus.NO_CONTENT; import java.util.Optional; +import java.util.UUID; import org.folio.domain.dto.EcsTlr; import org.folio.service.EcsTlrService; @@ -51,4 +53,30 @@ void ecsTlrShouldSuccessfullyBeCreated() { assertEquals(CREATED, response.getStatusCode()); assertEquals(mockRequest, response.getBody()); } + + @Test + void ecsTlrShouldSuccessfullyBeUpdated() { + var id = UUID.randomUUID(); + var mockRequest = new EcsTlr(); + mockRequest.setId(id.toString()); + when(requestsService.put(any(UUID.class), any(EcsTlr.class))).thenReturn(true); + + var response = requestsController.putEcsTlrById(id, mockRequest); + assertEquals(NO_CONTENT, response.getStatusCode()); + } + + @Test + void ecsTlrShouldNotBeFound() { + var id = UUID.randomUUID(); + var mockRequest = new EcsTlr(); + mockRequest.setId(UUID.randomUUID().toString()); + + when(requestsService.put(any(UUID.class), any(EcsTlr.class))).thenReturn(false); + var putResponse = requestsController.putEcsTlrById(id, mockRequest); + assertEquals(NOT_FOUND, putResponse.getStatusCode()); + + when(requestsService.delete(any(UUID.class))).thenReturn(false); + var deleteResponse = requestsController.deleteEcsTlrById(id); + assertEquals(NOT_FOUND, deleteResponse.getStatusCode()); + } } diff --git a/src/test/java/org/folio/service/EcsTlrServiceTest.java b/src/test/java/org/folio/service/EcsTlrServiceTest.java index 4eaf0752..942cd25b 100644 --- a/src/test/java/org/folio/service/EcsTlrServiceTest.java +++ b/src/test/java/org/folio/service/EcsTlrServiceTest.java @@ -1,10 +1,13 @@ package org.folio.service; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.util.Optional; import java.util.UUID; import org.folio.domain.dto.EcsTlr; @@ -38,7 +41,7 @@ void getById() { } @Test - void postEcsTlr() { + void ecsTlrShouldBeCreatedThenUpdatedAndDeleted() { var id = UUID.randomUUID(); var instanceId = UUID.randomUUID(); var requesterId = UUID.randomUUID(); @@ -82,5 +85,13 @@ void postEcsTlr() { assertEquals(patronComments, postEcsTlr.getPatronComments()); assertEquals(fulfillmentPreference, postEcsTlr.getFulfillmentPreference()); assertEquals(pickupServicePointId.toString(), postEcsTlr.getPickupServicePointId()); + + when(ecsTlrRepository.findById(any(UUID.class))).thenReturn(Optional.of(mockEcsTlrEntity)); + assertTrue(ecsTlrService.put(id, ecsTlr)); + assertTrue(ecsTlrService.delete(id)); + + when(ecsTlrRepository.findById(any(UUID.class))).thenReturn(Optional.empty()); + assertFalse(ecsTlrService.put(id, ecsTlr)); + assertFalse(ecsTlrService.delete(id)); } } From 597d741cc7c9e5c36b2978f6e4ee08a628a1a1a4 Mon Sep 17 00:00:00 2001 From: Roman_Barannyk Date: Mon, 22 Jan 2024 18:02:45 +0200 Subject: [PATCH 04/11] MODTLR-9 add test for removing --- .../java/org/folio/controller/EcsTlrControllerTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/java/org/folio/controller/EcsTlrControllerTest.java b/src/test/java/org/folio/controller/EcsTlrControllerTest.java index 0b2b9596..fd8e42bd 100644 --- a/src/test/java/org/folio/controller/EcsTlrControllerTest.java +++ b/src/test/java/org/folio/controller/EcsTlrControllerTest.java @@ -65,6 +65,12 @@ void ecsTlrShouldSuccessfullyBeUpdated() { assertEquals(NO_CONTENT, response.getStatusCode()); } + @Test + void ecsTlrShouldSuccessfullyBeDeleted() { + when(requestsService.delete(any(UUID.class))).thenReturn(true); + assertEquals(NO_CONTENT, requestsController.deleteEcsTlrById(UUID.randomUUID()).getStatusCode()); + } + @Test void ecsTlrShouldNotBeFound() { var id = UUID.randomUUID(); From 6000b5f9715feee3e79d1036472fb3c432100273 Mon Sep 17 00:00:00 2001 From: Roman_Barannyk Date: Fri, 26 Jan 2024 22:35:41 +0200 Subject: [PATCH 05/11] MODTLR-9 incorporating review comments --- .../folio/controller/EcsTlrController.java | 21 +++++++----- .../java/org/folio/service/EcsTlrService.java | 4 +-- .../folio/service/impl/EcsTlrServiceImpl.java | 32 ++++++++++--------- src/main/resources/swagger.api/ecs-tlr.yaml | 10 +++--- .../controller/EcsTlrControllerTest.java | 6 ++-- .../org/folio/service/EcsTlrServiceTest.java | 6 ++-- 6 files changed, 43 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/folio/controller/EcsTlrController.java b/src/main/java/org/folio/controller/EcsTlrController.java index db79d8fe..e2c93d10 100644 --- a/src/main/java/org/folio/controller/EcsTlrController.java +++ b/src/main/java/org/folio/controller/EcsTlrController.java @@ -10,6 +10,7 @@ import org.folio.domain.dto.EcsTlr; import org.folio.rest.resource.TlrApi; import org.folio.service.EcsTlrService; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; @@ -36,24 +37,28 @@ public ResponseEntity getEcsTlrById(UUID requestId) { public ResponseEntity postEcsTlr(EcsTlr ecsTlr) { log.debug("postEcsTlr:: parameters ecsTlr: {}", ecsTlr); - return ResponseEntity.status(CREATED).body(ecsTlrService.post(ecsTlr)); + return ResponseEntity.status(CREATED).body(ecsTlrService.create(ecsTlr)); } @Override public ResponseEntity putEcsTlrById(UUID requestId, EcsTlr ecsTlr) { - log.debug("putEcsTlrById:: parameters requestId: {}", requestId); + log.debug("putEcsTlrById:: parameters requestId: {}, ecsTlr: {}", () -> requestId, () -> ecsTlr); - return ecsTlrService.put(requestId, ecsTlr) - ? ResponseEntity.status(NO_CONTENT).build() - : ResponseEntity.status(NOT_FOUND).build(); + HttpStatus httpStatus = ecsTlrService.update(requestId, ecsTlr) + ? NO_CONTENT + : NOT_FOUND; + + return ResponseEntity.status(httpStatus).build(); } @Override public ResponseEntity deleteEcsTlrById(UUID requestId) { log.debug("deleteEcsTlrById:: parameters requestId: {}", requestId); - return ecsTlrService.delete(requestId) - ? ResponseEntity.status(NO_CONTENT).build() - : ResponseEntity.status(NOT_FOUND).build(); + HttpStatus httpStatus = ecsTlrService.delete(requestId) + ? NO_CONTENT + : NOT_FOUND; + + return ResponseEntity.status(httpStatus).build(); } } diff --git a/src/main/java/org/folio/service/EcsTlrService.java b/src/main/java/org/folio/service/EcsTlrService.java index 80b4614c..3843f010 100644 --- a/src/main/java/org/folio/service/EcsTlrService.java +++ b/src/main/java/org/folio/service/EcsTlrService.java @@ -7,7 +7,7 @@ public interface EcsTlrService { Optional get(UUID requestId); - EcsTlr post(EcsTlr ecsTlr); - boolean put(UUID requestId, EcsTlr ecsTlr); + EcsTlr create(EcsTlr ecsTlr); + boolean update(UUID requestId, EcsTlr ecsTlr); boolean delete(UUID requestId); } diff --git a/src/main/java/org/folio/service/impl/EcsTlrServiceImpl.java b/src/main/java/org/folio/service/impl/EcsTlrServiceImpl.java index 289a960f..b2fee046 100644 --- a/src/main/java/org/folio/service/impl/EcsTlrServiceImpl.java +++ b/src/main/java/org/folio/service/impl/EcsTlrServiceImpl.java @@ -29,30 +29,32 @@ public Optional get(UUID id) { } @Override - public EcsTlr post(EcsTlr ecsTlr) { - log.debug("post:: parameters ecsTlr: {}", () -> ecsTlr); + public EcsTlr create(EcsTlr ecsTlr) { + log.debug("create:: parameters ecsTlr: {}", () -> ecsTlr); return requestsMapper.mapEntityToDto(ecsTlrRepository.save( requestsMapper.mapDtoToEntity(ecsTlr))); } @Override - public boolean put(UUID requestId, EcsTlr ecsTlr) { - log.debug("put:: requestId: {}, ecsTlr: {}", requestId, ecsTlr); - - return ecsTlrRepository.findById(requestId) - .map(ecsTlrEntity -> requestsMapper.mapDtoToEntity(ecsTlr)) - .map(ecsTlrRepository::save) - .isPresent(); + public boolean update(UUID requestId, EcsTlr ecsTlr) { + log.debug("update:: parameters requestId: {}, ecsTlr: {}", () -> requestId, () -> ecsTlr); + + if (ecsTlrRepository.existsById(requestId)) { + ecsTlrRepository.save(requestsMapper.mapDtoToEntity(ecsTlr)); + return true; + } + return false; } @Override public boolean delete(UUID requestId) { - return ecsTlrRepository.findById(requestId) - .map(ecsTlrEntity -> { - ecsTlrRepository.deleteById(ecsTlrEntity.getId()); - return ecsTlrEntity; - }) - .isPresent(); + log.debug("delete:: parameters requestId: {}", () -> requestId); + + if (ecsTlrRepository.existsById(requestId)) { + ecsTlrRepository.deleteById(requestId); + return true; + } + return false; } } diff --git a/src/main/resources/swagger.api/ecs-tlr.yaml b/src/main/resources/swagger.api/ecs-tlr.yaml index 7b04ca1f..e4006845 100644 --- a/src/main/resources/swagger.api/ecs-tlr.yaml +++ b/src/main/resources/swagger.api/ecs-tlr.yaml @@ -36,7 +36,7 @@ paths: '500': $ref: '#/components/responses/internalServerErrorResponse' put: - description: Update ECS TLR by id + description: Update ECS TLR by ID operationId: putEcsTlrById requestBody: content: @@ -56,7 +56,7 @@ paths: '500': $ref: '#/components/responses/internalServerErrorResponse' delete: - description: Remove ECS TLR by id + description: Remove ECS TLR by ID operationId: deleteEcsTlrById parameters: - $ref: '#/components/parameters/requestId' @@ -97,7 +97,7 @@ components: example: errors: - message: Request is invalid - code: notfound.request + code: invalid.request total_records: 1 schema: $ref: "#/components/schemas/errorResponse" @@ -107,8 +107,8 @@ components: application/json: example: errors: - - message: Request is invalid - code: invalid.request + - message: Request not found + code: notfound.request total_records: 1 schema: $ref: "#/components/schemas/errorResponse" diff --git a/src/test/java/org/folio/controller/EcsTlrControllerTest.java b/src/test/java/org/folio/controller/EcsTlrControllerTest.java index fd8e42bd..e85fe1e8 100644 --- a/src/test/java/org/folio/controller/EcsTlrControllerTest.java +++ b/src/test/java/org/folio/controller/EcsTlrControllerTest.java @@ -46,7 +46,7 @@ void getById() { @Test void ecsTlrShouldSuccessfullyBeCreated() { var mockRequest = new EcsTlr(); - when(requestsService.post(any(EcsTlr.class))).thenReturn(mockRequest); + when(requestsService.create(any(EcsTlr.class))).thenReturn(mockRequest); var response = requestsController.postEcsTlr(new EcsTlr()); @@ -59,7 +59,7 @@ void ecsTlrShouldSuccessfullyBeUpdated() { var id = UUID.randomUUID(); var mockRequest = new EcsTlr(); mockRequest.setId(id.toString()); - when(requestsService.put(any(UUID.class), any(EcsTlr.class))).thenReturn(true); + when(requestsService.update(any(UUID.class), any(EcsTlr.class))).thenReturn(true); var response = requestsController.putEcsTlrById(id, mockRequest); assertEquals(NO_CONTENT, response.getStatusCode()); @@ -77,7 +77,7 @@ void ecsTlrShouldNotBeFound() { var mockRequest = new EcsTlr(); mockRequest.setId(UUID.randomUUID().toString()); - when(requestsService.put(any(UUID.class), any(EcsTlr.class))).thenReturn(false); + when(requestsService.update(any(UUID.class), any(EcsTlr.class))).thenReturn(false); var putResponse = requestsController.putEcsTlrById(id, mockRequest); assertEquals(NOT_FOUND, putResponse.getStatusCode()); diff --git a/src/test/java/org/folio/service/EcsTlrServiceTest.java b/src/test/java/org/folio/service/EcsTlrServiceTest.java index 942cd25b..b338f5e7 100644 --- a/src/test/java/org/folio/service/EcsTlrServiceTest.java +++ b/src/test/java/org/folio/service/EcsTlrServiceTest.java @@ -75,7 +75,7 @@ void ecsTlrShouldBeCreatedThenUpdatedAndDeleted() { ecsTlr.setPickupServicePointId(pickupServicePointId.toString()); when(ecsTlrRepository.save(any(EcsTlrEntity.class))).thenReturn(mockEcsTlrEntity); - var postEcsTlr = ecsTlrService.post(ecsTlr); + var postEcsTlr = ecsTlrService.create(ecsTlr); assertEquals(id.toString(), postEcsTlr.getId()); assertEquals(instanceId.toString(), postEcsTlr.getInstanceId()); @@ -87,11 +87,11 @@ void ecsTlrShouldBeCreatedThenUpdatedAndDeleted() { assertEquals(pickupServicePointId.toString(), postEcsTlr.getPickupServicePointId()); when(ecsTlrRepository.findById(any(UUID.class))).thenReturn(Optional.of(mockEcsTlrEntity)); - assertTrue(ecsTlrService.put(id, ecsTlr)); + assertTrue(ecsTlrService.update(id, ecsTlr)); assertTrue(ecsTlrService.delete(id)); when(ecsTlrRepository.findById(any(UUID.class))).thenReturn(Optional.empty()); - assertFalse(ecsTlrService.put(id, ecsTlr)); + assertFalse(ecsTlrService.update(id, ecsTlr)); assertFalse(ecsTlrService.delete(id)); } } From c501afc76cb256d7a7a5744316d68f5aed6052d3 Mon Sep 17 00:00:00 2001 From: Roman_Barannyk Date: Fri, 26 Jan 2024 23:03:36 +0200 Subject: [PATCH 06/11] MODTLR-9 update test --- src/test/java/org/folio/service/EcsTlrServiceTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/folio/service/EcsTlrServiceTest.java b/src/test/java/org/folio/service/EcsTlrServiceTest.java index 84fe7702..395f724e 100644 --- a/src/test/java/org/folio/service/EcsTlrServiceTest.java +++ b/src/test/java/org/folio/service/EcsTlrServiceTest.java @@ -95,11 +95,11 @@ void ecsTlrShouldBeCreatedThenUpdatedAndDeleted() { assertEquals(fulfillmentPreference, postEcsTlr.getFulfillmentPreference()); assertEquals(pickupServicePointId.toString(), postEcsTlr.getPickupServicePointId()); - when(ecsTlrRepository.findById(any(UUID.class))).thenReturn(Optional.of(mockEcsTlrEntity)); + when(ecsTlrRepository.existsById(any(UUID.class))).thenReturn(true); assertTrue(ecsTlrService.update(id, ecsTlr)); assertTrue(ecsTlrService.delete(id)); - when(ecsTlrRepository.findById(any(UUID.class))).thenReturn(Optional.empty()); + when(ecsTlrRepository.existsById(any(UUID.class))).thenReturn(false); assertFalse(ecsTlrService.update(id, ecsTlr)); assertFalse(ecsTlrService.delete(id)); } From ddf0cf4ed029904aa7ea24a9d718b813fc3db20c Mon Sep 17 00:00:00 2001 From: Roman_Barannyk Date: Fri, 26 Jan 2024 23:15:41 +0200 Subject: [PATCH 07/11] MODTLR-9 update sample --- src/main/resources/swagger.api/examples/EcsTlr.sample | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/swagger.api/examples/EcsTlr.sample b/src/main/resources/swagger.api/examples/EcsTlr.sample index 1da9f5c2..1d26623c 100644 --- a/src/main/resources/swagger.api/examples/EcsTlr.sample +++ b/src/main/resources/swagger.api/examples/EcsTlr.sample @@ -5,6 +5,7 @@ "requestType": "Hold", "requestLevel": "Title", "requestExpirationDate": "2024-01-01T23:11:00-01:00", + "requestDate": "2024-01-01T00:12:00-01:00" "patronComments": "test comment", "fulfillmentPreference": "Hold Shelf", "pickupServicePointId": "71ff4b72-70a0-40f6-9f73-6db29ced80a3" From ffef07f73591ad73314fcc2b713a9d7f09ec4f9c Mon Sep 17 00:00:00 2001 From: Roman_Barannyk Date: Tue, 30 Jan 2024 13:33:56 +0200 Subject: [PATCH 08/11] MODTLR-9 update schema --- src/main/resources/swagger.api/ecs-tlr.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/resources/swagger.api/ecs-tlr.yaml b/src/main/resources/swagger.api/ecs-tlr.yaml index 9952d482..3d5bf10b 100644 --- a/src/main/resources/swagger.api/ecs-tlr.yaml +++ b/src/main/resources/swagger.api/ecs-tlr.yaml @@ -99,7 +99,6 @@ components: example: errors: - message: Request is invalid - code: invalid.request total_records: 1 schema: $ref: "#/components/schemas/errorResponse" @@ -110,7 +109,6 @@ components: example: errors: - message: Request not found - code: notfound.request total_records: 1 schema: $ref: "#/components/schemas/errorResponse" @@ -121,7 +119,6 @@ components: example: errors: - message: Unexpected error - code: unexpected.error total_records: 1 schema: $ref: "#/components/schemas/errorResponse" From 12c11257852d59b0c95e91460ea7d0d41855effa Mon Sep 17 00:00:00 2001 From: Roman_Barannyk Date: Tue, 30 Jan 2024 14:40:53 +0200 Subject: [PATCH 09/11] MODTLR-9 fix formatting --- .../java/org/folio/controller/EcsTlrController.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/folio/controller/EcsTlrController.java b/src/main/java/org/folio/controller/EcsTlrController.java index e2c93d10..f1fc043d 100644 --- a/src/main/java/org/folio/controller/EcsTlrController.java +++ b/src/main/java/org/folio/controller/EcsTlrController.java @@ -43,10 +43,7 @@ public ResponseEntity postEcsTlr(EcsTlr ecsTlr) { @Override public ResponseEntity putEcsTlrById(UUID requestId, EcsTlr ecsTlr) { log.debug("putEcsTlrById:: parameters requestId: {}, ecsTlr: {}", () -> requestId, () -> ecsTlr); - - HttpStatus httpStatus = ecsTlrService.update(requestId, ecsTlr) - ? NO_CONTENT - : NOT_FOUND; + HttpStatus httpStatus = ecsTlrService.update(requestId, ecsTlr) ? NO_CONTENT : NOT_FOUND; return ResponseEntity.status(httpStatus).build(); } @@ -54,10 +51,7 @@ public ResponseEntity putEcsTlrById(UUID requestId, EcsTlr ecsTlr) { @Override public ResponseEntity deleteEcsTlrById(UUID requestId) { log.debug("deleteEcsTlrById:: parameters requestId: {}", requestId); - - HttpStatus httpStatus = ecsTlrService.delete(requestId) - ? NO_CONTENT - : NOT_FOUND; + HttpStatus httpStatus = ecsTlrService.delete(requestId) ? NO_CONTENT : NOT_FOUND; return ResponseEntity.status(httpStatus).build(); } From 65a3b9b0a7b38c7b5efee8bcaeb42fc0e675af0f Mon Sep 17 00:00:00 2001 From: Roman_Barannyk Date: Tue, 30 Jan 2024 17:56:33 +0200 Subject: [PATCH 10/11] MODTLR-9 incorporating review comments --- src/main/java/org/folio/controller/EcsTlrController.java | 6 ++++-- src/main/resources/swagger.api/examples/EcsTlr.sample | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/folio/controller/EcsTlrController.java b/src/main/java/org/folio/controller/EcsTlrController.java index f1fc043d..552876f1 100644 --- a/src/main/java/org/folio/controller/EcsTlrController.java +++ b/src/main/java/org/folio/controller/EcsTlrController.java @@ -43,7 +43,8 @@ public ResponseEntity postEcsTlr(EcsTlr ecsTlr) { @Override public ResponseEntity putEcsTlrById(UUID requestId, EcsTlr ecsTlr) { log.debug("putEcsTlrById:: parameters requestId: {}, ecsTlr: {}", () -> requestId, () -> ecsTlr); - HttpStatus httpStatus = ecsTlrService.update(requestId, ecsTlr) ? NO_CONTENT : NOT_FOUND; + boolean requestUpdated = ecsTlrService.update(requestId, ecsTlr); + HttpStatus httpStatus = requestUpdated ? NO_CONTENT : NOT_FOUND; return ResponseEntity.status(httpStatus).build(); } @@ -51,7 +52,8 @@ public ResponseEntity putEcsTlrById(UUID requestId, EcsTlr ecsTlr) { @Override public ResponseEntity deleteEcsTlrById(UUID requestId) { log.debug("deleteEcsTlrById:: parameters requestId: {}", requestId); - HttpStatus httpStatus = ecsTlrService.delete(requestId) ? NO_CONTENT : NOT_FOUND; + boolean requestDeleted = ecsTlrService.delete(requestId); + HttpStatus httpStatus = requestDeleted ? NO_CONTENT : NOT_FOUND; return ResponseEntity.status(httpStatus).build(); } diff --git a/src/main/resources/swagger.api/examples/EcsTlr.sample b/src/main/resources/swagger.api/examples/EcsTlr.sample index 1d26623c..98709261 100644 --- a/src/main/resources/swagger.api/examples/EcsTlr.sample +++ b/src/main/resources/swagger.api/examples/EcsTlr.sample @@ -4,8 +4,8 @@ "requesterId": "4565999e-1994-4aab-9282-185731b4ce66", "requestType": "Hold", "requestLevel": "Title", - "requestExpirationDate": "2024-01-01T23:11:00-01:00", - "requestDate": "2024-01-01T00:12:00-01:00" + "requestExpirationDate": "2024-01-01T23:11:00-00:00", + "requestDate": "2024-01-01T00:12:00-00:00" "patronComments": "test comment", "fulfillmentPreference": "Hold Shelf", "pickupServicePointId": "71ff4b72-70a0-40f6-9f73-6db29ced80a3" From 05ab601435fc2caae1683a7bfb1de59c90710e27 Mon Sep 17 00:00:00 2001 From: Roman_Barannyk Date: Tue, 30 Jan 2024 18:43:39 +0200 Subject: [PATCH 11/11] MODTLR-9 incorporating review comments --- src/main/java/org/folio/controller/EcsTlrController.java | 6 +++--- src/main/resources/swagger.api/examples/EcsTlr.sample | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/folio/controller/EcsTlrController.java b/src/main/java/org/folio/controller/EcsTlrController.java index 552876f1..800910e0 100644 --- a/src/main/java/org/folio/controller/EcsTlrController.java +++ b/src/main/java/org/folio/controller/EcsTlrController.java @@ -35,7 +35,7 @@ public ResponseEntity getEcsTlrById(UUID requestId) { @Override public ResponseEntity postEcsTlr(EcsTlr ecsTlr) { - log.debug("postEcsTlr:: parameters ecsTlr: {}", ecsTlr); + log.debug("postEcsTlr:: parameters ecsTlr: {}", () -> ecsTlr); return ResponseEntity.status(CREATED).body(ecsTlrService.create(ecsTlr)); } @@ -44,7 +44,7 @@ public ResponseEntity postEcsTlr(EcsTlr ecsTlr) { public ResponseEntity putEcsTlrById(UUID requestId, EcsTlr ecsTlr) { log.debug("putEcsTlrById:: parameters requestId: {}, ecsTlr: {}", () -> requestId, () -> ecsTlr); boolean requestUpdated = ecsTlrService.update(requestId, ecsTlr); - HttpStatus httpStatus = requestUpdated ? NO_CONTENT : NOT_FOUND; + HttpStatus httpStatus = requestUpdated ? NO_CONTENT : NOT_FOUND; return ResponseEntity.status(httpStatus).build(); } @@ -53,7 +53,7 @@ public ResponseEntity putEcsTlrById(UUID requestId, EcsTlr ecsTlr) { public ResponseEntity deleteEcsTlrById(UUID requestId) { log.debug("deleteEcsTlrById:: parameters requestId: {}", requestId); boolean requestDeleted = ecsTlrService.delete(requestId); - HttpStatus httpStatus = requestDeleted ? NO_CONTENT : NOT_FOUND; + HttpStatus httpStatus = requestDeleted ? NO_CONTENT : NOT_FOUND; return ResponseEntity.status(httpStatus).build(); } diff --git a/src/main/resources/swagger.api/examples/EcsTlr.sample b/src/main/resources/swagger.api/examples/EcsTlr.sample index 98709261..61123530 100644 --- a/src/main/resources/swagger.api/examples/EcsTlr.sample +++ b/src/main/resources/swagger.api/examples/EcsTlr.sample @@ -4,8 +4,8 @@ "requesterId": "4565999e-1994-4aab-9282-185731b4ce66", "requestType": "Hold", "requestLevel": "Title", - "requestExpirationDate": "2024-01-01T23:11:00-00:00", - "requestDate": "2024-01-01T00:12:00-00:00" + "requestExpirationDate": "2024-01-01T23:11:00+00:00", + "requestDate": "2024-01-01T00:12:00+00:00" "patronComments": "test comment", "fulfillmentPreference": "Hold Shelf", "pickupServicePointId": "71ff4b72-70a0-40f6-9f73-6db29ced80a3"