Search in sources :

Example 6 with TagDefinition

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

the class XmlMarkupCollectionSerializationHandler method scanElements.

private void scanElements(StringBuilder contentBuilder, Element element, Stack<String> elementStack, TagManager tagManager, TagLibrary tagLibrary, Map<String, String> namespacePrefixToTagsetIdMap, AnnotationCollection userMarkupCollection, String docId, int docLength) throws Exception {
    int start = contentBuilder.length();
    StringBuilder pathBuilder = new StringBuilder();
    for (int j = 0; j < elementStack.size(); j++) {
        pathBuilder.append("/" + elementStack.get(j));
    }
    String parentPath = pathBuilder.toString();
    elementStack.push(element.getLocalName());
    String path = parentPath + "/" + elementStack.peek();
    String tagName = element.getLocalName();
    String prefix = element.getNamespacePrefix();
    String tagsetId = namespacePrefixToTagsetIdMap.get(prefix);
    if (tagsetId == null) {
        tagsetId = KnownTagsetDefinitionName.DEFAULT_INTRINSIC_XML.asTagsetId();
    }
    TagsetDefinition tagset = tagLibrary.getTagsetDefinition(tagsetId);
    String tagId = idGenerator.generate();
    TagDefinition tagDefinition = tagset.getTagDefinitionsByName(tagName).findFirst().orElse(null);
    String pathPropertyDefId = null;
    if (tagDefinition == null) {
        tagDefinition = new TagDefinition(tagId, elementStack.peek(), // no parent, hierarchy is collected in annotation property
        null, tagsetId);
        tagDefinition.addSystemPropertyDefinition(new PropertyDefinition(idGenerator.generate(PropertyDefinition.SystemPropertyName.catma_displaycolor.name()), PropertyDefinition.SystemPropertyName.catma_displaycolor.name(), Collections.singletonList(ColorConverter.toRGBIntAsString(ColorConverter.randomHex()))));
        tagDefinition.addSystemPropertyDefinition(new PropertyDefinition(idGenerator.generate(PropertyDefinition.SystemPropertyName.catma_markupauthor.name()), PropertyDefinition.SystemPropertyName.catma_markupauthor.name(), Collections.singletonList(author)));
        pathPropertyDefId = idGenerator.generate();
        PropertyDefinition pathDef = new PropertyDefinition(pathPropertyDefId, "path", Collections.emptyList());
        tagDefinition.addUserDefinedPropertyDefinition(pathDef);
        tagManager.addTagDefinition(tagset, tagDefinition);
    } else {
        pathPropertyDefId = tagDefinition.getPropertyDefinition("path").getUuid();
    }
    for (int idx = 0; idx < element.getChildCount(); idx++) {
        Node curChild = element.getChild(idx);
        if (curChild instanceof Text) {
            xmlContentHandler.addTextContent(contentBuilder, element, curChild.getValue());
        } else if (curChild instanceof Element) {
            // descent
            scanElements(contentBuilder, (Element) curChild, elementStack, tagManager, tagLibrary, namespacePrefixToTagsetIdMap, userMarkupCollection, docId, docLength);
        }
    }
    if (element.getChildCount() != 0) {
        xmlContentHandler.addBreak(contentBuilder, element);
    }
    int end = contentBuilder.length();
    Range range = new Range(start, end);
    if (range.isSinglePoint()) {
        int newStart = range.getStartPoint();
        if (newStart > 0) {
            newStart = newStart - 1;
        }
        int newEnd = range.getEndPoint();
        if (newEnd < docLength - 1) {
            newEnd = newEnd + 1;
        }
        range = new Range(newStart, newEnd);
    }
    TagInstance tagInstance = new TagInstance(idGenerator.generate(), tagDefinition.getUuid(), author, ZonedDateTime.now().format(DateTimeFormatter.ofPattern(Version.DATETIMEPATTERN)), tagDefinition.getUserDefinedPropertyDefinitions(), tagDefinition.getTagsetDefinitionUuid());
    for (int i = 0; i < element.getAttributeCount(); i++) {
        PropertyDefinition propertyDefinition = tagDefinition.getPropertyDefinition(element.getAttribute(i).getQualifiedName());
        if (propertyDefinition == null) {
            propertyDefinition = new PropertyDefinition(idGenerator.generate(), element.getAttribute(i).getQualifiedName(), Collections.singleton(element.getAttribute(i).getValue()));
            tagManager.addUserDefinedPropertyDefinition(tagDefinition, propertyDefinition);
        } else if (!propertyDefinition.getPossibleValueList().contains(element.getAttribute(i).getValue())) {
            List<String> newValueList = new ArrayList<>();
            newValueList.addAll(propertyDefinition.getPossibleValueList());
            newValueList.add(element.getAttribute(i).getValue());
            propertyDefinition.setPossibleValueList(newValueList);
        }
        Property property = new Property(propertyDefinition.getUuid(), Collections.singleton(element.getAttribute(i).getValue()));
        tagInstance.addUserDefinedProperty(property);
    }
    Property pathProperty = new Property(pathPropertyDefId, Collections.singletonList(path));
    tagInstance.addUserDefinedProperty(pathProperty);
    TagReference tagReference = new TagReference(tagInstance, docId, range, userMarkupCollection.getId());
    userMarkupCollection.addTagReference(tagReference);
    elementStack.pop();
}
Also used : TagDefinition(de.catma.tag.TagDefinition) Node(nu.xom.Node) Element(nu.xom.Element) Text(nu.xom.Text) Range(de.catma.document.Range) PropertyDefinition(de.catma.tag.PropertyDefinition) TagsetDefinition(de.catma.tag.TagsetDefinition) TagInstance(de.catma.tag.TagInstance) ArrayList(java.util.ArrayList) List(java.util.List) TagReference(de.catma.document.annotation.TagReference) Property(de.catma.tag.Property)

