Skip to content

Commit

Permalink
[Fix] Fix getReference error on vocabulary removal.
Browse files Browse the repository at this point in the history
  • Loading branch information
ledsoft committed Jul 22, 2024
1 parent 182e388 commit c3a2ccb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,10 @@ public void removeVocabulary(@Parameter(description = ApiDoc.ID_LOCAL_NAME_DESCR
@RequestParam(name = QueryParams.NAMESPACE,
required = false) Optional<String> namespace) {
final URI identifier = resolveIdentifier(namespace.orElse(config.getNamespace().getVocabulary()), localName);
final Vocabulary toRemove = vocabularyService.getReference(identifier);
vocabularyService.remove(toRemove);
LOG.debug("Vocabulary {} removed.", toRemove);
vocabularyService.find(identifier).ifPresent(toRemove -> {
vocabularyService.remove(toRemove);
LOG.debug("Vocabulary {} removed.", toRemove);
});
}

@Operation(description = "Validates the terms in a vocabulary with the specified identifier.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ public long getLastModified() {

@PreAuthorize("@vocabularyAuthorizationService.canRemove(#instance)")
@CacheEvict(allEntries = true)
@Transactional
@Override
public void remove(Vocabulary instance) {
if (instance.getDocument() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,11 @@ void getByIdUsesSpecifiedNamespaceInsteadOfDefaultOneForResolvingIdentifier() th
@Test
void removeVocabularyReturns2xxForEmptyVocabulary() throws Exception {
final Vocabulary vocabulary = Generator.generateVocabulary();
vocabulary.setUri(Generator.generateUri());
final String fragment = IdentifierResolver.extractIdentifierFragment(vocabulary.getUri());
mockMvc.perform(delete(PATH + "/" + fragment)).andExpect(status().is2xxSuccessful()).andReturn();
vocabulary.setUri(VOCABULARY_URI);
when(idResolverMock.resolveIdentifier(configMock.getNamespace().getVocabulary(), FRAGMENT))
.thenReturn(VOCABULARY_URI);
when(serviceMock.find(VOCABULARY_URI)).thenReturn(Optional.of(vocabulary));
mockMvc.perform(delete(PATH + "/" + FRAGMENT)).andExpect(status().is2xxSuccessful()).andReturn();
}

@Test
Expand All @@ -276,7 +278,10 @@ void removeVocabularyReturns4xxForNotRemovableVocabulary() throws Exception {
.when(serviceMock).remove(any());

final Vocabulary vocabulary = Generator.generateVocabulary();
vocabulary.setUri(Generator.generateUri());
vocabulary.setUri(VOCABULARY_URI);
when(idResolverMock.resolveIdentifier(configMock.getNamespace().getVocabulary(), FRAGMENT))
.thenReturn(VOCABULARY_URI);
when(serviceMock.find(vocabulary.getUri())).thenReturn(Optional.of(vocabulary));
final String fragment = IdentifierResolver.extractIdentifierFragment(vocabulary.getUri());
mockMvc.perform(delete(PATH + "/" + fragment)).andExpect(status().is4xxClientError()).andReturn();
}
Expand Down Expand Up @@ -615,7 +620,7 @@ void updateAccessControlLevelThrowsBadRequestForRecordUriNotMatchingPath() throw
record.setHolder(Generator.generateUserWithId());

mockMvc.perform(put(PATH + "/" + FRAGMENT + "/acl/records/" + Generator.randomInt())
.content(toJson(record)).contentType(MediaType.APPLICATION_JSON))
.content(toJson(record)).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());
verify(serviceMock, never()).updateAccessControlLevel(any(Vocabulary.class), any(AccessControlRecord.class));
}
Expand Down

0 comments on commit c3a2ccb

Please sign in to comment.