Search in sources :

Example 1 with Parameter

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;
}
Also used : Errors(org.folio.rest.jaxrs.model.Errors) ArrayList(java.util.ArrayList) Error(org.folio.rest.jaxrs.model.Error) Parameter(org.folio.rest.jaxrs.model.Parameter)

Example 2 with Parameter

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));
    }
}
Also used : Parameter(org.folio.rest.jaxrs.model.Parameter)

Example 3 with Parameter

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 };
}
Also used : JsonObject(io.vertx.core.json.JsonObject) Error(org.folio.rest.jaxrs.model.Error) Parameter(org.folio.rest.jaxrs.model.Parameter) JsonObject(io.vertx.core.json.JsonObject) IOException(java.io.IOException) UnrecognizedPropertyException(com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException)

Aggregations

Parameter (org.folio.rest.jaxrs.model.Parameter)3 Error (org.folio.rest.jaxrs.model.Error)2 UnrecognizedPropertyException (com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException)1 JsonObject (io.vertx.core.json.JsonObject)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 MessagingException (javax.mail.MessagingException)1 Errors (org.folio.rest.jaxrs.model.Errors)1