Skip to content

Commit

Permalink
[MODORDERS-989] - Implemented endpoint to restore piece status
Browse files Browse the repository at this point in the history
  • Loading branch information
Khamidulla Abdulkhakimov authored and Khamidulla Abdulkhakimov committed Jan 16, 2024
1 parent cbe8a8a commit 745930c
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 4 deletions.
34 changes: 34 additions & 0 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,34 @@
"orders-storage.reporting-codes.item.get"
]
},
{
"methods": [
"POST"
],
"pathPattern": "/orders/restore",
"permissionsRequired": [
"orders.restore.collection.post"
],
"modulePermissions": [
"orders-storage.pieces.collection.get",
"orders-storage.pieces.item.put",
"orders-storage.po-lines.collection.get",
"orders-storage.po-lines.item.put",
"orders-storage.purchase-orders.item.get",
"orders-storage.purchase-orders.item.put",
"orders-storage.titles.collection.get",
"inventory.items.collection.get",
"inventory.items.item.put",
"inventory-storage.holdings.collection.get",
"inventory-storage.holdings.item.post",
"acquisitions-units-storage.units.collection.get",
"acquisitions-units-storage.memberships.collection.get",
"orders-storage.purchase-orders.collection.get",
"finance.encumbrances.item.put",
"finance.order-transaction-summaries.item.put",
"finance.transactions.collection.get"
]
},
{
"methods": [
"GET"
Expand Down Expand Up @@ -1277,6 +1305,11 @@
"displayName": "Orders - Check-in items",
"description": "Check-in items spanning one or more po-lines in this order"
},
{
"permissionName": "orders.restore.collection.post",
"displayName": "Orders - Restore items",
"description": "Restore items spanning one or more po-lines in this order"
},
{
"permissionName": "orders.receiving-history.collection.get",
"displayName": "Orders - Receiving history",
Expand Down Expand Up @@ -1697,6 +1730,7 @@
"orders.po-number.item.post",
"orders.receiving.collection.post",
"orders.check-in.collection.post",
"orders.restore.collection.post",
"orders.receiving-history.collection.get",
"orders.pieces.all",
"orders.acquisitions-units-assignments.all",
Expand Down
39 changes: 39 additions & 0 deletions ramls/restoration.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#%RAML 1.0
title: Restoration
baseUri: https://github.com/folio-org/mod-orders
version: v1
protocols: [ HTTP, HTTPS ]

documentation:
- title: Orders Business Logic API
content: <b>API for transition pieces status from unreceivable to expected</b>

types:
receiving-collection: !include acq-models/mod-orders/schemas/receivingCollection.json
receiving-results: !include acq-models/mod-orders/schemas/receivingResults.json
errors: !include raml-util/schemas/errors.schema
UUID:
type: string
pattern: ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$

traits:
validate: !include raml-util/traits/validation.raml

resourceTypes:
post-with-200: !include rtypes/post-json-200.raml

/orders/restore:
displayName: Restore items
description: |
Receive items spanning one or more PO lines. The endpoint is used to:
- receive pieces and associated inventory items
- move a received piece back to "Expected" in case "receivedItems" element's "itemStatus" is "On order"
type:
post-with-200:
requestSchema: receiving-collection
responseSchema: receiving-results
requestExample: !include acq-models/mod-orders/examples/receivingCollection.sample
responseExample: !include acq-models/mod-orders/examples/receivingResults.sample
is: [validate]
post:
description: Receive items spanning one or more PO lines
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private void addPieceIfValid(Piece piece, Map<String, List<Piece>> piecesByPoLin
// request
if (piecesByLineId.containsKey(poLineId) && piecesByLineId.get(poLineId).containsKey(pieceId)) {
// Validate if the piece is not yet received
if (piece.getReceivingStatus() == ReceivingStatus.EXPECTED || isRevertToOnOrder(piece)) {
if (!ReceivingStatus.RECEIVED.equals(piece.getReceivingStatus()) || isRevertToOnOrder(piece)) {
piecesByPoLine.computeIfAbsent(poLineId, v -> new ArrayList<>())
.add(piece);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/folio/helper/ReceivingHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public ReceivingHelper(Map<String, String> okapiHeaders, Context ctx) {
receivingItems = null;
}

public Future<ReceivingResults> receiveItems(ReceivingCollection receivingCollection, RequestContext requestContext) {
public Future<ReceivingResults> receiveItems(ReceivingCollection receivingCollection, RequestContext requestContext) {
return getPoLines(new ArrayList<>(receivingItems.keySet()), requestContext)
.compose(poLines -> removeForbiddenEntities(poLines, receivingItems, requestContext))
.compose(vVoid -> processReceiveItems(receivingCollection, requestContext));
Expand Down Expand Up @@ -251,7 +251,7 @@ protected Map<String, List<Piece>> updatePieceRecordsWithoutItems(Map<String, Li
* @param piece
* piece record to be updated with receiving info
*/
private void updatePieceWithReceivingInfo(Piece piece) {
protected void updatePieceWithReceivingInfo(Piece piece) {
// Get ReceivedItem corresponding to piece record
ReceivedItem receivedItem = piecesByLineId.get(piece.getPoLineId())
.get(piece.getId());
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/org/folio/helper/RestoreHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.folio.helper;

import io.vertx.core.Context;
import io.vertx.core.Future;
import org.folio.rest.core.models.RequestContext;
import org.folio.rest.jaxrs.model.Piece;
import org.folio.rest.jaxrs.model.ReceivingCollection;
import org.folio.rest.jaxrs.model.ReceivingResults;

import java.util.Map;

public class RestoreHelper extends ReceivingHelper {

public RestoreHelper(ReceivingCollection receivingCollection, Map<String, String> okapiHeaders, Context ctx) {
super(receivingCollection, okapiHeaders, ctx);
}

public Future<ReceivingResults> restorePiece(ReceivingCollection restorationCollection, RequestContext requestContext) {
return receiveItems(restorationCollection, requestContext);
}

@Override
protected boolean isRevertToOnOrder(Piece piece) {
return piece.getReceivingStatus() == Piece.ReceivingStatus.UNRECEIVABLE
&& inventoryManager
.isOnOrderItemStatus(piecesByLineId.get(piece.getPoLineId()).get(piece.getId()));
}

@Override
protected void updatePieceWithReceivingInfo(Piece piece) {
super.updatePieceWithReceivingInfo(piece);

piece.setReceivedDate(null);
piece.setReceivingStatus(Piece.ReceivingStatus.EXPECTED);
}
}
13 changes: 12 additions & 1 deletion src/main/java/org/folio/rest/impl/ReceivingAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@
import org.apache.logging.log4j.Logger;
import org.folio.helper.CheckinHelper;
import org.folio.helper.ReceivingHelper;
import org.folio.helper.RestoreHelper;
import org.folio.rest.annotations.Validate;
import org.folio.rest.core.models.RequestContext;
import org.folio.rest.jaxrs.model.CheckinCollection;
import org.folio.rest.jaxrs.model.ReceivingCollection;
import org.folio.rest.jaxrs.resource.OrdersCheckIn;
import org.folio.rest.jaxrs.resource.OrdersReceive;
import org.folio.rest.jaxrs.resource.OrdersRestore;
import org.folio.rest.jaxrs.resource.OrdersReceivingHistory;

import io.vertx.core.AsyncResult;
import io.vertx.core.Context;
import io.vertx.core.Handler;
import io.vertx.core.json.JsonObject;

public class ReceivingAPI implements OrdersReceive, OrdersCheckIn, OrdersReceivingHistory {
public class ReceivingAPI implements OrdersReceive, OrdersCheckIn, OrdersReceivingHistory, OrdersRestore {

private static final Logger logger = LogManager.getLogger();

Expand Down Expand Up @@ -66,4 +68,13 @@ public void getOrdersReceivingHistory(String totalRecords, int offset, int limit
})
.onFailure(t -> handleErrorResponse(asyncResultHandler, helper, t));
}

@Override
public void postOrdersRestore(ReceivingCollection entity, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
logger.info("Restoring {} items", entity.getTotalRecords());
RestoreHelper helper = new RestoreHelper(entity, okapiHeaders, vertxContext);
helper.restorePiece(entity, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(result -> asyncResultHandler.handle(succeededFuture(helper.buildOkResponse(result))))
.onFailure(t -> handleErrorResponse(asyncResultHandler, helper, t));
}
}

0 comments on commit 745930c

Please sign in to comment.