Search in sources :

Example 21 with QueryResultRow

use of de.catma.queryengine.result.QueryResultRow in project catma by forTEXT.

the class KwicPanel method annotateSelection.

@SuppressWarnings("unchecked")
private void annotateSelection(Set<QueryResultRow> selectedRows, WizardContext result) throws Exception {
    List<Property> properties = (List<Property>) result.get(AnnotationWizardContextKey.PROPERTIES);
    Map<String, AnnotationCollectionReference> collectionRefsByDocId = (Map<String, AnnotationCollectionReference>) result.get(AnnotationWizardContextKey.COLLECTIONREFS_BY_DOCID);
    TagDefinition tag = (TagDefinition) result.get(AnnotationWizardContextKey.TAG);
    AnnotationCollectionManager collectionManager = new AnnotationCollectionManager(project);
    for (AnnotationCollectionReference ref : collectionRefsByDocId.values()) {
        collectionManager.add(project.getUserMarkupCollection(ref));
    }
    for (QueryResultRow row : selectedRows) {
        AnnotationCollectionReference collectionRef = collectionRefsByDocId.get(row.getSourceDocumentId());
        TagInstance tagInstance = new TagInstance(idGenerator.generate(), tag.getUuid(), project.getUser().getIdentifier(), ZonedDateTime.now().format(DateTimeFormatter.ofPattern(Version.DATETIMEPATTERN)), tag.getUserDefinedPropertyDefinitions(), tag.getTagsetDefinitionUuid());
        List<TagReference> tagReferences = new ArrayList<TagReference>();
        for (Property protoProp : properties) {
            tagInstance.getUserDefinedPropetyByUuid(protoProp.getPropertyDefinitionId()).setPropertyValueList(protoProp.getPropertyValueList());
        }
        Set<Range> ranges = row.getRanges();
        for (Range range : ranges) {
            TagReference tagReference = new TagReference(tagInstance, row.getSourceDocumentId(), range, collectionRef.getId());
            tagReferences.add(tagReference);
        }
        collectionManager.addTagReferences(tagReferences, collectionRef.getId());
    }
}
Also used : TagDefinition(de.catma.tag.TagDefinition) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) QueryResultRow(de.catma.queryengine.result.QueryResultRow) ArrayList(java.util.ArrayList) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Range(de.catma.document.Range) AnnotationCollectionManager(de.catma.document.annotation.AnnotationCollectionManager) TagInstance(de.catma.tag.TagInstance) List(java.util.List) ArrayList(java.util.ArrayList) TagReference(de.catma.document.annotation.TagReference) Property(de.catma.tag.Property) Map(java.util.Map)

Example 22 with QueryResultRow

use of de.catma.queryengine.result.QueryResultRow in project catma by forTEXT.

the class KwicPanel method handleRemoveAnnotationsRequest.

