/** handles Hibernate validation exception */
  public void afterThrowing(Method m, Object[] args, Object target, InvalidStateException e) {

    Logger log = LoggerFactory.getLogger(target.getClass());

    StringBuilder logText = new StringBuilder(excMessage(e));
    if (e.getInvalidValues() != null && e.getInvalidValues().length > 0) {
      for (InvalidValue each : e.getInvalidValues()) {
        logText.append(" : ").append(each.getPropertyPath()).append(" ");
        logText.append("'").append(each.getMessage()).append("'");
        logText.append(" ");
        logText.append(each.getPropertyPath()).append("=");
        logText.append(each.getValue());
      }
      logText.append(" rootBean=").append(e.getInvalidValues()[0].getRootBean());
    }

    if (isJmsContext()) {
      LogMessage message =
          new LogMessage(
              mapLogCode(mapLogCode(ValidationException.ERROR_CODE)), logText.toString());
      log.error("{}", message);
    } else {
      LogMessage message =
          new LogMessage(mapLogCode(ValidationException.ERROR_CODE), logText.toString());
      log.debug("{}", message);
    }

    ValidationException newException = new ValidationException(excMessage(e));
    newException.setLogged(true);
    newException.setInvalidValues(e.getInvalidValues());
    throw newException;
  }
 @Override
 @SuppressWarnings("unchecked")
 public Collection<String> validateGraph(
     FacesContext context, Object value, Set<String> profiles) {
   if (null == context) {
     throw new FacesException(INPUT_PARAMETERS_IS_NOT_CORRECT);
   }
   Collection<String> validationMessages = null;
   if (null != value) {
     ClassValidator<Object> validator =
         (ClassValidator<Object>) getValidator(context, value.getClass());
     if (validator.hasValidationRules()) {
       InvalidValue[] invalidValues = validator.getInvalidValues(value);
       if (null != invalidValues && invalidValues.length > 0) {
         validationMessages = new ArrayList<String>(invalidValues.length);
         for (int i = 0; i < invalidValues.length; i++) {
           InvalidValue invalidValue = invalidValues[i];
           validationMessages.add(invalidValue.getMessage());
         }
       }
     }
     if (null != parent) {
       Collection<String> parentMessages = parent.validateGraph(context, value, profiles);
       if (null != validationMessages) {
         if (null != parentMessages) {
           validationMessages.addAll(parentMessages);
         }
       } else {
         validationMessages = parentMessages;
       }
     }
   }
   return validationMessages;
 }
예제 #3
0
 @SuppressWarnings("unchecked")
 protected void validateModelObject() {
   final T o = getPersistentObjectModel().getObject();
   ClassValidator<T> v =
       validator == null ? v = new ClassValidator(Hibernate.getClass(o)) : validator;
   for (final InvalidValue iv : v.getInvalidValues(o)) {
     error(iv.getPropertyName() + " " + iv.getMessage());
   }
 }
예제 #4
0
  @SuppressWarnings("unchecked")
  public List<Message> validate(Object object) {
    List<Message> errors = new ArrayList<Message>();
    ClassValidator<Object> validator =
        (ClassValidator<Object>) locator.getValidator(object.getClass(), localization.getBundle());
    InvalidValue[] invalidValues = validator.getInvalidValues(object);

    for (InvalidValue value : invalidValues) {
      errors.add(new ValidationMessage(value.getMessage(), value.getPropertyPath()));
    }
    return errors;
  }
 @Override
 protected Collection<String> validate(
     FacesContext facesContext, Object base, String property, Object value, Set<String> profiles) {
   InvalidValue[] invalidValues = validateBean(facesContext, base, property, value);
   if (null == invalidValues) {
     return null;
   } else {
     Collection<String> result = new ArrayList<String>(invalidValues.length);
     for (int i = 0; i < invalidValues.length; i++) {
       InvalidValue invalidValue = invalidValues[i];
       result.add(invalidValue.getMessage());
     }
     return result;
   }
 }