use of org.folio.rest.jaxrs.model.Title in project mod-orders by folio-org.
the class PieceUpdateFlowInventoryManager method nonPackageUpdateTitleWithInstance.
private CompletableFuture<String> nonPackageUpdateTitleWithInstance(PieceUpdateHolder holder, RequestContext requestContext) {
CompositePoLine poLineToSave = holder.getPoLineToSave();
Piece pieceToUpdate = holder.getPieceToUpdate();
if (poLineToSave.getInstanceId() == null && !PoLineCommonUtil.isInventoryUpdateNotRequired(poLineToSave)) {
return titlesService.getTitleById(pieceToUpdate.getTitleId(), requestContext).thenCompose(title -> {
if (title.getInstanceId() == null) {
return createTitleInstance(title, requestContext);
}
return completedFuture(title.getInstanceId());
}).thenApply(instanceId -> poLineToSave.withInstanceId(instanceId).getInstanceId());
}
return completedFuture(poLineToSave.getInstanceId());
}
use of org.folio.rest.jaxrs.model.Title in project mod-orders by folio-org.
the class TitlesService method createTitle.
public CompletableFuture<Title> createTitle(Title title, RequestContext requestContext) {
CompletableFuture<Title> future = new CompletableFuture<>();
populateTitle(title, title.getPoLineId(), requestContext).thenCompose(v -> {
RequestEntry requestEntry = new RequestEntry(ENDPOINT);
return restClient.post(requestEntry, title, requestContext, Title.class);
}).thenAccept(future::complete).exceptionally(t -> {
future.completeExceptionally(t);
return null;
});
return future;
}
use of org.folio.rest.jaxrs.model.Title in project mod-orders by folio-org.
the class CheckinReceivePiecesHelper method processHoldingsUpdate.
protected CompletableFuture<Void> processHoldingsUpdate(Map<String, Map<String, Location>> pieceLocationsGroupedByPoLine, Map<String, List<Piece>> piecesGroupedByPoLine, PoLineAndTitleById poLinesAndTitlesById, RequestContext requestContext) {
List<CompletableFuture<Boolean>> futuresForHoldingsUpdates = new ArrayList<>();
StreamEx.ofValues(piecesGroupedByPoLine).flatMap(List::stream).forEach(piece -> {
CompositePoLine poLine = poLinesAndTitlesById.poLineById.get(piece.getPoLineId());
if (poLine == null) {
logger.error("POLine associated with piece '{}' cannot be found", piece.getId());
addError(piece.getPoLineId(), piece.getId(), ITEM_UPDATE_FAILED.toError());
return;
}
Title title = poLinesAndTitlesById.titleById.get(piece.getTitleId());
if (title == null) {
logger.error("Piece with id {} : title with id {} was not found within the po line titles.", piece.getId(), piece.getTitleId());
addError(piece.getPoLineId(), piece.getId(), ITEM_UPDATE_FAILED.toError());
return;
}
Location receivedPieceLocation = pieceLocationsGroupedByPoLine.get(poLine.getId()).get(piece.getId());
if (holdingUpdateOnCheckinReceiveRequired(piece, receivedPieceLocation, poLine)) {
futuresForHoldingsUpdates.add(createHoldingsForChangedLocations(piece, title.getInstanceId(), receivedPieceLocation, requestContext));
}
});
return collectResultsOnSuccess(futuresForHoldingsUpdates).thenAccept(results -> {
if (logger.isDebugEnabled()) {
long successQty = results.stream().filter(result -> result).count();
logger.debug("{} out of {} holdings successfully processed", successQty, results.size());
}
});
}
use of org.folio.rest.jaxrs.model.Title in project mod-orders by folio-org.
the class CheckinReceivePiecesHelper method processItemsUpdate.
protected CompletableFuture<Map<String, List<Piece>>> processItemsUpdate(Map<String, Map<String, Location>> pieceLocationsGroupedByPoLine, Map<String, List<Piece>> piecesGroupedByPoLine, List<JsonObject> items, PoLineAndTitleById poLinesAndTitlesById, RequestContext requestContext) {
List<CompletableFuture<Boolean>> futuresForItemsUpdates = new ArrayList<>();
Map<String, Piece> piecesWithItems = collectPiecesWithItemId(piecesGroupedByPoLine);
// If there are no pieces with ItemId, continue
if (piecesWithItems.isEmpty()) {
return completedFuture(piecesGroupedByPoLine);
}
for (JsonObject item : items) {
String itemId = item.getString(ID);
Piece piece = piecesWithItems.get(itemId);
CompositePoLine poLine = poLinesAndTitlesById.poLineById.get(piece.getPoLineId());
if (poLine == null)
continue;
Title title = poLinesAndTitlesById.titleById.get(piece.getTitleId());
if (title == null)
continue;
Location pieceLocation = pieceLocationsGroupedByPoLine.get(poLine.getId()).get(piece.getId());
if (holdingUpdateOnCheckinReceiveRequired(piece, pieceLocation, poLine) && !isRevertToOnOrder(piece)) {
String holdingKey = buildProcessedHoldingKey(pieceLocation, title.getInstanceId());
String holdingId = processedHoldings.get(holdingKey);
item.put(ITEM_HOLDINGS_RECORD_ID, holdingId);
}
futuresForItemsUpdates.add(receiveInventoryItemAndUpdatePiece(item, piece, requestContext));
}
return collectResultsOnSuccess(futuresForItemsUpdates).thenApply(results -> {
if (logger.isDebugEnabled()) {
long successQty = results.stream().filter(result -> result).count();
logger.debug("{} out of {} inventory item(s) successfully updated", successQty, results.size());
}
return piecesGroupedByPoLine;
});
}
use of org.folio.rest.jaxrs.model.Title in project mod-orders by folio-org.
the class InventoryManager method buildInstanceRecordJsonObject.
public JsonObject buildInstanceRecordJsonObject(Title title, JsonObject lookupObj) {
JsonObject instance = new JsonObject();
// MODORDERS-145 The Source and source code are required by schema
instance.put(INSTANCE_SOURCE, SOURCE_FOLIO);
instance.put(INSTANCE_TITLE, title.getTitle());
if (title.getEdition() != null) {
instance.put(INSTANCE_EDITIONS, new JsonArray(singletonList(title.getEdition())));
}
instance.put(INSTANCE_STATUS_ID, lookupObj.getString(INSTANCE_STATUSES));
instance.put(INSTANCE_TYPE_ID, lookupObj.getString(INSTANCE_TYPES));
if (title.getPublisher() != null || title.getPublishedDate() != null) {
JsonObject publication = new JsonObject();
publication.put(INSTANCE_PUBLISHER, title.getPublisher());
publication.put(INSTANCE_DATE_OF_PUBLICATION, title.getPublishedDate());
instance.put(INSTANCE_PUBLICATION, new JsonArray(singletonList(publication)));
}
List<Contributor> titleContributors = title.getContributors();
if (isNotEmpty(titleContributors)) {
List<JsonObject> contributors = titleContributors.stream().map(compPolContributor -> {
JsonObject invContributor = new JsonObject();
invContributor.put(CONTRIBUTOR_NAME_TYPE_ID, compPolContributor.getContributorNameTypeId());
invContributor.put(CONTRIBUTOR_NAME, compPolContributor.getContributor());
return invContributor;
}).collect(toList());
instance.put(INSTANCE_CONTRIBUTORS, contributors);
}
List<ProductId> productIds = title.getProductIds();
if (CollectionUtils.isNotEmpty(productIds)) {
List<JsonObject> identifiers = productIds.stream().map(pId -> {
JsonObject identifier = new JsonObject();
identifier.put(INSTANCE_IDENTIFIER_TYPE_ID, pId.getProductIdType());
identifier.put(INSTANCE_IDENTIFIER_TYPE_VALUE, pId.getProductId());
return identifier;
}).collect(toList());
instance.put(INSTANCE_IDENTIFIERS, new JsonArray(identifiers));
}
return instance;
}
Aggregations