Search in sources :

Example 1 with AnnotationConflict

use of de.catma.project.conflict.AnnotationConflict 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)

Example 2 with AnnotationConflict

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

the class GitMarkupCollectionHandler method getBothModifiedAnnotationConflict.

private AnnotationConflict getBothModifiedAnnotationConflict(String projectId, String collectionId, String serializedConflictingAnnotation) throws Exception {
    String masterVersion = serializedConflictingAnnotation.replaceAll("\\Q<<<<<<< HEAD\\E(\\r\\n|\\r|\\n)", "").replaceAll("\\Q=======\\E(\\r\\n|\\r|\\n|.)*?\\Q>>>>>>> \\E.+?(\\r\\n|\\r|\\n)", "");
    String devVersion = serializedConflictingAnnotation.replaceAll("\\Q<<<<<<< HEAD\\E(\\r\\n|\\r|\\n|.)*?\\Q=======\\E(\\r\\n|\\r|\\n)", "").replaceAll("\\Q>>>>>>> \\E.+?(\\r\\n|\\r|\\n)", "");
    JsonLdWebAnnotation masterVersionJsonLdWebAnnotation = new SerializationHelper<JsonLdWebAnnotation>().deserialize(masterVersion, JsonLdWebAnnotation.class);
    JsonLdWebAnnotation devVersionJsonLdWebAnnotation = new SerializationHelper<JsonLdWebAnnotation>().deserialize(devVersion, JsonLdWebAnnotation.class);
    List<TagReference> masterTagReferences = masterVersionJsonLdWebAnnotation.toTagReferenceList(projectId, collectionId);
    List<TagReference> devTagReferences = devVersionJsonLdWebAnnotation.toTagReferenceList(projectId, collectionId);
    AnnotationConflict annotationConflict = new AnnotationConflict(devTagReferences.get(0).getTagInstance(), devTagReferences, masterTagReferences.get(0).getTagInstance(), masterTagReferences);
    return annotationConflict;
}
Also used : AnnotationConflict(de.catma.project.conflict.AnnotationConflict) TagReference(de.catma.document.annotation.TagReference) JsonLdWebAnnotation(de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotation)

Example 3 with AnnotationConflict

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

the class GitMarkupCollectionHandler method getDeleteByUsAnnotationConflict.

private AnnotationConflict getDeleteByUsAnnotationConflict(String projectId, String collectionId, String serializedConflictingAnnotation) throws Exception {
    JsonLdWebAnnotation devVersionJsonLdWebAnnotation = new SerializationHelper<JsonLdWebAnnotation>().deserialize(serializedConflictingAnnotation, JsonLdWebAnnotation.class);
    List<TagReference> devTagReferences = devVersionJsonLdWebAnnotation.toTagReferenceList(projectId, collectionId);
    AnnotationConflict annotationConflict = new AnnotationConflict(devTagReferences.get(0).getTagInstance(), devTagReferences, null, Collections.emptyList());
    return annotationConflict;
}
Also used : AnnotationConflict(de.catma.project.conflict.AnnotationConflict) TagReference(de.catma.document.annotation.TagReference) JsonLdWebAnnotation(de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotation)

Example 4 with AnnotationConflict

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

the class GitMarkupCollectionHandler method getDeleteByThemAnnotationConflict.

private AnnotationConflict getDeleteByThemAnnotationConflict(String projectId, String collectionId, String serializedConflictingAnnotation) throws Exception {
    JsonLdWebAnnotation masterVersionJsonLdWebAnnotation = new SerializationHelper<JsonLdWebAnnotation>().deserialize(serializedConflictingAnnotation, JsonLdWebAnnotation.class);
    List<TagReference> masterTagReferences = masterVersionJsonLdWebAnnotation.toTagReferenceList(projectId, collectionId);
    AnnotationConflict annotationConflict = new AnnotationConflict(null, Collections.emptyList(), masterTagReferences.get(0).getTagInstance(), masterTagReferences);
    return annotationConflict;
}
Also used : AnnotationConflict(de.catma.project.conflict.AnnotationConflict) TagReference(de.catma.document.annotation.TagReference) JsonLdWebAnnotation(de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotation)

Aggregations

AnnotationConflict (de.catma.project.conflict.AnnotationConflict)4 TagReference (de.catma.document.annotation.TagReference)3 JsonLdWebAnnotation (de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotation)3 ContentInfoSet (de.catma.document.source.ContentInfoSet)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