Search in sources :

Example 36 with WebContext

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();
    }
}
Also used : WebContext(org.folio.inventory.common.WebContext) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ClientErrorResponse(org.folio.inventory.support.http.server.ClientErrorResponse) Router(io.vertx.ext.web.Router) RecordPreProcessor(support.fakes.processors.RecordPreProcessor) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) RoutingContext(io.vertx.ext.web.RoutingContext) BodyHandler(io.vertx.ext.web.handler.BodyHandler) StringUtils(org.apache.commons.lang3.StringUtils) Supplier(java.util.function.Supplier) ID_FOR_FAILURE(api.ApiTestSuite.ID_FOR_FAILURE) ArrayList(java.util.ArrayList) ServerErrorResponse(org.folio.inventory.support.http.server.ServerErrorResponse) JsonResponse(org.folio.inventory.support.http.server.JsonResponse) ID_FOR_OPTIMISTIC_LOCKING_FAILURE(api.ApiTestSuite.ID_FOR_OPTIMISTIC_LOCKING_FAILURE) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) EndpointFailureHandler(org.folio.inventory.support.EndpointFailureHandler) Collection(java.util.Collection) DateTime(org.joda.time.DateTime) HttpHeaders(io.vertx.core.http.HttpHeaders) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) AbstractVerticle(io.vertx.core.AbstractVerticle) ValidationError(org.folio.inventory.support.http.server.ValidationError) SuccessResponse(org.folio.inventory.support.http.server.SuccessResponse) WebContext(org.folio.inventory.common.WebContext) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) ValidationError(org.folio.inventory.support.http.server.ValidationError)

Aggregations

WebContext (org.folio.inventory.common.WebContext)36 JsonObject (io.vertx.core.json.JsonObject)27 RoutingContext (io.vertx.ext.web.RoutingContext)20 Router (io.vertx.ext.web.Router)19 Collectors (java.util.stream.Collectors)17 JsonArray (io.vertx.core.json.JsonArray)16 ServerErrorResponse (org.folio.inventory.support.http.server.ServerErrorResponse)16 BodyHandler (io.vertx.ext.web.handler.BodyHandler)15 MalformedURLException (java.net.MalformedURLException)15 URL (java.net.URL)15 ArrayList (java.util.ArrayList)15 List (java.util.List)15 CollectionResourceClient (org.folio.inventory.storage.external.CollectionResourceClient)15 HttpClient (io.vertx.core.http.HttpClient)14 CompletableFuture (java.util.concurrent.CompletableFuture)14 Storage (org.folio.inventory.storage.Storage)14 JsonResponse (org.folio.inventory.support.http.server.JsonResponse)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)12 ClientErrorResponse (org.folio.inventory.support.http.server.ClientErrorResponse)12 PagingParameters (org.folio.inventory.common.api.request.PagingParameters)11