Search in sources :

Example 6 with GitTagsetHeader

use of de.catma.repository.git.serialization.models.GitTagsetHeader in project catma by forTEXT.

the class GitTagsetHandlerTest 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 for Tagset", "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());
        GitTagsetHandler gitTagsetHandler = new GitTagsetHandler(jGitRepoManager, this.gitLabServerManager);
        String name = "Test Tagset";
        String description = "Test Tagset Description";
        String tagsetId = gitTagsetHandler.create(projectId, null, name, description);
        // we don't add the tagsetId to this.tagsetReposToDeleteOnTearDown as deletion of the
        // project will take care of that for us
        assertNotNull(tagsetId);
        assert tagsetId.startsWith("CATMA_");
        File expectedRepoPath = new File(jGitRepoManager.getRepositoryBasePath(), GitTagsetHandler.getTagsetRepositoryName(tagsetId));
        assert expectedRepoPath.exists();
        assert expectedRepoPath.isDirectory();
        assert Arrays.asList(expectedRepoPath.list()).contains("header.json");
        GitTagsetHeader expectedHeader = new GitTagsetHeader(name, description);
        String serialized = FileUtils.readFileToString(new File(expectedRepoPath, "header.json"), StandardCharsets.UTF_8);
        GitTagsetHeader actualHeader = new SerializationHelper<GitTagsetHeader>().deserialize(serialized, GitTagsetHeader.class);
        assertEquals(expectedHeader.getName(), actualHeader.getName());
        assertEquals(expectedHeader.getDescription(), actualHeader.getDescription());
    }
}
Also used : ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) GitTagsetHeader(de.catma.repository.git.serialization.models.GitTagsetHeader) 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 7 with GitTagsetHeader

use of de.catma.repository.git.serialization.models.GitTagsetHeader in project catma by forTEXT.

the class GitTagsetHandler method removeTagDefinition.

public String removeTagDefinition(String projectId, TagDefinition tagDefinition) throws IOException {
    try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        String tagsetGitRepositoryName = projectRootRepositoryName + "/" + GitProjectHandler.TAGSET_SUBMODULES_DIRECTORY_NAME + "/" + tagDefinition.getTagsetDefinitionUuid();
        localGitRepoManager.open(projectId, tagsetGitRepositoryName);
        // write header.json with deletion journal
        File tagsetHeaderFile = new File(localGitRepoManager.getRepositoryWorkTree(), HEADER_FILE_NAME);
        String serializedTagsetHeader = FileUtils.readFileToString(tagsetHeaderFile, StandardCharsets.UTF_8);
        GitTagsetHeader gitTagsetHeader = new SerializationHelper<GitTagsetHeader>().deserialize(serializedTagsetHeader, GitTagsetHeader.class);
        serializedTagsetHeader = new SerializationHelper<GitTagsetHeader>().serialize(gitTagsetHeader);
        gitTagsetHeader.getDeletedDefinitions().add(tagDefinition.getUuid());
        serializedTagsetHeader = new SerializationHelper<GitTagsetHeader>().serialize(gitTagsetHeader);
        localGitRepoManager.add(tagsetHeaderFile, serializedTagsetHeader.getBytes(StandardCharsets.UTF_8));
        String targetTagDefinitionsFolderRelativePath = (StringUtils.isEmpty(tagDefinition.getParentUuid()) ? "" : (tagDefinition.getParentUuid() + "/")) + tagDefinition.getUuid();
        File targetTagDefinitionsFolderAbsolutePath = Paths.get(localGitRepoManager.getRepositoryWorkTree().toString(), targetTagDefinitionsFolderRelativePath).toFile();
        String tagsetRevision = localGitRepoManager.removeAndCommit(targetTagDefinitionsFolderAbsolutePath, // delete empty parent tag directory
        !StringUtils.isEmpty(tagDefinition.getParentUuid()), String.format("Removing Tag %1$s with ID %2$s", tagDefinition.getName(), tagDefinition.getUuid()), remoteGitServerManager.getUsername(), remoteGitServerManager.getEmail());
        return tagsetRevision;
    }
}
Also used : SerializationHelper(de.catma.repository.git.serialization.SerializationHelper) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) GitTagsetHeader(de.catma.repository.git.serialization.models.GitTagsetHeader) File(java.io.File)

Example 8 with GitTagsetHeader

use of de.catma.repository.git.serialization.models.GitTagsetHeader in project catma by forTEXT.

the class GitTagsetHandler method getContentInfoSet.

public ContentInfoSet getContentInfoSet(String projectId, String tagsetId) throws IOException {
    try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        localGitRepoManager.open(projectId, projectRootRepositoryName);
        String tagsetSubmoduleName = String.format("%s/%s", GitProjectHandler.TAGSET_SUBMODULES_DIRECTORY_NAME, tagsetId);
        File tagsetHeaderFile = new File(localGitRepoManager.getRepositoryWorkTree(), tagsetSubmoduleName + "/" + HEADER_FILE_NAME);
        String serialized = FileUtils.readFileToString(tagsetHeaderFile, StandardCharsets.UTF_8);
        GitTagsetHeader gitTagsetHeader = new SerializationHelper<GitTagsetHeader>().deserialize(serialized, GitTagsetHeader.class);
        ContentInfoSet contentInfoSet = new ContentInfoSet();
        contentInfoSet.setTitle(gitTagsetHeader.getName());
        return contentInfoSet;
    }
}
Also used : ContentInfoSet(de.catma.document.source.ContentInfoSet) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) GitTagsetHeader(de.catma.repository.git.serialization.models.GitTagsetHeader) File(java.io.File)

Example 9 with GitTagsetHeader

use of de.catma.repository.git.serialization.models.GitTagsetHeader in project catma by forTEXT.

