Skip to content

Commit

Permalink
[MODORDERS-986] - Error thrown during change instance connection (#829)
Browse files Browse the repository at this point in the history
* [MODORDERS-986] - Fixed NPE
  • Loading branch information
Abdulkhakimov authored Jan 29, 2024
1 parent caa4a85 commit b85aa14
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -167,6 +168,9 @@ private Future<PoLine> 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);
})
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/folio/TestConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/folio/rest/impl/PurchaseOrderLinesApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit b85aa14

Please sign in to comment.