Search in sources :

Example 1 with InstancesValidators

use of org.folio.inventory.validation.InstancesValidators in project mod-inventory by folio-org.

the class Instances method update.

private void update(RoutingContext rContext) {
    WebContext wContext = new WebContext(rContext);
    JsonObject instanceRequest = rContext.getBodyAsJson();
    Instance updatedInstance = Instance.fromJson(instanceRequest);
    InstanceCollection instanceCollection = storage.getInstanceCollection(wContext);
    completedFuture(updatedInstance).thenCompose(InstancePrecedingSucceedingTitleValidators::refuseWhenUnconnectedHasNoTitle).thenCompose(instance -> instanceCollection.findById(rContext.request().getParam("id"))).thenCompose(InstancesValidators::refuseWhenInstanceNotFound).thenCompose(existingInstance -> fetchPrecedingSucceedingTitles(new Success<>(existingInstance), rContext, wContext)).thenCompose(existingInstance -> refuseWhenBlockedFieldsChanged(existingInstance, updatedInstance)).thenCompose(existingInstance -> refuseWhenHridChanged(existingInstance, updatedInstance)).thenAccept(existingInstance -> updateInstance(updatedInstance, rContext, wContext)).exceptionally(doExceptionally(rContext));
}
Also used : FailureResponseConsumer(org.folio.inventory.support.http.server.FailureResponseConsumer) URL(java.net.URL) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Router(io.vertx.ext.web.Router) JsonArrayHelper(org.folio.inventory.support.JsonArrayHelper) RoutingContext(io.vertx.ext.web.RoutingContext) BodyHandler(io.vertx.ext.web.handler.BodyHandler) StringUtils(org.apache.commons.lang3.StringUtils) EndpointFailureHandler.handleFailure(org.folio.inventory.support.EndpointFailureHandler.handleFailure) ServerErrorResponse(org.folio.inventory.support.http.server.ServerErrorResponse) CollectionResourceClient(org.folio.inventory.storage.external.CollectionResourceClient) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) EndpointFailureHandler.doExceptionally(org.folio.inventory.support.EndpointFailureHandler.doExceptionally) SuccessResponse.noContent(org.folio.inventory.support.http.server.SuccessResponse.noContent) EndpointFailureHandler.getKnownException(org.folio.inventory.support.EndpointFailureHandler.getKnownException) RedirectResponse(org.folio.inventory.support.http.server.RedirectResponse) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Storage(org.folio.inventory.storage.Storage) InstancePrecedingSucceedingTitleValidators(org.folio.inventory.validation.InstancePrecedingSucceedingTitleValidators) Objects(java.util.Objects) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) InstanceRelationshipToChild(org.folio.inventory.domain.instances.InstanceRelationshipToChild) UnprocessableEntityException(org.folio.inventory.exceptions.UnprocessableEntityException) Instance(org.folio.inventory.domain.instances.Instance) CompletableFutures.failedFuture(org.folio.inventory.support.CompletableFutures.failedFuture) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpClient(io.vertx.core.http.HttpClient) WebContext(org.folio.inventory.common.WebContext) ClientErrorResponse(org.folio.inventory.support.http.server.ClientErrorResponse) InstancesValidators.refuseWhenHridChanged(org.folio.inventory.validation.InstancesValidators.refuseWhenHridChanged) InstancesValidators(org.folio.inventory.validation.InstancesValidators) Response(org.folio.inventory.support.http.client.Response) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) InstanceCollection(org.folio.inventory.domain.instances.InstanceCollection) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) ArrayList(java.util.ArrayList) JsonResponse(org.folio.inventory.support.http.server.JsonResponse) MultipleRecordsFetchClient(org.folio.inventory.storage.external.MultipleRecordsFetchClient) ObjectUtils(org.apache.commons.lang3.ObjectUtils) InstanceRelationship(org.folio.inventory.domain.instances.InstanceRelationship) SourceStorageRecordsClient(org.folio.rest.client.SourceStorageRecordsClient) MalformedURLException(java.net.MalformedURLException) COMMA(io.netty.util.internal.StringUtil.COMMA) InstanceRelationshipToParent(org.folio.inventory.domain.instances.InstanceRelationshipToParent) PrecedingSucceedingTitle(org.folio.inventory.domain.instances.titles.PrecedingSucceedingTitle) JsonArray(io.vertx.core.json.JsonArray) InstanceRelationshipsService(org.folio.inventory.services.InstanceRelationshipsService) HttpStatus(org.folio.HttpStatus) Success(org.folio.inventory.common.domain.Success) CqlQuery(org.folio.inventory.storage.external.CqlQuery) Collections(java.util.Collections) WebContext(org.folio.inventory.common.WebContext) Instance(org.folio.inventory.domain.instances.Instance) InstanceCollection(org.folio.inventory.domain.instances.InstanceCollection) JsonObject(io.vertx.core.json.JsonObject) Success(org.folio.inventory.common.domain.Success)

Aggregations

COMMA (io.netty.util.internal.StringUtil.COMMA)1 HttpClient (io.vertx.core.http.HttpClient)1 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 Router (io.vertx.ext.web.Router)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 BodyHandler (io.vertx.ext.web.handler.BodyHandler)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 String.format (java.lang.String.format)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1