From c17820b5980a969367d6fd08397e919a63393949 Mon Sep 17 00:00:00 2001 From: KABOPOK <104580781+KABOPOK@users.noreply.github.com> Date: Tue, 5 Nov 2024 22:58:55 +0300 Subject: [PATCH] 73 add checkArchived method (#78) Co-authored-by: KABOPOK --- .../agroscience/fields/v2/services/DefaultService.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/agroscience/fields/v2/services/DefaultService.java b/src/main/java/agroscience/fields/v2/services/DefaultService.java index 4a72a4a..61faff9 100644 --- a/src/main/java/agroscience/fields/v2/services/DefaultService.java +++ b/src/main/java/agroscience/fields/v2/services/DefaultService.java @@ -2,6 +2,7 @@ import static java.lang.String.format; +import agroscience.fields.v2.entities.ArchivedEntity; import jakarta.persistence.EntityNotFoundException; import java.util.Optional; import java.util.UUID; @@ -18,4 +19,10 @@ protected static T getOrThrow(UUID id, Function> function return function.apply(id).orElseThrow(() -> new EntityNotFoundException(format(NOT_FOUND, id))); } + protected static void checkArchived(UUID id, T entity) { + if (entity instanceof ArchivedEntity && ((ArchivedEntity) entity).isArchived()) { + throw new EntityNotFoundException(format(NOT_FOUND + "because archived", id)); + } + } + } \ No newline at end of file