Example 7 with TagDefinition

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

the class CollectionQueryResultRowItem method addChildRowItems.

@Override
public void addChildRowItems(TreeData<QueryResultRowItem> treeData, LoadingCache<String, KwicProvider> kwicProviderCache) {
    try {
        for (QueryResultRow row : getRows()) {
            if (row instanceof TagQueryResultRow) {
                TagQueryResultRow tRow = (TagQueryResultRow) row;
                KwicProvider kwicProvider = kwicProviderCache.get(row.getSourceDocumentId());
                TagDefinition tagDefinition = project.getTagManager().getTagLibrary().getTagDefinition(tRow.getTagDefinitionId());
                KwicQueryResultRowItem item = new KwicQueryResultRowItem(tRow, AnnotatedTextProvider.buildAnnotatedText(new ArrayList<>(tRow.getRanges()), kwicProvider, tagDefinition), AnnotatedTextProvider.buildAnnotatedKeywordInContext(new ArrayList<>(tRow.getRanges()), kwicProvider, tagDefinition, tRow.getTagDefinitionPath()), true);
                if (!treeData.contains(item)) {
                    treeData.addItem(this, item);
                }
            }
        }
    } catch (Exception e) {
        ((ErrorHandler) UI.getCurrent()).showAndLogError("error displaying annotated kwic query results", e);
    }
}
Also used : TagDefinition(de.catma.tag.TagDefinition) QueryResultRow(de.catma.queryengine.result.QueryResultRow) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) KwicProvider(de.catma.indexer.KwicProvider) ArrayList(java.util.ArrayList)

Example 8 with TagDefinition

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

the class TagSelectionPanel method handleAddSubtagRequest.

