Search in sources :

Example 1 with GitTagDefinition

use of de.catma.repository.git.serialization.model_wrappers.GitTagDefinition in project catma by forTEXT.

the class GitTagsetHandlerTest method createTagDefinitionWithParent.

@Test
public void createTagDefinitionWithParent() throws Exception {
    try (ILocalGitRepositoryManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
        this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
        // create a project
        GitProjectManager gitProjectManager = new GitProjectManager(RepositoryPropertyKey.GitBasedRepositoryBasePath.getValue(), UserIdentification.userToMap(this.catmaUser.getIdentifier()));
        String projectId = gitProjectManager.create("Test CATMA Project for Tagset", "This is a test CATMA project");
        this.projectsToDeleteOnTearDown.add(projectId);
        GitProjectHandler gitProjectHandler = new GitProjectHandler(null, projectId, jGitRepoManager, gitLabServerManager);
        // create a tagset
        String tagsetId = gitProjectHandler.createTagset(null, "Test Tagset", null);
        // we don't add the tagsetId to this.tagsetReposToDeleteOnTearDown as deletion of the project will take
        // care of that for us
        // create a TagDefinition object that has a (fake) parent
        String tagDefinitionId = this.idGenerator.generate();
        String parentTagDefinitionId = this.idGenerator.generate();
        Version tagDefinitionVersion = new Version();
        TagDefinition tagDefinition = new TagDefinition(null, tagDefinitionId, "FakeTagDefinitionName", tagDefinitionVersion, null, parentTagDefinitionId);
        // call createTagDefinition
        GitTagsetHandler gitTagsetHandler = new GitTagsetHandler(jGitRepoManager, this.gitLabServerManager);
        String returnedTagDefinitionId = gitTagsetHandler.createOrUpdateTagDefinition(projectId, tagsetId, tagDefinition);
        assertNotNull(returnedTagDefinitionId);
        assert returnedTagDefinitionId.startsWith("CATMA_");
        // the JGitRepoManager instance should always be in a detached state after GitTagsetHandler calls return
        assertFalse(jGitRepoManager.isAttached());
        assertEquals(tagDefinitionId, returnedTagDefinitionId);
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        File expectedTagDefinitionPath = Paths.get(jGitRepoManager.getRepositoryBasePath().toString(), projectRootRepositoryName, GitProjectHandler.TAGSET_SUBMODULES_DIRECTORY_NAME, tagsetId, parentTagDefinitionId, tagDefinition.getUuid()).toFile();
        assert expectedTagDefinitionPath.exists() : "Directory does not exist";
        assert expectedTagDefinitionPath.isDirectory() : "Path is not a directory";
        assert Arrays.asList(expectedTagDefinitionPath.list()).contains("propertydefs.json");
        GitTagDefinition expectedGitTagDefinition = new GitTagDefinition(tagDefinition);
        String actualSerializedGitTagDefinition = FileUtils.readFileToString(new File(expectedTagDefinitionPath, "propertydefs.json"), StandardCharsets.UTF_8);
        GitTagDefinition actualGitTagDefinition = new SerializationHelper<GitTagDefinition>().deserialize(actualSerializedGitTagDefinition, GitTagDefinition.class);
        assertEquals(expectedGitTagDefinition.getTagsetDefinitionUuid(), actualGitTagDefinition.getTagsetDefinitionUuid());
        assertEquals(expectedGitTagDefinition.getParentUuid(), actualGitTagDefinition.getParentUuid());
        assertEquals(expectedGitTagDefinition.getUuid(), actualGitTagDefinition.getUuid());
        assertEquals(expectedGitTagDefinition.getName(), actualGitTagDefinition.getName());
    // TODO: assert tag definition
    }
}
Also used : GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition) TagDefinition(de.catma.tag.TagDefinition) GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) Version(de.catma.tag.Version) 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 2 with GitTagDefinition

use of de.catma.repository.git.serialization.model_wrappers.GitTagDefinition in project catma by forTEXT.

the class GitTagsetHandler method createOrUpdateTagDefinition.

public void createOrUpdateTagDefinition(String projectId, String tagsetId, TagDefinition tagDefinition) throws IOException {
    try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        String targetPropertyDefinitionsFileRelativePath = (StringUtils.isEmpty(tagDefinition.getParentUuid()) ? "" : (tagDefinition.getParentUuid() + "/")) + tagDefinition.getUuid() + "/propertydefs.json";
        String tagsetGitRepositoryName = projectRootRepositoryName + "/" + GitProjectHandler.TAGSET_SUBMODULES_DIRECTORY_NAME + "/" + tagsetId;
        localGitRepoManager.open(projectId, tagsetGitRepositoryName);
        File targetPropertyDefinitionsFileAbsolutePath = Paths.get(localGitRepoManager.getRepositoryWorkTree().toString(), targetPropertyDefinitionsFileRelativePath).toFile();
        GitTagDefinition gitTagDefinition = new GitTagDefinition(tagDefinition);
        String serializedGitTagDefinition = new SerializationHelper<GitTagDefinition>().serialize(gitTagDefinition);
        localGitRepoManager.add(targetPropertyDefinitionsFileAbsolutePath.getAbsoluteFile(), serializedGitTagDefinition.getBytes(StandardCharsets.UTF_8));
    }
}
Also used : GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) File(java.io.File)

