use of org.folio.inventory.support.http.server.JsonResponse.unprocessableEntity in project mod-inventory by folio-org.
the class MoveApi method moveItems.
private void moveItems(RoutingContext routingContext) {
WebContext context = new WebContext(routingContext);
JsonObject itemsMoveJsonRequest = routingContext.getBodyAsJson();
Optional<ValidationError> validationError = itemsMoveHasRequiredFields(itemsMoveJsonRequest);
if (validationError.isPresent()) {
unprocessableEntity(routingContext.response(), validationError.get());
return;
}
String toHoldingsRecordId = itemsMoveJsonRequest.getString(TO_HOLDINGS_RECORD_ID);
List<String> itemIdsToUpdate = toListOfStrings(itemsMoveJsonRequest.getJsonArray(ITEM_IDS));
storage.getHoldingCollection(context).findById(toHoldingsRecordId).thenAccept(holding -> {
if (Objects.nonNull(holding)) {
try {
CollectionResourceClient itemsStorageClient = createItemStorageClient(createHttpClient(routingContext, context), context);
MultipleRecordsFetchClient itemsFetchClient = createItemsFetchClient(itemsStorageClient);
itemsFetchClient.find(itemIdsToUpdate, this::fetchByIdCql).thenAccept(jsons -> {
List<Item> itemsToUpdate = updateHoldingsRecordIdForItems(toHoldingsRecordId, jsons);
updateItems(routingContext, context, itemIdsToUpdate, itemsToUpdate);
}).exceptionally(e -> {
ServerErrorResponse.internalError(routingContext.response(), e);
return null;
});
} catch (Exception e) {
ServerErrorResponse.internalError(routingContext.response(), e);
}
} else {
JsonResponse.unprocessableEntity(routingContext.response(), String.format("Holding with id=%s not found", toHoldingsRecordId));
}
}).exceptionally(e -> {
ServerErrorResponse.internalError(routingContext.response(), e);
return null;
});
}
use of org.folio.inventory.support.http.server.JsonResponse.unprocessableEntity in project mod-inventory by folio-org.
the class MoveApi method moveHoldings.
private void moveHoldings(RoutingContext routingContext) {
WebContext context = new WebContext(routingContext);
JsonObject holdingsMoveJsonRequest = routingContext.getBodyAsJson();
Optional<ValidationError> validationError = holdingsMoveHasRequiredFields(holdingsMoveJsonRequest);
if (validationError.isPresent()) {
unprocessableEntity(routingContext.response(), validationError.get());
return;
}
String toInstanceId = holdingsMoveJsonRequest.getString(TO_INSTANCE_ID);
List<String> holdingsRecordsIdsToUpdate = toListOfStrings(holdingsMoveJsonRequest.getJsonArray(HOLDINGS_RECORD_IDS));
storage.getInstanceCollection(context).findById(toInstanceId).thenAccept(instance -> {
if (instance == null) {
JsonResponse.unprocessableEntity(routingContext.response(), String.format("Instance with id=%s not found", toInstanceId));
return;
}
try {
CollectionResourceClient holdingsStorageClient = createHoldingsStorageClient(createHttpClient(routingContext, context), context);
MultipleRecordsFetchClient holdingsRecordFetchClient = createHoldingsRecordsFetchClient(holdingsStorageClient);
holdingsRecordFetchClient.find(holdingsRecordsIdsToUpdate, this::fetchByIdCql).thenAccept(jsons -> {
List<HoldingsRecord> holdingsRecordsToUpdate = updateInstanceIdForHoldings(toInstanceId, jsons);
updateHoldings(routingContext, context, holdingsRecordsIdsToUpdate, holdingsRecordsToUpdate);
}).exceptionally(e -> {
ServerErrorResponse.internalError(routingContext.response(), e);
return null;
});
} catch (Exception e) {
ServerErrorResponse.internalError(routingContext.response(), e);
}
}).exceptionally(e -> {
ServerErrorResponse.internalError(routingContext.response(), e);
return null;
});
}
Aggregations