diff --git a/dmp-backend/core/pom.xml b/dmp-backend/core/pom.xml index 331016e96..286d048f7 100644 --- a/dmp-backend/core/pom.xml +++ b/dmp-backend/core/pom.xml @@ -32,7 +32,7 @@ gr.cite validation - 3.0.0 + 3.0.1 gr.cite diff --git a/dmp-backend/pom.xml b/dmp-backend/pom.xml index 62751f2d5..a84638b7f 100644 --- a/dmp-backend/pom.xml +++ b/dmp-backend/pom.xml @@ -330,7 +330,7 @@ gr.cite validation - 3.0.0 + 3.0.1 gr.cite diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/controllerhandler/ValidatorRequestBodyAdvice.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/controllerhandler/ValidatorRequestBodyAdvice.java deleted file mode 100644 index b22398f06..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/controllerhandler/ValidatorRequestBodyAdvice.java +++ /dev/null @@ -1,61 +0,0 @@ -package eu.eudat.controllers.controllerhandler; - -import gr.cite.tools.exception.MyApplicationException; -import gr.cite.tools.validation.ValidationFilterAnnotation; -import gr.cite.tools.validation.Validator; -import gr.cite.tools.validation.ValidatorFactory; -import org.jetbrains.annotations.NotNull; -import org.springframework.core.MethodParameter; -import org.springframework.http.HttpInputMessage; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.RestControllerAdvice; -import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice; - -import java.io.IOException; -import java.lang.reflect.Type; -import java.util.Objects; - -@ControllerAdvice -@RestControllerAdvice -public class ValidatorRequestBodyAdvice implements RequestBodyAdvice { - private final ValidatorFactory validatorFactory; - - public ValidatorRequestBodyAdvice(ValidatorFactory validatorFactory) { - this.validatorFactory = validatorFactory; - } - - @Override - public @NotNull Object afterBodyRead(@NotNull Object body, @NotNull HttpInputMessage inputMessage, MethodParameter parameter, @NotNull Type targetType, - @NotNull Class> converterType) { - if (parameter.getMethod() != null) { - ValidationFilterAnnotation[] annotations = parameter.getMethod().getAnnotationsByType((ValidationFilterAnnotation.class)); - - if (annotations == null) return body; - for (ValidationFilterAnnotation annotation : annotations){ - if (!Objects.equals(parameter.getParameterName(), annotation.argumentName())) continue; - - Validator validator = validatorFactory.validator(annotation.validator()); - if (validator == null) throw new MyApplicationException("validator not provided"); - - validator.validateForce(body); - } - } - return body; - } - - @Override - public Object handleEmptyBody(Object body, @NotNull HttpInputMessage inputMessage, @NotNull MethodParameter parameter, @NotNull Type targetType, @NotNull Class> converterType) { - return body; - } - - @Override - public boolean supports(MethodParameter parameter, @NotNull Type targetType, @NotNull Class> converterType) { - return parameter.getMethod() != null && parameter.getMethod().isAnnotationPresent((ValidationFilterAnnotation.class)); - } - - @Override - public @NotNull HttpInputMessage beforeBodyRead(@NotNull HttpInputMessage inputMessage, @NotNull MethodParameter parameter, @NotNull Type targetType, @NotNull Class> converterType) throws IOException { - return inputMessage; - } -} \ No newline at end of file