use of org.folio.inventory.support.http.server.ValidationError 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.ValidationError in project mod-inventory by folio-org.
the class FakeStorageModule method checkRequiredProperties.
private void checkRequiredProperties(RoutingContext routingContext) {
JsonObject body = getJsonFromBody(routingContext);
List<ValidationError> errors = new ArrayList<>();
requiredProperties.forEach(requiredProperty -> {
if (getPropertyValue(body, requiredProperty) == null) {
errors.add(new ValidationError("Required property missing", requiredProperty, ""));
}
});
if (errors.isEmpty()) {
routingContext.next();
} else {
JsonResponse.unprocessableEntity(routingContext.response(), errors);
}
}
use of org.folio.inventory.support.http.server.ValidationError in project mod-inventory by folio-org.
the class InstancePrecedingSucceedingTitleValidators method refuseWhenUnconnectedHasNoTitle.
public static CompletableFuture<Instance> refuseWhenUnconnectedHasNoTitle(Instance instance) {
final ValidationError succeedingError = new ValidationError("Title is required for unconnected succeeding title", "succeedingTitles.title", null);
final ValidationError precedingError = new ValidationError("Title is required for unconnected preceding title", "precedingTitles.title", null);
return refuseWhenUnconnectedHasNoTitle(instance, instance.getSucceedingTitles(), succeedingError).thenCompose(prev -> refuseWhenUnconnectedHasNoTitle(instance, instance.getPrecedingTitles(), precedingError));
}
use of org.folio.inventory.support.http.server.ValidationError in project mod-inventory by folio-org.
the class MoveValidator method itemsMoveHasRequiredFields.
public static Optional<ValidationError> itemsMoveHasRequiredFields(JsonObject itemsMoveRequest) {
final String toHoldingsRecordId = JsonHelper.getString(itemsMoveRequest, TO_HOLDINGS_RECORD_ID);
if (StringUtils.isBlank(toHoldingsRecordId)) {
return Optional.of(new ValidationError("toHoldingsRecordId is a required field", TO_HOLDINGS_RECORD_ID, null));
}
List<String> itemIds = JsonArrayHelper.toListOfStrings(itemsMoveRequest.getJsonArray(ITEM_IDS));
if (itemIds.isEmpty()) {
return Optional.of(new ValidationError("Item ids aren't specified", "itemIds", null));
}
return Optional.empty();
}
use of org.folio.inventory.support.http.server.ValidationError in project mod-inventory by folio-org.
the class MoveValidator method holdingsMoveHasRequiredFields.
public static Optional<ValidationError> holdingsMoveHasRequiredFields(JsonObject holdingsMoveRequest) {
final String toInstanceId = JsonHelper.getString(holdingsMoveRequest, TO_INSTANCE_ID);
if (StringUtils.isBlank(toInstanceId)) {
return Optional.of(new ValidationError("toInstanceId is a required field", TO_INSTANCE_ID, null));
}
List<String> holdingsRecordIds = JsonArrayHelper.toListOfStrings(holdingsMoveRequest.getJsonArray(HOLDINGS_RECORD_IDS));
if (holdingsRecordIds.isEmpty()) {
return Optional.of(new ValidationError("Holdings record ids aren't specified", HOLDINGS_RECORD_IDS, null));
}
return Optional.empty();
}
Aggregations