diff --git a/src/main/java/cz/cvut/kbss/termit/service/repository/BaseRepositoryService.java b/src/main/java/cz/cvut/kbss/termit/service/repository/BaseRepositoryService.java index d64aaec7c..ee983b752 100644 --- a/src/main/java/cz/cvut/kbss/termit/service/repository/BaseRepositoryService.java +++ b/src/main/java/cz/cvut/kbss/termit/service/repository/BaseRepositoryService.java @@ -152,7 +152,7 @@ private Class resolveGenericType() { // Adapted from https://gist.github.com/yunspace/930d4d40a787a1f6a7d1 final List typeParameters = new TypeResolver().resolve(this.getClass()).typeParametersFor(BaseRepositoryService.class); - assert typeParameters.size() >= 1; + assert !typeParameters.isEmpty(); return (Class) typeParameters.get(0).getErasedType(); } @@ -230,10 +230,9 @@ protected void preUpdate(@NonNull T instance) { } /** - * Override this method to plug custom behavior into the transactional cycle of {@link #update(HasIdentifier)} )}. + * Override this method to plug custom behavior into the transactional cycle of {@link #update(HasIdentifier)}. * - * @param instance The updated instance which will be returned by {@link #update(HasIdentifier)} )}, not {@code - * null} + * @param instance The updated instance which will be returned by {@link #update(HasIdentifier)}, not {@code null} */ protected void postUpdate(@NonNull T instance) { // Do nothing diff --git a/src/main/java/cz/cvut/kbss/termit/service/repository/ResourceRepositoryService.java b/src/main/java/cz/cvut/kbss/termit/service/repository/ResourceRepositoryService.java index d4aea03bf..4bdd88dad 100644 --- a/src/main/java/cz/cvut/kbss/termit/service/repository/ResourceRepositoryService.java +++ b/src/main/java/cz/cvut/kbss/termit/service/repository/ResourceRepositoryService.java @@ -27,6 +27,7 @@ import cz.cvut.kbss.termit.persistence.dao.TermOccurrenceDao; import cz.cvut.kbss.termit.service.IdentifierResolver; import cz.cvut.kbss.termit.util.Configuration; +import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -72,7 +73,7 @@ protected Resource mapToDto(Resource entity) { } @Override - protected void prePersist(Resource instance) { + protected void prePersist(@NotNull Resource instance) { super.prePersist(instance); if (instance.getUri() == null) { instance.setUri(idResolver.generateIdentifier(cfgNamespace.getResource(), instance.getLabel())); @@ -97,17 +98,16 @@ public void persist(Resource resource, Vocabulary vocabulary) { } @Override - protected void preRemove(Resource instance) { + protected void preRemove(@NotNull Resource instance) { LOG.trace("Removing term occurrences in resource {} which is about to be removed.", instance); termOccurrenceDao.removeAll(instance); removeFromParentDocumentIfFile(instance); } private void removeFromParentDocumentIfFile(Resource instance) { - if (!(instance instanceof File)) { + if (!(instance instanceof File file)) { return; } - final File file = (File) instance; final Document parent = file.getDocument(); if (parent != null) { LOG.trace("Removing file {} from its parent document {}.", instance, parent); diff --git a/src/main/java/cz/cvut/kbss/termit/service/repository/TermRepositoryService.java b/src/main/java/cz/cvut/kbss/termit/service/repository/TermRepositoryService.java index 57c642a36..f9b09a1b7 100644 --- a/src/main/java/cz/cvut/kbss/termit/service/repository/TermRepositoryService.java +++ b/src/main/java/cz/cvut/kbss/termit/service/repository/TermRepositoryService.java @@ -125,7 +125,7 @@ private void pruneEmptyTranslations(Term instance) { } @Override - protected void postUpdate(Term instance) { + protected void postUpdate(@NotNull Term instance) { final Vocabulary vocabulary = vocabularyService.getRequiredReference(instance.getVocabulary()); if (instance.hasParentInSameVocabulary()) { vocabulary.getGlossary().removeRootTerm(instance); @@ -427,7 +427,7 @@ protected void preRemove(@NotNull Term instance) { } @Override - protected void postRemove(Term instance) { + protected void postRemove(@NotNull Term instance) { super.postRemove(instance); if (!instance.hasParentInSameVocabulary()) { final Vocabulary v = vocabularyService.findRequired(instance.getVocabulary()); diff --git a/src/main/java/cz/cvut/kbss/termit/service/repository/UserRepositoryService.java b/src/main/java/cz/cvut/kbss/termit/service/repository/UserRepositoryService.java index 4437cc833..3daf1bb1d 100644 --- a/src/main/java/cz/cvut/kbss/termit/service/repository/UserRepositoryService.java +++ b/src/main/java/cz/cvut/kbss/termit/service/repository/UserRepositoryService.java @@ -23,6 +23,7 @@ import cz.cvut.kbss.termit.persistence.dao.UserAccountDao; import cz.cvut.kbss.termit.service.IdentifierResolver; import cz.cvut.kbss.termit.util.Configuration; +import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; @@ -72,13 +73,13 @@ protected UserAccount mapToDto(UserAccount entity) { } @Override - protected UserAccount postLoad(UserAccount instance) { + protected UserAccount postLoad(@NotNull UserAccount instance) { instance.erasePassword(); return instance; } @Override - protected void prePersist(UserAccount instance) { + protected void prePersist(@NotNull UserAccount instance) { super.prePersist(instance); if (instance.getUri() == null) { instance.setUri(idResolver @@ -90,7 +91,7 @@ protected void prePersist(UserAccount instance) { } @Override - protected void preUpdate(UserAccount instance) { + protected void preUpdate(@NotNull UserAccount instance) { final UserAccount original = userAccountDao.find(instance.getUri()).orElseThrow( () -> new NotFoundException("User " + instance + " does not exist.")); if (instance.getPassword() != null) {