Example 3 with GitTagDefinition

use of de.catma.repository.git.serialization.model_wrappers.GitTagDefinition in project catma by forTEXT.

the class GitTagsetHandler method removePropertyDefinition.

public String removePropertyDefinition(String projectId, TagsetDefinition tagsetDefinition, TagDefinition tagDefinition, PropertyDefinition propertyDefinition) throws IOException {
    try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        String tagsetGitRepositoryName = projectRootRepositoryName + "/" + GitProjectHandler.TAGSET_SUBMODULES_DIRECTORY_NAME + "/" + tagsetDefinition.getUuid();
        localGitRepoManager.open(projectId, tagsetGitRepositoryName);
        // write header.json with deletion journal
        File targetHeaderFile = new File(localGitRepoManager.getRepositoryWorkTree(), HEADER_FILE_NAME);
        GitTagsetHeader header = new GitTagsetHeader(tagsetDefinition.getName(), // TODO: description
        "", new TreeSet<>(tagsetDefinition.getDeletedDefinitions()));
        String serializedHeader = new SerializationHelper<GitTagsetHeader>().serialize(header);
        localGitRepoManager.add(targetHeaderFile, serializedHeader.getBytes(StandardCharsets.UTF_8));
        String targetPropertyDefinitionsFileRelativePath = (StringUtils.isEmpty(tagDefinition.getParentUuid()) ? "" : (tagDefinition.getParentUuid() + "/")) + tagDefinition.getUuid() + "/propertydefs.json";
        File targetPropertyDefinitionsFileAbsolutePath = Paths.get(localGitRepoManager.getRepositoryWorkTree().toString(), targetPropertyDefinitionsFileRelativePath).toFile();
        GitTagDefinition gitTagDefinition = new GitTagDefinition(tagDefinition);
        String serializedGitTagDefinition = new SerializationHelper<GitTagDefinition>().serialize(gitTagDefinition);
        String tagsetRevision = localGitRepoManager.addAndCommit(targetPropertyDefinitionsFileAbsolutePath, serializedGitTagDefinition.getBytes(StandardCharsets.UTF_8), String.format("Removed Property Definition %1$s with ID %2$s from Tag %3$s with ID %4$s", propertyDefinition.getName(), propertyDefinition.getUuid(), tagDefinition.getName(), tagDefinition.getUuid()), remoteGitServerManager.getUsername(), remoteGitServerManager.getEmail());
        return tagsetRevision;
    }
}
Also used : GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) GitTagsetHeader(de.catma.repository.git.serialization.models.GitTagsetHeader) File(java.io.File)

Example 4 with GitTagDefinition

use of de.catma.repository.git.serialization.model_wrappers.GitTagDefinition in project catma by forTEXT.

the class GitTagsetHandler method getBothModifiedTagConflict.

private TagConflict getBothModifiedTagConflict(String projectId, String tagsetId, String serializedConflictingTag) throws Exception {
    String masterVersion = serializedConflictingTag.replaceAll("\\Q<<<<<<< HEAD\\E(\\r\\n|\\r|\\n)", "").replaceAll("\\Q=======\\E(\\r\\n|\\r|\\n|.)*?\\Q>>>>>>> \\E.+?(\\r\\n|\\r|\\n)", "");
    String devVersion = serializedConflictingTag.replaceAll("\\Q<<<<<<< HEAD\\E(\\r\\n|\\r|\\n|.)*?\\Q=======\\E(\\r\\n|\\r|\\n)", "").replaceAll("\\Q>>>>>>> \\E.+?(\\r\\n|\\r|\\n)", "");
    GitTagDefinition gitMasterTagDefinition = new SerializationHelper<GitTagDefinition>().deserialize(masterVersion, GitTagDefinition.class);
    TagDefinition masterTagDefinition = gitMasterTagDefinition.getTagDefinition();
    GitTagDefinition gitDevTagDefinition = new SerializationHelper<GitTagDefinition>().deserialize(devVersion, GitTagDefinition.class);
    TagDefinition devTagDefinition = gitDevTagDefinition.getTagDefinition();
    TagConflict tagConflict = new TagConflict(masterTagDefinition, devTagDefinition);
    return tagConflict;
}
Also used : GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition) TagDefinition(de.catma.tag.TagDefinition) TagConflict(de.catma.project.conflict.TagConflict) GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition)

Example 5 with GitTagDefinition

