Search in sources :

Example 1 with GitTagsetHeader

use of de.catma.repository.git.serialization.models.GitTagsetHeader 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 2 with GitTagsetHeader

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

the class GitTagsetHandler method getTagsetConflict.

public TagsetConflict getTagsetConflict(String projectId, String tagsetId) throws Exception {
    try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        localGitRepoManager.open(projectId, projectRootRepositoryName);
        String tagsetSubmoduleRelDir = GitProjectHandler.TAGSET_SUBMODULES_DIRECTORY_NAME + "/" + tagsetId;
        File tagsetSubmoduleAbsPath = new File(localGitRepoManager.getRepositoryWorkTree().toString(), tagsetSubmoduleRelDir);
        localGitRepoManager.detach();
        String tagsetGitRepositoryName = projectRootRepositoryName + "/" + tagsetSubmoduleRelDir;
        localGitRepoManager.open(projectId, tagsetGitRepositoryName);
        Status status = localGitRepoManager.getStatus();
        File tagsetHeaderFile = new File(tagsetSubmoduleAbsPath, HEADER_FILE_NAME);
        String serializedTagsetHeaderFile = FileUtils.readFileToString(tagsetHeaderFile, StandardCharsets.UTF_8);
        TagsetConflict tagsetConflict = null;
        if (status.getConflictingStageState().containsKey(HEADER_FILE_NAME)) {
            GitTagsetHeader gitTagsetHeader = resolveTagsetHeaderConflict(serializedTagsetHeaderFile, status.getConflictingStageState().get(HEADER_FILE_NAME));
            serializedTagsetHeaderFile = new SerializationHelper<GitTagsetHeader>().serialize(gitTagsetHeader);
            localGitRepoManager.add(tagsetHeaderFile.getAbsoluteFile(), serializedTagsetHeaderFile.getBytes(StandardCharsets.UTF_8));
            tagsetConflict = new TagsetConflict(projectId, tagsetId, gitTagsetHeader.getName(), gitTagsetHeader.getDeletedDefinitions());
            tagsetConflict.setHeaderConflict(true);
            status = localGitRepoManager.getStatus();
        } else {
            GitTagsetHeader gitTagsetHeader = new SerializationHelper<GitTagsetHeader>().deserialize(serializedTagsetHeaderFile, GitTagsetHeader.class);
            tagsetConflict = new TagsetConflict(projectId, tagsetId, gitTagsetHeader.getName(), gitTagsetHeader.getDeletedDefinitions());
        }
        for (Entry<String, StageState> entry : status.getConflictingStageState().entrySet()) {
            String relativeTagPathname = entry.getKey();
            String absTagPathname = tagsetSubmoduleAbsPath + "/" + relativeTagPathname;
            StageState stageState = entry.getValue();
            switch(stageState) {
                case BOTH_MODIFIED:
                    {
                        String serializedConflictingTag = FileUtils.readFileToString(new File(absTagPathname), StandardCharsets.UTF_8);
                        TagConflict tagConflict = getBothModifiedTagConflict(projectId, tagsetId, serializedConflictingTag);
                        tagsetConflict.addTagConflict(tagConflict);
                        break;
                    }
                case DELETED_BY_THEM:
                    {
                        // them is the user on the dev branch here
                        // in this case the file comes from us (the team on the master branch)
                        String serializedConflictingTag = FileUtils.readFileToString(new File(absTagPathname), StandardCharsets.UTF_8);
                        TagConflict tagConflict = getDeleteByThemTagConflict(projectId, tagsetId, serializedConflictingTag);
                        tagsetConflict.addTagConflict(tagConflict);
                        break;
                    }
                case DELETED_BY_US:
                    {
                        // us is the team on the master branch here
                        // in this case the file comes from them (the user on the dev branch)
                        String serializedConflictingTag = FileUtils.readFileToString(new File(absTagPathname), StandardCharsets.UTF_8);
                        TagConflict tagConflict = getDeleteByUsTagConflict(projectId, tagsetId, serializedConflictingTag);
                        tagsetConflict.addTagConflict(tagConflict);
                        break;
                    }
                // TODO:
                default:
                    System.out.println("not handled");
            }
        }
        return tagsetConflict;
    }
}
Also used : Status(org.eclipse.jgit.api.Status) SerializationHelper(de.catma.repository.git.serialization.SerializationHelper) TagConflict(de.catma.project.conflict.TagConflict) StageState(org.eclipse.jgit.lib.IndexDiff.StageState) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) GitTagsetHeader(de.catma.repository.git.serialization.models.GitTagsetHeader) File(java.io.File) TagsetConflict(de.catma.project.conflict.TagsetConflict)

Example 3 with GitTagsetHeader

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

the class GitTagsetHandler method updateTagsetDefinition.

public String updateTagsetDefinition(String projectId, TagsetDefinition tagsetDefinition) throws Exception {
    try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        String tagsetGitRepositoryName = projectRootRepositoryName + "/" + GitProjectHandler.TAGSET_SUBMODULES_DIRECTORY_NAME + "/" + tagsetDefinition.getUuid();
        localGitRepoManager.open(projectId, tagsetGitRepositoryName);
        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 tagsetRevision = localGitRepoManager.addAndCommit(targetHeaderFile, serializedHeader.getBytes(StandardCharsets.UTF_8), String.format("Updated metadata of Tagset %1$s with ID %2$s", tagsetDefinition.getName(), tagsetDefinition.getUuid()), remoteGitServerManager.getUsername(), remoteGitServerManager.getEmail());
        return tagsetRevision;
    }
}
Also used : ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) GitTagsetHeader(de.catma.repository.git.serialization.models.GitTagsetHeader) File(java.io.File)

Example 4 with GitTagsetHeader

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

the class GitTagsetHandler method removeFromDeletedJournal.

public void removeFromDeletedJournal(String projectId, String tagsetId, String tagOrPropertyId) throws Exception {
    try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        String tagsetGitRepositoryName = projectRootRepositoryName + "/" + GitProjectHandler.TAGSET_SUBMODULES_DIRECTORY_NAME + "/" + tagsetId;
        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);
        gitTagsetHeader.getDeletedDefinitions().remove(tagOrPropertyId);
        serializedTagsetHeader = new SerializationHelper<GitTagsetHeader>().serialize(gitTagsetHeader);
        localGitRepoManager.add(tagsetHeaderFile, serializedTagsetHeader.getBytes(StandardCharsets.UTF_8));
    }
}
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 5 with GitTagsetHeader

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

the class GitTagsetHandler method getTagset.

public TagsetDefinition getTagset(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);
        TagsetDefinition tagsetdefinition = new TagsetDefinition(tagsetId, gitTagsetHeader.getName(), null, gitTagsetHeader.getDeletedDefinitions());
        String tagsetDefinitionRevisionHash = localGitRepoManager.getSubmoduleHeadRevisionHash(tagsetSubmoduleName);
        tagsetdefinition.setRevisionHash(tagsetDefinitionRevisionHash);
        ArrayList<TagDefinition> tagDefinitions = this.openTagDefinitions(tagsetHeaderFile.getParentFile());
        for (TagDefinition tagdefinition : tagDefinitions) {
            tagsetdefinition.addTagDefinition(tagdefinition);
        }
        return tagsetdefinition;
    }
}
Also used : TagsetDefinition(de.catma.tag.TagsetDefinition) GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition) TagDefinition(de.catma.tag.TagDefinition) 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