From 4e01c2a0900a1134c7249c7c231d3908dd1f4ba1 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 15 Jan 2025 13:27:04 +0100 Subject: [PATCH] remove unused EntityExistsValidator --- .../debitor/HsOfficeDebitorController.java | 4 -- .../persistence/EntityExistsValidator.java | 38 ------------------- 2 files changed, 42 deletions(-) delete mode 100644 src/main/java/net/hostsharing/hsadminng/persistence/EntityExistsValidator.java diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java index 6b7dc93e..2e0ff210 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java @@ -12,7 +12,6 @@ import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealRepository; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealRepository; import net.hostsharing.hsadminng.mapper.StrictMapper; -import net.hostsharing.hsadminng.persistence.EntityExistsValidator; import org.apache.commons.lang3.Validate; import org.hibernate.Hibernate; import org.springframework.beans.factory.annotation.Autowired; @@ -57,9 +56,6 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi { @Autowired private HsOfficeBankAccountRepository bankAccountRepo; - @Autowired - private EntityExistsValidator entityValidator; - @PersistenceContext private EntityManager em; diff --git a/src/main/java/net/hostsharing/hsadminng/persistence/EntityExistsValidator.java b/src/main/java/net/hostsharing/hsadminng/persistence/EntityExistsValidator.java deleted file mode 100644 index 1b29e007..00000000 --- a/src/main/java/net/hostsharing/hsadminng/persistence/EntityExistsValidator.java +++ /dev/null @@ -1,38 +0,0 @@ -package net.hostsharing.hsadminng.persistence; - -import net.hostsharing.hsadminng.errors.DisplayAs.DisplayName; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import jakarta.persistence.Entity; -import jakarta.validation.ValidationException; - -@Service -public class EntityExistsValidator { - - @Autowired - private EntityManagerWrapper em; - - public > void validateEntityExists(final String property, final T entitySkeleton) { - final var foundEntity = em.find(entityClass(entitySkeleton), entitySkeleton.getUuid()); - if ( foundEntity == null) { - throw new ValidationException("Unable to find " + DisplayName.of(entitySkeleton) + " by " + property + ": " + entitySkeleton.getUuid()); - } - } - - private static > Class entityClass(final T entityOrProxy) { - final var entityClass = entityClass(entityOrProxy.getClass()); - if (entityClass == null) { - throw new IllegalArgumentException("@Entity not found in superclass hierarchy of " + entityOrProxy.getClass()); - } - return entityClass; - } - - private static Class entityClass(final Class entityOrProxyClass) { - return entityOrProxyClass.isAnnotationPresent(Entity.class) - ? entityOrProxyClass - : entityOrProxyClass.getSuperclass() == null - ? null - : entityClass(entityOrProxyClass.getSuperclass()); - } -}