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