本文整理汇总了Java中com.baidu.unbiz.fluentvalidator.ValidatorContext类的典型用法代码示例。如果您正苦于以下问题:Java ValidatorContext类的具体用法?Java ValidatorContext怎么用?Java ValidatorContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ValidatorContext类属于com.baidu.unbiz.fluentvalidator包,在下文中一共展示了ValidatorContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, T t) {
Class<?>[] groups = GroupingHolder.getGrouping();
Set<ConstraintViolation<T>> constraintViolations;
if (ArrayUtil.isEmpty(groups)) {
constraintViolations = HIBERANTE_VALIDATOR.validate(t);
} else {
constraintViolations = HIBERANTE_VALIDATOR.validate(t, groups);
}
if (CollectionUtil.isEmpty(constraintViolations)) {
return true;
} else {
for (ConstraintViolation<T> constraintViolation : constraintViolations) {
context.addError(constraintViolationTransformer.toValidationError(constraintViolation)
.setErrorCode(hibernateDefaultErrorCode));
}
return false;
}
}
示例2: validate
import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, String t) {
Boolean ignoreManufacturer = context.getAttribute("ignoreManufacturer", Boolean.class);
if (ignoreManufacturer != null && ignoreManufacturer) {
return true;
}
if (!manufacturerService.getAllManufacturers().contains(t)) {
context.addError(ValidationError.create(String.format(CarError.MANUFACTURER_ERROR.msg(), t))
.setErrorCode(CarError.MANUFACTURER_ERROR.code())
.setField("manufacturer")
.setInvalidValue(t));
return false;
}
return true;
}
示例3: validate
import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, String s) {
if (null == s || s.length() > max || s.length() < min) {
context.addError(ValidationError.create(String.format("%s长度必须介于%s~%s之间!", fieldName, min, max))
.setErrorCode(-1)
.setField(fieldName)
.setInvalidValue(s));
return false;
}
return true;
}
示例4: validate
import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, Integer integer) {
if (null == integer || integer.intValue() > max || integer.intValue() < min) {
context.addError(ValidationError.create(String.format("%s必须大于%s,小于%s", fieldName, max, min))
.setErrorCode(-1)
.setField(fieldName)
.setInvalidValue(integer));
return false;
}
return true;
}
示例5: validate
import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, String s) {
if (null == s) {
context.addError(ValidationError.create(String.format("%s不能为空!", fieldName))
.setErrorCode(-1)
.setField(fieldName)
.setInvalidValue(s));
return false;
}
return true;
}
示例6: validate
import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, String str) {
if (str.startsWith("Mr")) {
//context.addErrorMsg("用户名不能以Mr开头");
context.addError(ValidationError.create("用户名不能以Mr开头").setErrorCode(100));
return false;
}
return true;
}
示例7: validate
import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, Company company) {
if (company.getId() <= 0) {
context.addErrorMsg(String.format(ErrorMsg.COMPANY_ID_INVALID.msg(), company.getId()));
return false;
}
Date date = company.getEstablishTime();
// company established time must before 2010-1-1
if (date.after(DateUtil.getDate(2010, 1, 1))) {
context.addErrorMsg(String.format(ErrorMsg.COMPANY_DATE_INVALID.msg(), date));
return false;
}
return true;
}
示例8: validate
import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, String t) {
String myname = context.getAttribute("myname", String.class);
if (myname != null && myname.equals("pass")) {
return true;
}
System.out.println("check " + t);
if (!t.startsWith("abc")) {
context.addError(ValidationError.create("string should be abc").setErrorCode(100).setField("str")
.setInvalidValue(t));
return false;
}
return true;
}
示例9: validate
import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, Integer t) {
if (t != 2 && t != 5 && t != 7) {
context.addErrorMsg(String.format(CarError.SEATCOUNT_ERROR.msg(), t));
return false;
}
return true;
}
示例10: validate
import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, Car car) {
Closure<List<String>> closure = context.getClosure("manufacturerClosure");
if (closure != null) {
List<String> manufacturers = closure.executeAndGetResult();
if (!manufacturers.contains(car.getManufacturer())) {
context.addErrorMsg(String.format(CarError.MANUFACTURER_ERROR.msg(), car.getManufacturer()));
return false;
}
}
return true;
}
示例11: validate
import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, String t) {
if (t.startsWith("NYC") || t.startsWith("LA") || t.startsWith("BEIJING")) {
if (!normalMockRpcService.isValid(t)) {
context.addErrorMsg(String.format(CarError.LICENSEPLATE_ERROR.msg(), t));
return false;
}
} else {
if (abNormalMockRpcService.isValid(t)) {
context.addErrorMsg(String.format(CarError.LICENSEPLATE_ERROR.msg(), t));
return false;
}
}
return true;
}
示例12: validate
import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, Object t) {
if (t == null) {
context.addErrorMsg("Null is not expected!");
return false;
}
return true;
}
示例13: validate
import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, Car car) {
if (car.getSeatCount() != 2 && car.getSeatCount() != 5 && car.getSeatCount() != 7) {
context.addErrorMsg(String.format(CarError.SEATCOUNT_ERROR.msg(), car.getSeatCount()));
return false;
}
return true;
}
示例14: validate
import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, String t) {
Boolean ignoreManufacturer = context.getAttribute("ignoreManufacturer", Boolean.class);
if (ignoreManufacturer != null && ignoreManufacturer) {
return true;
}
if (!manufacturerService.getAllManufacturers().contains(t)) {
context.addErrorMsg(String.format(CarError.MANUFACTURER_ERROR.msg(), t));
return false;
}
return true;
}
示例15: validate
import com.baidu.unbiz.fluentvalidator.ValidatorContext; //导入依赖的package包/类
@Override
public boolean validate(ValidatorContext context, Car car) {
if (!car.getLicensePlate().startsWith("NYC")
&& !car.getLicensePlate().startsWith("LA")
&& !car.getLicensePlate().startsWith("BEIJING")) {
context.addErrorMsg(String.format(CarError.LICENSEPLATE_ERROR.msg(), car.getLicensePlate()));
return false;
}
return true;
}