@Override
    public void validate(IValidatable<String> validatable) {
      String vcName = validatable.getValue();

      final CoverageStoreInfo store = getCatalog().getStore(storeId, CoverageStoreInfo.class);
      List<CoverageInfo> coverages = getCatalog().getCoveragesByCoverageStore(store);
      for (CoverageInfo curr : coverages) {
        CoverageView currvc =
            curr.getMetadata().get(CoverageView.COVERAGE_VIEW, CoverageView.class);
        if (currvc != null) {
          if (coverageInfoId == null || !coverageInfoId.equals(curr.getId())) {
            if (currvc.getName().equals(vcName) && newCoverage) {
              Map<String, Object> map = new HashMap<>();
              map.put("name", vcName);
              map.put("coverageName", curr.getName());
              IValidationError err =
                  new ValidationError("duplicateCoverageViewName")
                      .addKey("duplicateCoverageViewName")
                      .setVariables(map);
              validatable.error(err);
              return;
            }
          }
        }
      }
    }
Esempio n. 2
0
    @Override
    public void validate(IValidatable<String> validatable) {
      String username = validatable.getValue();
      String orgUsername = ((UserManageBackingBean) getDefaultModelObject()).getOriginalUsername();

      if ((StringUtils.isNotBlank(orgUsername)
          && !username.equalsIgnoreCase(orgUsername)
          && userService.getUser(username) != null)) {
        validatable.error(new ValidationError("admin.user.errorUsernameExists"));
      }
    }
  @Override
  public void validate(IValidatable<String> validatable) {
    final String duracion = validatable.getValue();
    Double duracionParseada;

    if (!duracionPattern.matcher(duracion).matches()) {
      error(validatable, "Duración con formato equivocado");
    } else if (wrongPattern.matcher(duracion).matches()) {
      error(validatable, "Duración no puede ser cero.");
    } else if (decimalPattern.matcher(duracion).matches()) {

      duracionParseada = Double.parseDouble(duracion.replace(',', '.'));
      if (duracionParseada >= 24) {
        error(validatable, "Duración no puede ser mayor a 24 horas");
      }

    } else if (horaPattern.matcher(duracion).matches()) {
      int pos = duracion.indexOf(":");
      String strHora = duracion.substring(0, pos);
      duracionParseada = Double.parseDouble(strHora);

      if (duracionParseada >= 24) {
        error(validatable, "Duración no puede ser mayor a 24 horas");
      }
    }
  }
 @Override
 protected void onValidate(IValidatable<String> validatable) {
   final String nodeName = (String) validatable.getValue();
   if (!Pattern.matches("[a-zA-Z0-9]*", nodeName)) {
     error(validatable, "NodeNameValidator.policyname");
   }
 }
 public void validate(final IValidatable<Z> validatable) {
   final Z value = validatable.getValue();
   final Z min = this.getMinimum();
   final Z max = this.getMaximum();
   if ((min != null && ((Comparable) value).compareTo(min) < 0)
       || (max != null && ((Comparable) value).compareTo(max) > 0)) {
     final ValidationError error = new ValidationError();
     error.addMessageKey(this.resourceKey());
     if (min != null) {
       error.setVariable("minimum", min);
     }
     if (max != null) {
       error.setVariable("maximum", max);
     }
     validatable.error(error);
   }
 }
    @Override
    public void validate(IValidatable validatable) {
      // logger.debug("in validate");
      if (validatable != null
          && buttonAction.equals(BUTTON_ACTION.SUBMIT)
          && StringUtils.isEmpty((String) validatable.getValue())) {

        // logger.debug("hit error " + buttonAction);

        validatable.error(
            new IValidationError() {
              @Override
              public String getErrorMessage(IErrorMessageSource messageSource) {
                return message;
              }
            });
      }
    }
Esempio n. 7
0
  @Override
  protected ValidationError decorate(ValidationError error, IValidatable<Date> validatable) {
    error = super.decorate(error, validatable);

    error.setVariable("inputdate", validatable.getValue());

    // format variables if format has been specified
    if (format != null) {
      SimpleDateFormat sdf = new SimpleDateFormat(format);
      if (getMinimum() != null) {
        error.setVariable("minimum", sdf.format(getMinimum()));
      }
      if (getMaximum() != null) {
        error.setVariable("maximum", sdf.format(getMaximum()));
      }
      error.setVariable("inputdate", sdf.format(validatable.getValue()));
    }

    return error;
  }
  /** @see AbstractValidator#onValidate(IValidatable) */
  protected void onValidate(IValidatable validatable) {
    // setup list
    List<String> regexs = new ArrayList<String>();
    regexs.add("\\+?([0-9]+|\\s+)+(\\w+)?+"); // matches 1,2,3,5 with 10
    regexs.add("\\({1}[0-9]+\\){1}([0-9]+|\\s+)+(\\w+)?+"); // matches 4 with 10
    regexs.add("([0-9]+(\\-|\\.)?)+(\\w+)?+"); // matches 6, 7 with 10
    regexs.add("\\({1}[0-9]+\\){1}([0-9]+|\\s+|\\-?|\\.?)+(\\w+)?+"); // matches 8,9 with 10

    // check each, if none, error
    for (String r : regexs) {
      Pattern p = Pattern.compile(r);
      if (p.matcher((String) validatable.getValue()).matches()) {
        return;
      }
    }

    // if we haven't matched, error.
    error(validatable);
  }
 private void error(IValidatable<String> validatable, String errorKey) {
   ValidationError error = new ValidationError();
   error.addKey(getClass().getSimpleName() + "." + errorKey);
   error.setMessage(errorKey);
   validatable.error(error);
 }
 @Override
 public void validate(IValidatable<T> validatable) {
   if (!predicate.apply(validatable.getValue())) {
     validatable.error(decorate(new ValidationError(this)));
   }
 }