Search in sources :

Example 1 with DocumentChangeEvent

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));
}
Also used : DocumentChangeEvent(de.catma.project.event.DocumentChangeEvent)

Example 2 with DocumentChangeEvent

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);
    }
}
Also used : Locale(java.util.Locale) TermExtractor(de.catma.indexer.TermExtractor) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) ByteArrayInputStream(java.io.ByteArrayInputStream) MediaType(org.apache.tika.mime.MediaType) List(java.util.List) ArrayList(java.util.ArrayList) DocumentChangeEvent(de.catma.project.event.DocumentChangeEvent) StandardContentHandler(de.catma.document.source.contenthandler.StandardContentHandler) File(java.io.File)

Example 3 with DocumentChangeEvent

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));
}
Also used : AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) DocumentChangeEvent(de.catma.project.event.DocumentChangeEvent) HashSet(java.util.HashSet)

Example 4 with DocumentChangeEvent

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();
    }
}
Also used : SelectionListener(com.vaadin.event.selection.SelectionListener) VerticalLayout(com.vaadin.ui.VerticalLayout) SelectionEvent(com.vaadin.event.selection.SelectionEvent) UI(com.vaadin.ui.UI) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) HashSet(java.util.HashSet) EventBus(com.google.common.eventbus.EventBus) Notification(com.vaadin.ui.Notification) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Label(com.vaadin.ui.Label) TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) DocumentChangeEvent(de.catma.project.event.DocumentChangeEvent) TreeGridFactory(de.catma.ui.component.TreeGridFactory) Subscribe(com.google.common.eventbus.Subscribe) SelectionModel(com.vaadin.data.SelectionModel) TreeData(com.vaadin.data.TreeData) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Project(de.catma.project.Project) Collection(java.util.Collection) Set(java.util.Set) TreeGrid(com.vaadin.ui.TreeGrid) SourceDocument(de.catma.document.source.SourceDocument) ProjectReadyEvent(de.catma.project.event.ProjectReadyEvent) Collectors(java.util.stream.Collectors) MarginInfo(com.vaadin.shared.ui.MarginInfo) ItemClick(com.vaadin.ui.Grid.ItemClick) List(java.util.List) Type(com.vaadin.ui.Notification.Type) ChangeType(de.catma.project.event.ChangeType) Corpus(de.catma.document.corpus.Corpus) Optional(java.util.Optional) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) CollectionChangeEvent(de.catma.project.event.CollectionChangeEvent) Collections(java.util.Collections) RBACPermission(de.catma.rbac.RBACPermission) Grid(com.vaadin.ui.Grid) HashSet(java.util.HashSet) Set(java.util.Set) Optional(java.util.Optional) SourceDocument(de.catma.document.source.SourceDocument) SelectionModel(com.vaadin.data.SelectionModel) List(java.util.List) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

DocumentChangeEvent (de.catma.project.event.DocumentChangeEvent)4 AnnotationCollectionReference (de.catma.document.annotation.AnnotationCollectionReference)2 HashSet (java.util.HashSet)2 List (java.util.List)2 EventBus (com.google.common.eventbus.EventBus)1 Subscribe (com.google.common.eventbus.Subscribe)1 SelectionModel (com.vaadin.data.SelectionModel)1 TreeData (com.vaadin.data.TreeData)1 TreeDataProvider (com.vaadin.data.provider.TreeDataProvider)1 SelectionEvent (com.vaadin.event.selection.SelectionEvent)1 SelectionListener (com.vaadin.event.selection.SelectionListener)1 MarginInfo (com.vaadin.shared.ui.MarginInfo)1 Grid (com.vaadin.ui.Grid)1 ItemClick (com.vaadin.ui.Grid.ItemClick)1 Label (com.vaadin.ui.Label)1 Notification (com.vaadin.ui.Notification)1 Type (com.vaadin.ui.Notification.Type)1 TreeGrid (com.vaadin.ui.TreeGrid)1 UI (com.vaadin.ui.UI)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1