Skip to content

Commit

Permalink
MODTLR-10 Add requestDate to ECS TLR schema, fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksandrVidinieiev committed Jan 24, 2024
1 parent d8ec708 commit e20dc4e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/folio/domain/entity/EcsTlrEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class EcsTlrEntity {
private String requestType;
private String requestLevel;
private Date requestExpirationDate;
private Date requestDate;
private String patronComments;
private String fulfillmentPreference;
private UUID pickupServicePointId;
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/org/folio/service/impl/EcsTlrServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,20 @@ public Optional<EcsTlr> get(UUID id) {
@Override
public EcsTlr create(EcsTlr ecsTlr) {
log.debug("create:: parameters ecsTlr: {}", () -> ecsTlr);
Request mappedRequest = requestsMapper.mapDtoToRequest(ecsTlr);
Request cretedRequest = tenantScopedExecutionService.execute("dummy-tenant", // TODO: replace with real tenantId
() -> circulationClient.createTitleLevelRequest(mappedRequest));
log.info("create:: title-level request created: {}", cretedRequest.getId());
createRequest(ecsTlr, "dummy-tenant"); // TODO: replace with real tenantId

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

private Request createRequest(EcsTlr ecsTlr, String tenantId) {
log.info("createRequest:: creating request for ECS TLR {} and tenant {}", ecsTlr.getId(), tenantId);
Request mappedRequest = requestsMapper.mapDtoToRequest(ecsTlr);
Request createdRequest = tenantScopedExecutionService.execute(tenantId,
() -> circulationClient.createTitleLevelRequest(mappedRequest));
log.info("createRequest:: request created: {}", createdRequest.getId());
log.debug("createRequest:: request={}", () -> createdRequest);

return createdRequest;
}
}
1 change: 1 addition & 0 deletions src/main/resources/db/changelog/changes/initial_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<column name="requester_id" type="uuid"/>
<column name="request_type" type="varchar(255)"/>
<column name="request_level" type="varchar(255)"/>
<column name="request_date" type="timestamp with time zone"/>
<column name="request_expiration_date" type="timestamp with time zone"/>
<column name="patron_comments" type="varchar(255)"/>
<column name="fulfillment_preference" type="varchar(255)"/>
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/swagger.api/schemas/EcsTlr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ EcsTlr:
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
Expand Down
11 changes: 10 additions & 1 deletion src/test/java/org/folio/service/EcsTlrServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.UUID;

import org.folio.domain.dto.EcsTlr;
import org.folio.domain.dto.Request;
import org.folio.domain.entity.EcsTlrEntity;
import org.folio.domain.mapper.EcsTlrMapper;
import org.folio.domain.mapper.EcsTlrMapperImpl;
Expand All @@ -28,6 +29,8 @@ class EcsTlrServiceTest {
private EcsTlrServiceImpl ecsTlrService;
@Mock
private EcsTlrRepository ecsTlrRepository;
@Mock
private TenantScopedExecutionService tenantScopedExecutionService;
@Spy
private final EcsTlrMapper ecsTlrMapper = new EcsTlrMapperImpl();

Expand All @@ -46,7 +49,8 @@ void postEcsTlr() {
var requestType = EcsTlr.RequestTypeEnum.PAGE;
var requestLevel = EcsTlr.RequestLevelEnum.TITLE;
var fulfillmentPreference = EcsTlr.FulfillmentPreferenceEnum.HOLD_SHELF;
var requestExpirationDate = DateTime.now().toDate();
var requestExpirationDate = DateTime.now().plusDays(7).toDate();
var requestDate = DateTime.now().toDate();
var patronComments = "Test comment";

var mockEcsTlrEntity = new EcsTlrEntity();
Expand All @@ -56,6 +60,7 @@ void postEcsTlr() {
mockEcsTlrEntity.setRequestType(requestType.toString());
mockEcsTlrEntity.setRequestLevel(requestLevel.getValue());
mockEcsTlrEntity.setRequestExpirationDate(requestExpirationDate);
mockEcsTlrEntity.setRequestDate(requestDate);
mockEcsTlrEntity.setPatronComments(patronComments);
mockEcsTlrEntity.setFulfillmentPreference(fulfillmentPreference.getValue());
mockEcsTlrEntity.setPickupServicePointId(pickupServicePointId);
Expand All @@ -67,18 +72,22 @@ void postEcsTlr() {
ecsTlr.setRequestType(requestType);
ecsTlr.setRequestLevel(requestLevel);
ecsTlr.setRequestExpirationDate(requestExpirationDate);
ecsTlr.setRequestDate(requestDate);
ecsTlr.setPatronComments(patronComments);
ecsTlr.setFulfillmentPreference(fulfillmentPreference);
ecsTlr.setPickupServicePointId(pickupServicePointId.toString());

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.create(ecsTlr);

assertEquals(id.toString(), postEcsTlr.getId());
assertEquals(instanceId.toString(), postEcsTlr.getInstanceId());
assertEquals(requesterId.toString(), postEcsTlr.getRequesterId());
assertEquals(requestType, postEcsTlr.getRequestType());
assertEquals(requestExpirationDate, postEcsTlr.getRequestExpirationDate());
assertEquals(requestDate, postEcsTlr.getRequestDate());
assertEquals(patronComments, postEcsTlr.getPatronComments());
assertEquals(fulfillmentPreference, postEcsTlr.getFulfillmentPreference());
assertEquals(pickupServicePointId.toString(), postEcsTlr.getPickupServicePointId());
Expand Down

0 comments on commit e20dc4e

Please sign in to comment.