From bb1ffb8bfd4bfdeec097531a763f4e05bf22a9b4 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 17 Oct 2021 15:44:09 +0200 Subject: [PATCH] bugfixes --- executor-pool/pom.xml | 6 ---- .../java/ch/unisg/common/SelfValidating.java | 30 +++++++++++++++++++ .../AddNewExecutorToExecutorPoolCommand.java | 2 +- ...tAllExecutorInExecutorPoolByTypeQuery.java | 2 +- ...RemoveExecutorFromExecutorPoolCommand.java | 2 +- .../Executor1ApplicationTests.java} | 4 +-- 6 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 executor-pool/src/main/java/ch/unisg/common/SelfValidating.java rename executor1/src/test/java/ch/unisg/{executor2/Executor2ApplicationTests.java => executor1/Executor1ApplicationTests.java} (70%) diff --git a/executor-pool/pom.xml b/executor-pool/pom.xml index 59d5b2a..850b2e1 100644 --- a/executor-pool/pom.xml +++ b/executor-pool/pom.xml @@ -54,12 +54,6 @@ jakarta.validation jakarta.validation-api - - ch.unisg - tapas-tasks - 0.0.1-SNAPSHOT - compile - javax.transaction javax.transaction-api diff --git a/executor-pool/src/main/java/ch/unisg/common/SelfValidating.java b/executor-pool/src/main/java/ch/unisg/common/SelfValidating.java new file mode 100644 index 0000000..cacf16e --- /dev/null +++ b/executor-pool/src/main/java/ch/unisg/common/SelfValidating.java @@ -0,0 +1,30 @@ +package ch.unisg.common; + +import javax.validation.ConstraintViolation; +import javax.validation.ConstraintViolationException; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; +import java.util.Set; + +public class SelfValidating { + + private Validator validator; + + public SelfValidating() { + ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); + validator = factory.getValidator(); + } + + /** + * Evaluates all Bean Validations on the attributes of this + * instance. + */ + protected void validateSelf() { + @SuppressWarnings("unchecked") + Set> violations = validator.validate((T) this); + if (!violations.isEmpty()) { + throw new ConstraintViolationException(violations); + } + } +} diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/AddNewExecutorToExecutorPoolCommand.java b/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/AddNewExecutorToExecutorPoolCommand.java index 26b495e..2682610 100644 --- a/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/AddNewExecutorToExecutorPoolCommand.java +++ b/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/AddNewExecutorToExecutorPoolCommand.java @@ -1,7 +1,7 @@ package ch.unisg.executorpool.application.port.in; +import ch.unisg.common.SelfValidating; import ch.unisg.executorpool.domain.ExecutorPool; -import ch.unisg.tapastasks.common.SelfValidating; import ch.unisg.executorpool.domain.ExecutorClass.ExecutorIp; import ch.unisg.executorpool.domain.ExecutorClass.ExecutorPort; import ch.unisg.executorpool.domain.ExecutorClass.ExecutorTaskType; diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/GetAllExecutorInExecutorPoolByTypeQuery.java b/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/GetAllExecutorInExecutorPoolByTypeQuery.java index 509dba5..c812eab 100644 --- a/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/GetAllExecutorInExecutorPoolByTypeQuery.java +++ b/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/GetAllExecutorInExecutorPoolByTypeQuery.java @@ -1,7 +1,7 @@ package ch.unisg.executorpool.application.port.in; import ch.unisg.executorpool.domain.ExecutorClass.ExecutorTaskType; -import ch.unisg.tapastasks.common.SelfValidating; +import ch.unisg.common.SelfValidating; import lombok.Value; import javax.validation.constraints.NotNull; diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/RemoveExecutorFromExecutorPoolCommand.java b/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/RemoveExecutorFromExecutorPoolCommand.java index a35b9ed..11763a9 100644 --- a/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/RemoveExecutorFromExecutorPoolCommand.java +++ b/executor-pool/src/main/java/ch/unisg/executorpool/application/port/in/RemoveExecutorFromExecutorPoolCommand.java @@ -1,7 +1,7 @@ package ch.unisg.executorpool.application.port.in; import ch.unisg.executorpool.domain.ExecutorClass; -import ch.unisg.tapastasks.common.SelfValidating; +import ch.unisg.common.SelfValidating; import ch.unisg.executorpool.domain.ExecutorClass.ExecutorIp; import ch.unisg.executorpool.domain.ExecutorClass.ExecutorPort; import lombok.Value; diff --git a/executor1/src/test/java/ch/unisg/executor2/Executor2ApplicationTests.java b/executor1/src/test/java/ch/unisg/executor1/Executor1ApplicationTests.java similarity index 70% rename from executor1/src/test/java/ch/unisg/executor2/Executor2ApplicationTests.java rename to executor1/src/test/java/ch/unisg/executor1/Executor1ApplicationTests.java index 5724a1c..889c9cd 100644 --- a/executor1/src/test/java/ch/unisg/executor2/Executor2ApplicationTests.java +++ b/executor1/src/test/java/ch/unisg/executor1/Executor1ApplicationTests.java @@ -1,10 +1,10 @@ -package ch.unisg.executor2; +package ch.unisg.executor1; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest -class Executor2ApplicationTests { +class Executor1ApplicationTests { @Test void contextLoads() {