private void handleAddSubtagRequest() {
    final List<TagDefinition> parentTags = tagsetGrid.getSelectedItems().stream().filter(tagsetTreeItem -> tagsetTreeItem instanceof TagDataItem).map(tagsetTreeItem -> ((TagDataItem) tagsetTreeItem).getTag()).collect(Collectors.toList());
    for (TagDefinition parentTag : parentTags) {
        if (!project.hasPermission(project.getRoleForTagset(parentTag.getTagsetDefinitionUuid()), RBACPermission.TAGSET_WRITE)) {
            Notification.show("Info", String.format("You do not have the permission to make changes to the Tagset of Tag %1$s, " + "Please contact the Project maintainer!", parentTag.getName()), Type.HUMANIZED_MESSAGE);
            return;
        }
    }
    if (!parentTags.isEmpty()) {
        AddSubtagDialog addTagDialog = new AddSubtagDialog(new SaveCancelListener<TagDefinition>() {

            public void savePressed(TagDefinition result) {
                for (TagDefinition parent : parentTags) {
                    TagsetDefinition tagset = project.getTagManager().getTagLibrary().getTagsetDefinition(parent);
                    TagDefinition tag = new TagDefinition(result);
                    tag.setUuid(idGenerator.generate());
                    tag.setParentUuid(parent.getUuid());
                    tag.setTagsetDefinitionUuid(tagset.getUuid());
                    project.getTagManager().addTagDefinition(tagset, tag);
                }
            }
        });
        addTagDialog.show();
    } else {
        Notification.show("Info", "Please select at least one parent Tag!", Type.HUMANIZED_MESSAGE);
    }
}
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) SearchFilterProvider(de.catma.ui.component.actiongrid.SearchFilterProvider) MaterialTheme(com.github.appreciated.material.MaterialTheme) Notification(com.vaadin.ui.Notification) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Label(com.vaadin.ui.Label) TagsetDefinition(de.catma.tag.TagsetDefinition) TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) Pair(de.catma.util.Pair) Version(de.catma.tag.Version) TreeGridFactory(de.catma.ui.component.TreeGridFactory) IDGenerator(de.catma.util.IDGenerator) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) TreeData(com.vaadin.data.TreeData) Project(de.catma.project.Project) Collection(java.util.Collection) TreeGrid(com.vaadin.ui.TreeGrid) Collectors(java.util.stream.Collectors) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) ContextMenu(com.vaadin.contextmenu.ContextMenu) List(java.util.List) Type(com.vaadin.ui.Notification.Type) PropertyChangeListener(java.beans.PropertyChangeListener) TagDefinition(de.catma.tag.TagDefinition) SerializablePredicate(com.vaadin.server.SerializablePredicate) Optional(java.util.Optional) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) SingleTextInputDialog(de.catma.ui.dialog.SingleTextInputDialog) SelectionMode(com.vaadin.ui.Grid.SelectionMode) RBACPermission(de.catma.rbac.RBACPermission) TagDefinition(de.catma.tag.TagDefinition) TagsetDefinition(de.catma.tag.TagsetDefinition)

Example 9 with TagDefinition

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

the class TagsView method initListeners.