private void handleRemoveAnnotationsRequest(EventBus eventBus) {
    final Set<QueryResultRow> selectedRows = kwicGrid.getSelectedItems();
    if (selectedRows.isEmpty()) {
        Notification.show("Info", "Please select one or more Annotation rows!", Type.HUMANIZED_MESSAGE);
        return;
    }
    int annotationRows = 0;
    List<AnnotationCollectionReference> annotationCollectionReferences = new ArrayList<>();
    boolean resourcesMissing = false;
    boolean permissionsMissing = false;
    Set<String> tagInstanceIdsToBeRemoved = new HashSet<String>();
    Set<QueryResultRow> rowsToBeRemoved = new HashSet<>();
    try {
        LoadingCache<String, Boolean> collectionIdToHasWritePermission = CacheBuilder.newBuilder().build(new CacheLoader<String, Boolean>() {

            @Override
            public Boolean load(String collectionId) throws Exception {
                return project.hasPermission(project.getRoleForCollection(collectionId), RBACPermission.COLLECTION_WRITE);
            }
        });
        for (QueryResultRow row : selectedRows) {
            if (row instanceof TagQueryResultRow) {
                annotationRows++;
                if (project.hasDocument(row.getSourceDocumentId())) {
                    SourceDocument document = project.getSourceDocument(row.getSourceDocumentId());
                    AnnotationCollectionReference collRef = document.getUserMarkupCollectionReference(((TagQueryResultRow) row).getMarkupCollectionId());
                    if (collRef != null) {
                        if (collectionIdToHasWritePermission.get(collRef.getId())) {
                            annotationCollectionReferences.add(collRef);
                            tagInstanceIdsToBeRemoved.add(((TagQueryResultRow) row).getTagInstanceId());
                            rowsToBeRemoved.add(row);
                        } else {
                            permissionsMissing = true;
                        }
                    } else {
                        resourcesMissing = true;
                    }
                } else {
                    resourcesMissing = true;
                }
            }
        }
        if (permissionsMissing) {
            Notification.show("Info", "You do not have the write permission for one or more Collections referenced by your selection. Those Collections will be ignored!", Type.HUMANIZED_MESSAGE);
        }
        if (annotationRows == 0) {
            Notification.show("Info", "Your selection does not contain any Annotations! Please select Annotations only!", Type.HUMANIZED_MESSAGE);
            return;
        }
        if (annotationCollectionReferences.isEmpty()) {
            Notification.show("Info", "The Documents and/or Collections referenced by your selection are no longer part of the Project!", Type.HUMANIZED_MESSAGE);
            return;
        }
        if (resourcesMissing) {
            Notification.show("Info", "Some of the Documents and/or Collections referenced by your selection " + "are no longer part of the Project and will be ignored, " + "see columns 'Document' and 'Collection' for details!", Type.HUMANIZED_MESSAGE);
        }
        if (annotationRows != selectedRows.size()) {
            Notification.show("Info", "Some rows of your selection do not represent Annotations and will be ignored, see column 'Tag' for details!", Type.HUMANIZED_MESSAGE);
        }
        AnnotationCollectionManager collectionManager = new AnnotationCollectionManager(project);
        for (AnnotationCollectionReference ref : annotationCollectionReferences) {
            collectionManager.add(project.getUserMarkupCollection(ref));
        }
        collectionManager.removeTagInstance(tagInstanceIdsToBeRemoved, true);
        kwicDataProvider.getItems().removeAll(rowsToBeRemoved);
        kwicDataProvider.refreshAll();
    } catch (Exception e) {
        ((ErrorHandler) UI.getCurrent()).showAndLogError("error deleting Annotations!", e);
    }
}
Also used : TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) QueryResultRow(de.catma.queryengine.result.QueryResultRow) ArrayList(java.util.ArrayList) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) AnnotationCollectionManager(de.catma.document.annotation.AnnotationCollectionManager) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) HashSet(java.util.HashSet)

Example 23 with QueryResultRow

use of de.catma.queryengine.result.QueryResultRow in project catma by forTEXT.

the class KwicPanel method handleAnnotateSelectedRequest.

