Skip to content

Commit

Permalink
check releases when deleting a vocabulary
Browse files Browse the repository at this point in the history
  • Loading branch information
marcos-lg committed Apr 9, 2024
1 parent 7b47579 commit c3395a7
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.gbif.vocabulary.model.utils.PrePersist;
import org.gbif.vocabulary.persistence.mappers.ConceptMapper;
import org.gbif.vocabulary.persistence.mappers.VocabularyMapper;
import org.gbif.vocabulary.persistence.mappers.VocabularyReleaseMapper;
import org.gbif.vocabulary.service.VocabularyService;

import java.util.List;
Expand Down Expand Up @@ -60,11 +61,16 @@ public class DefaultVocabularyService implements VocabularyService {

private final VocabularyMapper vocabularyMapper;
private final ConceptMapper conceptMapper;
private final VocabularyReleaseMapper vocabularyReleaseMapper;

@Autowired
public DefaultVocabularyService(VocabularyMapper vocabularyMapper, ConceptMapper conceptMapper) {
public DefaultVocabularyService(
VocabularyMapper vocabularyMapper,
ConceptMapper conceptMapper,
VocabularyReleaseMapper vocabularyReleaseMapper) {
this.vocabularyMapper = vocabularyMapper;
this.conceptMapper = conceptMapper;
this.vocabularyReleaseMapper = vocabularyReleaseMapper;
}

@Override
Expand Down Expand Up @@ -242,6 +248,9 @@ public void restoreDeprecated(long key, boolean restoreDeprecatedConcepts) {
@Secured(UserRoles.VOCABULARY_ADMIN)
@Override
public void deleteVocabulary(long vocabularyKey) {
if (vocabularyReleaseMapper.count(vocabularyKey, null) > 0) {
throw new IllegalArgumentException("Can't delete a vocabulary that was already released");
}
conceptMapper.deleteAllConcepts(vocabularyKey);
vocabularyMapper.delete(vocabularyKey);
}
Expand Down

0 comments on commit c3395a7

Please sign in to comment.