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"));
}
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());
}
}
}
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()));
}
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()));
}
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()));
}
Aggregations