private void handleAnnotateSelectedRequest(EventBus eventBus) {
    final Set<QueryResultRow> selectedRows = kwicGrid.getSelectedItems();
    if (selectedRows.isEmpty()) {
        Notification.show("Info", "Please select one or more rows to annotate!", Type.HUMANIZED_MESSAGE);
        return;
    }
    Set<String> documentIds = kwicDataProvider.getItems().stream().map(row -> row.getSourceDocumentId()).collect(Collectors.toSet());
    WizardContext wizardContext = new WizardContext();
    wizardContext.put(AnnotationWizardContextKey.DOCUMENTIDS, documentIds);
    AnnotationWizard wizard = new AnnotationWizard(eventBus, project, wizardContext, new SaveCancelListener<WizardContext>() {

        @Override
        public void savePressed(WizardContext result) {
            try {
                annotateSelection(selectedRows, result);
            } catch (Exception e) {
                ((ErrorHandler) UI.getCurrent()).showAndLogError("error annotating selected rows", e);
            }
        }
    });
    wizard.show();
}
Also used : BackgroundServiceProvider(de.catma.backgroundservice.BackgroundServiceProvider) DisplaySetting(de.catma.ui.module.analyze.queryresultpanel.DisplaySetting) MenuItem(com.vaadin.ui.MenuBar.MenuItem) LoadingCache(com.google.common.cache.LoadingCache) ZonedDateTime(java.time.ZonedDateTime) UI(com.vaadin.ui.UI) QueryResultRowArray(de.catma.queryengine.result.QueryResultRowArray) SearchFilterProvider(de.catma.ui.component.actiongrid.SearchFilterProvider) KwicProvider(de.catma.indexer.KwicProvider) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Map(java.util.Map) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) VaadinIcons(com.vaadin.icons.VaadinIcons) Version(de.catma.tag.Version) AnnotationWizard(de.catma.ui.module.analyze.visualization.kwic.annotation.AnnotationWizard) IconButton(de.catma.ui.component.IconButton) ExpansionListener(de.catma.ui.module.analyze.visualization.ExpansionListener) Set(java.util.Set) TagInstance(de.catma.tag.TagInstance) Collectors(java.util.stream.Collectors) MarginInfo(com.vaadin.shared.ui.MarginInfo) ItemClick(com.vaadin.ui.Grid.ItemClick) ItemClickListener(com.vaadin.ui.components.grid.ItemClickListener) TagReference(de.catma.document.annotation.TagReference) CacheLoader(com.google.common.cache.CacheLoader) List(java.util.List) Type(com.vaadin.ui.Notification.Type) TagDefinition(de.catma.tag.TagDefinition) CacheBuilder(com.google.common.cache.CacheBuilder) SelectionMode(com.vaadin.ui.Grid.SelectionMode) RBACPermission(de.catma.rbac.RBACPermission) StreamResource(com.vaadin.server.StreamResource) Range(de.catma.document.Range) ClickListener(com.vaadin.ui.Button.ClickListener) Column(com.vaadin.ui.Grid.Column) VerticalLayout(com.vaadin.ui.VerticalLayout) AnnotationCollectionManager(de.catma.document.annotation.AnnotationCollectionManager) LocalDateTime(java.time.LocalDateTime) Query(com.vaadin.data.provider.Query) WizardContext(de.catma.ui.dialog.wizard.WizardContext) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) ActionGridBar(de.catma.ui.component.actiongrid.ActionGridBar) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) EventBus(com.google.common.eventbus.EventBus) Registration(com.vaadin.shared.Registration) Notification(com.vaadin.ui.Notification) Label(com.vaadin.ui.Label) IDGenerator(de.catma.util.IDGenerator) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) CSVExportGroupedStreamSource(de.catma.ui.module.analyze.CSVExportGroupedStreamSource) ListDataProvider(com.vaadin.data.provider.ListDataProvider) ContentMode(com.vaadin.shared.ui.ContentMode) Property(de.catma.tag.Property) ClickEvent(com.vaadin.ui.Button.ClickEvent) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Project(de.catma.project.Project) QueryResultRow(de.catma.queryengine.result.QueryResultRow) SourceDocument(de.catma.document.source.SourceDocument) Visualization(de.catma.ui.module.analyze.visualization.Visualization) ContextMenu(com.vaadin.contextmenu.ContextMenu) QueryResultRowInAnnotateEvent(de.catma.ui.events.QueryResultRowInAnnotateEvent) DateTimeFormatter(java.time.format.DateTimeFormatter) FileDownloader(com.vaadin.server.FileDownloader) SerializablePredicate(com.vaadin.server.SerializablePredicate) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) CSVExportFlatStreamSource(de.catma.ui.module.analyze.CSVExportFlatStreamSource) AnnotationWizardContextKey(de.catma.ui.module.analyze.visualization.kwic.annotation.AnnotationWizardContextKey) Grid(com.vaadin.ui.Grid) ErrorHandler(de.catma.ui.module.main.ErrorHandler) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) QueryResultRow(de.catma.queryengine.result.QueryResultRow) WizardContext(de.catma.ui.dialog.wizard.WizardContext) AnnotationWizard(de.catma.ui.module.analyze.visualization.kwic.annotation.AnnotationWizard)

Example 24 with QueryResultRow

use of de.catma.queryengine.result.QueryResultRow in project catma by forTEXT.

the class KwicPanel method initActions.

