Skip to content

Commit

Permalink
[SCA] Minor SCA-based improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
ledsoft committed Apr 15, 2024
1 parent 960b41e commit ee005c7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private Class<T> resolveGenericType() {
// Adapted from https://gist.github.com/yunspace/930d4d40a787a1f6a7d1
final List<ResolvedType> typeParameters =
new TypeResolver().resolve(this.getClass()).typeParametersFor(BaseRepositoryService.class);
assert typeParameters.size() >= 1;
assert !typeParameters.isEmpty();
return (Class<T>) typeParameters.get(0).getErasedType();
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit ee005c7

Please sign in to comment.