Skip to content

Commit

Permalink
[MODORDERS-1143] Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Saba-Zedginidze-EPAM committed Sep 19, 2024
1 parent d16822e commit 15cbe2a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/main/java/org/folio/helper/PurchaseOrderLineHelper.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.folio.helper;

import static io.vertx.core.json.JsonObject.mapFrom;
import static org.apache.commons.collections4.CollectionUtils.isEqualCollection;
import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;
import static org.apache.commons.collections4.CollectionUtils.isEmpty;
import static org.folio.orders.utils.HelperUtils.calculateEstimatedPrice;
import static org.folio.orders.utils.HelperUtils.convertToCompositePoLine;
import static org.folio.orders.utils.HelperUtils.convertToPoLine;
import static org.folio.orders.utils.HelperUtils.getPoLineLimit;
import static org.folio.orders.utils.PoLineCommonUtil.verifyProtectedFieldsChanged;
import static org.folio.orders.utils.ProtectedOperationType.DELETE;
Expand Down Expand Up @@ -209,7 +210,7 @@ public Future<CompositePoLine> createPoLineWithOrder(CompositePoLine compPoLine,
updateEstimatedPrice(compPoLine);
PoLineCommonUtil.updateLocationsQuantity(compPoLine.getLocations());

var line = mapFrom(compPoLine).mapTo(PoLine.class);
var line = convertToPoLine(compPoLine);
List<Future<Void>> subObjFuts = new ArrayList<>();
subObjFuts.add(createAlerts(compPoLine, line, requestContext));
subObjFuts.add(createReportingCodes(compPoLine, line, requestContext));
Expand Down Expand Up @@ -446,11 +447,14 @@ public Future<Void> updatePoLines(CompositePurchaseOrder poFromStorage, Composit
if (poFromStorage.getWorkflowStatus() != PENDING && getNewPoLines(compPO, existingPoLines).findAny().isPresent()) {
throw new HttpException(422, poFromStorage.getWorkflowStatus() == OPEN ? ErrorCodes.ORDER_OPEN : ErrorCodes.ORDER_CLOSED);
}
validatePoLineProtectedFieldsChangedOrder(compPO, existingPoLines);
validatePoLineProtectedFieldsChangedOrder(poFromStorage, compPO, existingPoLines);
return handlePoLines(compPO, existingPoLines, requestContext);
}

private void validatePoLineProtectedFieldsChangedOrder(CompositePurchaseOrder compPO, List<PoLine> existingPoLines) {
private void validatePoLineProtectedFieldsChangedOrder(CompositePurchaseOrder poFromStorage, CompositePurchaseOrder compPO, List<PoLine> existingPoLines) {
if (poFromStorage.getWorkflowStatus() == PENDING) {
return;
}
compPO.getCompositePoLines().forEach(poLine -> {
var fields = POLineProtectedFieldsUtil.getFieldNames(poLine.getOrderFormat().value());
var correspondingLine = findCorrespondingCompositePoLine(poLine, existingPoLines);
Expand Down Expand Up @@ -637,8 +641,8 @@ private Future<CompositePoLine> getLineWithInstanceId(CompositePoLine line, Requ
});
}

private CompositePurchaseOrder addLineToCompOrder(CompositePurchaseOrder compOrder, PoLine poLine) {
var compPoLine = JsonObject.mapFrom(poLine.withAlerts(null).withReportingCodes(null)).mapTo(CompositePoLine.class);
private CompositePurchaseOrder addLineToCompOrder(CompositePurchaseOrder compOrder, PoLine lineFromStorage) {
var compPoLine = convertToCompositePoLine(lineFromStorage);
compOrder.getCompositePoLines().add(compPoLine);
return compOrder;
}
Expand Down Expand Up @@ -718,7 +722,7 @@ static boolean hasAlteredExchangeRate(Cost oldCost, Cost newCost) {
private Future<Void> validateAccessProviders(CompositePoLine compOrderLine, RequestContext requestContext) {
return organizationService.validateAccessProviders(Collections.singletonList(compOrderLine), requestContext)
.map(errors -> {
if (!isNotEmpty(errors.getErrors())) {
if (isNotEmpty(errors.getErrors())) {
throw new HttpException(422, errors.getErrors().get(0));
}
return null;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/folio/orders/utils/HelperUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,13 @@ private static boolean isCompletedPoLine(PoLine line) {
&& (receiptStatus == FULLY_RECEIVED || receiptStatus == RECEIPT_NOT_REQUIRED || receiptStatus == ReceiptStatus.CANCELLED);
}

public static CompositePoLine convertToCompositePoLine(PoLine poLine) {
JsonObject pol = JsonObject.mapFrom(poLine);
pol.remove(ALERTS);
pol.remove(REPORTING_CODES);
return pol.mapTo(CompositePoLine.class);
}

public static PoLine convertToPoLine(CompositePoLine compPoLine) {
JsonObject pol = JsonObject.mapFrom(compPoLine);
pol.remove(ALERTS);
Expand Down

0 comments on commit 15cbe2a

Please sign in to comment.