use of org.folio.circulation.support.http.server.ValidationError in project mod-circulation by folio-org.
the class FakeStorageModule method checkUniqueProperties.
private void checkUniqueProperties(RoutingContext routingContext) {
if (uniqueProperties.isEmpty()) {
routingContext.next();
return;
}
final WebContext context = new WebContext(routingContext);
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(format("%s with this %s already exists", recordTypeName, uniqueProperty), uniqueProperty, proposedValue));
context.write(new ValidationErrorFailure(errors));
}
});
if (errors.isEmpty()) {
routingContext.next();
}
}
use of org.folio.circulation.support.http.server.ValidationError in project mod-circulation by folio-org.
the class FakeStorageModule method checkRequiredProperties.
private void checkRequiredProperties(RoutingContext routingContext) {
final WebContext context = new WebContext(routingContext);
JsonObject body = getJsonFromBody(routingContext);
ArrayList<ValidationError> errors = new ArrayList<>();
requiredProperties.forEach(requiredProperty -> {
if (!body.getMap().containsKey(requiredProperty)) {
errors.add(new ValidationError("Required property missing", requiredProperty, ""));
}
});
if (errors.isEmpty()) {
routingContext.next();
} else {
context.write(new ValidationErrorFailure(errors));
}
}
use of org.folio.circulation.support.http.server.ValidationError in project mod-circulation by folio-org.
the class RequestByInstanceIdResourceTests method getExpectedErrorMessages.
@Test
void getExpectedErrorMessages() {
HttpFailure validationError = ValidationErrorFailure.singleValidationError(new ValidationError("validationError", "someParam", "null"));
String errorMessage = RequestByInstanceIdResource.getErrorMessage(validationError);
assertTrue(errorMessage.contains("validationError"));
HttpFailure serverErrorFailure = new ServerErrorFailure("serverError");
errorMessage = RequestByInstanceIdResource.getErrorMessage(serverErrorFailure);
assertEquals("serverError", errorMessage);
HttpFailure badRequestFailure = new BadRequestFailure("badRequestFailure");
errorMessage = RequestByInstanceIdResource.getErrorMessage(badRequestFailure);
assertEquals("badRequestFailure", errorMessage);
Response fakeResponse = new Response(500, "fakeResponseFailure", "text/javascript");
HttpFailure forwardOnFailure = new ForwardOnFailure(fakeResponse);
errorMessage = RequestByInstanceIdResource.getErrorMessage(forwardOnFailure);
assertEquals("fakeResponseFailure", errorMessage);
}
use of org.folio.circulation.support.http.server.ValidationError in project mod-circulation by folio-org.
the class RequestServiceUtility method refuseWhenMovedToDifferentInstance.
static Result<RequestAndRelatedRecords> refuseWhenMovedToDifferentInstance(RequestAndRelatedRecords requestAndRelatedRecords) {
Request request = requestAndRelatedRecords.getRequest();
Item item = request.getItem();
if (!Objects.equals(item.getInstanceId(), request.getInstanceId())) {
HashMap<String, String> parameters = new HashMap<>();
parameters.put(ITEM_ID, request.getItemId());
parameters.put(INSTANCE_ID, item.getInstanceId());
return failedValidation(new ValidationError("Request can only be moved to an item with the same instance ID", parameters));
}
return succeeded(requestAndRelatedRecords);
}
use of org.folio.circulation.support.http.server.ValidationError in project mod-circulation by folio-org.
the class RequestServiceUtility method refuseWhenUserIsInactive.
static Result<RequestAndRelatedRecords> refuseWhenUserIsInactive(RequestAndRelatedRecords request) {
User requester = request.getRequest().getRequester();
if (requester != null && requester.isInactive()) {
Map<String, String> parameters = new HashMap<>();
parameters.put(REQUESTER_ID, request.getRequest().getUserId());
parameters.put(ITEM_ID, request.getRequest().getItemId());
String message = "Inactive users cannot make requests";
return failedValidation(new ValidationError(message, parameters));
} else {
return of(() -> request);
}
}
Aggregations