Skip to content

Commit

Permalink
73 add checkArchived method (#78)
Browse files Browse the repository at this point in the history
Co-authored-by: KABOPOK <[email protected]>
  • Loading branch information
KABOPOK and KABOPOK authored Nov 5, 2024
1 parent e1ff9f9 commit c17820b
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,4 +19,10 @@ protected static <T> T getOrThrow(UUID id, Function<UUID, Optional<T>> function
return function.apply(id).orElseThrow(() -> new EntityNotFoundException(format(NOT_FOUND, id)));
}

protected static <T> void checkArchived(UUID id, T entity) {
if (entity instanceof ArchivedEntity && ((ArchivedEntity) entity).isArchived()) {
throw new EntityNotFoundException(format(NOT_FOUND + "because archived", id));
}
}

}

0 comments on commit c17820b

Please sign in to comment.