use of org.folio.inventory.common.WebContext in project mod-inventory by folio-org.
the class FakeStorageModule method checkUniqueProperties.
private void checkUniqueProperties(RoutingContext routingContext) {
if (uniqueProperties.isEmpty()) {
routingContext.next();
return;
}
JsonObject body = getJsonFromBody(routingContext);
ArrayList<ValidationError> errors = new ArrayList<>();
uniqueProperties.forEach(uniqueProperty -> {
String proposedValue = body.getString(uniqueProperty);
Map<String, JsonObject> records = getResourcesForTenant(new WebContext(routingContext));
if (records.values().stream().map(record -> record.getString(uniqueProperty)).anyMatch(usedValue -> usedValue.equals(proposedValue))) {
errors.add(new ValidationError(String.format("%s with this %s already exists", recordTypeName, uniqueProperty), uniqueProperty, proposedValue));
JsonResponse.unprocessableEntity(routingContext.response(), errors);
}
});
if (errors.isEmpty()) {
routingContext.next();
}
}
Aggregations