private void initActions(EventBus eventBus) {
    ContextMenu moreOptionsMenu = kwicGridComponent.getActionGridBar().getBtnMoreOptionsContextMenu();
    moreOptionsMenu.addItem("Annotate selected rows", mi -> handleAnnotateSelectedRequest(eventBus));
    ActionGridBar actionBar = kwicGridComponent.getActionGridBar();
    actionBar.addButtonAfterSearchField(btnClearSelectedRows);
    btnClearSelectedRows.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            handleRemoveRowRequest();
        }
    });
    miRemoveAnnotations = moreOptionsMenu.addItem("Remove selected Annotations", mi -> handleRemoveAnnotationsRequest(eventBus));
    miRemoveAnnotations.setEnabled(false);
    MenuItem miExport = moreOptionsMenu.addItem("Export");
    MenuItem miCSVFlatExport = miExport.addItem("Export as CSV");
    StreamResource csvFlatExportResource = new StreamResource(new CSVExportFlatStreamSource(() -> getFilteredQueryResult(), project, kwicItemHandler.getKwicProviderCache(), ((BackgroundServiceProvider) UI.getCurrent())), "CATMA-KWIC_Export-" + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME) + ".csv");
    csvFlatExportResource.setCacheTime(0);
    csvFlatExportResource.setMIMEType("text/comma-separated-values");
    FileDownloader csvFlatExportFileDownloader = new FileDownloader(csvFlatExportResource);
    csvFlatExportFileDownloader.extend(miCSVFlatExport);
    kwicGridComponent.setSearchFilterProvider(new SearchFilterProvider<QueryResultRow>() {

        @Override
        public SerializablePredicate<QueryResultRow> createSearchFilter(String searchInput) {
            return (row) -> kwicItemHandler.containsSearchInput(row, searchInput);
        }
    });
    btExpandCompress.addClickListener(clickEvent -> handleMaxMinRequest());
    defaultDoubleClickRegistration = kwicGrid.addItemClickListener(clickEvent -> handleKwicItemClick(clickEvent, eventBus));
}
Also used : BackgroundServiceProvider(de.catma.backgroundservice.BackgroundServiceProvider) DisplaySetting(de.catma.ui.module.analyze.queryresultpanel.DisplaySetting) MenuItem(com.vaadin.ui.MenuBar.MenuItem) LoadingCache(com.google.common.cache.LoadingCache) ZonedDateTime(java.time.ZonedDateTime) UI(com.vaadin.ui.UI) QueryResultRowArray(de.catma.queryengine.result.QueryResultRowArray) SearchFilterProvider(de.catma.ui.component.actiongrid.SearchFilterProvider) KwicProvider(de.catma.indexer.KwicProvider) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Map(java.util.Map) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) VaadinIcons(com.vaadin.icons.VaadinIcons) Version(de.catma.tag.Version) AnnotationWizard(de.catma.ui.module.analyze.visualization.kwic.annotation.AnnotationWizard) IconButton(de.catma.ui.component.IconButton) ExpansionListener(de.catma.ui.module.analyze.visualization.ExpansionListener) Set(java.util.Set) TagInstance(de.catma.tag.TagInstance) Collectors(java.util.stream.Collectors) MarginInfo(com.vaadin.shared.ui.MarginInfo) ItemClick(com.vaadin.ui.Grid.ItemClick) ItemClickListener(com.vaadin.ui.components.grid.ItemClickListener) TagReference(de.catma.document.annotation.TagReference) CacheLoader(com.google.common.cache.CacheLoader) List(java.util.List) Type(com.vaadin.ui.Notification.Type) TagDefinition(de.catma.tag.TagDefinition) CacheBuilder(com.google.common.cache.CacheBuilder) SelectionMode(com.vaadin.ui.Grid.SelectionMode) RBACPermission(de.catma.rbac.RBACPermission) StreamResource(com.vaadin.server.StreamResource) Range(de.catma.document.Range) ClickListener(com.vaadin.ui.Button.ClickListener) Column(com.vaadin.ui.Grid.Column) VerticalLayout(com.vaadin.ui.VerticalLayout) AnnotationCollectionManager(de.catma.document.annotation.AnnotationCollectionManager) LocalDateTime(java.time.LocalDateTime) Query(com.vaadin.data.provider.Query) WizardContext(de.catma.ui.dialog.wizard.WizardContext) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) ActionGridBar(de.catma.ui.component.actiongrid.ActionGridBar) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) EventBus(com.google.common.eventbus.EventBus) Registration(com.vaadin.shared.Registration) Notification(com.vaadin.ui.Notification) Label(com.vaadin.ui.Label) IDGenerator(de.catma.util.IDGenerator) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) CSVExportGroupedStreamSource(de.catma.ui.module.analyze.CSVExportGroupedStreamSource) ListDataProvider(com.vaadin.data.provider.ListDataProvider) ContentMode(com.vaadin.shared.ui.ContentMode) Property(de.catma.tag.Property) ClickEvent(com.vaadin.ui.Button.ClickEvent) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Project(de.catma.project.Project) QueryResultRow(de.catma.queryengine.result.QueryResultRow) SourceDocument(de.catma.document.source.SourceDocument) Visualization(de.catma.ui.module.analyze.visualization.Visualization) ContextMenu(com.vaadin.contextmenu.ContextMenu) QueryResultRowInAnnotateEvent(de.catma.ui.events.QueryResultRowInAnnotateEvent) DateTimeFormatter(java.time.format.DateTimeFormatter) FileDownloader(com.vaadin.server.FileDownloader) SerializablePredicate(com.vaadin.server.SerializablePredicate) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) CSVExportFlatStreamSource(de.catma.ui.module.analyze.CSVExportFlatStreamSource) AnnotationWizardContextKey(de.catma.ui.module.analyze.visualization.kwic.annotation.AnnotationWizardContextKey) Grid(com.vaadin.ui.Grid) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) QueryResultRow(de.catma.queryengine.result.QueryResultRow) ClickEvent(com.vaadin.ui.Button.ClickEvent) ActionGridBar(de.catma.ui.component.actiongrid.ActionGridBar) ContextMenu(com.vaadin.contextmenu.ContextMenu) MenuItem(com.vaadin.ui.MenuBar.MenuItem) SerializablePredicate(com.vaadin.server.SerializablePredicate) CSVExportFlatStreamSource(de.catma.ui.module.analyze.CSVExportFlatStreamSource) StreamResource(com.vaadin.server.StreamResource) FileDownloader(com.vaadin.server.FileDownloader) ItemClickListener(com.vaadin.ui.components.grid.ItemClickListener) ClickListener(com.vaadin.ui.Button.ClickListener)

