Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/folio-org/mod-tlr into MO…
Browse files Browse the repository at this point in the history
…DTLR-13

# Conflicts:
#	src/main/java/org/folio/service/EcsTlrService.java
#	src/main/java/org/folio/service/impl/EcsTlrServiceImpl.java
  • Loading branch information
MagzhanArtykov committed Jan 31, 2024
2 parents 8c672a7 + 2f90e5d commit bc93969
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Project [MODTLR](https://issues.folio.org/browse/MODTLR).
22 changes: 22 additions & 0 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@
"modulePermissions": [
"circulation.requests.item.post"
]
},
{
"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": []
}
]
},
Expand Down Expand Up @@ -60,6 +72,16 @@
"permissionName": "tlr.ecs-tlr.post",
"displayName": "ecs-tlr - create ECS TLR",
"description": "Create ECS TLR"
},
{
"permissionName": "tlr.ecs-tlr.put",
"displayName": "ecs-tlr - update ECS TLR",
"description": "Update ECS TLR"
},
{
"permissionName": "tlr.ecs-tlr.delete",
"displayName": "ecs-tlr - remove ECS TLR",
"description": "Remove ECS TLR"
}
],
"requires": [],
Expand Down
27 changes: 24 additions & 3 deletions src/main/java/org/folio/controller/EcsTlrController.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
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;

import java.util.UUID;

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;

Expand All @@ -23,7 +26,7 @@ public class EcsTlrController implements TlrApi {

@Override
public ResponseEntity<EcsTlr> getEcsTlrById(UUID requestId) {
log.debug("getEcsTlrById:: parameters id: {}", requestId);
log.debug("getEcsTlrById:: parameters requestId: {}", requestId);

return ecsTlrService.get(requestId)
.map(ResponseEntity.status(OK)::body)
Expand All @@ -32,8 +35,26 @@ public ResponseEntity<EcsTlr> getEcsTlrById(UUID requestId) {

@Override
public ResponseEntity<EcsTlr> postEcsTlr(EcsTlr ecsTlr) {
log.debug("postEcsTlr:: parameters 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<Void> 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;

return ResponseEntity.status(httpStatus).build();
}

@Override
public ResponseEntity<Void> deleteEcsTlrById(UUID requestId) {
log.debug("deleteEcsTlrById:: parameters requestId: {}", requestId);
boolean requestDeleted = ecsTlrService.delete(requestId);
HttpStatus httpStatus = requestDeleted ? NO_CONTENT : NOT_FOUND;

return ResponseEntity.status(httpStatus).build();
}
}
4 changes: 3 additions & 1 deletion src/main/java/org/folio/service/EcsTlrService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

public interface EcsTlrService {
Optional<EcsTlr> get(UUID requestId);
EcsTlr post(EcsTlr ecsTlr);
EcsTlr create(EcsTlr ecsTlr);
boolean update(UUID requestId, EcsTlr ecsTlr);
boolean delete(UUID requestId);
void updateRequestItem(UUID tlrRequestId, UUID itemId);
}
26 changes: 24 additions & 2 deletions src/main/java/org/folio/service/impl/EcsTlrServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,36 @@ public Optional<EcsTlr> 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);
createRemoteRequest(ecsTlr, "university"); // TODO: replace with real tenantId

return requestsMapper.mapEntityToDto(ecsTlrRepository.save(
requestsMapper.mapDtoToEntity(ecsTlr)));
}

@Override
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) {
log.debug("delete:: parameters requestId: {}", () -> requestId);

if (ecsTlrRepository.existsById(requestId)) {
ecsTlrRepository.deleteById(requestId);
return true;
}
return false;
}

@Override
public void updateRequestItem(UUID tlrRequestId, UUID itemId) {
log.debug("updateRequestItem:: parameters tlrRequestId: {}, itemId: {}", tlrRequestId, itemId);
Expand Down
53 changes: 45 additions & 8 deletions src/main/resources/swagger.api/ecs-tlr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,41 @@ 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
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/ecs-tlr"
required: true
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:
Expand Down Expand Up @@ -70,7 +99,16 @@ components:
example:
errors:
- message: Request is invalid
code: invalid.request
total_records: 1
schema:
$ref: "#/components/schemas/errorResponse"
notFoundResponse:
description: Not found
content:
application/json:
example:
errors:
- message: Request not found
total_records: 1
schema:
$ref: "#/components/schemas/errorResponse"
Expand All @@ -81,7 +119,6 @@ components:
example:
errors:
- message: Unexpected error
code: unexpected.error
total_records: 1
schema:
$ref: "#/components/schemas/errorResponse"
12 changes: 12 additions & 0 deletions src/main/resources/swagger.api/examples/EcsTlr.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"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+00:00",
"requestDate": "2024-01-01T00:12:00+00:00"
"patronComments": "test comment",
"fulfillmentPreference": "Hold Shelf",
"pickupServicePointId": "71ff4b72-70a0-40f6-9f73-6db29ced80a3"
}
2 changes: 1 addition & 1 deletion src/main/resources/swagger.api/schemas/EcsTlr.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
37 changes: 36 additions & 1 deletion src/test/java/org/folio/controller/EcsTlrControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +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.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;
Expand Down Expand Up @@ -43,11 +46,43 @@ 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());

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.update(any(UUID.class), any(EcsTlr.class))).thenReturn(true);

var response = requestsController.putEcsTlrById(id, mockRequest);
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();
var mockRequest = new EcsTlr();
mockRequest.setId(UUID.randomUUID().toString());

when(requestsService.update(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());
}
}
15 changes: 13 additions & 2 deletions src/test/java/org/folio/service/EcsTlrServiceTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -41,7 +44,7 @@ void getById() {
}

@Test
void postEcsTlr() {
void ecsTlrShouldBeCreatedThenUpdatedAndDeleted() {
var id = UUID.randomUUID();
var instanceId = UUID.randomUUID();
var requesterId = UUID.randomUUID();
Expand Down Expand Up @@ -80,7 +83,7 @@ void postEcsTlr() {
when(ecsTlrRepository.save(any(EcsTlrEntity.class))).thenReturn(mockEcsTlrEntity);
when(tenantScopedExecutionService.execute(any(String.class), any()))
.thenReturn(new Request().id(UUID.randomUUID().toString()));
var postEcsTlr = ecsTlrService.post(ecsTlr);
var postEcsTlr = ecsTlrService.create(ecsTlr);

assertEquals(id.toString(), postEcsTlr.getId());
assertEquals(instanceId.toString(), postEcsTlr.getInstanceId());
Expand All @@ -91,5 +94,13 @@ void postEcsTlr() {
assertEquals(patronComments, postEcsTlr.getPatronComments());
assertEquals(fulfillmentPreference, postEcsTlr.getFulfillmentPreference());
assertEquals(pickupServicePointId.toString(), postEcsTlr.getPickupServicePointId());

when(ecsTlrRepository.existsById(any(UUID.class))).thenReturn(true);
assertTrue(ecsTlrService.update(id, ecsTlr));
assertTrue(ecsTlrService.delete(id));

when(ecsTlrRepository.existsById(any(UUID.class))).thenReturn(false);
assertFalse(ecsTlrService.update(id, ecsTlr));
assertFalse(ecsTlrService.delete(id));
}
}

0 comments on commit bc93969

Please sign in to comment.