leap.core.validation.Validation类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(213)

本文整理了Java中leap.core.validation.Validation类的一些代码示例,展示了Validation类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Validation类的具体详情如下:
包路径:leap.core.validation.Validation
类名称:Validation

Validation介绍

暂无

代码示例

代码示例来源:origin: org.leapframework/leap-orm

@Override
public Errors validate(EntityWrapper entity, Iterable<String> fields) {
  Validation validation = validationManager.createValidation();
  validate(entity, validation, 1, fields);
  return validation.errors();
}

代码示例来源:origin: org.leapframework/jmms-core

@Override
  public boolean checkAndConvert(Validation validation, String name, Object value, Out<Object> out) {
    try {
      out.set(Converts.convert(value, targetType));
      return true;
    }catch (ConvertException e) {
      validation.addError(name, "Can't convert to '" + targetType.getSimpleName() + "', invalid data type");
      return false;
    }
  }
}

代码示例来源:origin: org.leapframework/leap-orm

protected boolean validateField(EntityWrapper entity, Validation validation, int maxErrors, FieldMapping fm, FieldValidator[] validators){
  Object value = entity.get(fm.getFieldName());
  
  //Validates : not null
  if(!fm.isNullable()){
    if(!validation.stateRequired(fm.getFieldName(), value)){
      return validation.maxErrorsReached(maxErrors);
    }
  }
  
  //Validated by validators
  for(int i=0;i<validators.length;i++){
    validators[i].validate(entity, fm, value, validation, maxErrors);
    if(validation.maxErrorsReached(maxErrors)){
      return true;
    }
  }
  
  return false;
}

代码示例来源:origin: org.leapframework/leap-core

@Override
public boolean stateValidate(String name, Object bean) {
  Validation v = createNewValidation(name);
  
  if(!v.stateValidate(bean)){
    addErrors(v.errors());
    return false;
  }
  
  return true;
}

代码示例来源:origin: org.leapframework/leap-core

protected boolean validateProperty(String name, Object bean, Validation validation, int maxErrors, ValidatedProperty vp){
  BeanProperty p = vp.property;
  Object v = p.getValue(bean);
  
  boolean pass = true;
  boolean validateBean = false;
  String fullPropertyName = (Strings.isEmpty(name) ? "" : name + ".") + p.getName();
  //Validated by validators
  for(int i=0;i<vp.validators.length;i++){
    Validator validator = vp.validators[i];
    if(validator == BEAN_VALIDATOR) {
      validateBean = true;
      continue;
    }else{
      if(!validation.stateValidate(fullPropertyName, v, validator)){
        pass = false;
        if(validation.maxErrorsReached(maxErrors)){
          break;
        }
      }
    }
  }
  if(validateBean && pass && null != v) {
    return validate(fullPropertyName, v, validation, maxErrors);
  }
  return pass;
}

代码示例来源:origin: org.leapframework/leap-oauth2-server

Validation validation = context.validation();
String errorKey = INVALID_REQUEST_INVALID_USERNAME;
if(context.validation().hasErrors()){
  NamedError error = validation.errors().first();
  if(Strings.equals(error.getName(),UsernamePasswordCredentials.PASSWORD)){
    errorKey = INVALID_REQUEST_INVALID_PASSWORD;

代码示例来源:origin: org.leapframework/leap-websecurity

@Override
  public boolean resolveCredentials(AuthenticationContext context, RequestBase request, Out<Credentials> out) throws ServletException, IOException {
    if(request.isMethod(Method.POST) && request.hasParameter(usernameParameter)){
      //Validates username
      String username = request.getParameter(usernameParameter);
      if(context.validation()
            .required(usernameParameter, username)
            .errors().contains(usernameParameter)){
        return true;
      }
      context.setIdentity(username);
      //Validates password if necessary
      String password = request.getParameter(passwordParameter);
      if(passwordRequired && context.validation().required(passwordParameter, password)
          .errors().contains(passwordParameter)){
        return true;
      }
      
      log.debug("Resolved 'UsernamePasswordCredentials' : [username={}]",username);
      
      out.set(new SimpleUsernamePasswordCredentials(username, password));
      return true;
    }
    
    return false;
  }
}

代码示例来源:origin: org.leapframework/leap-orm

protected boolean validateEntity(EntityWrapper entity,Validation validation,int maxErrors,EntityValidator[] validators){
    boolean pass = true;
    
    for(int i=0;i<validators.length;i++){
      if(!validators[i].validate(entity, validation, maxErrors)){
        pass = false;
        if(validation.maxErrorsReached(maxErrors)){
          break;
        }
      }
    }
    return pass;
  }
}

代码示例来源:origin: org.leapframework/leap-orm

@Override
public boolean validate(EntityWrapper entity, FieldMapping fm, Object value, Validation validation, int maxErrors) {
  return validation.stateValidate(fm.getFieldName(), value, validator);
}

