T203 added javadoc
This commit is contained in:
@@ -7,7 +7,11 @@ import java.lang.annotation.Retention;
|
|||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
//TODO: Find usage and document or remove it
|
/**
|
||||||
|
* Annotation interface that is used to annotate Integer fields that contain http status values.
|
||||||
|
* It provides validation and throws an error when trying to send response with incorrect status.
|
||||||
|
* @author Rafał Żukowicz
|
||||||
|
*/
|
||||||
@Target({ ElementType.FIELD})
|
@Target({ ElementType.FIELD})
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Constraint(validatedBy = HttpCodeValidation.class )
|
@Constraint(validatedBy = HttpCodeValidation.class )
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.release11.klaus.model.constraints;
|
package com.release11.klaus.model.constraints;
|
||||||
|
|
||||||
|
import com.release11.klaus.model.MockedMessage;
|
||||||
|
import com.release11.klaus.model.MockedMessageDto;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
||||||
import javax.validation.ConstraintValidator;
|
import javax.validation.ConstraintValidator;
|
||||||
@@ -8,10 +10,18 @@ import java.util.Set;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
//TODO: Find usage and document or remove it
|
/**
|
||||||
|
* It's validator class. It checks if status value of {@link com.release11.klaus.model.MockedMessageDto} is within bonds of http status values map.
|
||||||
|
* @author Rafał Żukowicz
|
||||||
|
*/
|
||||||
public class HttpCodeValidation implements ConstraintValidator<HttpCode, Integer> {
|
public class HttpCodeValidation implements ConstraintValidator<HttpCode, Integer> {
|
||||||
private Set<Integer> allowedValues;
|
private Set<Integer> allowedValues;
|
||||||
|
|
||||||
|
//TODO: Find use of targetEnum
|
||||||
|
/**
|
||||||
|
* Initializes {@link #allowedValues} with possible http status values.
|
||||||
|
* @param targetEnum HttpCode context
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void initialize(HttpCode targetEnum) {
|
public void initialize(HttpCode targetEnum) {
|
||||||
allowedValues = Stream.of(HttpStatus.values())
|
allowedValues = Stream.of(HttpStatus.values())
|
||||||
@@ -19,6 +29,12 @@ public class HttpCodeValidation implements ConstraintValidator<HttpCode, Integer
|
|||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: Find use of ConstraintValidatorContext
|
||||||
|
/**
|
||||||
|
* @param integer value of {@link MockedMessageDto#getHttpStatus()} or {@link MockedMessage#getHttpStatus()}
|
||||||
|
* @param context context for validation
|
||||||
|
* @return true if valid
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(Integer integer, ConstraintValidatorContext context) {
|
public boolean isValid(Integer integer, ConstraintValidatorContext context) {
|
||||||
return allowedValues.contains(integer);
|
return allowedValues.contains(integer);
|
||||||
|
|||||||
Reference in New Issue
Block a user