use of de.catma.repository.git.serialization.model_wrappers.GitTagDefinition in project catma by forTEXT.

the class GitTagsetHandlerTest method createTagDefinitionWithoutParent.

@Test
public void createTagDefinitionWithoutParent() throws Exception {
    try (ILocalGitRepositoryManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
        this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
        // create a project
        GitProjectManager gitProjectManager = new GitProjectManager(RepositoryPropertyKey.GitBasedRepositoryBasePath.getValue(), UserIdentification.userToMap(this.catmaUser.getIdentifier()));
        String projectId = gitProjectManager.create("Test CATMA Project for Tagset", "This is a test CATMA project");
        this.projectsToDeleteOnTearDown.add(projectId);
        GitProjectHandler gitProjectHandler = new GitProjectHandler(null, projectId, jGitRepoManager, gitLabServerManager);
        // create a tagset
        String tagsetId = gitProjectHandler.createTagset(null, "Test Tagset", null);
        // we don't add the tagsetId to this.tagsetReposToDeleteOnTearDown as deletion of the project will take
        // care of that for us
        // create a TagDefinition object
        String tagDefinitionId = this.idGenerator.generate();
        Version tagDefinitionVersion = new Version();
        TagDefinition tagDefinition = new TagDefinition(null, tagDefinitionId, "FakeTagDefinitionName", tagDefinitionVersion, null, null);
        PropertyDefinition propertyDefinition = new PropertyDefinition("Weather", Arrays.asList("Good", "Bad", "Toto, I've a feeling we're not in Kansas anymore."));
        tagDefinition.addUserDefinedPropertyDefinition(propertyDefinition);
        // call createTagDefinition
        GitTagsetHandler gitTagsetHandler = new GitTagsetHandler(jGitRepoManager, this.gitLabServerManager);
        String returnedTagDefinitionId = gitTagsetHandler.createOrUpdateTagDefinition(projectId, tagsetId, tagDefinition);
        assertNotNull(returnedTagDefinitionId);
        assert returnedTagDefinitionId.startsWith("CATMA_");
        // the JGitRepoManager instance should always be in a detached state after GitTagsetHandler calls return
        assertFalse(jGitRepoManager.isAttached());
        assertEquals(tagDefinitionId, returnedTagDefinitionId);
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        File expectedTagDefinitionPath = Paths.get(jGitRepoManager.getRepositoryBasePath().toString(), projectRootRepositoryName, GitProjectHandler.TAGSET_SUBMODULES_DIRECTORY_NAME, tagsetId, tagDefinition.getUuid()).toFile();
        assert expectedTagDefinitionPath.exists() : "Directory does not exist";
        assert expectedTagDefinitionPath.isDirectory() : "Path is not a directory";
        assert Arrays.asList(expectedTagDefinitionPath.list()).contains("propertydefs.json");
        GitTagDefinition expectedGitTagDefinition = new GitTagDefinition(tagDefinition);
        String actualSerializedGitTagDefinition = FileUtils.readFileToString(new File(expectedTagDefinitionPath, "propertydefs.json"), StandardCharsets.UTF_8);
        GitTagDefinition actualGitTagDefinition = new SerializationHelper<GitTagDefinition>().deserialize(actualSerializedGitTagDefinition, GitTagDefinition.class);
        assertEquals(expectedGitTagDefinition.getTagsetDefinitionUuid(), actualGitTagDefinition.getTagsetDefinitionUuid());
        assertEquals(expectedGitTagDefinition.getParentUuid(), actualGitTagDefinition.getParentUuid());
        assertEquals(expectedGitTagDefinition.getUuid(), actualGitTagDefinition.getUuid());
        assertEquals(expectedGitTagDefinition.getName(), actualGitTagDefinition.getName());
    // TODO: assert tag definition and properties
    }
}
Also used : GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition) TagDefinition(de.catma.tag.TagDefinition) GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) Version(de.catma.tag.Version) JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) PropertyDefinition(de.catma.tag.PropertyDefinition) 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)

Aggregations

GitTagDefinition (de.catma.repository.git.serialization.model_wrappers.GitTagDefinition)8 TagDefinition (de.catma.tag.TagDefinition)6 File (java.io.File)5 ILocalGitRepositoryManager (de.catma.repository.git.interfaces.ILocalGitRepositoryManager)4 TagConflict (de.catma.project.conflict.TagConflict)3 GitLabServerManagerTest (de.catma.repository.git.managers.GitLabServerManagerTest)2 JGitRepoManager (de.catma.repository.git.managers.JGitRepoManager)2 JsonLdWebAnnotationTest (de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotationTest)2 Version (de.catma.tag.Version)2 Test (org.junit.Test)2 GitTagsetHeader (de.catma.repository.git.serialization.models.GitTagsetHeader)1 PropertyDefinition (de.catma.tag.PropertyDefinition)1 ArrayList (java.util.ArrayList)1