代码示例来源:origin: org.leapframework/jmms-core

protected boolean validateRequired(Validation validation, String name, Object value) {
  return validation.stateRequired(name, value);
}

代码示例来源:origin: org.leapframework/leap-oauth2

Validation validation = context.validation();
String errorKey = INVALID_REQUEST_INVALID_USERNAME;
if(context.validation().hasErrors()){
  NamedError error = validation.errors().first();
  if(Strings.equals(error.getName(),UsernamePasswordCredentials.PASSWORD)){
    errorKey = INVALID_REQUEST_INVALID_PASSWORD;

代码示例来源:origin: org.leapframework/leap-orm

protected boolean validateField(EntityWrapper entity, Validation validation, int maxErrors, FieldMapping fm) {
  FieldValidator[] validators = fm.getValidators();
  if(validators.length > 0){
    if(validateField(entity, validation, maxErrors, fm, validators)){
      return false;
    }
    if(validation.maxErrorsReached(maxErrors)){
      return false;
    }
  }
  return true;
}

代码示例来源:origin: org.leapframework/leap-orm

protected boolean validateField(EntityWrapper entity,Validation validation,int maxErrors,FieldMapping fm,Validator validator,Object value){
  return validation.stateValidate(fm.getFieldName(),value,validator);
}

代码示例来源:origin: org.leapframework/jmms-core

protected boolean validateNumber(Validation validation, String name, Object value) {
  if(validated.hasNumberValidation()) {
    BigDecimal n = Converts.convert(value, BigDecimal.class);
    if(null != maximum && n.compareTo(maximum) > 0) {
      validation.addError(name, "The number must <= " + validated.getMaximum());
      return false;
    }
    if(null != minimum && n.compareTo(minimum) < 0) {
      validation.addError(name, "The number must >= " + validated.getMinimum());
      return false;
    }
  }
  return true;
}

代码示例来源:origin: org.leapframework/leap-orm

@Override
public Errors validate(EntityMapping em, Object entity, int maxErrors, Iterable<String> fields) {
  Validation validation = validationManager.createValidation();
  entityValidator.validate(EntityWrapper.wrap(ormContext, em, entity), validation, maxErrors, fields);
  return validation.errors();
}

代码示例来源:origin: org.leapframework/leap-core

protected boolean validate(String name, Object bean, Validation validation, int maxErrors, BeanType bt, ValidatedProperty[] vps) {
  //Validate properties
  
  boolean pass = true;
  
  for(int i=0;i<vps.length;i++){
    ValidatedProperty vp = vps[i];
    
    if(!validateProperty(name, bean, validation, maxErrors, vp)){
      pass = false;
      
      if(validation.maxErrorsReached(maxErrors)){
        return pass;
      }
    }
  }
  
  if(bean instanceof Validatable){
    return ((Validatable) bean).validate(validation,maxErrors);
  }
  
  return pass;
}

代码示例来源:origin: org.leapframework/jmms-core

@Override
protected boolean doValidate(Validation validation, String name, Object value, Out<Object> out) {
  if(!(value instanceof Map)) {
    validation.addError(name, "Invalid value, must be a map");
    return false;
  }
  if(null != valueValidator) {
    Map map = (Map)value;
    Map converted = null;
    Out<Object> entryOut = new Out<>();
    for(Object object : map.entrySet()) {
      Map.Entry entry = (Map.Entry)object;
      if(!valueValidator.validate(validation, qname(name, entry.getKey().toString()), entry.getValue(), entryOut)) {
        return false;
      }
      if(entryOut.isPresent()) {
        if(null == converted) {
          converted = new HashMap();
        }
        converted.put(entry.getKey(), entryOut.getAndReset());
      }
    }
    if(null != converted) {
      map.putAll(converted);
    }
  }
  return true;
}

代码示例来源:origin: org.leapframework/leap-core

@Override
public void validate(String name, Object bean) throws ValidationException {
  Validation validation = validationManager.createValidation();
  if(!validate(name, bean, validation, 1)) {
    throw new ValidationException(validation.errors());
  }
}

代码示例来源:origin: org.leapframework/leap-orm

if(validation.maxErrorsReached(maxErrors)){
  return false;
  if(validation.maxErrorsReached(maxErrors)){
    return false;

代码示例来源:origin: org.leapframework/jmms-core

protected boolean doValidateArray(Validation validation, String name, Enumerable e) {
  int size = e.size();
  if(null != validated.getMinItems() && size < validated.getMinItems()) {
    validation.addError(name, "The array's size must be >= " + validated.getMinItems());
    return false;
  }
  if(null != validated.getMaxItems() && size > validated.getMaxItems()) {
    validation.addError(name, "The array's size must <= " + validated.getMaxItems());
    return false;
  }
  return true;
}

相关文章