private void initListeners() {
    tagChangedListener = new PropertyChangeListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            Object newValue = evt.getNewValue();
            Object oldValue = evt.getOldValue();
            if (oldValue == null) {
                // created
                Pair<TagsetDefinition, TagDefinition> value = (Pair<TagsetDefinition, TagDefinition>) newValue;
                TagsetDefinition tagset = value.getFirst();
                TagDefinition tag = value.getSecond();
                if (tag.getParentUuid().isEmpty()) {
                    tagsetData.getRootItems().stream().map(tagsetTreeItem -> (TagsetDataItem) tagsetTreeItem).filter(tagsetDataItem -> tagsetDataItem.getTagset().getUuid().equals(tagset.getUuid())).findFirst().ifPresent(tagsetDataItem -> {
                        TagDataItem tagDataItem = new TagDataItem(tag, tagsetDataItem.isEditable());
                        if (!tagsetData.contains(tagDataItem)) {
                            tagsetData.addItem(tagsetDataItem, tagDataItem);
                            tagsetDataProvider.refreshAll();
                            tagsetGrid.expand(tagsetDataItem);
                        }
                    });
                } else {
                    tagsetData.getRootItems().stream().map(tagsetTreeItem -> (TagsetDataItem) tagsetTreeItem).filter(tagsetDataItem -> tagsetDataItem.getTagset().getUuid().equals(tagset.getUuid())).findFirst().ifPresent(tagsetDataItem -> {
                        TagDataItem tagDataItem = new TagDataItem(tag, tagsetDataItem.isEditable());
                        if (!tagsetData.contains(tagDataItem)) {
                            TagDefinition parentTag = project.getTagManager().getTagLibrary().getTagDefinition(tag.getParentUuid());
                            TagsetTreeItem parentTagItem = new TagDataItem(parentTag, tagsetDataItem.isEditable());
                            tagsetData.addItem(parentTagItem, tagDataItem);
                            tagsetDataProvider.refreshAll();
                            tagsetGrid.expand(parentTagItem);
                        }
                    });
                }
            } else if (newValue == null) {
                // removed
                Pair<TagsetDefinition, TagDefinition> deleted = (Pair<TagsetDefinition, TagDefinition>) oldValue;
                TagDefinition deletedTag = deleted.getSecond();
                tagsetData.removeItem(new TagDataItem(deletedTag, true));
                tagsetDataProvider.refreshAll();
                tagsetGrid.deselectAll();
            } else {
                // update
                TagDefinition tag = (TagDefinition) newValue;
                TagsetDefinition tagset = (TagsetDefinition) oldValue;
                tagsetData.getRootItems().stream().map(tagsetTreeItem -> (TagsetDataItem) tagsetTreeItem).filter(tagsetDataItem -> tagsetDataItem.getTagset().getUuid().equals(tagset.getUuid())).findFirst().ifPresent(tagsetDataItem -> {
                    TagDataItem oldItem = new TagDataItem(tag, tagsetDataItem.isEditable());
                    String parentTagId = tag.getParentUuid();
                    TagsetTreeItem parent = tagsetDataItem;
                    if (!parentTagId.isEmpty()) {
                        parent = new TagDataItem(tagset.getTagDefinition(parentTagId), tagsetDataItem.isEditable());
                    }
                    tagsetData.removeItem(oldItem);
                    TagDataItem tagDataItem = new TagDataItem(tag, tagsetDataItem.isEditable());
                    tagDataItem.setPropertiesExpanded(true);
                    tagsetData.addItem(parent, tagDataItem);
                    addTagSubTree(tagset, tag, tagDataItem);
                    // TODO: sort
                    tagsetDataProvider.refreshAll();
                    showExpandedProperties(tagDataItem);
                });
            }
        }
    };
    project.getTagManager().addPropertyChangeListener(TagManagerEvent.tagDefinitionChanged, tagChangedListener);
    propertyDefinitionChangedListener = new PropertyChangeListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            Object newValue = evt.getNewValue();
            Object oldValue = evt.getOldValue();
            TagDefinition tag = null;
            if (oldValue == null) {
                // created
                Pair<PropertyDefinition, TagDefinition> newData = (Pair<PropertyDefinition, TagDefinition>) newValue;
                tag = newData.getSecond();
            } else if (newValue == null) {
                // removed
                Pair<PropertyDefinition, Pair<TagDefinition, TagsetDefinition>> oldData = (Pair<PropertyDefinition, Pair<TagDefinition, TagsetDefinition>>) oldValue;
                tag = oldData.getSecond().getFirst();
            } else {
                // update
                tag = (TagDefinition) oldValue;
            }
            TagsetTreeItem parentItem = null;
            if (tag.getParentUuid().isEmpty()) {
                parentItem = new TagsetDataItem(project.getTagManager().getTagLibrary().getTagsetDefinition(tag.getTagsetDefinitionUuid()));
            } else {
                parentItem = new TagDataItem(project.getTagManager().getTagLibrary().getTagDefinition(tag.getParentUuid()));
            }
            final String tagId = tag.getUuid();
            tagsetData.getChildren(parentItem).stream().map(tagsetTreeItem -> (TagDataItem) tagsetTreeItem).filter(tagDataItem -> tagDataItem.getTag().getUuid().equals(tagId)).findFirst().ifPresent(tagDataItem -> {
                tagDataItem.setPropertiesExpanded(false);
                hideExpandedProperties(tagDataItem);
                tagDataItem.setPropertiesExpanded(true);
                showExpandedProperties(tagDataItem);
            });
            tagsetDataProvider.refreshAll();
            tagsetGrid.deselectAll();
        }
    };
    project.getTagManager().addPropertyChangeListener(TagManagerEvent.userPropertyDefinitionChanged, propertyDefinitionChangedListener);
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) PropertyDefinition(de.catma.tag.PropertyDefinition) UI(com.vaadin.ui.UI) ConfirmDialog(org.vaadin.dialogs.ConfirmDialog) Multimap(com.google.common.collect.Multimap) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) SearchFilterProvider(de.catma.ui.component.actiongrid.SearchFilterProvider) ArrayList(java.util.ArrayList) EventBus(com.google.common.eventbus.EventBus) MaterialTheme(com.github.appreciated.material.MaterialTheme) Notification(com.vaadin.ui.Notification) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Label(com.vaadin.ui.Label) TagsetDefinition(de.catma.tag.TagsetDefinition) SliderPanel(org.vaadin.sliderpanel.SliderPanel) TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) Pair(de.catma.util.Pair) Version(de.catma.tag.Version) TreeGridFactory(de.catma.ui.component.TreeGridFactory) IDGenerator(de.catma.util.IDGenerator) ButtonRenderer(com.vaadin.ui.renderers.ButtonRenderer) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) TreeData(com.vaadin.data.TreeData) Project(de.catma.project.Project) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) TreeGrid(com.vaadin.ui.TreeGrid) Collectors(java.util.stream.Collectors) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) ContextMenu(com.vaadin.contextmenu.ContextMenu) List(java.util.List) Type(com.vaadin.ui.Notification.Type) RendererClickEvent(com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent) PropertyChangeListener(java.beans.PropertyChangeListener) HorizontalLayout(com.vaadin.ui.HorizontalLayout) TagDefinition(de.catma.tag.TagDefinition) SerializablePredicate(com.vaadin.server.SerializablePredicate) Optional(java.util.Optional) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) SingleTextInputDialog(de.catma.ui.dialog.SingleTextInputDialog) SliderPanelBuilder(org.vaadin.sliderpanel.SliderPanelBuilder) SelectionMode(com.vaadin.ui.Grid.SelectionMode) StyleGenerator(com.vaadin.ui.StyleGenerator) RBACPermission(de.catma.rbac.RBACPermission) SliderMode(org.vaadin.sliderpanel.client.SliderMode) HugeCard(de.catma.ui.component.hugecard.HugeCard) TagDefinition(de.catma.tag.TagDefinition) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) PropertyDefinition(de.catma.tag.PropertyDefinition) TagsetDefinition(de.catma.tag.TagsetDefinition) Pair(de.catma.util.Pair)

