use of org.folio.inventory.common.WebContext in project mod-inventory by folio-org.
the class FakeStorageModule method get.
private void get(RoutingContext routingContext) {
WebContext context = new WebContext(routingContext);
String id = routingContext.request().getParam("id");
Map<String, JsonObject> resourcesForTenant = getResourcesForTenant(context);
if (resourcesForTenant.containsKey(id)) {
final JsonObject resourceRepresentation = resourcesForTenant.get(id);
System.out.printf("Found %s resource: %s%n", recordTypeName, resourceRepresentation.encodePrettily());
JsonResponse.success(routingContext.response(), resourceRepresentation);
} else {
System.out.printf("Failed to find %s resource: %s%n", recordTypeName, id);
ClientErrorResponse.notFound(routingContext.response());
}
}
use of org.folio.inventory.common.WebContext in project mod-inventory by folio-org.
the class FakeStorageModule method create.
private void create(RoutingContext routingContext) {
WebContext context = new WebContext(routingContext);
JsonObject body = getJsonFromBody(routingContext);
setDefaultProperties(body);
String id = body.getString("id");
createElement(context, body).thenAccept(notUsed -> {
System.out.printf("Created %s resource: %s%n", recordTypeName, id);
JsonResponse.created(routingContext.response(), body);
}).exceptionally(error -> {
EndpointFailureHandler.handleFailure(EndpointFailureHandler.getKnownException(error), routingContext);
return null;
});
}
use of org.folio.inventory.common.WebContext in project mod-inventory by folio-org.
the class FakeStorageModule method replace.
private void replace(RoutingContext routingContext) {
WebContext context = new WebContext(routingContext);
String id = routingContext.request().getParam("id");
JsonObject rawBody = getJsonFromBody(routingContext);
Map<String, JsonObject> resourcesForTenant = getResourcesForTenant(context);
preProcessRecords(resourcesForTenant.get(id), rawBody).thenAccept(body -> {
setDefaultProperties(body);
if (ID_FOR_FAILURE.toString().equals(id)) {
ServerErrorResponse.internalError(routingContext.response(), "Test Internal Server Error");
} else if (ID_FOR_OPTIMISTIC_LOCKING_FAILURE.toString().equals(id)) {
ClientErrorResponse.optimisticLocking(routingContext.response(), "Optimistic Locking");
} else if (resourcesForTenant.containsKey(id)) {
System.out.printf("Replaced %s resource: %s%n", recordTypeName, id);
resourcesForTenant.replace(id, body);
SuccessResponse.noContent(routingContext.response());
} else {
System.out.printf("Created %s resource: %s%n", recordTypeName, id);
resourcesForTenant.put(id, body);
SuccessResponse.noContent(routingContext.response());
}
});
}
use of org.folio.inventory.common.WebContext in project mod-inventory by folio-org.
the class FakeStorageModule method empty.
private void empty(RoutingContext routingContext) {
WebContext context = new WebContext(routingContext);
if (!hasCollectionDelete) {
ClientErrorResponse.notFound(routingContext.response());
return;
}
Map<String, JsonObject> resourcesForTenant = getResourcesForTenant(context);
resourcesForTenant.clear();
SuccessResponse.noContent(routingContext.response());
}
use of org.folio.inventory.common.WebContext in project mod-inventory by folio-org.
the class Items method getById.
private void getById(RoutingContext routingContext) {
WebContext context = new WebContext(routingContext);
storage.getItemCollection(context).findById(routingContext.request().getParam("id"), (Success<Item> itemResponse) -> {
Item item = itemResponse.getResult();
if (item != null) {
respondWithItemRepresentation(item, STATUS_SUCCESS, routingContext, context);
} else {
ClientErrorResponse.notFound(routingContext.response());
}
}, FailureResponseConsumer.serverError(routingContext.response()));
}
Aggregations