update to current version
all initial features implemented tbd: etrack front
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.release11.klaus.model.constraints;
|
||||
|
||||
import javax.validation.Constraint;
|
||||
import javax.validation.Payload;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
@Target({ ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Constraint(validatedBy = HttpCodeValidation.class )
|
||||
public @interface HttpCode {
|
||||
String message() default "must be a valid http code";
|
||||
|
||||
Class<?>[] groups() default { };
|
||||
Class<? extends Payload>[] payload() default { };
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.release11.klaus.model.constraints;
|
||||
|
||||
import com.release11.klaus.repository.MockedResponseRepository;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import javax.validation.ConstraintValidator;
|
||||
import javax.validation.ConstraintValidatorContext;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class HttpCodeValidation implements ConstraintValidator<HttpCode, Integer> {
|
||||
private Set<Integer> allowedValues;
|
||||
|
||||
@Override
|
||||
public void initialize(HttpCode targetEnum) {
|
||||
allowedValues = Stream.of(HttpStatus.values())
|
||||
.map(HttpStatus::value)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(Integer integer, ConstraintValidatorContext context) {
|
||||
return allowedValues.contains(integer);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user