Search in sources :

Example 1 with JGitRepoManager

use of de.catma.repository.git.managers.JGitRepoManager in project catma by forTEXT.

the class JsonLdWebAnnotationTest method serialize.

@Test
public void serialize() throws Exception {
    try (JGitRepoManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
        this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
        HashMap<String, Object> getJsonLdWebAnnotationResult = JsonLdWebAnnotationTest.getJsonLdWebAnnotation(jGitRepoManager, this.gitLabServerManager, this.catmaUser);
        this.projectsToDeleteOnTearDown.add((String) getJsonLdWebAnnotationResult.get("projectUuid"));
        JsonLdWebAnnotation jsonLdWebAnnotation = (JsonLdWebAnnotation) getJsonLdWebAnnotationResult.get("jsonLdWebAnnotation");
        String serialized = new SerializationHelper<JsonLdWebAnnotation>().serialize(jsonLdWebAnnotation);
        String expectedSerializedRepresentation = JsonLdWebAnnotationTest.EXPECTED_SERIALIZED_ANNOTATION.replaceAll("[\n\t]", "");
        expectedSerializedRepresentation = String.format(expectedSerializedRepresentation, getJsonLdWebAnnotationResult.get("projectRootRepositoryName"), getJsonLdWebAnnotationResult.get("tagsetDefinitionUuid"), getJsonLdWebAnnotationResult.get("tagDefinitionUuid"), getJsonLdWebAnnotationResult.get("userPropertyDefinitionUuid"), getJsonLdWebAnnotationResult.get("systemPropertyDefinitionUuid"), getJsonLdWebAnnotationResult.get("userMarkupCollectionUuid"), getJsonLdWebAnnotationResult.get("tagInstanceUuid"), getJsonLdWebAnnotationResult.get("sourceDocumentUuid"));
        assertEquals(expectedSerializedRepresentation, serialized);
    }
}
Also used : JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) GitLabServerManagerTest(de.catma.repository.git.managers.GitLabServerManagerTest) Test(org.junit.Test)

Example 2 with JGitRepoManager

use of de.catma.repository.git.managers.JGitRepoManager in project catma by forTEXT.

the class GitMarkupCollectionHandlerTest method createTagInstance.

@Test
public void createTagInstance() throws Exception {
    try (JGitRepoManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
        this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
        HashMap<String, Object> getJsonLdWebAnnotationResult = JsonLdWebAnnotationTest.getJsonLdWebAnnotation(jGitRepoManager, this.gitLabServerManager, this.catmaUser);
        JsonLdWebAnnotation jsonLdWebAnnotation = (JsonLdWebAnnotation) getJsonLdWebAnnotationResult.get("jsonLdWebAnnotation");
        String projectId = (String) getJsonLdWebAnnotationResult.get("projectUuid");
        String markupCollectionId = (String) getJsonLdWebAnnotationResult.get("userMarkupCollectionUuid");
        String tagsetId = (String) getJsonLdWebAnnotationResult.get("tagsetDefinitionUuid");
        String tagInstanceId = (String) getJsonLdWebAnnotationResult.get("tagInstanceUuid");
        this.projectsToDeleteOnTearDown.add(projectId);
        // add the tagset to the markup collection
        GitMarkupCollectionHandler gitMarkupCollectionHandler = new GitMarkupCollectionHandler(jGitRepoManager, this.gitLabServerManager);
        // TODO: use the real tagset hash - currently the handler does not validate it at all
        gitMarkupCollectionHandler.addTagset(projectId, markupCollectionId, tagsetId, "fakeTagsetVersion");
        // the JGitRepoManager instance should always be in a detached state after GitMarkupCollectionHandler calls
        // return
        assertFalse(jGitRepoManager.isAttached());
        // create the tag instance
        gitMarkupCollectionHandler.createTagInstance(projectId, markupCollectionId, jsonLdWebAnnotation);
        // the JGitRepoManager instance should always be in a detached state after GitMarkupCollectionHandler
        // calls return
        assertFalse(jGitRepoManager.isAttached());
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        jGitRepoManager.open(projectId, projectRootRepositoryName);
        File expectedTagInstanceJsonFilePath = new File(jGitRepoManager.getRepositoryWorkTree(), String.format("%s/%s/annotations/%s.json", GitProjectHandler.MARKUP_COLLECTION_SUBMODULES_DIRECTORY_NAME, markupCollectionId, tagInstanceId));
        assert expectedTagInstanceJsonFilePath.exists();
        assert expectedTagInstanceJsonFilePath.isFile();
        String expectedTagInstanceJsonFileContents = JsonLdWebAnnotationTest.EXPECTED_SERIALIZED_ANNOTATION.replaceAll("[\n\t]", "");
        expectedTagInstanceJsonFileContents = String.format(expectedTagInstanceJsonFileContents, getJsonLdWebAnnotationResult.get("projectRootRepositoryName"), getJsonLdWebAnnotationResult.get("tagsetDefinitionUuid"), getJsonLdWebAnnotationResult.get("tagDefinitionUuid"), getJsonLdWebAnnotationResult.get("userPropertyDefinitionUuid"), getJsonLdWebAnnotationResult.get("systemPropertyDefinitionUuid"), getJsonLdWebAnnotationResult.get("userMarkupCollectionUuid"), getJsonLdWebAnnotationResult.get("tagInstanceUuid"), getJsonLdWebAnnotationResult.get("sourceDocumentUuid"));
        assertEquals(expectedTagInstanceJsonFileContents, FileUtils.readFileToString(expectedTagInstanceJsonFilePath, StandardCharsets.UTF_8));
    }
}
Also used : JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) JsonLdWebAnnotation(de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotation) File(java.io.File) GitLabServerManagerTest(de.catma.repository.git.managers.GitLabServerManagerTest) Test(org.junit.Test) JsonLdWebAnnotationTest(de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotationTest)

