Skip to content

Commit

Permalink
[MODORDERS-970] - Do not overwrite Item fields when piece fields are …
Browse files Browse the repository at this point in the history
…null/empty
  • Loading branch information
imerabishvili committed Jan 15, 2024
1 parent b8bd184 commit 98a199e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
29 changes: 21 additions & 8 deletions src/main/java/org/folio/service/inventory/InventoryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1269,14 +1269,27 @@ private Future<List<JsonObject>> fetchHoldingsByFundIds(List<String> holdingIds,
}

private void updateItemWithPieceFields(Piece piece, JsonObject item) {
Optional.ofNullable(piece.getEnumeration())
.ifPresentOrElse(enumeration -> item.put(ITEM_ENUMERATION, enumeration), () -> item.remove(ITEM_ENUMERATION));
Optional.ofNullable(piece.getCopyNumber())
.ifPresentOrElse(copyNumber -> item.put(COPY_NUMBER, copyNumber), () -> item.remove(COPY_NUMBER));
Optional.ofNullable(piece.getChronology())
.ifPresentOrElse(chronology -> item.put(ITEM_CHRONOLOGY, chronology), () -> item.remove(ITEM_CHRONOLOGY));
Optional.ofNullable(piece.getDiscoverySuppress())
.ifPresentOrElse(discSup -> item.put(ITEM_DISCOVERY_SUPPRESS, discSup), () -> item.remove(ITEM_DISCOVERY_SUPPRESS));
if (StringUtils.isNotEmpty(piece.getEnumeration())) {
item.put(ITEM_ENUMERATION, piece.getEnumeration());
}
if (StringUtils.isNotEmpty(piece.getCopyNumber())) {
item.put(COPY_NUMBER, piece.getCopyNumber());
}
if (StringUtils.isNotEmpty(piece.getChronology())) {
item.put(ITEM_CHRONOLOGY, piece.getChronology());
}
if (StringUtils.isNotEmpty(piece.getBarcode())) {
item.put(ITEM_BARCODE, piece.getBarcode());
}
if (StringUtils.isNotEmpty(piece.getAccessionNumber())) {
item.put(ITEM_ACCESSION_NUMBER, piece.getAccessionNumber());
}
if (StringUtils.isNotEmpty(piece.getCallNumber())) {
item.put(ITEM_LEVEL_CALL_NUMBER, piece.getCallNumber());
}
if (piece.getDiscoverySuppress() != null) {
item.put(ITEM_DISCOVERY_SUPPRESS, piece.getDiscoverySuppress());
}
}

public Future<SharingInstance> createShadowInstanceIfNeeded(String instanceId, RequestContext requestContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static org.folio.service.inventory.InventoryManager.ID;
import static org.folio.service.inventory.InventoryManager.ITEM_HOLDINGS_RECORD_ID;
import static org.folio.service.inventory.InventoryManager.ITEM_PURCHASE_ORDER_LINE_IDENTIFIER;
import static org.folio.service.inventory.InventoryManager.COPY_NUMBER;

import java.util.Optional;

Expand Down Expand Up @@ -127,8 +126,6 @@ private Future<String> handleItem(PieceUpdateHolder holder, RequestContext reque
private Future<Void> updateItemWithFields(JsonObject item, CompositePoLine compPOL, Piece piece) {
Optional.ofNullable(piece.getHoldingId())
.ifPresent(pieceHoldingId -> item.put(ITEM_HOLDINGS_RECORD_ID, piece.getHoldingId()));
Optional.ofNullable(piece.getCopyNumber())
.ifPresentOrElse(copyNumber -> item.put(COPY_NUMBER, copyNumber), () -> item.remove(COPY_NUMBER));
item.put(ITEM_PURCHASE_ORDER_LINE_IDENTIFIER, compPOL.getId());
return Future.succeededFuture();
}
Expand Down

0 comments on commit 98a199e

Please sign in to comment.