use of org.folio.rest.jaxrs.model.Errors in project raml-module-builder by folio-org.
the class RestRoutingTest method isValidRequest.
private <T> T isValidRequest(T t, Class<T> clazz) {
Errors errors = new Errors();
Object[] o = RestRouting.isValidRequest(null, t, errors, List.of(), clazz);
assertThat(errors.getErrors(), is(empty()));
return (T) o[1];
}
use of org.folio.rest.jaxrs.model.Errors in project raml-module-builder by folio-org.
the class RestRoutingTest method isValidRequestSuccess.
@Test
void isValidRequestSuccess() {
Errors errors = new Errors();
RestRouting.isValidRequest(null, new Foo("id", null), errors, List.of(), null);
assertThat(errors.getErrors(), is(empty()));
}
use of org.folio.rest.jaxrs.model.Errors in project raml-module-builder by folio-org.
the class RestRouting method parseNonAnnotated.
private static void parseNonAnnotated(RoutingContext rc, Buffer body, Object[] paramArray, Map<String, String> okapiHeaders, String valueType, int order) throws JsonProcessingException, ReflectiveOperationException {
// this will also validate the json against the pojo created from the schema
Class<?> entityClazz = Class.forName(valueType);
HttpServerRequest request = rc.request();
if (valueType.equals("io.vertx.ext.web.RoutingContext")) {
paramArray[order] = rc;
} else if (valueType.equals("java.util.Map")) {
paramArray[order] = okapiHeaders;
} else if (valueType.equals("io.vertx.core.Context")) {
paramArray[order] = rc.vertx().getOrCreateContext();
} else if (valueType.equals("io.vertx.core.Handler")) {
// will set it later in invoke
paramArray[order] = null;
} else if (!valueType.equals("java.io.InputStream")) {
// we have special handling for the Result Handler and context, it is also assumed that
// an inputsteam parameter occurs when application/octet is declared in the raml
// in which case the content will be streamed to he function
String bodyContent = body == null ? null : body.toString();
withRequestId(rc, () -> LOGGER.debug("{} -------- bodyContent -------- {}", rc.request().path(), bodyContent));
if (bodyContent != null) {
if ("java.io.Reader".equals(valueType)) {
paramArray[order] = new StringReader(bodyContent);
} else if ("java.lang.String".equals(valueType)) {
paramArray[order] = bodyContent;
} else if (bodyContent.length() > 0) {
try {
paramArray[order] = MAPPER.readValue(bodyContent, entityClazz);
} catch (UnrecognizedPropertyException e) {
withRequestId(rc, () -> LOGGER.error(e.getMessage(), e));
endRequestWithError(rc, HttpStatus.HTTP_UNPROCESSABLE_ENTITY.toInt(), true, JsonUtils.entity2String(ValidationHelper.createValidationErrorMessage("", "", e.getMessage())));
return;
}
}
}
Errors errorResp = new Errors();
// is this request only to validate a field value and not an actual
// request for additional processing
List<String> field2validate = request.params().getAll("validate_field");
Object[] resp = isValidRequest(rc, paramArray[order], errorResp, field2validate, entityClazz);
boolean isValid = (boolean) resp[0];
paramArray[order] = resp[1];
if (!isValid) {
endRequestWithError(rc, HttpStatus.HTTP_UNPROCESSABLE_ENTITY.toInt(), true, JsonUtils.entity2String(errorResp));
return;
}
if (!field2validate.isEmpty()) {
// valid request for the field to validate request made
AsyncResponseResult arr = new AsyncResponseResult();
ResponseImpl ri = new ResponseImpl();
ri.setStatus(200);
arr.setResult(ri);
// right now this is the only flag available to stop
// any additional responses for this request. to fix
sendResponse(rc, arr, 0, null);
return;
}
MetadataUtil.populateMetadata(paramArray[order], okapiHeaders);
}
}
use of org.folio.rest.jaxrs.model.Errors in project raml-module-builder by folio-org.
the class PgUtil method respond422.
static Future<Response> respond422(Method response422Method, String key, String value, String message) {
try {
Errors errors = ValidationHelper.createValidationErrorMessage(key, value, message);
Response response = (Response) response422Method.invoke(null, errors);
return Future.succeededFuture(response);
} catch (IllegalAccessException | InvocationTargetException | NullPointerException e) {
throw new IllegalArgumentException(e);
}
}
Aggregations