parent
53f6ef7cca
commit
a3aa4cc682
|
@ -31,20 +31,20 @@ public class AddCapacityInfo {
|
||||||
* The Capacity type.
|
* The Capacity type.
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "capacityType 能力类型不能为空", groups = ValidGroups.AddDeviceValid.class)
|
@NotNull(message = "capacityType 能力类型不能为空", groups = ValidGroups.AddDeviceValid.class)
|
||||||
@ValidBaseEnum(enumClass = DisposeCapacityType.class, message = "capacityType 字段取值为", groups = ValidGroups.AddDeviceValid.class)
|
@ValidBaseEnum(enumClass = DisposeCapacityType.class, groups = ValidGroups.AddDeviceValid.class)
|
||||||
private Integer capacityType;
|
private Integer capacityType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Object type.
|
* The Object type.
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "objectType 处置对象类型不能为空", groups = ValidGroups.AddDeviceValid.class)
|
@NotNull(message = "objectType 处置对象类型不能为空", groups = ValidGroups.AddDeviceValid.class)
|
||||||
@ValidBaseEnum(enumClass = DisposeObjectType.class, message = "objectType 字段取值为", groups = ValidGroups.AddDeviceValid.class)
|
@ValidBaseEnum(enumClass = DisposeObjectType.class, groups = ValidGroups.AddDeviceValid.class)
|
||||||
private Integer objectType;
|
private Integer objectType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Ip type.
|
* The Ip type.
|
||||||
*/
|
*/
|
||||||
@ValidBaseEnum(enumClass = IpAddrType.class, message = "objectType 字段取值为", groups = ValidGroups.AddDeviceValid.class)
|
@ValidBaseEnum(enumClass = IpAddrType.class, groups = ValidGroups.AddDeviceValid.class)
|
||||||
private Integer ipType;
|
private Integer ipType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,6 +16,7 @@ import lombok.NoArgsConstructor;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,8 +50,7 @@ public class AddDeviceInfo {
|
||||||
* The Device type.
|
* The Device type.
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "deviceType 设备类型不能为空", groups = ValidGroups.UpgradeDeviceValid.class)
|
@NotNull(message = "deviceType 设备类型不能为空", groups = ValidGroups.UpgradeDeviceValid.class)
|
||||||
@ValidBaseEnum(enumClass = DisposeDeviceType.class, message = "deviceType 字段取值为", groups =
|
@ValidBaseEnum(enumClass = DisposeDeviceType.class, groups = ValidGroups.UpgradeDeviceValid.class)
|
||||||
ValidGroups.UpgradeDeviceValid.class)
|
|
||||||
private Integer deviceType;
|
private Integer deviceType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,7 +99,7 @@ public class AddDeviceInfo {
|
||||||
* The Url type.
|
* The Url type.
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "urlType URL类型不能为空", groups = ValidGroups.AddDeviceValid.class)
|
@NotNull(message = "urlType URL类型不能为空", groups = ValidGroups.AddDeviceValid.class)
|
||||||
@ValidBaseEnum(enumClass = HttpType.class, message = "urlType 字段取值为", groups = ValidGroups.AddDeviceValid.class)
|
@ValidBaseEnum(enumClass = HttpType.class, groups = ValidGroups.AddDeviceValid.class)
|
||||||
private Integer urlType;
|
private Integer urlType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,6 +111,7 @@ public class AddDeviceInfo {
|
||||||
* The Capacity.
|
* The Capacity.
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "capacity 处置设备能力不能为空", groups = ValidGroups.AddDeviceValid.class)
|
@NotNull(message = "capacity 处置设备能力不能为空", groups = ValidGroups.AddDeviceValid.class)
|
||||||
|
@Size(min = 1, message = "capacity 至少需要包含一种能力", groups = ValidGroups.AddDeviceValid.class)
|
||||||
@Valid
|
@Valid
|
||||||
private List<AddCapacityInfo> capacity;
|
private List<AddCapacityInfo> capacity;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,8 +37,7 @@ public class TaskStartReq {
|
||||||
* The Type.
|
* The Type.
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "type 处置类型不能为空", groups = ValidGroups.TaskStartReqCommonValid.class)
|
@NotNull(message = "type 处置类型不能为空", groups = ValidGroups.TaskStartReqCommonValid.class)
|
||||||
@ValidBaseEnum(enumClass = DisposeCapacityType.class, message = "type 字段取值为", groups =
|
@ValidBaseEnum(enumClass = DisposeCapacityType.class, groups = ValidGroups.TaskStartReqCommonValid.class)
|
||||||
ValidGroups.TaskStartReqCommonValid.class)
|
|
||||||
private Integer type;
|
private Integer type;
|
||||||
/**
|
/**
|
||||||
* The Dispose ip.
|
* The Dispose ip.
|
||||||
|
@ -62,14 +61,12 @@ public class TaskStartReq {
|
||||||
/**
|
/**
|
||||||
* The Flow direction.
|
* The Flow direction.
|
||||||
*/
|
*/
|
||||||
@ValidBaseEnum(enumClass = NetflowDirection.class, message = "flowDirection 字段取值为", groups =
|
@ValidBaseEnum(enumClass = NetflowDirection.class, groups = ValidGroups.TaskStartReqCommonValid.class)
|
||||||
ValidGroups.TaskStartReqCommonValid.class)
|
|
||||||
private Integer flowDirection;
|
private Integer flowDirection;
|
||||||
/**
|
/**
|
||||||
* The Attack type.
|
* The Attack type.
|
||||||
*/
|
*/
|
||||||
@ValidBaseEnumArray(enumClass = DDoSAttackType.class, message = "attackType 字段取值为", groups =
|
@ValidBaseEnumArray(enumClass = DDoSAttackType.class, groups = ValidGroups.TaskStartReqCommonValid.class)
|
||||||
ValidGroups.TaskStartReqCommonValid.class)
|
|
||||||
@Size(min = 1, message = "attackType 必须指定最少一种攻击类型", groups = ValidGroups.TaskStartReqCommonValid.class)
|
@Size(min = 1, message = "attackType 必须指定最少一种攻击类型", groups = ValidGroups.TaskStartReqCommonValid.class)
|
||||||
private Integer[] attackType;
|
private Integer[] attackType;
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -33,7 +33,7 @@ public @interface ValidBaseEnum {
|
||||||
*
|
*
|
||||||
* @return the string
|
* @return the string
|
||||||
*/
|
*/
|
||||||
String message();
|
String message() default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Groups class [ ].
|
* Groups class [ ].
|
||||||
|
|
|
@ -33,7 +33,7 @@ public @interface ValidBaseEnumArray {
|
||||||
*
|
*
|
||||||
* @return the string
|
* @return the string
|
||||||
*/
|
*/
|
||||||
String message();
|
String message() default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Groups class [ ].
|
* Groups class [ ].
|
||||||
|
|
|
@ -15,11 +15,18 @@ import java.util.regex.Pattern;
|
||||||
* @author <huangxin@cmhi.chinamoblie.com>
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
*/
|
*/
|
||||||
public class ValidArrayIpAddrImpl implements ConstraintValidator<ValidArrayIpAddr, String[]> {
|
public class ValidArrayIpAddrImpl implements ConstraintValidator<ValidArrayIpAddr, String[]> {
|
||||||
|
/**
|
||||||
|
* Is valid boolean.
|
||||||
|
*
|
||||||
|
* @param strings the strings
|
||||||
|
* @param constraintValidatorContext the constraint validator context
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(String[] strings, ConstraintValidatorContext constraintValidatorContext) {
|
public boolean isValid(String[] strings, ConstraintValidatorContext constraintValidatorContext) {
|
||||||
|
|
||||||
if (strings == null || strings.length == 0) {
|
if (strings == null || strings.length == 0) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String s : strings) {
|
for (String s : strings) {
|
||||||
|
@ -43,6 +50,11 @@ public class ValidArrayIpAddrImpl implements ConstraintValidator<ValidArrayIpAdd
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize.
|
||||||
|
*
|
||||||
|
* @param constraintAnnotation the constraint annotation
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void initialize(ValidArrayIpAddr constraintAnnotation) {
|
public void initialize(ValidArrayIpAddr constraintAnnotation) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.dispose.validation.valids.impl;
|
||||||
|
|
||||||
import com.dispose.common.BaseEnum;
|
import com.dispose.common.BaseEnum;
|
||||||
import com.dispose.validation.valids.ValidBaseEnumArray;
|
import com.dispose.validation.valids.ValidBaseEnumArray;
|
||||||
|
import org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorContextImpl;
|
||||||
|
|
||||||
import javax.validation.ConstraintValidator;
|
import javax.validation.ConstraintValidator;
|
||||||
import javax.validation.ConstraintValidatorContext;
|
import javax.validation.ConstraintValidatorContext;
|
||||||
|
@ -10,7 +11,7 @@ import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Valid custom base enum array.
|
* The type Valid base enum array.
|
||||||
*
|
*
|
||||||
* @author <huangxin@cmhi.chinamoblie.com>
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
*/
|
*/
|
||||||
|
@ -40,18 +41,28 @@ public class ValidBaseEnumArrayImpl implements ConstraintValidator<ValidBaseEnum
|
||||||
* Is valid boolean.
|
* Is valid boolean.
|
||||||
*
|
*
|
||||||
* @param integers the integers
|
* @param integers the integers
|
||||||
* @param constraintValidatorContext the constraint validator context
|
* @param ctx the ctx
|
||||||
* @return the boolean
|
* @return the boolean
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(Integer[] integers, ConstraintValidatorContext constraintValidatorContext) {
|
public boolean isValid(Integer[] integers, ConstraintValidatorContext ctx) {
|
||||||
constraintValidatorContext.disableDefaultConstraintViolation();
|
|
||||||
List<Integer> enumValues =
|
|
||||||
Arrays.stream(enumClass.getEnumConstants()).map(BaseEnum::getValue).collect(Collectors.toList());
|
|
||||||
|
|
||||||
String errMsg = this.message + " " + enumValues.toString();
|
// null 与 空元素,由其它校验器处理
|
||||||
|
if (integers == null || integers.length == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
constraintValidatorContext.buildConstraintViolationWithTemplate(errMsg).addConstraintViolation();
|
List<Integer> enumValues = Arrays.stream(enumClass.getEnumConstants())
|
||||||
|
.map(BaseEnum::getValue).collect(Collectors.toList());
|
||||||
|
|
||||||
|
String errMsg = this.message +
|
||||||
|
((ConstraintValidatorContextImpl) ctx).getConstraintViolationCreationContexts()
|
||||||
|
.get(0).getPath().getLeafNode().getName()
|
||||||
|
+ " 字段取值范围:" + enumValues.toString();
|
||||||
|
|
||||||
|
// 重新设置消息
|
||||||
|
ctx.disableDefaultConstraintViolation();
|
||||||
|
ctx.buildConstraintViolationWithTemplate(errMsg).addConstraintViolation();
|
||||||
|
|
||||||
return Arrays.stream(integers).allMatch(enumValues::contains);
|
return Arrays.stream(integers).allMatch(enumValues::contains);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.dispose.validation.valids.impl;
|
||||||
import com.dispose.common.BaseEnum;
|
import com.dispose.common.BaseEnum;
|
||||||
import com.dispose.validation.valids.ValidBaseEnum;
|
import com.dispose.validation.valids.ValidBaseEnum;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorContextImpl;
|
||||||
|
|
||||||
import javax.validation.ConstraintValidator;
|
import javax.validation.ConstraintValidator;
|
||||||
import javax.validation.ConstraintValidatorContext;
|
import javax.validation.ConstraintValidatorContext;
|
||||||
|
@ -43,18 +44,28 @@ public class ValidBaseEnumImpl implements ConstraintValidator<ValidBaseEnum, Int
|
||||||
* Is valid boolean.
|
* Is valid boolean.
|
||||||
*
|
*
|
||||||
* @param integer the integer
|
* @param integer the integer
|
||||||
* @param constraintValidatorContext the constraint validator context
|
* @param ctx the constraint validator context
|
||||||
* @return the boolean
|
* @return the boolean
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(Integer integer, ConstraintValidatorContext constraintValidatorContext) {
|
public boolean isValid(Integer integer, ConstraintValidatorContext ctx) {
|
||||||
constraintValidatorContext.disableDefaultConstraintViolation();
|
|
||||||
List<Integer> enumValues =
|
|
||||||
Arrays.stream(enumClass.getEnumConstants()).map(BaseEnum::getValue).collect(Collectors.toList());
|
|
||||||
|
|
||||||
String errMsg = this.message + " " + enumValues.toString();
|
// null 由其它校验器处理
|
||||||
|
if (integer == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
constraintValidatorContext.buildConstraintViolationWithTemplate(errMsg).addConstraintViolation();
|
List<Integer> enumValues = Arrays.stream(enumClass.getEnumConstants())
|
||||||
|
.map(BaseEnum::getValue).collect(Collectors.toList());
|
||||||
|
|
||||||
|
String errMsg = this.message +
|
||||||
|
((ConstraintValidatorContextImpl) ctx).getConstraintViolationCreationContexts()
|
||||||
|
.get(0).getPath().getLeafNode().getName()
|
||||||
|
+ " 字段取值范围:" + enumValues.toString();
|
||||||
|
|
||||||
|
// 重新设置消息
|
||||||
|
ctx.disableDefaultConstraintViolation();
|
||||||
|
ctx.buildConstraintViolationWithTemplate(errMsg).addConstraintViolation();
|
||||||
|
|
||||||
return enumValues.contains(integer);
|
return enumValues.contains(integer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class ValidIpAddrImpl implements ConstraintValidator<ValidIpAddr, String>
|
||||||
public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
|
public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
|
||||||
|
|
||||||
if(s == null || s.length() == 0) {
|
if(s == null || s.length() == 0) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Pattern.matches(ConstValue.IP_ADDR_REG, s)) {
|
if (!Pattern.matches(ConstValue.IP_ADDR_REG, s)) {
|
||||||
|
|
|
@ -33,6 +33,10 @@ public class ValidIpPortImpl implements ConstraintValidator<ValidIpPort, String>
|
||||||
final int minSocketPort = 1;
|
final int minSocketPort = 1;
|
||||||
final int maxSocketPort = 65535;
|
final int maxSocketPort = 65535;
|
||||||
|
|
||||||
|
if (s == null || s.length() == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int port = Integer.parseInt(s);
|
int port = Integer.parseInt(s);
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class ValidIpSegmentImpl implements ConstraintValidator<ValidIpSegment, S
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(String str, ConstraintValidatorContext constraintValidatorContext) {
|
public boolean isValid(String str, ConstraintValidatorContext constraintValidatorContext) {
|
||||||
if (str == null || str.length() == 0) {
|
if (str == null || str.length() == 0) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String s : str.split(DisposeConfigValue.SPLIT_CHAR)) {
|
for (String s : str.split(DisposeConfigValue.SPLIT_CHAR)) {
|
||||||
|
|
Loading…
Reference in New Issue