use of org.folio.rest.jaxrs.model.Parameter in project raml-module-builder by folio-org.
the class ValidationHelper method createValidationErrorMessage.
public static Errors createValidationErrorMessage(String field, String value, String message) {
Errors e = new Errors();
Error error = new Error();
Parameter p = new Parameter();
p.setKey(field);
p.setValue(value);
error.getParameters().add(p);
error.setMessage(message);
error.setCode("-1");
error.setType(RTFConsts.VALIDATION_FIELD_ERROR);
List<Error> l = new ArrayList<>();
l.add(error);
e.setErrors(l);
return e;
}
use of org.folio.rest.jaxrs.model.Parameter in project raml-module-builder by folio-org.
the class FileDataHandler method updateStatus.
/**
* update after every bulk so that we can resume if a crash occurs
*/
private void updateStatus(Job conf) {
// allow one update call
if (!jobComplete) {
jobComplete = true;
} else {
return;
}
Parameter p1 = new Parameter();
p1.setKey("total_success");
p1.setValue(String.valueOf(successCount[0]));
Parameter p2 = new Parameter();
p2.setKey("total_errors");
p2.setValue(String.valueOf(errorCount[0]));
Parameter p3 = new Parameter();
p3.setKey("processing_error_ids");
p3.setValue(processingErrorIds.toString());
conf.getParameters().add(p1);
conf.getParameters().add(p2);
conf.getParameters().add(p3);
if (stopWithError) {
replyHandler.handle(io.vertx.core.Future.failedFuture(RTFConsts.STATUS_ERROR_THRESHOLD));
} else {
replyHandler.handle(io.vertx.core.Future.succeededFuture(conf));
}
}
use of org.folio.rest.jaxrs.model.Parameter in project raml-module-builder by folio-org.
the class RestVerticle method isValidRequest.
/**
* return whether the request is valid [0] and a cleaned up version of the object [1]
* cleaned up meaning,
* @param errorResp
* @param paramArray
* @param rc
* @param validRequest
* @param entityClazz
*/
private Object[] isValidRequest(RoutingContext rc, Object content, Errors errorResp, boolean[] validRequest, List<String> singleField, Class<?> entityClazz) {
Set<? extends ConstraintViolation<?>> validationErrors = validationFactory.getValidator().validate(content);
boolean ret = true;
if (validationErrors.size() > 0) {
for (ConstraintViolation<?> cv : validationErrors) {
if ("must be null".equals(cv.getMessage())) {
/**
* read only fields are marked with a 'must be null' annotation @null
* so the client should not pass them in, if they were passed in, remove them here
* so that they do not reach the implementing function
*/
try {
if (!(content instanceof JsonObject)) {
content = JsonObject.mapFrom(content);
}
((JsonObject) content).remove(cv.getPropertyPath().toString());
continue;
} catch (Exception e) {
log.warn("Failed to remove " + cv.getPropertyPath().toString() + " field from body when calling " + rc.request().absoluteURI(), e);
}
}
Error error = new Error();
Parameter p = new Parameter();
String field = cv.getPropertyPath().toString();
p.setKey(field);
Object val = cv.getInvalidValue();
if (val == null) {
p.setValue("null");
} else {
p.setValue(val.toString());
}
error.getParameters().add(p);
error.setMessage(cv.getMessage());
error.setCode("-1");
error.setType(RTFConsts.VALIDATION_FIELD_ERROR);
// or there are validation errors and this is not a per field validation request
if ((singleField != null && singleField.contains(field)) || singleField.isEmpty()) {
errorResp.getErrors().add(error);
ret = false;
}
// sb.append("\n" + cv.getPropertyPath() + " " + cv.getMessage() + ",");
}
if (content instanceof JsonObject) {
// we have sanitized the passed in object by removing read-only fields
try {
content = MAPPER.readValue(((JsonObject) content).encode(), entityClazz);
} catch (IOException e) {
log.error("Failed to serialize body content after removing read-only fields when calling " + rc.request().absoluteURI(), e);
}
}
}
return new Object[] { Boolean.valueOf(ret), content };
}
Aggregations