/** 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;
  }
Пример #2
0
  public void testContentDaoInvalidContentEmptyName() throws Exception {

    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);
    ContentItem item = generateTestContent();
    item.setName("");

    try {
      contentDao.createContent(root, item);
      Assert.fail("able to create invalid content.");
    } catch (InvalidStateException e) {
      Assert.assertEquals("name", e.getInvalidValues()[0].getPropertyName());
    }
  }