protected final String getTemplate(final EntityViolationType type, final String message) { return type.name() + ";" + message; }
/** * Constructs a map of violations out of given <tt>ConstraintViolation</tt> set. * * @param entityClassSimpleName simple class name of invalid entity * @param violations as returned by bean validation */ public InvalidEntityException( final String entityClassSimpleName, final Set<ConstraintViolation<Object>> violations) { super(); this.entityClassSimpleName = entityClassSimpleName; violations.forEach(violation -> { int firstComma = violation.getMessageTemplate().indexOf(';'); final String key = violation.getMessageTemplate().substring( 0, firstComma > 0 ? firstComma : violation.getMessageTemplate().length()); final String message = violation.getMessageTemplate().substring(firstComma > 0 ? firstComma + 1 : 0); EntityViolationType entityViolationType; try { entityViolationType = EntityViolationType.valueOf(key.trim()); } catch (IllegalArgumentException e) { entityViolationType = EntityViolationType.Standard; } entityViolationType.setMessage(message.trim()); entityViolationType.setPropertyPath(violation.getPropertyPath().toString()); if (!this.violations.containsKey(violation.getLeafBean().getClass())) { this.violations.put(violation.getLeafBean().getClass(), EnumSet.noneOf(EntityViolationType.class)); } this.violations.get(violation.getLeafBean().getClass()).add(entityViolationType); }); }
for (EntityViolationType violationType : violation.getValue()) { builder.header(RESTHeaders.ERROR_INFO, exType.getInfoHeaderValue(violationType.name() + ": " + violationType.getMessage())); error.getElements().add(violationType.name() + ": " + violationType.getMessage());
/** * Constructs a singleton map of violations from given parameters. * * @param entityClass class of invalid entity * @param entityViolationType type of violation found * @param message message to be associated to the violation */ public InvalidEntityException( final Class<?> entityClass, final EntityViolationType entityViolationType, final String message) { super(); this.entityClassSimpleName = entityClass.getSimpleName(); entityViolationType.setMessage(message.trim()); this.violations.put(entityClass, EnumSet.noneOf(EntityViolationType.class)); this.violations.get(entityClass).add(entityViolationType); }