Example 25 with QueryResultRow

use of de.catma.queryengine.result.QueryResultRow in project catma by forTEXT.

the class QueryResultPanel method addQueryResultRows.

public void addQueryResultRows(QueryResultRowArray rows) {
    @SuppressWarnings("unchecked") final TreeDataProvider<QueryResultRowItem> dataProvider = ((TreeDataProvider<QueryResultRowItem>) queryResultGrid.getDataProvider());
    boolean rowsAdded = false;
    for (QueryResultRow row : rows) {
        if (!((QueryResultRowArray) queryResult).contains(row)) {
            ((QueryResultRowArray) queryResult).add(row);
            rowsAdded = true;
            // update existing items
            dataProvider.getTreeData().getRootItems().forEach(item -> item.addQueryResultRow(row, dataProvider.getTreeData(), kwicProviderCache));
        }
    }
    ;
    if (rowsAdded) {
        if (!dataProvider.getTreeData().equals(phraseBasedTreeData)) {
            phraseBasedTreeData = null;
        }
        if (!dataProvider.getTreeData().equals(tagBasedTreeData)) {
            tagBasedTreeData = null;
        }
        if (!dataProvider.getTreeData().equals(flatTagBasedTreeData)) {
            flatTagBasedTreeData = null;
        }
        if (!dataProvider.getTreeData().equals(propertiesAsColumnsTagBasedTreeData)) {
            propertiesAsColumnsTagBasedTreeData = null;
        }
    }
    // add new root items
    displaySetting.addQueryResultRootItems(this, rows);
    tokenCount = ((QueryResultRowArray) queryResult).size();
    dataProvider.refreshAll();
    if (!dataProvider.getTreeData().getRootItems().isEmpty() && queryResultGrid.getSelectedItems().isEmpty()) {
        queryResultGrid.getDataCommunicator().fetchItemsWithRange(0, 1).stream().findFirst().ifPresent(item -> queryResultGrid.select(item));
    }
}
Also used : TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) QueryResultRow(de.catma.queryengine.result.QueryResultRow) QueryResultRowArray(de.catma.queryengine.result.QueryResultRowArray)

Aggregations

QueryResultRow (de.catma.queryengine.result.QueryResultRow)29 TagQueryResultRow (de.catma.queryengine.result.TagQueryResultRow)22 QueryResultRowArray (de.catma.queryengine.result.QueryResultRowArray)18 SourceDocument (de.catma.document.source.SourceDocument)13 Range (de.catma.document.Range)12 KwicProvider (de.catma.indexer.KwicProvider)10 Project (de.catma.project.Project)10 QueryResult (de.catma.queryengine.result.QueryResult)10 ArrayList (java.util.ArrayList)10 AnnotationCollectionReference (de.catma.document.annotation.AnnotationCollectionReference)8 TagDefinition (de.catma.tag.TagDefinition)8 UI (com.vaadin.ui.UI)6 HashSet (java.util.HashSet)6 CacheLoader (com.google.common.cache.CacheLoader)5 LoadingCache (com.google.common.cache.LoadingCache)5 Query (com.vaadin.data.provider.Query)5 AnnotationCollectionManager (de.catma.document.annotation.AnnotationCollectionManager)5 List (java.util.List)5 Map (java.util.Map)5 CacheBuilder (com.google.common.cache.CacheBuilder)4