Skip to content

Commit

Permalink
[MODORDERS-1169]. Update tests, fix POL location bug, change API logg…
Browse files Browse the repository at this point in the history
…er level
  • Loading branch information
BKadirkhodjaev committed Aug 22, 2024
1 parent ef83a4d commit 32d3479
Show file tree
Hide file tree
Showing 32 changed files with 370 additions and 266 deletions.
3 changes: 1 addition & 2 deletions src/main/java/org/folio/helper/CheckinHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ private Future<Map<String, List<Piece>>> createItemsWithPieceUpdate(CheckinColle
.map(PoLineCommonUtil::convertToCompositePoLine)
.compose(compPol -> purchaseOrderStorageService.getPurchaseOrderByIdAsJson(compPol.getPurchaseOrderId(), requestContext)
.map(HelperUtils::convertToCompositePurchaseOrder)
.compose(purchaseOrder -> pieceCreateFlowInventoryManager.processInventory(purchaseOrder, compPol, piece,
checkInPiece.getCreateItem(), requestContext))
.compose(purchaseOrder -> pieceCreateFlowInventoryManager.processInventory(purchaseOrder, compPol, piece, checkInPiece.getCreateItem(), requestContext))
.map(voidResult -> new PiecesHolder.PiecePoLineDto(poLineId, piece))));
} else if (checkInPiece.getId().equals(piece.getId()) && InventoryUtils.allowItemRecreate(srcTenantId, dstTenantId) && Objects.nonNull(piece.getItemId())) {
pieceFutures.add(purchaseOrderLineService.getOrderLineById(poLineId, requestContext)
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/org/folio/helper/CheckinReceivePiecesHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.vertx.core.Context;
import io.vertx.core.Future;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import one.util.streamex.EntryStream;
import one.util.streamex.StreamEx;
Expand Down Expand Up @@ -362,24 +361,25 @@ private PoLine updateRelatedPoLineDetails(PoLine poLine,
return poLine;
}


short updatedLocations = 0;
var compositePoLine = PoLineCommonUtil.convertToCompositePoLine(poLine);
for (Piece pieceToUpdate : successfullyProcessed) {
Optional<Piece> relatedStoragePiece = piecesFromStorage.stream()
.filter(piece -> piece.getId().equals(pieceToUpdate.getId()))
.findFirst();
if (relatedStoragePiece.isEmpty()) {
continue;
}
CompositePoLine compositePoLine = PoLineCommonUtil.convertToCompositePoLine(poLine);
PieceUpdateHolder holder = new PieceUpdateHolder();
holder.withPieceFromStorage(relatedStoragePiece.get());
holder.withPieceToUpdate(pieceToUpdate);
holder.withPoLineOnly(compositePoLine);
pieceUpdateFlowPoLineService.updatePoLineWithoutSave(holder);

return HelperUtils.convertToPoLine(compositePoLine);
updatedLocations++;
}

return poLine;
return updatedLocations > 0 ? HelperUtils.convertToPoLine(compositePoLine) : poLine;
}

/**
Expand Down Expand Up @@ -623,14 +623,18 @@ private Future<Boolean> createHoldingsForChangedLocations(Piece piece, String in
return Future.succeededFuture(true);
}

// Get the initial tenant on the piece from storage
String srcTenantId = piece.getReceivingTenantId();
// Get the new tenant from the CheckInPiece object coming from the UI
String dstTenantId = getReceivingTenantId(piece);
Location location = new Location().withLocationId(getLocationId(piece)).withHoldingId(getHoldingId(piece));
RequestContext locationContext = RequestContextUtil.createContextWithNewTenantId(requestContext, dstTenantId);
logger.info("createHoldingsForChangedLocations:: Creating shadow instance and holding if needed, srcTenantId: {}, dstTenantId: {}, locationId: {}, holdingId: {}",
srcTenantId, dstTenantId, location.getLocationId(), location.getHoldingId());
return inventoryInstanceManager.createShadowInstanceIfNeeded(instanceId, locationContext)
.compose(instance -> {
// Does not create a holding for every piece so will be
// called conditionally only for cases without an affiliation change
if (Objects.isNull(srcTenantId) || (srcTenantId.equals(dstTenantId))) {
return inventoryHoldingManager.getOrCreateHoldingsRecord(instanceId, location, locationContext);
}
Expand Down Expand Up @@ -789,8 +793,8 @@ private String buildProcessedHoldingKey(Piece piece, String instanceId) {
String locationId = getLocationId(piece);
String holdingId = getHoldingId(piece);
String receivingTenantId = getReceivingTenantId(piece);
// In case of affiliation change current holding is irrelevant because we will create a new holding in the
// destination tenant, so we need to block the creation of instances per affiliation-changed piece here
// In case of affiliation change current holding is irrelevant because we will create a new holding in the
// another tenant, so we need to block the creation of instances per affiliation-changed piece here
if (Objects.nonNull(receivingTenantId)) {
return receivingTenantId + instanceId;
} else {
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/folio/rest/impl/AcquisitionsUnitsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void postAcquisitionsUnitsUnits(AcquisitionsUnit entity, Map<String, Stri
acquisitionsUnitsService.createAcquisitionsUnit(entity, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(unit -> {
if (logger.isInfoEnabled()) {
logger.info("Successfully created new acquisitions unit: {} ", JsonObject.mapFrom(unit).encodePrettily());
logger.debug("Successfully created new acquisitions unit: {} ", JsonObject.mapFrom(unit).encodePrettily());
}
asyncResultHandler.handle(succeededFuture(buildResponseWithLocation(
okapiHeaders.get(OKAPI_URL), resourceByIdPath(ACQUISITIONS_UNITS, unit.getId()), unit)));
Expand All @@ -64,7 +64,7 @@ public void getAcquisitionsUnitsUnits(String query, String totalRecords, int off
acquisitionsUnitsService.getAcquisitionsUnits(query, offset, limit, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(units -> {
if (logger.isInfoEnabled()) {
logger.info("Successfully retrieved acquisitions units: {}", JsonObject.mapFrom(units).encodePrettily());
logger.debug("Successfully retrieved acquisitions units: {}", JsonObject.mapFrom(units).encodePrettily());
}
asyncResultHandler.handle(succeededFuture(buildOkResponse(units)));
})
Expand All @@ -82,7 +82,7 @@ public void putAcquisitionsUnitsUnitsById(String id, AcquisitionsUnit entity, Ma
} else {
acquisitionsUnitsService.updateAcquisitionsUnit(entity.withId(id), new RequestContext(vertxContext, okapiHeaders))
.onSuccess(units -> {
logger.info("Successfully updated acquisitions unit with id={}", id);
logger.debug("Successfully updated acquisitions unit with id={}", id);
asyncResultHandler.handle(succeededFuture(buildNoContentResponse()));
})
.onFailure(t -> handleErrorResponse(asyncResultHandler, t));
Expand All @@ -97,7 +97,7 @@ public void getAcquisitionsUnitsUnitsById(String id, Map<String, String> okapiHe
acquisitionsUnitsService.getAcquisitionsUnit(id, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(unit -> {
if (logger.isInfoEnabled()) {
logger.info("Successfully retrieved acquisitions unit: {}", JsonObject.mapFrom(unit).encodePrettily());
logger.debug("Successfully retrieved acquisitions unit: {}", JsonObject.mapFrom(unit).encodePrettily());
}
asyncResultHandler.handle(succeededFuture(buildOkResponse(unit)));
})
Expand All @@ -112,7 +112,7 @@ public void deleteAcquisitionsUnitsUnitsById(String id, Map<String, String> okap
acquisitionsUnitsService.deleteAcquisitionsUnit(id, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(ok -> {
if (logger.isInfoEnabled()) {
logger.info("Successfully deleted acquisitions unit with id={}", id);
logger.debug("Successfully deleted acquisitions unit with id={}", id);
}
asyncResultHandler.handle(succeededFuture(buildNoContentResponse()));
})
Expand All @@ -127,7 +127,7 @@ public void postAcquisitionsUnitsMemberships(AcquisitionsUnitMembership entity,
acquisitionsUnitsService.createAcquisitionsUnitsMembership(entity, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(membership -> {
if (logger.isInfoEnabled()) {
logger.info("Successfully created new acquisitions units membership: {}", JsonObject.mapFrom(membership).encodePrettily());
logger.debug("Successfully created new acquisitions units membership: {}", JsonObject.mapFrom(membership).encodePrettily());
}
asyncResultHandler.handle(
succeededFuture(buildResponseWithLocation(okapiHeaders.get(OKAPI_URL), resourceByIdPath(ACQUISITIONS_MEMBERSHIPS, membership.getId()), membership)));
Expand All @@ -142,7 +142,7 @@ public void getAcquisitionsUnitsMemberships(String query, String totalRecords, i
acquisitionsUnitsService.getAcquisitionsUnitsMemberships(query, offset, limit, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(memberships -> {
if (logger.isInfoEnabled()) {
logger.info("Successfully retrieved acquisitions units memberships: {}", JsonObject.mapFrom(memberships).encodePrettily());
logger.debug("Successfully retrieved acquisitions units memberships: {}", JsonObject.mapFrom(memberships).encodePrettily());
}
asyncResultHandler.handle(succeededFuture(buildOkResponse(memberships)));
})
Expand All @@ -158,7 +158,7 @@ public void putAcquisitionsUnitsMembershipsById(String id, AcquisitionsUnitMembe
} else {
acquisitionsUnitsService.updateAcquisitionsUnitsMembership(entity.withId(id), new RequestContext(vertxContext, okapiHeaders))
.onSuccess(membership -> {
logger.info("Successfully updated acquisitions units membership with id={}", id);
logger.debug("Successfully updated acquisitions units membership with id={}", id);
asyncResultHandler.handle(succeededFuture(buildNoContentResponse()));
})
.onFailure(t -> handleErrorResponse(asyncResultHandler, t));
Expand All @@ -171,7 +171,7 @@ public void getAcquisitionsUnitsMembershipsById(String id, Map<String, String> o
acquisitionsUnitsService.getAcquisitionsUnitsMembership(id, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(membership -> {
if (logger.isInfoEnabled()) {
logger.info("Successfully retrieved acquisitions units membership: {}", JsonObject.mapFrom(membership).encodePrettily());
logger.debug("Successfully retrieved acquisitions units membership: {}", JsonObject.mapFrom(membership).encodePrettily());
}
asyncResultHandler.handle(succeededFuture(buildOkResponse(membership)));
})
Expand All @@ -185,7 +185,7 @@ public void deleteAcquisitionsUnitsMembershipsById(String id, Map<String, String
acquisitionsUnitsService.deleteAcquisitionsUnitsMembership(id, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(ok -> {
if (logger.isInfoEnabled()) {
logger.info("Successfully deleted acquisitions units membership with id={}", id);
logger.debug("Successfully deleted acquisitions units membership with id={}", id);
}
asyncResultHandler.handle(succeededFuture(buildNoContentResponse()));
})
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/folio/rest/impl/CompositePoLineAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ public void postOrdersOrderLines(CompositePoLine poLine, Map<String, String> oka
@Validate
public void getOrdersOrderLinesById(String lineId, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
logger.info("Started Invocation of POLine Request with id = {}", lineId);
logger.debug("Started Invocation of POLine Request with id = {}", lineId);
helper.getCompositePoLine(lineId, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(poLine -> {
if (logger.isInfoEnabled()) {
logger.info("Received PO Line Response: {}", JsonObject.mapFrom(poLine)
logger.debug("Received PO Line Response: {}", JsonObject.mapFrom(poLine)
.encodePrettily());
}
asyncResultHandler.handle(succeededFuture(buildOkResponse(poLine)));
Expand All @@ -110,7 +110,7 @@ public void deleteOrdersOrderLinesById(String lineId, Map<String, String> okapiH
@Validate
public void putOrdersOrderLinesById(String lineId, CompositePoLine poLine, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
logger.info("Handling PUT Order Line operation...");
logger.debug("Handling PUT Order Line operation...");
// Set id if this is available only in path
RequestContext requestContext = new RequestContext(vertxContext, okapiHeaders);
if (StringUtils.isEmpty(poLine.getId())) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/folio/rest/impl/HoldingsSummaryAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void getOrdersHoldingSummaryById(String holdingId, Map<String, String> ok
holdingsSummaryService.getHoldingsSummary(holdingId, requestContext)
.onSuccess(holdingSummary -> {
if (logger.isInfoEnabled()) {
logger.info("Successfully retrieved : {}", JsonObject.mapFrom(holdingSummary).encodePrettily());
logger.debug("Successfully retrieved : {}", JsonObject.mapFrom(holdingSummary).encodePrettily());
}
asyncResultHandler.handle(succeededFuture(this.buildOkResponse(holdingSummary)));
})
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/folio/rest/impl/OrderTemplatesAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void postOrdersOrderTemplates(OrderTemplate entity, Map<String, String> o
orderTemplatesHelper.createOrderTemplate(entity)
.onSuccess(template -> {
if (logger.isInfoEnabled()) {
logger.info("Successfully created new order template: {}", JsonObject.mapFrom(template)
logger.debug("Successfully created new order template: {}", JsonObject.mapFrom(template)
.encodePrettily());
}
asyncResultHandler.handle(succeededFuture(
Expand All @@ -54,7 +54,7 @@ public void getOrdersOrderTemplates(String query, String totalRecords, int offse
helper.getOrderTemplates(query, offset, limit)
.onSuccess(templates -> {
if (logger.isInfoEnabled()) {
logger.info("Successfully retrieved order templates collection: {}", JsonObject.mapFrom(templates).encodePrettily());
logger.debug("Successfully retrieved order templates collection: {}", JsonObject.mapFrom(templates).encodePrettily());
}
asyncResultHandler.handle(succeededFuture(helper.buildOkResponse(templates)));
})
Expand All @@ -78,7 +78,7 @@ public void putOrdersOrderTemplatesById(String id, OrderTemplate entity, Map<Str
} else {
helper.updateOrderTemplate(entity.withId(id))
.onSuccess(template -> {
logger.info("Successfully updated order template with id={}", id);
logger.debug("Successfully updated order template with id={}", id);
asyncResultHandler.handle(succeededFuture(helper.buildNoContentResponse()));
})
.onFailure(t -> handlePostPutErrorResponse(asyncResultHandler, t, helper));
Expand All @@ -102,7 +102,7 @@ public void getOrdersOrderTemplatesById(String id, Map<String, String> okapiHead
helper.getOrderTemplateById(id)
.onSuccess(template -> {
if (logger.isInfoEnabled()) {
logger.info("Successfully retrieved order template: {}", JsonObject.mapFrom(template)
logger.debug("Successfully retrieved order template: {}", JsonObject.mapFrom(template)
.encodePrettily());
}
asyncResultHandler.handle(succeededFuture(helper.buildOkResponse(template)));
Expand All @@ -118,7 +118,7 @@ public void deleteOrdersOrderTemplatesById(String id, Map<String, String> okapiH
helper.deleteOrderTemplate(id)
.onSuccess(ok -> {
if (logger.isInfoEnabled()) {
logger.info("Successfully deleted order template with id={}", id);
logger.debug("Successfully deleted order template with id={}", id);
}
asyncResultHandler.handle(succeededFuture(helper.buildNoContentResponse()));
})
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/folio/rest/impl/OrdersApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void getOrdersCompositeOrders(String totalRecords, int offset, int limit,
.getPurchaseOrders(limit, offset, query, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(orders -> {
if (logger.isInfoEnabled()) {
logger.info("Successfully retrieved orders: {}", JsonObject.mapFrom(orders).encodePrettily());
logger.debug("Successfully retrieved orders: {}", JsonObject.mapFrom(orders).encodePrettily());
}
asyncResultHandler.handle(succeededFuture(buildOkResponse(orders)));
})
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/folio/rest/impl/PiecesAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void postOrdersPieces(boolean createItem, Piece entity, Map<String, Strin
pieceCreateFlowManager.createPiece(entity, createItem, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(piece -> {
if (logger.isInfoEnabled()) {
logger.info("Successfully created piece: {}", JsonObject.mapFrom(piece)
logger.debug("Successfully created piece: {}", JsonObject.mapFrom(piece)
.encodePrettily());
}
asyncResultHandler.handle(succeededFuture(buildCreatedResponse(piece)));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/folio/rest/impl/PoNumberAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public PoNumberAPI() {
@Validate
public void getOrdersPoNumber(Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler,
Context vertxContext) {
logger.info("Receiving generated poNumber ...");
logger.debug("Receiving generated poNumber ...");

poNumberHelper.getPoNumber(new RequestContext(vertxContext, okapiHeaders))
.onSuccess(result -> asyncResultHandler.handle(succeededFuture(buildOkResponse(result))))
Expand Down
Loading

0 comments on commit 32d3479

Please sign in to comment.