Search in sources :

Example 6 with WebContext

use of org.folio.inventory.common.WebContext in project mod-inventory by folio-org.

the class ItemRepresentationTest method jsonContainsVersion.

@Test
public void jsonContainsVersion() throws Throwable {
    WebContext webContext = when(mock(WebContext.class).absoluteUrl(any())).thenReturn(new URL("http://localhost")).getMock();
    JsonObject instance = new JsonObject().put("contributors", new JsonArray());
    Item item = new Item(UUID.randomUUID().toString(), "123", null, new Status(ItemStatusName.AVAILABLE), null, null, null);
    JsonObject json = new ItemRepresentation("items").toJson(item, null, instance, null, null, null, null, null, null, webContext);
    assertThat(json.getString("_version"), is("123"));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Status(org.folio.inventory.domain.items.Status) Item(org.folio.inventory.domain.items.Item) WebContext(org.folio.inventory.common.WebContext) JsonObject(io.vertx.core.json.JsonObject) URL(java.net.URL) Test(org.junit.Test)

Example 7 with WebContext

use of org.folio.inventory.common.WebContext in project mod-inventory by folio-org.

the class Instances method getAll.

private void getAll(RoutingContext routingContext) {
    WebContext context = new WebContext(routingContext);
    String search = context.getStringParameter("query", null);
    PagingParameters pagingParameters = PagingParameters.from(context);
    if (pagingParameters == null) {
        ClientErrorResponse.badRequest(routingContext.response(), "limit and offset must be numeric when supplied");
        return;
    }
    if (search == null) {
        storage.getInstanceCollection(context).findAll(pagingParameters, (Success<MultipleRecords<Instance>> success) -> makeInstancesResponse(success, routingContext, context), FailureResponseConsumer.serverError(routingContext.response()));
    } else {
        try {
            storage.getInstanceCollection(context).findByCql(search, pagingParameters, success -> makeInstancesResponse(success, routingContext, context), FailureResponseConsumer.serverError(routingContext.response()));
        } catch (UnsupportedEncodingException e) {
            ServerErrorResponse.internalError(routingContext.response(), e.toString());
        }
    }
}
Also used : PagingParameters(org.folio.inventory.common.api.request.PagingParameters) WebContext(org.folio.inventory.common.WebContext) Instance(org.folio.inventory.domain.instances.Instance) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Success(org.folio.inventory.common.domain.Success)

Example 8 with WebContext

use of org.folio.inventory.common.WebContext in project mod-inventory by folio-org.

the class Instances method deleteById.

private void deleteById(RoutingContext routingContext) {
    WebContext context = new WebContext(routingContext);
    storage.getInstanceCollection(context).delete(routingContext.request().getParam("id"), v -> noContent(routingContext.response()), FailureResponseConsumer.serverError(routingContext.response()));
}
Also used : WebContext(org.folio.inventory.common.WebContext)

Example 9 with WebContext

use of org.folio.inventory.common.WebContext in project mod-inventory by folio-org.

the class Instances method getById.

private void getById(RoutingContext routingContext) {
    WebContext context = new WebContext(routingContext);
    storage.getInstanceCollection(context).findById(routingContext.request().getParam("id"), it -> {
        Instance instance = it.getResult();
        if (instance != null) {
            completedFuture(instance).thenCompose(response -> fetchInstanceRelationships(it, routingContext, context)).thenCompose(response -> fetchPrecedingSucceedingTitles(it, routingContext, context)).thenCompose(response -> setBoundWithFlag(it, routingContext, context)).thenAccept(response -> successResponse(routingContext, context, response));
        } else {
            ClientErrorResponse.notFound(routingContext.response());
        }
    }, FailureResponseConsumer.serverError(routingContext.response()));
}
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)

Example 10 with WebContext

use of org.folio.inventory.common.WebContext in project mod-inventory by folio-org.

the class Instances method deleteAll.

private void deleteAll(RoutingContext routingContext) {
    WebContext context = new WebContext(routingContext);
    storage.getInstanceCollection(context).empty(v -> noContent(routingContext.response()), FailureResponseConsumer.serverError(routingContext.response()));
}
Also used : WebContext(org.folio.inventory.common.WebContext)

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