the class GitTagsetHandler method resolveTagsetHeaderConflict.

private GitTagsetHeader resolveTagsetHeaderConflict(String serializedTagsetHeaderFile, StageState stageState) {
    if (stageState.equals(StageState.BOTH_MODIFIED)) {
        String masterVersion = serializedTagsetHeaderFile.replaceAll("\\Q<<<<<<< HEAD\\E(\\r\\n|\\r|\\n)", "").replaceAll("\\Q=======\\E(\\r\\n|\\r|\\n|.)*?\\Q>>>>>>> \\E.+?(\\r\\n|\\r|\\n)", "");
        String devVersion = serializedTagsetHeaderFile.replaceAll("\\Q<<<<<<< HEAD\\E(\\r\\n|\\r|\\n|.)*?\\Q=======\\E(\\r\\n|\\r|\\n)", "").replaceAll("\\Q>>>>>>> \\E.+?(\\r\\n|\\r|\\n)", "");
        GitTagsetHeader masterTagsetHeader = new SerializationHelper<GitTagsetHeader>().deserialize(masterVersion, GitTagsetHeader.class);
        GitTagsetHeader devTagsetHeader = new SerializationHelper<GitTagsetHeader>().deserialize(devVersion, GitTagsetHeader.class);
        String name = masterTagsetHeader.getName() == null ? "" : masterTagsetHeader.getName().trim();
        String devName = devTagsetHeader.getName() == null ? "" : devTagsetHeader.getName().trim();
        if (!name.equalsIgnoreCase(devName) && devName.length() > 0) {
            name = String.format("%s %s", name, devName);
        }
        String description = masterTagsetHeader.getDescription() == null ? "" : masterTagsetHeader.getDescription().trim();
        String devDescription = devTagsetHeader.getDescription() == null ? "" : devTagsetHeader.getDescription().trim();
        if (!description.equalsIgnoreCase(devDescription) && devDescription.length() > 0) {
            description = String.format("%s %s", description, devDescription);
        }
        TreeSet<String> deletedDefinitions = new TreeSet<>();
        deletedDefinitions.addAll(masterTagsetHeader.getDeletedDefinitions());
        deletedDefinitions.addAll(devTagsetHeader.getDeletedDefinitions());
        return new GitTagsetHeader(name, description, deletedDefinitions);
    } else {
        return new SerializationHelper<GitTagsetHeader>().deserialize(serializedTagsetHeaderFile, GitTagsetHeader.class);
    }
}
Also used : TreeSet(java.util.TreeSet) GitTagsetHeader(de.catma.repository.git.serialization.models.GitTagsetHeader)

Example 10 with GitTagsetHeader

use of de.catma.repository.git.serialization.models.GitTagsetHeader in project catma by forTEXT.

the class GitTagsetHandler method create.

/**
 * Creates a new tagset.
 * <p>
 * NB: You probably don't want to call this method directly (it doesn't create the submodule in the project root
 * repo). Instead call the <code>createTagset</code> method of the {@link GitProjectManager} class.
 *
 * @param projectId the ID of the project within which the tagset must be created
 * @param tagsetId the ID of the tagset to create. If none is provided, a new ID will be generated.
 * @param name the name of the new tagset
 * @param description the description of the new tagset
 * @return the new revisionhash
 * @throws IOException if an error occurs while creating the tagset
 */
public String create(String projectId, String tagsetId, String name, String description) throws IOException {
    try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
        // create the remote tagset repository
        CreateRepositoryResponse createRepositoryResponse = this.remoteGitServerManager.createRepository(tagsetId, tagsetId, projectId);
        // clone the repository locally
        localGitRepoManager.clone(projectId, createRepositoryResponse.repositoryHttpUrl, // destination path is created by the repo manager
        null, credentialsProvider);
        // write header.json into the local repo
        File targetHeaderFile = new File(localGitRepoManager.getRepositoryWorkTree(), HEADER_FILE_NAME);
        GitTagsetHeader header = new GitTagsetHeader(name, description, new TreeSet<>());
        String serializedHeader = new SerializationHelper<GitTagsetHeader>().serialize(header);
        String revisionHash = localGitRepoManager.addAndCommit(targetHeaderFile, serializedHeader.getBytes(StandardCharsets.UTF_8), String.format("Added Tagset %1$s with ID %2$s", name, tagsetId), remoteGitServerManager.getUsername(), remoteGitServerManager.getEmail());
        return revisionHash;
    }
}
Also used : ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) GitTagsetHeader(de.catma.repository.git.serialization.models.GitTagsetHeader) File(java.io.File)

Aggregations

GitTagsetHeader (de.catma.repository.git.serialization.models.GitTagsetHeader)10 ILocalGitRepositoryManager (de.catma.repository.git.interfaces.ILocalGitRepositoryManager)9 File (java.io.File)9 SerializationHelper (de.catma.repository.git.serialization.SerializationHelper)3 GitTagDefinition (de.catma.repository.git.serialization.model_wrappers.GitTagDefinition)2 ContentInfoSet (de.catma.document.source.ContentInfoSet)1 TagConflict (de.catma.project.conflict.TagConflict)1 TagsetConflict (de.catma.project.conflict.TagsetConflict)1 GitLabServerManagerTest (de.catma.repository.git.managers.GitLabServerManagerTest)1 JGitRepoManager (de.catma.repository.git.managers.JGitRepoManager)1 JsonLdWebAnnotationTest (de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotationTest)1 TagDefinition (de.catma.tag.TagDefinition)1 TagsetDefinition (de.catma.tag.TagsetDefinition)1 TreeSet (java.util.TreeSet)1 Status (org.eclipse.jgit.api.Status)1 StageState (org.eclipse.jgit.lib.IndexDiff.StageState)1 Test (org.junit.Test)1