use of de.catma.project.event.DocumentChangeEvent in project catma by forTEXT.
the class GraphWorktreeProject method update.
@Override
public void update(SourceDocument sourceDocument, ContentInfoSet contentInfoSet) throws Exception {
String sourceDocumentRevision = gitProjectHandler.updateSourceDocument(sourceDocument);
sourceDocument.setRevisionHash(sourceDocumentRevision);
String oldRootRevisionHash = this.rootRevisionHash;
// project commit
this.rootRevisionHash = gitProjectHandler.addSourceDocumentSubmoduleToStagedAndCommit(sourceDocument.getUuid(), String.format("Updated metadata of document \"%s\" with ID %s", sourceDocument.getSourceContentHandler().getSourceDocumentInfo().getContentInfoSet().getTitle(), sourceDocument.getUuid()), false);
graphProjectHandler.updateSourceDocument(this.rootRevisionHash, sourceDocument, oldRootRevisionHash);
eventBus.post(new DocumentChangeEvent(sourceDocument, ChangeType.UPDATED));
}
use of de.catma.project.event.DocumentChangeEvent in project catma by forTEXT.
the class GraphWorktreeProject method insert.
@Override
public void insert(SourceDocument sourceDocument, boolean deleteTempFile) throws IOException {
try {
File sourceTempFile = Paths.get(new File(this.tempDir).toURI()).resolve(sourceDocument.getUuid()).toFile();
String convertedFilename = sourceDocument.getUuid() + "." + UTF8_CONVERSION_FILE_EXTENSION;
logger.info("start tokenizing sourcedocument");
List<String> unseparableCharacterSequences = sourceDocument.getSourceContentHandler().getSourceDocumentInfo().getIndexInfoSet().getUnseparableCharacterSequences();
List<Character> userDefinedSeparatingCharacters = sourceDocument.getSourceContentHandler().getSourceDocumentInfo().getIndexInfoSet().getUserDefinedSeparatingCharacters();
Locale locale = sourceDocument.getSourceContentHandler().getSourceDocumentInfo().getIndexInfoSet().getLocale();
TermExtractor termExtractor = new TermExtractor(sourceDocument.getContent(), unseparableCharacterSequences, userDefinedSeparatingCharacters, locale);
final Map<String, List<TermInfo>> terms = termExtractor.getTerms();
logger.info("tokenization finished");
try (FileInputStream originalFileInputStream = new FileInputStream(sourceTempFile)) {
MediaType mediaType = MediaType.parse(sourceDocument.getSourceContentHandler().getSourceDocumentInfo().getTechInfoSet().getMimeType());
String extension = mediaType.getBaseType().getType();
if (extension == null || extension.isEmpty()) {
extension = "unknown";
}
String sourceDocRevisionHash = gitProjectHandler.createSourceDocument(sourceDocument.getUuid(), originalFileInputStream, sourceDocument.getUuid() + ORIG_INFIX + "." + extension, new ByteArrayInputStream(sourceDocument.getContent().getBytes(Charset.forName("UTF-8"))), convertedFilename, terms, sourceDocument.getUuid() + "." + TOKENIZED_FILE_EXTENSION, sourceDocument.getSourceContentHandler().getSourceDocumentInfo());
sourceDocument.unload();
StandardContentHandler contentHandler = new StandardContentHandler();
contentHandler.setSourceDocumentInfo(sourceDocument.getSourceContentHandler().getSourceDocumentInfo());
sourceDocument.setSourceContentHandler(contentHandler);
sourceDocument.setRevisionHash(sourceDocRevisionHash);
}
if (deleteTempFile) {
sourceTempFile.delete();
}
String oldRootRevisionHash = this.rootRevisionHash;
this.rootRevisionHash = gitProjectHandler.getRootRevisionHash();
graphProjectHandler.addSourceDocument(oldRootRevisionHash, this.rootRevisionHash, sourceDocument, getTokenizedSourceDocumentPath(sourceDocument.getUuid()));
eventBus.post(new DocumentChangeEvent(sourceDocument, ChangeType.CREATED));
} catch (Exception e) {
e.printStackTrace();
propertyChangeSupport.firePropertyChange(RepositoryChangeEvent.exceptionOccurred.name(), null, e);
}
}
use of de.catma.project.event.DocumentChangeEvent in project catma by forTEXT.
the class GraphWorktreeProject method delete.
@Override
public void delete(SourceDocument sourceDocument) throws Exception {
for (AnnotationCollectionReference collectionRef : new HashSet<>(sourceDocument.getUserMarkupCollectionRefs())) {
delete(collectionRef);
}
documentCache.invalidate(sourceDocument.getUuid());
String oldRootRevisionHash = this.rootRevisionHash;
gitProjectHandler.removeDocument(sourceDocument);
this.rootRevisionHash = gitProjectHandler.getRootRevisionHash();
graphProjectHandler.removeDocument(this.rootRevisionHash, sourceDocument, oldRootRevisionHash);
eventBus.post(new DocumentChangeEvent(sourceDocument, ChangeType.DELETED));
}
use of de.catma.project.event.DocumentChangeEvent in project catma by forTEXT.
the class AnalyzeResourcePanel method handleDocumentChanged.
@SuppressWarnings("unchecked")
@Subscribe
public void handleDocumentChanged(DocumentChangeEvent documentChangeEvent) {
if (documentChangeEvent.getChangeType().equals(ChangeType.CREATED)) {
SourceDocument document = documentChangeEvent.getDocument();
documentData.addItem(null, new DocumentDataItem(document));
} else if (documentChangeEvent.getChangeType().equals(ChangeType.DELETED)) {
Optional<DocumentTreeItem> optionalDocItem = documentData.getRootItems().stream().filter(item -> ((DocumentDataItem) item).getDocument().equals(documentChangeEvent.getDocument())).findAny();
if (optionalDocItem.isPresent()) {
DocumentTreeItem docItem = optionalDocItem.get();
List<DocumentTreeItem> children = documentData.getChildren(docItem);
documentData.removeItem(docItem);
Set<DocumentTreeItem> updated = new HashSet<>(children);
updated.add(docItem);
// selections needs manual update...
((SelectionModel.Multi<DocumentTreeItem>) documentTree.getSelectionModel()).updateSelection(Collections.emptySet(), updated);
corpusChangedListener.corpusChanged();
}
} else {
documentData.getRootItems().stream().filter(item -> ((DocumentDataItem) item).getDocument().equals(documentChangeEvent.getDocument())).findAny().ifPresent(item -> documentTree.getDataProvider().refreshItem(item));
corpusChangedListener.corpusChanged();
}
}
Aggregations