Search in sources :

Example 6 with SerializationHelper

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

the class GitSourceDocumentHandler method getSourceDocumentConflict.

public SourceDocumentConflict getSourceDocumentConflict(String projectId, String sourceDocumentId) throws Exception {
    try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
        // TODO: refactor how GitTagsetHandler and GitMarkupCollectionHandler open the submodule repo in their respective getConflict functions
        // no need to open the root repo first if we aren't going to do anything with it (check where else we may be doing this unnecessarily)
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        String sourceDocumentGitRepositoryName = String.format("%s/%s/%s", projectRootRepositoryName, GitProjectHandler.SOURCE_DOCUMENT_SUBMODULES_DIRECTORY_NAME, sourceDocumentId);
        localGitRepoManager.open(projectId, sourceDocumentGitRepositoryName);
        Status status = localGitRepoManager.getStatus();
        File headerFile = new File(localGitRepoManager.getRepositoryWorkTree(), HEADER_FILE_NAME);
        String serializedHeaderFile = FileUtils.readFileToString(headerFile, StandardCharsets.UTF_8);
        SourceDocumentConflict sourceDocumentConflict;
        if (status.getConflictingStageState().containsKey(HEADER_FILE_NAME)) {
            SourceDocumentInfo sourceDocumentInfo = resolveSourceDocumentHeaderConflict(serializedHeaderFile, status.getConflictingStageState().get(HEADER_FILE_NAME));
            serializedHeaderFile = new SerializationHelper<SourceDocumentInfo>().serialize(sourceDocumentInfo);
            localGitRepoManager.add(headerFile.getAbsoluteFile(), serializedHeaderFile.getBytes(StandardCharsets.UTF_8));
            sourceDocumentConflict = new SourceDocumentConflict(projectId, sourceDocumentId, sourceDocumentInfo.getContentInfoSet());
            sourceDocumentConflict.setHeaderConflict(true);
            status = localGitRepoManager.getStatus();
        } else {
            // for now there shouldn't be conflicts on anything other than the header file (nothing else about a document can currently be edited by users)
            throw new IllegalStateException("Unexpected document conflict");
        }
        // for now there shouldn't be conflicts on anything other than the header file (nothing else about a document can currently be edited by users)
        if (!status.getConflicting().isEmpty()) {
            throw new IllegalStateException("Unexpected document conflict");
        }
        return sourceDocumentConflict;
    }
}
Also used : Status(org.eclipse.jgit.api.Status) SerializationHelper(de.catma.repository.git.serialization.SerializationHelper) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) SourceDocumentConflict(de.catma.project.conflict.SourceDocumentConflict) File(java.io.File)

Example 7 with SerializationHelper

use of de.catma.repository.git.serialization.SerializationHelper 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 8 with SerializationHelper

use of de.catma.repository.git.serialization.SerializationHelper 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 9 with SerializationHelper

use of de.catma.repository.git.serialization.SerializationHelper 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)

Aggregations

SerializationHelper (de.catma.repository.git.serialization.SerializationHelper)9 File (java.io.File)7 ILocalGitRepositoryManager (de.catma.repository.git.interfaces.ILocalGitRepositoryManager)6 GitTagsetHeader (de.catma.repository.git.serialization.models.GitTagsetHeader)3 ArrayList (java.util.ArrayList)3 Status (org.eclipse.jgit.api.Status)3 TagReference (de.catma.document.annotation.TagReference)2 ContentInfoSet (de.catma.document.source.ContentInfoSet)2 CATMAPropertyKey (de.catma.properties.CATMAPropertyKey)2 GitMarkupCollectionHeader (de.catma.repository.git.serialization.models.GitMarkupCollectionHeader)2 IDGenerator (de.catma.util.IDGenerator)2 IOException (java.io.IOException)2 Level (java.util.logging.Level)2 Logger (java.util.logging.Logger)2 Collectors (java.util.stream.Collectors)2 StageState (org.eclipse.jgit.lib.IndexDiff.StageState)2 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 Maps (com.google.common.collect.Maps)1 EventBus (com.google.common.eventbus.EventBus)1