@Override
  public void validate(Object object, Errors errors) {

    DecoratorOUPropertiesDefinition metadato = (DecoratorOUPropertiesDefinition) object;

    // lo shortname non puo' essere vuoto

    String shortName = metadato.getShortName();

    // validazione shortname...deve essere unico e non nullo e formato solo da caratteri
    // alfabetici da 'a-zA-Z','_' e '-'
    boolean result = (shortName != null) && shortName.matches("^[a-z_\\-A-Z]*$");

    if (result && shortName.length() != 0) {

      ValidationResult result2 = null;

      // verifica se e' unica
      // controllo sul db che non ci siano shortname uguali
      result2 =
          validatorService.checkShortName(metadato.getObject().getClass(), metadato.getObject());
      if (!result2.isSuccess()) errors.rejectValue("shortName", result2.getMessage());

    } else {
      errors.rejectValue("shortName", "error.message.validation.shortname.pattern");
    }
  }
示例#2
0
  /** Verify the uniqueness of the subject. */
  public void validateVoce(Soggettario soggettario, String voce, Errors errors) {

    if (voce != null && soggettario != null) {
      ValidationUtils.rejectIfEmptyOrWhitespace(
          errors, "voce", "error.message.fallita.campo.obbligatorio");
      ValidationResult result = validatorService.controllaVoceSuSoggettario(soggettario, voce);
      if (!result.isSuccess()) {
        errors.rejectValue("voce", result.getMessage());
      }
    }
  }