Search in sources :

Example 11 with Property

use of de.catma.tag.Property in project catma by forTEXT.

the class EditAnnotationPropertiesDialog method getResult.

@Override
protected List<Property> getResult() {
    List<Property> result = new ArrayList<>();
    Iterator<Component> componentIterator = propertyTabSheet.iterator();
    while (componentIterator.hasNext()) {
        EditPropertyTab tab = (EditPropertyTab) componentIterator.next();
        if (tab.isChanged()) {
            Property property = tab.getProperty();
            property.setPropertyValueList(tab.getPropertyValues());
            result.add(property);
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Component(com.vaadin.ui.Component) Property(de.catma.tag.Property)

Example 12 with Property

use of de.catma.tag.Property in project catma by forTEXT.

the class AnnotationDetailsPanel method addAnnotation.

public void addAnnotation(Annotation annotation) throws IOException {
    Optional<AnnotationDataItem> optionalItem = findAnnotationDataItem(annotation.getTagInstance().getUuid());
    if (optionalItem.isPresent() && isAttached()) {
        annotationDetailsTree.collapse(annotationDetailData.getRootItems());
        annotationDetailsTree.select(optionalItem.get());
        annotationDetailsTree.expand(optionalItem.get());
        int itemIdx = annotationDetailData.getRootItems().indexOf(optionalItem.get());
        if (itemIdx >= 0) {
            annotationDetailsTree.scrollTo(itemIdx, ScrollDestination.START);
        }
    } else {
        AnnotationDataItem annotationDataItem = new AnnotationDataItem(annotation, project.getTagManager().getTagLibrary().getTagsetDefinition(annotation.getTagInstance().getTagsetId()), kwicProvider, project.hasPermission(project.getRoleForCollection(annotation.getUserMarkupCollection().getId()), RBACPermission.COLLECTION_WRITE), () -> isCurrentEditedCollection.apply(annotation.getUserMarkupCollection().getUuid()));
        annotationDetailsTree.collapse(annotationDetailData.getRootItems());
        annotationDetailData.addItem(null, annotationDataItem);
        String tagId = annotation.getTagInstance().getTagDefinitionId();
        for (Property property : annotation.getTagInstance().getUserDefinedProperties()) {
            TagDefinition tag = project.getTagManager().getTagLibrary().getTagDefinition(tagId);
            if (tag != null) {
                // may be deleted already
                PropertyDefinition propertyDef = tag.getPropertyDefinitionByUuid(property.getPropertyDefinitionId());
                if (propertyDef != null) {
                    // may be deleted already
                    AnnotationPropertyDataItem propertyDataItem = new AnnotationPropertyDataItem(property, () -> propertyDef.getName());
                    annotationDetailData.addItem(annotationDataItem, propertyDataItem);
                    for (String value : property.getPropertyValueList()) {
                        AnnotationPropertyValueDataItem valueDataItem = new AnnotationPropertyValueDataItem(value);
                        annotationDetailData.addItem(propertyDataItem, valueDataItem);
                    }
                }
            }
        }
        annotationDetailsProvider.refreshAll();
        if (isAttached()) {
            List<AnnotationTreeItem> items = new ArrayList<>();
            items.add(annotationDataItem);
            items.addAll(annotationDetailData.getChildren(annotationDataItem));
            annotationDetailsTree.expand(items);
            annotationDetailsTree.select(annotationDataItem);
            int itemIdx = annotationDetailData.getRootItems().size() - 1;
            if (itemIdx >= 0) {
                annotationDetailsTree.scrollTo(itemIdx, ScrollDestination.START);
            }
        }
    }
}
Also used : TagDefinition(de.catma.tag.TagDefinition) ArrayList(java.util.ArrayList) Property(de.catma.tag.Property) PropertyDefinition(de.catma.tag.PropertyDefinition)

Example 13 with Property

use of de.catma.tag.Property in project catma by forTEXT.

the class GitMarkupCollectionHandler method getCollection.

public AnnotationCollection getCollection(String projectId, String collectionId, TagLibrary tagLibrary, ProgressListener progressListener, boolean hasWritePermission, Function<String, Boolean> hasTagsetIdReadPermissionGetter) throws Exception {
    try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        localGitRepoManager.open(projectId, projectRootRepositoryName);
        String markupCollectionSubmoduleRelDir = GitProjectHandler.ANNOTATION_COLLECTION_SUBMODULES_DIRECTORY_NAME + "/" + collectionId;
        File markupCollectionSubmoduleAbsPath = new File(localGitRepoManager.getRepositoryWorkTree().toString(), markupCollectionSubmoduleRelDir);
        String markupCollectionRevisionHash = localGitRepoManager.getSubmoduleHeadRevisionHash(markupCollectionSubmoduleRelDir);
        // can't call open on an attached instance
        localGitRepoManager.detach();
        File markupCollectionHeaderFile = new File(markupCollectionSubmoduleAbsPath, HEADER_FILE_NAME);
        String serializedMarkupCollectionHeaderFile = FileUtils.readFileToString(markupCollectionHeaderFile, StandardCharsets.UTF_8);
        GitMarkupCollectionHeader markupCollectionHeader = new SerializationHelper<GitMarkupCollectionHeader>().deserialize(serializedMarkupCollectionHeaderFile, GitMarkupCollectionHeader.class);
        ContentInfoSet contentInfoSet = new ContentInfoSet(markupCollectionHeader.getAuthor(), markupCollectionHeader.getDescription(), markupCollectionHeader.getPublisher(), markupCollectionHeader.getName());
        AtomicInteger counter = new AtomicInteger();
        ArrayList<TagReference> tagReferences = this.openTagReferences(projectId, collectionId, contentInfoSet.getTitle(), markupCollectionSubmoduleAbsPath, progressListener, counter);
        // handle orphan Annotations
        ArrayListMultimap<TagInstance, TagReference> tagInstances = ArrayListMultimap.create();
        Set<String> orphanAnnotationIds = new HashSet<>();
        Iterator<TagReference> tagReferenceIterator = tagReferences.iterator();
        while (tagReferenceIterator.hasNext()) {
            TagReference tagReference = tagReferenceIterator.next();
            if (!orphanAnnotationIds.contains(tagReference.getTagInstanceId())) {
                String tagsetId = tagReference.getTagInstance().getTagsetId();
                boolean readPermission = hasTagsetIdReadPermissionGetter.apply(tagsetId);
                TagsetDefinition tagset = tagLibrary.getTagsetDefinition(tagsetId);
                String tagId = tagReference.getTagDefinitionId();
                if (readPermission && (tagset == null || tagset.isDeleted(tagId))) {
                    // Tag/Tagset has been deleted, we remove the stale Annotation as well
                    orphanAnnotationIds.add(tagReference.getTagInstanceId());
                    tagReferenceIterator.remove();
                } else {
                    // other orphan Annotations get ignored upon indexing
                    // until the corresponding Tag or its "deletion" info come along
                    tagInstances.put(tagReference.getTagInstance(), tagReference);
                }
            }
        }
        if (hasWritePermission) {
            removeTagInstances(projectId, collectionId, orphanAnnotationIds);
        }
        // handle orphan Properties
        if (hasWritePermission) {
            for (TagInstance tagInstance : tagInstances.keySet()) {
                TagsetDefinition tagset = tagLibrary.getTagsetDefinition(tagInstance.getTagsetId());
                if (tagset != null) {
                    Collection<Property> properties = tagInstance.getUserDefinedProperties();
                    for (Property property : new HashSet<>(properties)) {
                        // deleted property?
                        if (tagset.isDeleted(property.getPropertyDefinitionId())) {
                            // yes, we remove the stale property
                            tagInstance.removeUserDefinedProperty(property.getPropertyDefinitionId());
                            // and save the change
                            JsonLdWebAnnotation annotation = new JsonLdWebAnnotation(CATMAPropertyKey.GitLabServerUrl.getValue(), projectId, tagInstances.get(tagInstance), tagLibrary);
                            createTagInstance(projectId, collectionId, annotation);
                        }
                    }
                }
            }
        }
        AnnotationCollection userMarkupCollection = new AnnotationCollection(collectionId, contentInfoSet, tagLibrary, tagReferences, markupCollectionHeader.getSourceDocumentId(), markupCollectionHeader.getSourceDocumentVersion());
        userMarkupCollection.setRevisionHash(markupCollectionRevisionHash);
        return userMarkupCollection;
    }
}
Also used : AnnotationCollection(de.catma.document.annotation.AnnotationCollection) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) JsonLdWebAnnotation(de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotation) GitMarkupCollectionHeader(de.catma.repository.git.serialization.models.GitMarkupCollectionHeader) TagsetDefinition(de.catma.tag.TagsetDefinition) ContentInfoSet(de.catma.document.source.ContentInfoSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TagInstance(de.catma.tag.TagInstance) TagReference(de.catma.document.annotation.TagReference) File(java.io.File) Property(de.catma.tag.Property) HashSet(java.util.HashSet)

Example 14 with Property

use of de.catma.tag.Property in project catma by forTEXT.

the class TaggerView method tagInstanceAdded.

public void tagInstanceAdded(ClientTagInstance clientTagInstance) {
    AnnotationCollection collection = annotationPanel.getSelectedEditableCollection();
    if (collection == null) {
        // shouldn't happen, but just in case
        Notification.show("Info", "Please make sure you have an editable Collection available " + "and select this Collection as 'currently being edited'! " + "Your Annotation hasn't been saved!", Type.ERROR_MESSAGE);
    } else {
        TagLibrary tagLibrary = collection.getTagLibrary();
        TagDefinition tagDef = tagLibrary.getTagDefinition(clientTagInstance.getTagDefinitionID());
        TagInstance ti = new TagInstance(clientTagInstance.getInstanceID(), tagDef.getUuid(), project.getUser().getIdentifier(), ZonedDateTime.now().format(DateTimeFormatter.ofPattern(Version.DATETIMEPATTERN)), tagDef.getUserDefinedPropertyDefinitions(), tagDef.getTagsetDefinitionUuid());
        List<TagReference> tagReferences = new ArrayList<TagReference>();
        try {
            String userMarkupCollectionUuid = collection.getId();
            for (TextRange tr : clientTagInstance.getRanges()) {
                Range r = new Range(tr.getStartPos(), tr.getEndPos());
                TagReference ref = new TagReference(ti, sourceDocument.getUuid(), r, userMarkupCollectionUuid);
                tagReferences.add(ref);
            }
            final Annotation annotation = new Annotation(ti, tagReferences, collection, tagLibrary.getTagPath(tagDef));
            if (!tagDef.getUserDefinedPropertyDefinitions().isEmpty()) {
                EditAnnotationPropertiesDialog editAnnotationPropertiesDialog = new EditAnnotationPropertiesDialog(project, annotation, new SaveCancelListener<List<Property>>() {

                    @Override
                    public void savePressed(List<Property> notOfInterest) {
                        userMarkupCollectionManager.addTagReferences(tagReferences, collection);
                    }
                });
                editAnnotationPropertiesDialog.show();
            } else {
                userMarkupCollectionManager.addTagReferences(tagReferences, collection);
            }
        } catch (URISyntaxException e) {
            errorHandler.showAndLogError("Error adding Annotations!", e);
        }
    }
}
Also used : TagLibrary(de.catma.tag.TagLibrary) TagDefinition(de.catma.tag.TagDefinition) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) ArrayList(java.util.ArrayList) TextRange(de.catma.ui.client.ui.tagger.shared.TextRange) URISyntaxException(java.net.URISyntaxException) Range(de.catma.document.Range) TextRange(de.catma.ui.client.ui.tagger.shared.TextRange) Annotation(de.catma.document.annotation.Annotation) EditAnnotationPropertiesDialog(de.catma.ui.module.annotate.annotationpanel.EditAnnotationPropertiesDialog) TagInstance(de.catma.tag.TagInstance) ClientTagInstance(de.catma.ui.client.ui.tagger.shared.ClientTagInstance) TagReference(de.catma.document.annotation.TagReference) ArrayList(java.util.ArrayList) List(java.util.List) Property(de.catma.tag.Property)

Example 15 with Property

use of de.catma.tag.Property in project catma by forTEXT.

the class KwicPanel method initComponents.

private void initComponents() {
    setSizeFull();
    setMargin(false);
    setSpacing(false);
    btExpandCompress = new IconButton(expandResource);
    btExpandCompress.setVisible(false);
    kwicDataProvider = new ListDataProvider<>(new HashSet<>());
    kwicGrid = new Grid<QueryResultRow>(kwicDataProvider);
    kwicGrid.setSizeFull();
    kwicGrid.addColumn(row -> kwicItemHandler.getDocumentName(row)).setCaption("Document").setWidth(200).setHidable(true);
    kwicGrid.addColumn(row -> kwicItemHandler.getCollectionName(row)).setCaption("Collection").setWidth(200).setId(ColumnId.COLLECION_NAME.name()).setHidable(true).setHidden(true);
    Column<QueryResultRow, ?> backwardCtxColumn = kwicGrid.addColumn(row -> kwicItemHandler.getBackwardContext(row)).setCaption("Left Context").setStyleGenerator(row -> kwicItemHandler.getBackwardContextStyle(row)).setWidth(200);
    Column<QueryResultRow, ?> keywordColumn = kwicGrid.addColumn(row -> kwicItemHandler.getKeyword(row)).setCaption("Keyword").setWidth(200).setRenderer(new HtmlRenderer()).setStyleGenerator(row -> kwicItemHandler.getKeywordStyle(row)).setDescriptionGenerator(row -> kwicItemHandler.getKeywordDescription(row), ContentMode.HTML);
    kwicGrid.addColumn(row -> kwicItemHandler.getForwardContext(row)).setCaption("Right Context").setStyleGenerator(row -> kwicItemHandler.getForwardContextStyle(row)).setWidth(200);
    kwicGrid.addColumn(row -> row.getRange().getStartPoint()).setCaption("Start Point").setWidth(100).setId(ColumnId.START_POS.name()).setHidable(true);
    kwicGrid.addColumn(row -> row.getRange().getEndPoint()).setCaption("End Point").setWidth(100).setHidable(true);
    kwicGrid.addColumn(row -> kwicItemHandler.getTagPath(row)).setCaption("Tag").setHidable(true).setHidden(true).setId(ColumnId.TAG.name()).setWidth(200);
    kwicGrid.addColumn(row -> kwicItemHandler.getPropertyName(row)).setCaption("Property").setHidable(true).setHidden(true).setId(ColumnId.PROPERTY_NAME.name()).setWidth(200);
    kwicGrid.addColumn(row -> kwicItemHandler.getPropertyValue(row)).setCaption("Value").setHidable(true).setHidden(true).setId(ColumnId.PROPERTY_VALUE.name()).setWidth(200);
    kwicGrid.sort(keywordColumn);
    kwicGrid.getDefaultHeaderRow().getCell(keywordColumn).setStyleName("kwic-panel-keyword-header");
    kwicGrid.getDefaultHeaderRow().getCell(backwardCtxColumn).setStyleName("kwic-panel-backwardctx-header");
    kwicGridComponent = new ActionGridComponent<>(new Label("Keyword in context"), kwicGrid);
    kwicGridComponent.getActionGridBar().setAddBtnVisible(false);
    kwicGridComponent.getActionGridBar().addButtonRight(btExpandCompress);
    kwicGridComponent.setMargin(new MarginInfo(false, false, false, true));
    addComponent(kwicGridComponent);
    setExpandRatio(kwicGridComponent, 1f);
    btnClearSelectedRows = new IconButton(VaadinIcons.ERASER);
    btnClearSelectedRows.setVisible(false);
    btnClearSelectedRows.setDescription("Remove the selected rows from this list");
}
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) IconButton(de.catma.ui.component.IconButton) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) QueryResultRow(de.catma.queryengine.result.QueryResultRow) MarginInfo(com.vaadin.shared.ui.MarginInfo) Label(com.vaadin.ui.Label) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) HashSet(java.util.HashSet)

Aggregations

Property (de.catma.tag.Property)27 TagDefinition (de.catma.tag.TagDefinition)16 TagInstance (de.catma.tag.TagInstance)16 PropertyDefinition (de.catma.tag.PropertyDefinition)14 ArrayList (java.util.ArrayList)14 TagReference (de.catma.document.annotation.TagReference)10 List (java.util.List)9 Range (de.catma.document.Range)7 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)6 TagsetDefinition (de.catma.tag.TagsetDefinition)6 IDGenerator (de.catma.util.IDGenerator)6 AnnotationCollectionReference (de.catma.document.annotation.AnnotationCollectionReference)5 SourceDocument (de.catma.document.source.SourceDocument)5 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)4 TagManager (de.catma.tag.TagManager)4 File (java.io.File)4 HashSet (java.util.HashSet)4 Multimap (com.google.common.collect.Multimap)3 EventBus (com.google.common.eventbus.EventBus)3 TreeData (com.vaadin.data.TreeData)3