-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MODORDERS-1108] Update PiecesAPI CRUD methods to process inventory i…
…n desired tenant (#942) * [MODORDERS-1108] Refactor PieceCreateFlowInventoryManager * [MODORDERS-1108] Refactor PieceDeleteFlowManager * [MODORDERS-1108] Split PieceDeleteFlowManager and create PieceDeleteFlowInventoryManager * [MODORDERS-1108] Refactor PieceUpdateFlowInventoryManager * [MODORDERS-1108] Fix failing PieceUpdate/CreateFlowInventoryManagerTest * [MODORDERS-1108] Fix failing PieceCreateFlowInventoryManagerTest * [MODORDERS-1108] Rebuild * [MODORDERS-1108] Add support for mulitenant * [MODORDERS-1108] a small bug in binding * [MODORDERS-1112] Remove redundant code * [MODORDERS-1112] Make code readable, add PieceDeleteInventoryService, pass missed locationContext * [MODORDERS-1112] Static import createContextWithNewTenantId * [MODORDERS-1112] Update acq-models * [MODORDERS-1112] Minor refactoring * [MODORDERS-1122] Change correct attribute * [MODORDERS-1108] Remove BooleanUtils * [MODORDERS-1108] Replace TRUE with FALSE checks * Revert "[MODORDERS-1108] Replace TRUE with FALSE checks" This reverts commit 3132594.
- Loading branch information
1 parent
fc5216f
commit 241b810
Showing
15 changed files
with
349 additions
and
348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/org/folio/service/pieces/PieceDeleteInventoryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.folio.service.pieces; | ||
|
||
import io.vertx.core.Future; | ||
import io.vertx.core.json.JsonObject; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.folio.models.ItemStatus; | ||
import org.folio.models.pieces.PieceDeletionHolder; | ||
import org.folio.rest.core.models.RequestContext; | ||
import org.folio.rest.jaxrs.model.Piece; | ||
import org.folio.service.inventory.InventoryItemManager; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.folio.service.inventory.InventoryItemManager.ITEM_STATUS; | ||
import static org.folio.service.inventory.InventoryItemManager.ITEM_STATUS_NAME; | ||
|
||
public class PieceDeleteInventoryService { | ||
|
||
private final InventoryItemManager inventoryItemManager; | ||
|
||
public PieceDeleteInventoryService(InventoryItemManager inventoryItemManager) { | ||
this.inventoryItemManager = inventoryItemManager; | ||
} | ||
|
||
public Future<Void> deleteItem(PieceDeletionHolder holder, RequestContext requestContext) { | ||
var piece = holder.getPieceToDelete(); | ||
return getOnOrderItemForPiece(piece, requestContext) | ||
.compose(item -> Optional.ofNullable(item) | ||
.map(mItem -> inventoryItemManager.deleteItem(piece.getItemId(), true, requestContext)) | ||
.orElse(Future.succeededFuture())); | ||
} | ||
|
||
private Future<JsonObject> getOnOrderItemForPiece(Piece piece, RequestContext requestContext) { | ||
if (StringUtils.isEmpty(piece.getItemId())) { | ||
return Future.succeededFuture(); | ||
} | ||
return inventoryItemManager.getItemRecordById(piece.getItemId(), true, requestContext) | ||
.map(item -> getItemWithStatus(item, ItemStatus.ON_ORDER.value())); | ||
} | ||
|
||
private JsonObject getItemWithStatus(JsonObject item, String status) { | ||
return Optional.ofNullable(item) | ||
.map(itemObj -> itemObj.getJsonObject(ITEM_STATUS)) | ||
.filter(itemStatus -> status.equalsIgnoreCase(itemStatus.getString(ITEM_STATUS_NAME))) | ||
.orElse(null); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.