From 70c94c5bdc8fa09ef6046442608da9c9e1f87739 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Wed, 17 Jan 2024 12:04:33 +0200 Subject: [PATCH] update validator package --- dmp-backend/core/pom.xml | 2 +- dmp-backend/pom.xml | 2 +- .../ValidatorRequestBodyAdvice.java | 61 ------------------- 3 files changed, 2 insertions(+), 63 deletions(-) delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/controllers/controllerhandler/ValidatorRequestBodyAdvice.java 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