public void addSubissue(ValidationIssue subissue) { subissues.put(subissue.getSubject(), subissue); }
public void addError(String code, String message) { ValidationError error = new ValidationError(code, message); errors.add(error); }
@Override public String toString() { StringBuilder eb = new StringBuilder(); for (ValidationError e : errors) { eb.append(e.toString()).append(",\n"); } StringBuilder ib = new StringBuilder(); for (ValidationIssue vi : subissues.values()) { ib.append(vi.toString()).append(",\n"); } return "ValidationIssue : {" + " subject: '" + subject + "',\n" + " errors: {\n" + eb.toString() + " \n},\n" + " subissues: {\n" + ib.toString() + " \n}\n" + '}'; } }
private void buildValidationMessages(ValidationIssue issue, String superKey) { String key; if (StringUtils.isEmpty(superKey)) { key = issue.getSubject(); } else { key = superKey + '.' + issue.getSubject(); } for (Map.Entry<String, ValidationIssue> entry : issue.getSubissues().entrySet()) { buildValidationMessages(entry.getValue(), key); } if (issue.hasErrors()) { List<String> msgs = new ArrayList<>(); for (ValidationError ve : issue.getErrors()) { msgs.add(ve.getMessage()); } String msg = StringUtils.join(msgs, "; "); String msgKey = StringUtils.isEmpty(key) ? VALIDATION_KEY : key; messages.put(msgKey, msg); } }
protected ValidationIssue exportErrors() { ValidationIssue issue = new ValidationIssue(getSubject()); for (ValidationContext childContext : childContexts) { ValidationIssue childIssue = childContext.exportErrors(); if (childIssue != null) { issue.addSubissue(childIssue); } } if (hasErrors()) { // export errors for (ValidationError error : this.errors) { issue.addError(error); } return issue; } else if (issue.hasSubissues()) { return issue; } return null; }
public static Notice error(Exception ex) { if (ex instanceof ValidationException) { return new Notice(Type.ERROR, ((ValidationException) ex).getIssue()); } if (ex instanceof ApplicationException) { return new Notice(Type.ERROR, ex.getMessage()); } return new Notice(Type.ERROR, ExceptionUtils.getRootCauseMessage(ex)); }
/** * Validates the value. Throws exception if validation errors occurred * * @param value * @throws ValidationException if some validation errors occurred */ @Override public void accept(V value) throws ValidationException { ValidationContext<V> context = ValidationContext.ofRoot(rootSubject, value); rootCommand.execute(context); ValidationIssue issue = context.toIssue(); if (issue != null) { throw new ValidationException(issue); } }
protected void handleValidationError(ValidationException ex, int httpCode, HttpContext context) { String errMsg = MessageFormat.format("Restlet validation error: {0}", ExceptionUtils.getRootCauseMessage(ex)); log.error(errMsg); RestletErrorResponse response = new RestletErrorResponse(context.getRequest().getRequestURI(), httpCode, ex.getIssue()); restletDataPort.sendError(response, httpCode); }