Example 10 with TagDefinition

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

the class TagsView method deleteTags.

void deleteTags(List<TagDefinition> targetTags) {
    String msg = String.format("Are you sure you want to delete the following Tags: %1$s?", targetTags.stream().map(TagDefinition::getName).collect(Collectors.joining(",")));
    ConfirmDialog.show(UI.getCurrent(), "Warning", msg, "Delete", "Cancel", dlg -> {
        if (dlg.isConfirmed()) {
            for (TagDefinition tag : targetTags) {
                TagsetDefinition tagset = project.getTagManager().getTagLibrary().getTagsetDefinition(tag);
                project.getTagManager().removeTagDefinition(tagset, tag);
            }
        }
    });
}
Also used : TagDefinition(de.catma.tag.TagDefinition) TagsetDefinition(de.catma.tag.TagsetDefinition)

Aggregations

TagDefinition (de.catma.tag.TagDefinition)72 ArrayList (java.util.ArrayList)31 PropertyDefinition (de.catma.tag.PropertyDefinition)28 TagsetDefinition (de.catma.tag.TagsetDefinition)28 List (java.util.List)23 IDGenerator (de.catma.util.IDGenerator)22 Pair (de.catma.util.Pair)22 UI (com.vaadin.ui.UI)19 Project (de.catma.project.Project)19 ErrorHandler (de.catma.ui.module.main.ErrorHandler)19 PropertyChangeEvent (java.beans.PropertyChangeEvent)19 PropertyChangeListener (java.beans.PropertyChangeListener)19 IOException (java.io.IOException)19 Collection (java.util.Collection)19 Collectors (java.util.stream.Collectors)19 Notification (com.vaadin.ui.Notification)17 Type (com.vaadin.ui.Notification.Type)17 Set (java.util.Set)17 TagManagerEvent (de.catma.tag.TagManager.TagManagerEvent)16 SaveCancelListener (de.catma.ui.dialog.SaveCancelListener)16