From b85aa14fa4f0865923c30e27e643e38d9a38ca70 Mon Sep 17 00:00:00 2001 From: Abdulkhakimov <89521577+Abdulkhakimov@users.noreply.github.com> Date: Mon, 29 Jan 2024 20:43:22 +0500 Subject: [PATCH] [MODORDERS-986] - Error thrown during change instance connection (#829) * [MODORDERS-986] - Fixed NPE --- .../OrderLinePatchOperationService.java | 4 + src/test/java/org/folio/TestConstants.java | 1 + .../rest/impl/PurchaseOrderLinesApiTest.java | 15 +++ .../13c4c3c2-90d9-4090-8694-edae7e79e7ac.json | 94 +++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 src/test/resources/mockdata/lines/13c4c3c2-90d9-4090-8694-edae7e79e7ac.json diff --git a/src/main/java/org/folio/service/orders/lines/update/OrderLinePatchOperationService.java b/src/main/java/org/folio/service/orders/lines/update/OrderLinePatchOperationService.java index c00ac9655..18660cfdc 100644 --- a/src/main/java/org/folio/service/orders/lines/update/OrderLinePatchOperationService.java +++ b/src/main/java/org/folio/service/orders/lines/update/OrderLinePatchOperationService.java @@ -37,6 +37,7 @@ import org.folio.rest.core.models.RequestContext; import org.folio.rest.core.models.RequestEntry; import org.folio.rest.jaxrs.model.Contributor; +import org.folio.rest.jaxrs.model.Details; import org.folio.rest.jaxrs.model.PatchOrderLineRequest; import org.folio.rest.jaxrs.model.PoLine; import org.folio.rest.jaxrs.model.ProductId; @@ -167,6 +168,9 @@ private Future updatePoLineWithInstanceRecordInfo(JsonObject lookupObj, return null; }) .onSuccess(v -> { + if (Objects.isNull(poLine.getDetails())) { + poLine.setDetails(new Details()); + } poLine.getDetails().setProductIds(removeISBNDuplicates(productIds, isbnTypeId)); promise.complete(poLine); }) diff --git a/src/test/java/org/folio/TestConstants.java b/src/test/java/org/folio/TestConstants.java index 25b64d563..809f13c6e 100644 --- a/src/test/java/org/folio/TestConstants.java +++ b/src/test/java/org/folio/TestConstants.java @@ -39,6 +39,7 @@ private TestConstants() {} public static final String PO_ID_OPEN_TO_BE_CLOSED = "9d56b621-202d-414b-9e7f-5fefe4422ab3"; public static final String PO_ID_OPEN_TO_CANCEL = "f56c70bc-8a31-4f56-b606-c6d8e597b7c1"; public static final String PO_LINE_ID_FOR_SUCCESS_CASE = "fca5fa9e-15cb-4a3d-ab09-eeea99b97a47"; + public static final String PO_LINE_ID_WITHOUT_DETAILS = "13c4c3c2-90d9-4090-8694-edae7e79e7ac"; public static final String PO_LINE_ID_WRONG_EXPENSE_CLASS = "bd8f1901-c768-4bb1-b650-8c12c5f42fd8"; public static final String MIN_PO_ID = UUID.randomUUID().toString(); public static final String MIN_PO_LINE_ID = UUID.randomUUID().toString(); diff --git a/src/test/java/org/folio/rest/impl/PurchaseOrderLinesApiTest.java b/src/test/java/org/folio/rest/impl/PurchaseOrderLinesApiTest.java index 85bcbf5fd..ea8482648 100644 --- a/src/test/java/org/folio/rest/impl/PurchaseOrderLinesApiTest.java +++ b/src/test/java/org/folio/rest/impl/PurchaseOrderLinesApiTest.java @@ -28,6 +28,7 @@ import static org.folio.TestConstants.PO_ID_OPEN_STATUS; import static org.folio.TestConstants.PO_ID_PENDING_STATUS_WITH_PO_LINES; import static org.folio.TestConstants.PO_LINE_ID_FOR_SUCCESS_CASE; +import static org.folio.TestConstants.PO_LINE_ID_WITHOUT_DETAILS; import static org.folio.TestConstants.PO_LINE_ID_WRONG_EXPENSE_CLASS; import static org.folio.TestConstants.PO_LINE_NUMBER_VALUE; import static org.folio.TestConstants.PROTECTED_READ_ONLY_TENANT; @@ -1566,6 +1567,20 @@ void testPatchPoLineWithNewInstanceId() { verifyPatch(url, JsonObject.mapFrom(body).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_ID), "", 204); } + @Test + void testPatchPoLineWithEmptyDetails() { + String url = String.format(LINE_BY_ID_PATH, PO_LINE_ID_WITHOUT_DETAILS); + + PatchOrderLineRequest body = new PatchOrderLineRequest() + .withOperation(PatchOrderLineRequest.Operation.REPLACE_INSTANCE_REF) + .withReplaceInstanceRef(new ReplaceInstanceRef() + .withNewInstanceId("cd3288a4-898c-4347-a003-2d810ef70f03") + .withHoldingsOperation(ReplaceInstanceRef.HoldingsOperation.CREATE) + .withDeleteAbandonedHoldings(false)); + + verifyPatch(url, JsonObject.mapFrom(body).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_ID), "", 204); + } + @Test void testPatchPoLineWithEmptyBody() { String url = String.format(LINE_BY_ID_PATH, PO_LINE_ID_FOR_SUCCESS_CASE); diff --git a/src/test/resources/mockdata/lines/13c4c3c2-90d9-4090-8694-edae7e79e7ac.json b/src/test/resources/mockdata/lines/13c4c3c2-90d9-4090-8694-edae7e79e7ac.json new file mode 100644 index 000000000..f1c74155d --- /dev/null +++ b/src/test/resources/mockdata/lines/13c4c3c2-90d9-4090-8694-edae7e79e7ac.json @@ -0,0 +1,94 @@ +{ + "id" : "13c4c3c2-90d9-4090-8694-edae7e79e7ac", + "acquisitionMethod" : "Purchase At Vendor System", + "alerts" : [ ], + "cancellationRestriction" : false, + "cancellationRestrictionNote" : "ABCDEFGHIJKLMNOPQRSTUVW", + "claims": [ + { + "claimed": false, + "sent": "2018-10-09T00:00:00.000Z", + "grace": 30 + } + ], + "collection" : false, + "contributors" : [ { + "contributor" : "Ed Mashburn", + "contributorNameTypeId" : "fbdd42a8-e47d-4694-b448-cc571d1b44c3" + } ], + "cost": { + "currency": "USD", + "listUnitPrice": 24.99, + "quantityPhysical": 3 + }, + "description" : "ABCDEFGH", + "donor" : "ABCDEFGHIJKLM", + "fundDistribution": [ + { + "code": "HIST", + "fundId": "fb7b70f1-b898-4924-a991-0e4b6312bb5f", + "distributionType": "percentage", + "value": 80.0 + } + ], + "locations": [ + { + "locationId": "fcd64ce1-6995-48f0-840e-89ffa2288371", + "quantity": 1, + "quantityElectronic": 0, + "quantityPhysical": 1 + }, + { + "locationId": "53cf956f-c1df-410b-8bea-27f712cca7c0", + "quantity": 2, + "quantityElectronic": 0, + "quantityPhysical": 2 + } + ], + "orderFormat" : "Physical Resource", + "paymentStatus" : "Fully Paid", + "physical": { + "createInventory": "Instance, Holding, Item", + "volumes": [ + "vol. 1" + ], + "materialSupplier": "73d14bc5-d131-48c6-b380-f8e62f63c8b6", + "materialType": "2fa93835-ea37-479d-b133-1d2a2279fcd8", + "expectedReceiptDate": "2018-10-05T00:00:00.000Z", + "receiptDue": "2018-10-10T00:00:00.000Z" + }, + "poLineDescription" : "ABCDEFGHIJKLMNOPQRSTUVWXY", + "poLineNumber" : "1EFC4DA8526-1", + "publicationDate" : "2017", + "publisher" : "Schiffer Publishing", + "purchaseOrderId" : "00000000-1111-2222-8888-999999999999", + "receiptDate" : "2018-10-09T00:00:00.000+0000", + "receiptStatus" : "Awaiting Receipt", + "reportingCodes" : [ ], + "requester" : "Leo Bulero", + "rush" : true, + "selector" : "ABCD", + "source": "User", + "tags": { + "tagList": [ + "important" + ] + }, + "titleOrPackage" : "Kayak Fishing in the Northern Gulf Coast", + "vendorDetail": { + "instructions": "ABCDEFG", + "noteFromVendor": "ABCDEFGHIKJKLMNOP", + "referenceNumbers": [ + { + "refNumber": "123456-78", + "refNumberType": "Vendor title number", + "vendorDetailsSource": "OrderLine" + } + ], + "vendorAccount": "8910-25" + }, + "metadata": { + "createdDate": "2018-06-29T00:00:00.000", + "createdByUserId": "28d0f99c-d137-11e8-a8d5-f2801f1b9fd1" + } +}