Search in sources :

Example 11 with TagDefinition

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

the class TagsView 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 : 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) TagsetDefinition(de.catma.tag.TagsetDefinition)

Example 12 with TagDefinition

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

the class TagsView method addTags.

private void addTags(TagsetTreeItem tagsetItem, TagsetDefinition tagset) {
    for (TagDefinition tag : tagset) {
        if (tag.getParentUuid().isEmpty()) {
            TagDataItem tagItem = new TagDataItem(tag, tagsetItem.isEditable());
            tagsetData.addItem(tagsetItem, tagItem);
            addTagSubTree(tagset, tag, tagItem);
        }
    }
}
Also used : TagDefinition(de.catma.tag.TagDefinition)

Example 13 with TagDefinition

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

the class TagsView method handleAddPropertyRequest.

private void handleAddPropertyRequest() {
    final List<TagDefinition> targetTags = new ArrayList<>();
    if (tagsetGrid.getSelectedItems().size() == 1) {
        TagsetTreeItem selectedItem = tagsetGrid.getSelectedItems().iterator().next();
        while (!(selectedItem instanceof TagDataItem) && (selectedItem != null)) {
            selectedItem = tagsetData.getParent(selectedItem);
        }
        if (selectedItem != null) {
            targetTags.add(((TagDataItem) selectedItem).getTag());
        }
    } else {
        targetTags.addAll(tagsetGrid.getSelectedItems().stream().filter(tagsetTreeItem -> tagsetTreeItem instanceof TagDataItem).map(tagsetTreeItem -> ((TagDataItem) tagsetTreeItem).getTag()).collect(Collectors.toList()));
    }
    if (targetTags.isEmpty()) {
        Notification.show("Info", "Please select one ore more Tags first!", Type.TRAY_NOTIFICATION);
    } else {
        for (TagDefinition targetTag : targetTags) {
            if (!project.hasPermission(project.getRoleForTagset(targetTag.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!", targetTag.getName()), Type.HUMANIZED_MESSAGE);
                return;
            }
        }
        Multimap<String, PropertyDefinition> propertiesByName = ArrayListMultimap.create();
        for (TagDefinition tag : targetTags) {
            for (PropertyDefinition propertyDef : tag.getUserDefinedPropertyDefinitions()) {
                if (!propertiesByName.containsKey(propertyDef.getName()) || propertiesByName.get(propertyDef.getName()).iterator().next().getPossibleValueList().equals(propertyDef.getPossibleValueList())) {
                    propertiesByName.put(propertyDef.getName(), propertyDef);
                }
            }
        }
        List<PropertyDefinition> commonProperties = propertiesByName.asMap().entrySet().stream().filter(entry -> entry.getValue().size() == targetTags.size()).map(entry -> new PropertyDefinition(entry.getValue().iterator().next())).collect(Collectors.toList());
        // just a single tag's properties or is it a bulk(>1) edit?
        final boolean bulkEdit = targetTags.size() > 1;
        AddEditPropertyDialog addPropertyDialog = new AddEditPropertyDialog(bulkEdit, commonProperties, new SaveCancelListener<List<PropertyDefinition>>() {

            @Override
            public void savePressed(List<PropertyDefinition> result) {
                if (bulkEdit) {
                    handleBulkEditProperties(result, commonProperties, targetTags);
                } else {
                    handleSingleEditProperties(result, targetTags.iterator().next());
                }
            }
        });
        addPropertyDialog.show();
    }
}
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) ArrayList(java.util.ArrayList) PropertyDefinition(de.catma.tag.PropertyDefinition) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with TagDefinition

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

the class TagsView method handleBulkEditProperties.

private void handleBulkEditProperties(List<PropertyDefinition> editedProperties, List<PropertyDefinition> commonProperties, List<TagDefinition> targetTags) {
    final Set<String> availableCommonPropertyNames = editedProperties.stream().map(propertyDef -> propertyDef.getName()).collect(Collectors.toSet());
    final Set<String> deletedCommonProperyNames = commonProperties.stream().map(propertyDef -> propertyDef.getName()).filter(name -> !availableCommonPropertyNames.contains(name)).collect(Collectors.toSet());
    for (TagDefinition tag : targetTags) {
        TagsetDefinition tagset = project.getTagManager().getTagLibrary().getTagsetDefinition(tag);
        for (PropertyDefinition existingPropertyDef : new ArrayList<>(tag.getUserDefinedPropertyDefinitions())) {
            // handle deleted PropertyDefs
            if (deletedCommonProperyNames.contains(existingPropertyDef.getName())) {
                project.getTagManager().removeUserDefinedPropertyDefinition(existingPropertyDef, tag, tagset);
            } else // handle updated PropertyDefs
            if (availableCommonPropertyNames.contains(existingPropertyDef.getName())) {
                editedProperties.stream().filter(possiblyChangedPd -> possiblyChangedPd.getName().equals(existingPropertyDef.getName())).findFirst().ifPresent(possiblyChangedPd -> existingPropertyDef.setPossibleValueList(possiblyChangedPd.getPossibleValueList()));
                project.getTagManager().updateUserDefinedPropertyDefinition(tag, existingPropertyDef);
            }
        }
        // handle created PropertyDefs
        for (PropertyDefinition pd : editedProperties) {
            if (tag.getPropertyDefinition(pd.getName()) == null) {
                PropertyDefinition createdPropertyDefinition = new PropertyDefinition(pd);
                pd.setUuid(idGenerator.generate());
                project.getTagManager().addUserDefinedPropertyDefinition(tag, createdPropertyDefinition);
            }
        }
    }
}
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) TagsetDefinition(de.catma.tag.TagsetDefinition) ArrayList(java.util.ArrayList) PropertyDefinition(de.catma.tag.PropertyDefinition)

