diff --git a/pom.xml b/pom.xml index 63890f661..3a08b4394 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ 2.7.0 1.5.5.Final 2.2.0 - 1.1.2 + 1.1.3 0.13.2 1.9.20 diff --git a/src/main/java/cz/cvut/kbss/termit/service/business/VocabularyService.java b/src/main/java/cz/cvut/kbss/termit/service/business/VocabularyService.java index eed1b9b39..82c354228 100644 --- a/src/main/java/cz/cvut/kbss/termit/service/business/VocabularyService.java +++ b/src/main/java/cz/cvut/kbss/termit/service/business/VocabularyService.java @@ -198,9 +198,14 @@ public Set getRelatedVocabularies(Vocabulary entity) { * matching the one in the imported data * already exists */ + @Transactional @PreAuthorize("@vocabularyAuthorizationService.canCreate()") public Vocabulary importVocabulary(boolean rename, MultipartFile file) { - return repositoryService.importVocabulary(rename, file); + final Vocabulary imported = repositoryService.importVocabulary(rename, file); + final AccessControlList acl = aclService.createFor(imported); + imported.setAcl(acl.getUri()); + eventPublisher.publishEvent(new VocabularyCreatedEvent(imported)); + return imported; } /** diff --git a/src/test/java/cz/cvut/kbss/termit/service/repository/VocabularyServiceTest.java b/src/test/java/cz/cvut/kbss/termit/service/repository/VocabularyServiceTest.java index a44bcf043..1ddd672d9 100644 --- a/src/test/java/cz/cvut/kbss/termit/service/repository/VocabularyServiceTest.java +++ b/src/test/java/cz/cvut/kbss/termit/service/repository/VocabularyServiceTest.java @@ -14,6 +14,7 @@ import cz.cvut.kbss.termit.model.acl.AccessLevel; import cz.cvut.kbss.termit.model.acl.UserAccessControlRecord; import cz.cvut.kbss.termit.model.changetracking.AbstractChangeRecord; +import cz.cvut.kbss.termit.model.util.HasIdentifier; import cz.cvut.kbss.termit.persistence.context.VocabularyContextMapper; import cz.cvut.kbss.termit.persistence.snapshot.SnapshotCreator; import cz.cvut.kbss.termit.service.business.AccessControlListService; @@ -25,12 +26,17 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; +import org.mockito.InOrder; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEventPublisher; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.web.multipart.MultipartFile; +import java.nio.charset.StandardCharsets; import java.util.*; import static cz.cvut.kbss.termit.environment.Environment.termsToDtos; @@ -301,4 +307,36 @@ void createSnapshotClonesAccessControlListForNewVocabulary() { verify(aclService).clone(originalAcl); assertEquals(cloneAcl.getUri(), snapshotVoc.getAcl()); } + + @Test + void importNewVocabularyCreatesAccessControlListForImportedVocabulary() { + final MultipartFile fileToImport = new MockMultipartFile("test.ttl", "content to import".getBytes( + StandardCharsets.UTF_8)); + final Vocabulary persisted = Generator.generateVocabularyWithId(); + when(repositoryService.importVocabulary(anyBoolean(), any(MultipartFile.class))).thenReturn(persisted); + final AccessControlList acl = Generator.generateAccessControlList(false); + when(aclService.createFor(any(HasIdentifier.class))).thenReturn(acl); + + sut.importVocabulary(false, fileToImport); + final InOrder inOrder = inOrder(repositoryService, aclService); + inOrder.verify(repositoryService).importVocabulary(false, fileToImport); + inOrder.verify(aclService).createFor(persisted); + assertEquals(acl.getUri(), persisted.getAcl()); + } + + @Test + void importNewVocabularyPublishesVocabularyCreatedEvent() { + final MultipartFile fileToImport = new MockMultipartFile("test.ttl", "content to import".getBytes( + StandardCharsets.UTF_8)); + final Vocabulary persisted = Generator.generateVocabularyWithId(); + when(repositoryService.importVocabulary(anyBoolean(), any(MultipartFile.class))).thenReturn(persisted); + final AccessControlList acl = Generator.generateAccessControlList(false); + when(aclService.createFor(any(HasIdentifier.class))).thenReturn(acl); + + sut.importVocabulary(false, fileToImport); + final ArgumentCaptor captor = ArgumentCaptor.forClass(ApplicationEvent.class); + verify(eventPublisher).publishEvent(captor.capture()); + assertInstanceOf(VocabularyCreatedEvent.class, captor.getValue()); + assertEquals(persisted, captor.getValue().getSource()); + } }