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;
}
}
Aggregations