Search in sources :

Example 1 with CollectionConflict

use of de.catma.project.conflict.CollectionConflict in project catma by forTEXT.

the class GitMarkupCollectionHandler method getCollectionConflict.

public CollectionConflict getCollectionConflict(String projectId, String collectionId) throws Exception {
    try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        localGitRepoManager.open(projectId, projectRootRepositoryName);
        String collectionSubmoduleRelDir = GitProjectHandler.ANNOTATION_COLLECTION_SUBMODULES_DIRECTORY_NAME + "/" + collectionId;
        File collectionSubmoduleAbsPath = new File(localGitRepoManager.getRepositoryWorkTree().toString(), collectionSubmoduleRelDir);
        localGitRepoManager.detach();
        String collectionGitRepositoryName = projectRootRepositoryName + "/" + collectionSubmoduleRelDir;
        localGitRepoManager.open(projectId, collectionGitRepositoryName);
        Status status = localGitRepoManager.getStatus();
        File collectionHeaderFile = new File(collectionSubmoduleAbsPath, HEADER_FILE_NAME);
        String serializedCollectionHeaderFile = FileUtils.readFileToString(collectionHeaderFile, StandardCharsets.UTF_8);
        CollectionConflict collectionConflict;
        if (status.getConflictingStageState().containsKey(HEADER_FILE_NAME)) {
            GitMarkupCollectionHeader gitCollectionHeader = resolveCollectionHeaderConflict(serializedCollectionHeaderFile, status.getConflictingStageState().get(HEADER_FILE_NAME));
            serializedCollectionHeaderFile = new SerializationHelper<GitMarkupCollectionHeader>().serialize(gitCollectionHeader);
            localGitRepoManager.add(collectionHeaderFile.getAbsoluteFile(), serializedCollectionHeaderFile.getBytes(StandardCharsets.UTF_8));
            ContentInfoSet contentInfoSet = new ContentInfoSet(gitCollectionHeader.getAuthor(), gitCollectionHeader.getDescription(), gitCollectionHeader.getPublisher(), gitCollectionHeader.getName());
            collectionConflict = new CollectionConflict(projectId, collectionId, contentInfoSet, gitCollectionHeader.getSourceDocumentId());
            collectionConflict.setHeaderConflict(true);
            status = localGitRepoManager.getStatus();
        } else {
            GitMarkupCollectionHeader gitCollectionHeader = new SerializationHelper<GitMarkupCollectionHeader>().deserialize(serializedCollectionHeaderFile, GitMarkupCollectionHeader.class);
            ContentInfoSet contentInfoSet = new ContentInfoSet(gitCollectionHeader.getAuthor(), gitCollectionHeader.getDescription(), gitCollectionHeader.getPublisher(), gitCollectionHeader.getName());
            collectionConflict = new CollectionConflict(projectId, collectionId, contentInfoSet, gitCollectionHeader.getSourceDocumentId());
        }
        for (Entry<String, StageState> entry : status.getConflictingStageState().entrySet()) {
            String relativeAnnotationPathname = entry.getKey();
            String absAnnotationPathname = collectionSubmoduleAbsPath + "/" + relativeAnnotationPathname;
            StageState stageState = entry.getValue();
            switch(stageState) {
                case BOTH_MODIFIED:
                    {
                        String serializedConflictingAnnotation = FileUtils.readFileToString(new File(absAnnotationPathname), StandardCharsets.UTF_8);
                        AnnotationConflict annotationConflict = getBothModifiedAnnotationConflict(projectId, collectionId, serializedConflictingAnnotation);
                        collectionConflict.addAnnotationConflict(annotationConflict);
                        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 serializedConflictingAnnotation = FileUtils.readFileToString(new File(absAnnotationPathname), StandardCharsets.UTF_8);
                        AnnotationConflict annotationConflict = getDeleteByThemAnnotationConflict(projectId, collectionId, serializedConflictingAnnotation);
                        collectionConflict.addAnnotationConflict(annotationConflict);
                        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 serializedConflictingAnnotation = FileUtils.readFileToString(new File(absAnnotationPathname), StandardCharsets.UTF_8);
                        AnnotationConflict annotationConflict = getDeleteByUsAnnotationConflict(projectId, collectionId, serializedConflictingAnnotation);
                        collectionConflict.addAnnotationConflict(annotationConflict);
                        break;
                    }
                default:
                    {
                        // TODO:
                        System.out.println("not handled");
                    }
            }
        }
        return collectionConflict;
    }
}
Also used : Status(org.eclipse.jgit.api.Status) SerializationHelper(de.catma.repository.git.serialization.SerializationHelper) AnnotationConflict(de.catma.project.conflict.AnnotationConflict) ContentInfoSet(de.catma.document.source.ContentInfoSet) StageState(org.eclipse.jgit.lib.IndexDiff.StageState) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) File(java.io.File) GitMarkupCollectionHeader(de.catma.repository.git.serialization.models.GitMarkupCollectionHeader) CollectionConflict(de.catma.project.conflict.CollectionConflict)

Aggregations

ContentInfoSet (de.catma.document.source.ContentInfoSet)1 AnnotationConflict (de.catma.project.conflict.AnnotationConflict)1 CollectionConflict (de.catma.project.conflict.CollectionConflict)1 ILocalGitRepositoryManager (de.catma.repository.git.interfaces.ILocalGitRepositoryManager)1 SerializationHelper (de.catma.repository.git.serialization.SerializationHelper)1 GitMarkupCollectionHeader (de.catma.repository.git.serialization.models.GitMarkupCollectionHeader)1 File (java.io.File)1 Status (org.eclipse.jgit.api.Status)1 StageState (org.eclipse.jgit.lib.IndexDiff.StageState)1