Example 15 with TagDefinition

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

the class TagsetCSVExportStreamSource method getStream.

@Override
public InputStream getStream() {
    final UI ui = UI.getCurrent();
    Set<TagsetDefinition> tagsets = tagsetsSupplier.get();
    Project project = projectSupplier.get();
    if (tagsets != null && !tagsets.isEmpty()) {
        try {
            File tempFile = File.createTempFile(new IDGenerator().generate() + "_TagLibrary_Export", "xml");
            try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tempFile))) {
                try (CSVPrinter csvPrinter = new CSVPrinter(writer, CSVFormat.EXCEL.withDelimiter(';'))) {
                    csvPrinter.print("Tagset");
                    csvPrinter.print("Tagset ID");
                    csvPrinter.print("Tag");
                    csvPrinter.print("Tag ID");
                    csvPrinter.print("Tag Path");
                    csvPrinter.print("Tag Parent ID");
                    csvPrinter.print("Tag Color");
                    csvPrinter.print("Tag Author");
                    csvPrinter.print("Project Name");
                    csvPrinter.print("Project ID");
                    csvPrinter.print("Tag Properties & Values & Property ID");
                    csvPrinter.println();
                    for (TagsetDefinition tagset : tagsets) {
                        Collection<TagDefinition> sortedTags = tagset.stream().sorted((t1, t2) -> {
                            if (t1.getName().equals(t2.getName())) {
                                return t1.getUuid().compareTo(t2.getUuid());
                            }
                            return t1.getName().compareTo(t2.getName());
                        }).collect(Collectors.toList());
                        for (TagDefinition tag : sortedTags) {
                            csvPrinter.print(tagset.getName());
                            csvPrinter.print(tagset.getUuid());
                            csvPrinter.print(tag.getName());
                            csvPrinter.print(tag.getUuid());
                            csvPrinter.print(tagset.getTagPath(tag));
                            csvPrinter.print(tag.getParentUuid());
                            csvPrinter.print("#" + ColorConverter.toHex(tag.getColor()));
                            csvPrinter.print(tag.getAuthor());
                            csvPrinter.print(project.getName());
                            csvPrinter.print(project.getProjectId());
                            ArrayList<PropertyDefinition> sortedProperties = new ArrayList<>(tag.getUserDefinedPropertyDefinitions());
                            Collections.sort(sortedProperties, (p1, p2) -> {
                                if (p1.getName().equals(p2.getName())) {
                                    return p1.getUuid().compareTo(p2.getUuid());
                                }
                                return p1.getName().compareTo(p2.getName());
                            });
                            for (PropertyDefinition propertyDef : sortedProperties) {
                                csvPrinter.print(propertyDef.getName() + propertyDef.getPossibleValueList().stream().sorted().collect(Collectors.toList()) + " " + propertyDef.getUuid());
                            }
                            csvPrinter.println();
                        }
                    }
                }
            }
            return new FileInputStream(tempFile);
        } catch (Exception e) {
            ((ErrorHandler) ui).showAndLogError("Error exporting Tagsets to XML!", e);
        }
    }
    return null;
}
Also used : PropertyDefinition(de.catma.tag.PropertyDefinition) Project(de.catma.project.Project) Collection(java.util.Collection) UI(com.vaadin.ui.UI) FileOutputStream(java.io.FileOutputStream) Set(java.util.Set) FileInputStream(java.io.FileInputStream) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) File(java.io.File) ArrayList(java.util.ArrayList) ColorConverter(de.catma.util.ColorConverter) CSVFormat(org.apache.commons.csv.CSVFormat) ErrorHandler(de.catma.ui.module.main.ErrorHandler) TagDefinition(de.catma.tag.TagDefinition) TagsetDefinition(de.catma.tag.TagsetDefinition) OutputStreamWriter(java.io.OutputStreamWriter) IDGenerator(de.catma.util.IDGenerator) Collections(java.util.Collections) CSVPrinter(org.apache.commons.csv.CSVPrinter) InputStream(java.io.InputStream) StreamSource(com.vaadin.server.StreamResource.StreamSource) TagDefinition(de.catma.tag.TagDefinition) ArrayList(java.util.ArrayList) PropertyDefinition(de.catma.tag.PropertyDefinition) FileInputStream(java.io.FileInputStream) CSVPrinter(org.apache.commons.csv.CSVPrinter) TagsetDefinition(de.catma.tag.TagsetDefinition) Project(de.catma.project.Project) UI(com.vaadin.ui.UI) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) IDGenerator(de.catma.util.IDGenerator)

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