Example 3 with JGitRepoManager

use of de.catma.repository.git.managers.JGitRepoManager in project catma by forTEXT.

the class GitMarkupCollectionHandlerTest method create.

@Test
public void create() throws Exception {
    try (ILocalGitRepositoryManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
        this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
        GitProjectManager gitProjectHandler = new GitProjectManager(RepositoryPropertyKey.GitBasedRepositoryBasePath.getValue(), UserIdentification.userToMap(this.catmaUser.getIdentifier()));
        String projectId = gitProjectHandler.create("Test CATMA Project", "This is a test CATMA project");
        this.projectsToDeleteOnTearDown.add(projectId);
        // the JGitRepoManager instance should always be in a detached state after GitProjectHandler calls
        // return
        assertFalse(jGitRepoManager.isAttached());
        GitMarkupCollectionHandler gitMarkupCollectionHandler = new GitMarkupCollectionHandler(jGitRepoManager, this.gitLabServerManager);
        String markupCollectionId = gitMarkupCollectionHandler.create(projectId, null, "Test Markup Collection", null, "fakeSourceDocumentId", "fakeSourceDocumentVersion");
        // we don't add the markupCollectionId to this.markupCollectionReposToDeleteOnTearDown as deletion of the
        // project will take care of that for us
        assertNotNull(markupCollectionId);
        assert markupCollectionId.startsWith("CATMA_");
        // the JGitRepoManager instance should always be in a detached state after GitMarkupCollectionHandler
        // calls return
        assertFalse(jGitRepoManager.isAttached());
        File expectedRepoPath = new File(jGitRepoManager.getRepositoryBasePath(), GitMarkupCollectionHandler.getMarkupCollectionRepositoryName(markupCollectionId));
        assert expectedRepoPath.exists();
        assert expectedRepoPath.isDirectory();
        assert Arrays.asList(expectedRepoPath.list()).contains("header.json");
        String expectedSerializedHeader = "" + "{\n" + "\t\"author\":null,\n" + "\t\"description\":null,\n" + "\t\"name\":\"Test Markup Collection\",\n" + "\t\"publisher\":null,\n" + "\t\"sourceDocumentId\":\"fakeSourceDocumentId\",\n" + "\t\"sourceDocumentVersion\":\"fakeSourceDocumentVersion\",\n" + "\t\"tagsets\":{}\n" + "}";
        assertEquals(expectedSerializedHeader.replaceAll("[\n\t]", ""), FileUtils.readFileToString(new File(expectedRepoPath, "header.json"), StandardCharsets.UTF_8));
    }
}
Also used : ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) File(java.io.File) GitLabServerManagerTest(de.catma.repository.git.managers.GitLabServerManagerTest) Test(org.junit.Test) JsonLdWebAnnotationTest(de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotationTest)

Example 4 with JGitRepoManager

use of de.catma.repository.git.managers.JGitRepoManager in project catma by forTEXT.

the class GitMarkupCollectionHandlerTest method open.

