Skip to content

Commit

Permalink
MODTLR-98 Extend integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksandrVidinieiev committed Dec 9, 2024
1 parent e8b1913 commit 795db04
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 69 deletions.
28 changes: 11 additions & 17 deletions src/main/java/org/folio/service/impl/DcbServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,7 @@ public void createLendingTransaction(EcsTlrEntity ecsTlr) {
@Override
public void createBorrowerTransaction(EcsTlrEntity ecsTlr, Request request) {
log.info("createBorrowerTransaction:: creating borrower transaction for ECS TLR {}", ecsTlr::getId);
DcbItem dcbItem = new DcbItem()
.id(request.getItemId())
.title(request.getInstance().getTitle())
.barcode(request.getItem().getBarcode());
DcbTransaction transaction = new DcbTransaction()
.requestId(ecsTlr.getIntermediateRequestId().toString())
.item(dcbItem)
.role(BORROWER);
DcbTransaction transaction = buildTransaction(request, BORROWER, ecsTlr.getIntermediateRequestId());
final UUID transactionId = createTransaction(transaction, ecsTlr.getIntermediateRequestTenantId());
ecsTlr.setIntermediateRequestDcbTransactionId(transactionId);
log.info("createBorrowerTransaction:: borrower transaction {} for ECS TLR {} created",
Expand All @@ -73,32 +66,33 @@ public void createBorrowerTransaction(EcsTlrEntity ecsTlr, Request request) {
public void createBorrowingPickupTransaction(EcsTlrEntity ecsTlr, Request request) {
log.info("createBorrowingPickupTransaction:: creating borrowing-pickup transaction for ECS TLR {}",
ecsTlr::getId);
final UUID transactionId = createPickupTransaction(ecsTlr, request, BORROWING_PICKUP);
DcbTransaction transaction = buildTransaction(request, BORROWING_PICKUP, ecsTlr.getPrimaryRequestId());
final UUID transactionId = createTransaction(transaction, ecsTlr.getPrimaryRequestTenantId());
ecsTlr.setPrimaryRequestDcbTransactionId(transactionId);
log.info("createBorrowingPickupTransaction:: borrowing-pickup transaction {} for ECS TLR {} created",
() -> transactionId, ecsTlr::getId);
}

@Override
public void createPickupTransaction(EcsTlrEntity ecsTlr, Request request) {
log.info("createPickupTransaction:: creating pickup transaction for ECS TLR {}", ecsTlr.getId());
final UUID transactionId = createPickupTransaction(ecsTlr, request, PICKUP);
DcbTransaction transaction = buildTransaction(request, PICKUP, ecsTlr.getPrimaryRequestId());
final UUID transactionId = createTransaction(transaction, ecsTlr.getPrimaryRequestTenantId());
ecsTlr.setPrimaryRequestDcbTransactionId(transactionId);
log.info("createPickupTransaction:: pickup transaction {} for ECS TLR {} created",
() -> transactionId, ecsTlr::getId);
}

private UUID createPickupTransaction(EcsTlrEntity ecsTlr, Request request, RoleEnum role) {
private DcbTransaction buildTransaction(Request request, RoleEnum role, UUID requestId) {
DcbItem dcbItem = new DcbItem()
.id(request.getItemId())
.title(request.getInstance().getTitle())
.barcode(request.getItem().getBarcode());
DcbTransaction transaction = new DcbTransaction()
.requestId(ecsTlr.getPrimaryRequestId().toString())

return new DcbTransaction()
.requestId(requestId.toString())
.item(dcbItem)
.role(role);
final UUID transactionId = createTransaction(transaction, ecsTlr.getPrimaryRequestTenantId());
ecsTlr.setPrimaryRequestDcbTransactionId(transactionId);

return transactionId;
}

private UUID createTransaction(DcbTransaction transaction, String tenantId) {
Expand Down
24 changes: 10 additions & 14 deletions src/main/java/org/folio/service/impl/EcsTlrServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.folio.service.impl;

import static java.util.Optional.of;
import static org.folio.domain.dto.Request.EcsRequestPhaseEnum.INTERMEDIATE;
import static org.folio.domain.dto.Request.EcsRequestPhaseEnum.PRIMARY;

import java.util.Collection;
import java.util.List;
Expand All @@ -11,6 +13,7 @@
import org.folio.domain.RequestWrapper;
import org.folio.domain.dto.EcsTlr;
import org.folio.domain.dto.Request;
import org.folio.domain.dto.Request.EcsRequestPhaseEnum;
import org.folio.domain.entity.EcsTlrEntity;
import org.folio.domain.mapper.EcsTlrMapper;
import org.folio.exception.TenantPickingException;
Expand Down Expand Up @@ -141,21 +144,14 @@ private EcsTlrEntity save(EcsTlrEntity ecsTlr) {
}

private static Request buildPrimaryRequest(Request secondaryRequest) {
return new Request()
.id(secondaryRequest.getId())
.instanceId(secondaryRequest.getInstanceId())
.itemId(secondaryRequest.getItemId())
.holdingsRecordId(secondaryRequest.getHoldingsRecordId())
.requesterId(secondaryRequest.getRequesterId())
.requestDate(secondaryRequest.getRequestDate())
.requestLevel(secondaryRequest.getRequestLevel())
.requestType(secondaryRequest.getRequestType())
.ecsRequestPhase(Request.EcsRequestPhaseEnum.PRIMARY)
.fulfillmentPreference(secondaryRequest.getFulfillmentPreference())
.pickupServicePointId(secondaryRequest.getPickupServicePointId());
return buildRequest(secondaryRequest, PRIMARY);
}

private static Request buildIntermediateRequest(Request secondaryRequest) {
return buildRequest(secondaryRequest, INTERMEDIATE);
}

private static Request buildRequest(Request secondaryRequest, EcsRequestPhaseEnum ecsRequestPhase) {
return new Request()
.id(secondaryRequest.getId())
.instanceId(secondaryRequest.getInstanceId())
Expand All @@ -165,14 +161,14 @@ private static Request buildIntermediateRequest(Request secondaryRequest) {
.requestDate(secondaryRequest.getRequestDate())
.requestLevel(secondaryRequest.getRequestLevel())
.requestType(secondaryRequest.getRequestType())
.ecsRequestPhase(Request.EcsRequestPhaseEnum.INTERMEDIATE)
.ecsRequestPhase(ecsRequestPhase)
.fulfillmentPreference(secondaryRequest.getFulfillmentPreference())
.pickupServicePointId(secondaryRequest.getPickupServicePointId());
}

private Request buildSecondaryRequest(EcsTlrEntity ecsTlr) {
return requestsMapper.mapEntityToRequest(ecsTlr)
.ecsRequestPhase(Request.EcsRequestPhaseEnum.SECONDARY);
.ecsRequestPhase(EcsRequestPhaseEnum.SECONDARY);
}

private static void updateEcsTlr(EcsTlrEntity ecsTlr, RequestWrapper primaryRequest,
Expand Down
Loading

0 comments on commit 795db04

Please sign in to comment.