From 125f174b3b2a8196bbdbacbae42cdb5ceaebf7d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=A4ume?= Date: Wed, 9 Oct 2024 09:58:43 +0200 Subject: [PATCH] PMT-16: Update Manual Validation Method of Projects to Include the builtin. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dominik Säume --- src/main/java/de/hmmh/pmt/db/Project.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/hmmh/pmt/db/Project.java b/src/main/java/de/hmmh/pmt/db/Project.java index c66731a..0a70189 100644 --- a/src/main/java/de/hmmh/pmt/db/Project.java +++ b/src/main/java/de/hmmh/pmt/db/Project.java @@ -1,6 +1,9 @@ package de.hmmh.pmt.db; import jakarta.persistence.*; +import jakarta.validation.ConstraintViolation; +import jakarta.validation.Validation; +import jakarta.validation.Validator; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; @@ -10,6 +13,7 @@ import lombok.NoArgsConstructor; import lombok.Setter; import java.time.LocalDateTime; +import java.util.Set; @NoArgsConstructor @AllArgsConstructor @@ -46,7 +50,13 @@ public class Project { public boolean isValid() { - return plannedEnd.isAfter(start) && (realEnd == null || realEnd.isAfter(start)); + Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); + Set> violations = validator.validate(this); + + return violations.isEmpty() && + plannedEnd.isAfter(start) && + (realEnd == null || realEnd.isAfter(start)); } + }