@Test
public void open() throws Exception {
    // TODO: don't hardcode anything in assertions (markup collection name...)
    try (JGitRepoManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
        this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
        HashMap<String, Object> getJsonLdWebAnnotationResult = JsonLdWebAnnotationTest.getJsonLdWebAnnotation(jGitRepoManager, this.gitLabServerManager, this.catmaUser);
        JsonLdWebAnnotation jsonLdWebAnnotation = (JsonLdWebAnnotation) getJsonLdWebAnnotationResult.get("jsonLdWebAnnotation");
        String projectId = (String) getJsonLdWebAnnotationResult.get("projectUuid");
        String markupCollectionId = (String) getJsonLdWebAnnotationResult.get("userMarkupCollectionUuid");
        String tagsetId = (String) getJsonLdWebAnnotationResult.get("tagsetDefinitionUuid");
        this.projectsToDeleteOnTearDown.add(projectId);
        // add the tagset to the markup collection
        GitMarkupCollectionHandler gitMarkupCollectionHandler = new GitMarkupCollectionHandler(jGitRepoManager, this.gitLabServerManager);
        // TODO: use the real tagset hash - currently the handler does not validate it at all
        gitMarkupCollectionHandler.addTagset(projectId, markupCollectionId, tagsetId, "fakeTagsetVersion");
        // the JGitRepoManager instance should always be in a detached state after GitMarkupCollectionHandler calls
        // return
        assertFalse(jGitRepoManager.isAttached());
        // create the tag instance within the markup collection
        gitMarkupCollectionHandler.createTagInstance(projectId, markupCollectionId, jsonLdWebAnnotation);
        // the JGitRepoManager instance should always be in a detached state after GitMarkupCollectionHandler calls
        // return
        assertFalse(jGitRepoManager.isAttached());
        UserMarkupCollection markupCollection = gitMarkupCollectionHandler.open(projectId, markupCollectionId);
        // the JGitRepoManager instance should always be in a detached state after GitMarkupCollectionHandler
        // calls return
        assertFalse(jGitRepoManager.isAttached());
        assertNotNull(markupCollection);
        assertEquals("Test Markup Collection", markupCollection.getContentInfoSet().getTitle());
        assertEquals(2, markupCollection.getTagReferences().size());
        assertTrue(markupCollection.getTagReferences().get(0).getRange().equals(new Range(12, 18)));
        assertNotNull(markupCollection.getRevisionHash());
    }
}
Also used : JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) UserMarkupCollection(de.catma.document.standoffmarkup.usermarkup.UserMarkupCollection) JsonLdWebAnnotation(de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotation) Range(de.catma.document.Range) GitLabServerManagerTest(de.catma.repository.git.managers.GitLabServerManagerTest) Test(org.junit.Test) JsonLdWebAnnotationTest(de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotationTest)

Example 5 with JGitRepoManager

use of de.catma.repository.git.managers.JGitRepoManager in project catma by forTEXT.

the class GitProjectHandlerTest method create.

@Test
public void create() throws Exception {
    try (ILocalGitRepositoryManager jGitRepoManager = new JGitRepoManager(CATMAPropertyKey.GitBasedRepositoryBasePath.getValue(), gitlabManagerRestricted.getUser())) {
        directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
        BackgroundService mockBackgroundService = mock(BackgroundService.class);
        EventBus mockEventBus = mock(EventBus.class);
        GitProjectManager gitProjectManager = new GitProjectManager(CATMAPropertyKey.GitBasedRepositoryBasePath.getValue(), gitlabManagerRestricted, // noop deletion handler
        (projectId) -> {
        }, mockBackgroundService, mockEventBus);
        String projectId = gitProjectManager.create("Test CATMA Project", "This is a test CATMA project");
        // we don't add the projectId to projectsToDeleteOnTearDown as deletion of the user will take care of that for us
        assertNotNull(projectId);
        assert projectId.startsWith("CATMA_");
        // the JGitRepoManager instance should always be in a detached state after GitProjectManager calls return
        assertFalse(jGitRepoManager.isAttached());
        String expectedRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        File expectedRootRepositoryPath = Paths.get(jGitRepoManager.getRepositoryBasePath().getPath(), projectId, expectedRootRepositoryName).toFile();
        assert expectedRootRepositoryPath.exists();
        assert expectedRootRepositoryPath.isDirectory();
    }
}
Also used : BackgroundService(de.catma.backgroundservice.BackgroundService) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) EventBus(com.google.common.eventbus.EventBus) File(java.io.File) GitLabServerManagerTest(de.catma.repository.git.managers.GitLabServerManagerTest) Test(org.junit.jupiter.api.Test)

Aggregations

JGitRepoManager (de.catma.repository.git.managers.JGitRepoManager)23 GitLabServerManagerTest (de.catma.repository.git.managers.GitLabServerManagerTest)22 Test (org.junit.Test)18 ILocalGitRepositoryManager (de.catma.repository.git.interfaces.ILocalGitRepositoryManager)13 JsonLdWebAnnotationTest (de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotationTest)13 File (java.io.File)12 TagDefinition (de.catma.tag.TagDefinition)5 EventBus (com.google.common.eventbus.EventBus)4 BackgroundService (de.catma.backgroundservice.BackgroundService)4 ContentInfoSet (de.catma.document.source.ContentInfoSet)4 IndexInfoSet (de.catma.document.source.IndexInfoSet)4 SourceDocumentInfo (de.catma.document.source.SourceDocumentInfo)4 TechInfoSet (de.catma.document.source.TechInfoSet)4 IDGenerator (de.catma.util.IDGenerator)4 FileInputStream (java.io.FileInputStream)4 Test (org.junit.jupiter.api.Test)4 Range (de.catma.document.Range)3 TermExtractor (de.catma.indexer.TermExtractor)3 GitTagDefinition (de.catma.repository.git.serialization.model_wrappers.GitTagDefinition)3 PropertyDefinition (de.catma.tag.PropertyDefinition)3