use of de.catma.repository.git.serialization.SerializationHelper in project catma by forTEXT.
the class ProjectResourceExportApiRequestHandler method serializeProjectResources.
private String serializeProjectResources() {
try {
Export export = new Export();
for (SourceDocument sourceDocument : project.getSourceDocuments()) {
ArrayList<AnnotationCollection> annotationCollections = new ArrayList<>();
for (AnnotationCollectionReference annotationCollectionReference : sourceDocument.getUserMarkupCollectionRefs()) {
annotationCollections.add(project.getUserMarkupCollection(annotationCollectionReference));
}
ArrayList<TagDefinition> tagDefinitions = new ArrayList<>();
ArrayList<TagReference> tagReferences = new ArrayList<>();
for (AnnotationCollection annotationCollection : annotationCollections) {
for (TagsetDefinition tagsetDefinition : annotationCollection.getTagLibrary().getTagsetDefinitions()) {
tagDefinitions.addAll(tagsetDefinition.stream().collect(Collectors.toList()));
}
tagReferences.addAll(annotationCollection.getTagReferences());
}
ExportDocument exportDocument = new ExportDocument(new PreApiSourceDocument(sourceDocument, String.format("%s%s/doc/%s", BASE_URL, handlerPath.substring(1), sourceDocument.getUuid().toLowerCase())), tagDefinitions.stream().map(PreApiTagDefinition::new).collect(Collectors.toList()), tagReferences.stream().map((TagReference tagReference) -> {
try {
return new PreApiAnnotation(tagReference, tagDefinitions.stream().filter(td -> td.getUuid().equals(tagReference.getTagDefinitionId())).findFirst().get(), sourceDocument);
} catch (IOException e) {
logger.log(Level.WARNING, String.format("Error serializing TagReference: %s", tagReference), e);
return null;
}
}).collect(Collectors.toList()));
export.addExportDocument(exportDocument);
}
return new SerializationHelper<Export>().serialize(export);
} catch (Exception e) {
logger.log(Level.SEVERE, "Failed to serialize project resources", e);
return "{\"error\": \"Failed to serialize project resources, please contact CATMA support\"}";
}
}
use of de.catma.repository.git.serialization.SerializationHelper in project catma by forTEXT.
the class GitlabManagerRestricted method getCommentReplies.
@Override
public List<Reply> getCommentReplies(String projectId, Comment comment) throws IOException {
String resourceId = comment.getDocumentId();
String projectPath = projectId + "/" + resourceId;
NotesApi notesApi = restrictedGitLabApi.getNotesApi();
List<Reply> result = new ArrayList<Reply>();
try {
List<Note> notes = notesApi.getIssueNotes(projectPath, comment.getIid());
for (Note note : notes.stream().filter(n -> !n.getSystem()).collect(Collectors.toList())) {
// filter system notes
String noteBody = note.getBody();
Reply reply = null;
try {
reply = new SerializationHelper<Reply>().deserialize(noteBody, Reply.class);
reply.setCommentUuid(comment.getUuid());
reply.setId(note.getId());
reply.setUserId(note.getAuthor().getId());
reply.setUsername(note.getAuthor().getName());
} catch (Exception e) {
logger.log(Level.SEVERE, String.format("Error deserializing Reply #%1$d %2$s", note.getId(), noteBody), e);
IDGenerator idGenerator = new IDGenerator();
reply = new Reply(idGenerator.generate(), noteBody, note.getAuthor().getUsername(), note.getAuthor().getId(), comment.getUuid(), note.getId());
}
result.add(reply);
}
comment.setReplies(result);
return result;
} catch (GitLabApiException e) {
throw new IOException(String.format("Failed to retrieve Replies for Comment %1$s %2$d for resource %3$s in group %4$s!", comment.getUuid(), comment.getIid(), resourceId, projectId), e);
}
}
use of de.catma.repository.git.serialization.SerializationHelper in project catma by forTEXT.
the class GitMarkupCollectionHandler method openTagReferences.
private ArrayList<TagReference> openTagReferences(String projectId, String markupCollectionId, String collectionName, File parentDirectory, ProgressListener progressListener, AtomicInteger counter) throws Exception {
ArrayList<TagReference> tagReferences = new ArrayList<>();
List<String> contents = Arrays.asList(parentDirectory.list());
for (String item : contents) {
File target = new File(parentDirectory, item);
// if it is a directory, recurse into it adding results to the current tagReferences list
if (target.isDirectory() && !target.getName().equalsIgnoreCase(".git")) {
tagReferences.addAll(this.openTagReferences(projectId, markupCollectionId, collectionName, target, progressListener, counter));
} else // if item is <CATMA_UUID>.json, read it into a list of TagReference objects
if (target.isFile() && isTagInstanceFilename(target.getName())) {
counter.incrementAndGet();
if (counter.intValue() % 1000 == 0) {
progressListener.setProgress("Loading Annotations %1$s %2$d", collectionName, counter.intValue());
}
String serialized = readFileToString(target, StandardCharsets.UTF_8);
JsonLdWebAnnotation jsonLdWebAnnotation = new SerializationHelper<JsonLdWebAnnotation>().deserialize(serialized, JsonLdWebAnnotation.class);
tagReferences.addAll(jsonLdWebAnnotation.toTagReferenceList(projectId, markupCollectionId));
}
}
return tagReferences;
}
use of de.catma.repository.git.serialization.SerializationHelper 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.repository.git.serialization.SerializationHelper in project catma by forTEXT.
the class GitMarkupCollectionHandler method updateCollection.
public String updateCollection(String projectId, AnnotationCollectionReference collectionRef) throws Exception {
try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
String collectionGitRepositoryName = projectRootRepositoryName + "/" + GitProjectHandler.ANNOTATION_COLLECTION_SUBMODULES_DIRECTORY_NAME + "/" + collectionRef.getId();
localGitRepoManager.open(projectId, collectionGitRepositoryName);
ContentInfoSet contentInfoSet = collectionRef.getContentInfoSet();
File targetHeaderFile = new File(localGitRepoManager.getRepositoryWorkTree(), HEADER_FILE_NAME);
GitMarkupCollectionHeader header = new GitMarkupCollectionHeader(contentInfoSet.getTitle(), contentInfoSet.getDescription(), collectionRef.getSourceDocumentId(), collectionRef.getSourceDocumentRevisiohHash());
SerializationHelper<GitMarkupCollectionHeader> serializationHelper = new SerializationHelper<>();
String serializedHeader = serializationHelper.serialize(header);
localGitRepoManager.add(targetHeaderFile, // TODO: why are we doing this and then calling addAndCommit?
serializedHeader.getBytes(StandardCharsets.UTF_8));
String collectionRevision = localGitRepoManager.addAndCommit(targetHeaderFile, serializedHeader.getBytes(StandardCharsets.UTF_8), String.format("Updated metadata of Collection %1$s with ID %2$s", collectionRef.getName(), collectionRef.getId()), remoteGitServerManager.getUsername(), remoteGitServerManager.getEmail());
return collectionRevision;
}
}
Aggregations