use of de.catma.document.source.SourceDocument in project catma by forTEXT.
the class GraphWorktreeProject method synchronizeWithRemote.
@Override
public void synchronizeWithRemote(OpenProjectListener openProjectListener) throws Exception {
if (hasUncommittedChanges()) {
throw new IllegalStateException("There are uncommitted changes that need to be committed first!");
}
for (TagsetDefinition tagset : getTagsets()) {
gitProjectHandler.synchronizeTagsetWithRemote(tagset.getUuid());
}
for (SourceDocument document : getSourceDocuments()) {
gitProjectHandler.synchronizeSourceDocumentWithRemote(document.getUuid());
for (AnnotationCollectionReference collectionReference : document.getUserMarkupCollectionRefs()) {
gitProjectHandler.synchronizeCollectionWithRemote(collectionReference.getId());
}
}
gitProjectHandler.synchronizeWithRemote();
if (gitProjectHandler.hasConflicts()) {
gitProjectHandler.initAndUpdateSubmodules();
openProjectListener.conflictResolutionNeeded(new GitConflictedProject(projectReference, gitProjectHandler, documentId -> getSourceDocumentURI(documentId)));
} else {
boolean forceGraphReload = gitProjectHandler.loadRolesPerResource();
gitProjectHandler.initAndUpdateSubmodules();
gitProjectHandler.removeStaleSubmoduleDirectories();
gitProjectHandler.ensureDevBranches();
rootRevisionHash = gitProjectHandler.getRootRevisionHash();
ProgressListener progressListener = new ProgressListener() {
@Override
public void setProgress(String value, Object... args) {
openProjectListener.progress(value, args);
}
};
graphProjectHandler.ensureProjectRevisionIsLoaded(new ExecutionListener<TagManager>() {
@Override
public void error(Throwable t) {
openProjectListener.failure(t);
}
@Override
public void done(TagManager result) {
tagManager.load(result.getTagLibrary());
openProjectListener.ready(GraphWorktreeProject.this);
}
}, progressListener, rootRevisionHash, tagManager, () -> gitProjectHandler.getTagsets(), () -> gitProjectHandler.getDocuments(), (tagLibrary) -> gitProjectHandler.getCollections(tagLibrary, progressListener), forceGraphReload, backgroundService);
}
}
use of de.catma.document.source.SourceDocument in project catma by forTEXT.
the class GraphWorktreeProject method importCollection.
public void importCollection(List<TagsetDefinitionImportStatus> tagsetDefinitionImportStatusList, AnnotationCollection importAnnotationCollection) throws IOException {
// if updates to existing Tagsets are needed, update only the Tags
// that are actually referenced in the Collection
Set<String> tagDefinitionIds = importAnnotationCollection.getTagReferences().stream().map(tagRef -> tagRef.getTagDefinitionId()).collect(Collectors.toSet());
for (TagsetDefinitionImportStatus tagsetDefinitionImportStatus : tagsetDefinitionImportStatusList) {
tagsetDefinitionImportStatus.setUpdateFilter(tagDefinitionIds);
}
importTagsets(tagsetDefinitionImportStatusList);
importAnnotationCollection.setTagLibrary(tagManager.getTagLibrary());
try {
SourceDocument sourceDocument = getSourceDocument(importAnnotationCollection.getSourceDocumentId());
String umcRevisionHash = gitProjectHandler.createMarkupCollection(importAnnotationCollection.getId(), importAnnotationCollection.getName(), // description
importAnnotationCollection.getContentInfoSet().getDescription(), importAnnotationCollection.getSourceDocumentId(), importAnnotationCollection.getSourceDocumentRevisionHash());
String oldRootRevisionHash = this.rootRevisionHash;
this.rootRevisionHash = gitProjectHandler.getRootRevisionHash();
graphProjectHandler.addCollection(rootRevisionHash, importAnnotationCollection.getId(), importAnnotationCollection.getName(), umcRevisionHash, sourceDocument, tagManager.getTagLibrary(), oldRootRevisionHash);
AnnotationCollectionReference annotationCollectionReference = sourceDocument.getUserMarkupCollectionReference(importAnnotationCollection.getId());
eventBus.post(new CollectionChangeEvent(annotationCollectionReference, sourceDocument, ChangeType.CREATED));
AnnotationCollection createdAnnotationCollection = getUserMarkupCollection(annotationCollectionReference);
createdAnnotationCollection.addTagReferences(importAnnotationCollection.getTagReferences());
ArrayListMultimap<String, TagReference> tagReferencesByTagInstanceId = ArrayListMultimap.create();
importAnnotationCollection.getTagReferences().stream().forEach(tagReference -> tagReferencesByTagInstanceId.put(tagReference.getTagInstanceId(), tagReference));
for (String tagInstanceId : tagReferencesByTagInstanceId.keySet()) {
update(createdAnnotationCollection, tagReferencesByTagInstanceId.get(tagInstanceId));
}
commitChanges(String.format("Imported Annotations from Collection %1$s with ID %2$s", createdAnnotationCollection.getName(), createdAnnotationCollection.getId()));
} catch (Exception e) {
throw new IOException(String.format("Import of Collection %1$s failed! The import has been aborted.", importAnnotationCollection.getName()), e);
}
}
use of de.catma.document.source.SourceDocument in project catma by forTEXT.
the class TPGraphProjectHandler method removeTagReferences.
@Override
public void removeTagReferences(String rootRevisionHash, AnnotationCollection collection, List<TagReference> tagReferences) throws Exception {
logger.info("Removing " + tagReferences.size() + " references, graph size: " + graph);
Set<String> tagInstanceIds = tagReferences.stream().map(tr -> tr.getTagInstanceId()).collect(Collectors.toSet());
GraphTraversalSource g = graph.traversal();
g.V().has(nt(ProjectRevision), "revisionHash", rootRevisionHash).outE(rt(hasDocument)).inV().has(nt(SourceDocument), "documentId", collection.getSourceDocumentId()).outE(rt(hasCollection)).inV().has(nt(MarkupCollection), "collectionId", collection.getId()).outE(rt(hasInstance)).inV().has(nt(TagInstance), "tagInstanceId", P.within(tagInstanceIds)).store("instances").outE(rt(hasProperty)).inV().drop().cap("instances").unfold().drop().iterate();
logger.info("Finished removing " + tagReferences.size() + " references, graph size: " + graph);
}
use of de.catma.document.source.SourceDocument in project catma by forTEXT.
the class AnnotateResourcePanel method setSelectedDocument.
public void setSelectedDocument(SourceDocument sourceDocument) {
SourceDocument selected = getSelectedDocument();
if ((selected == null) || !selected.equals(sourceDocument)) {
for (DocumentTreeItem documentTreeItem : documentData.getRootItems()) {
if (documentTreeItem instanceof DocumentDataItem) {
DocumentDataItem documentDataItem = (DocumentDataItem) documentTreeItem;
if (documentDataItem.getDocument().equals(sourceDocument)) {
documentDataItem.setSelected(true);
documentTree.getDataProvider().refreshItem(documentDataItem);
documentTree.expand(documentDataItem);
}
}
}
}
}
use of de.catma.document.source.SourceDocument in project catma by forTEXT.
the class AnnotateResourcePanel method handleDocumentChanged.
@Subscribe
public void handleDocumentChanged(DocumentChangeEvent documentChangeEvent) {
SourceDocument currentlySelectedDocument = getSelectedDocument();
SourceDocument nextSelectedDocument = null;
if ((currentlySelectedDocument != null) && !(documentChangeEvent.getChangeType().equals(ChangeType.DELETED) && documentChangeEvent.getDocument().equals(currentlySelectedDocument))) {
nextSelectedDocument = currentlySelectedDocument;
}
initData(nextSelectedDocument, Collections.emptySet());
}
Aggregations