Search in sources :

Example 16 with TaxonomyTreeNode

use of org.olat.modules.taxonomy.model.TaxonomyTreeNode in project OpenOLAT by OpenOLAT.

the class TaxonomyTreeBuilder method buildTreeModel.

public TreeModel buildTreeModel() {
    GenericTreeModel gtm = new GenericTreeModel();
    TaxonomyTreeNode root = new TaxonomyTreeNode(taxonomy);
    root.setTitle("ROOT competence");
    gtm.setRootNode(root);
    if (taxonomy != null) {
        taxonomy = taxonomyService.getTaxonomy(taxonomy);
        if (StringHelper.containsNonWhitespace(rootTitle)) {
            root.setTitle(rootTitle);
        } else {
            root.setTitle(taxonomy.getDisplayName());
        }
        root.setUserObject(taxonomy);
        // taxonomy directory
        if (enableTemplates) {
            VFSContainer taxonomyDirectory = taxonomyService.getDocumentsLibrary(taxonomy);
            TaxonomyTreeNode taxonomyDirectorNode = new TaxonomyTreeNode(taxonomy, taxonomyDirectory, TaxonomyTreeNodeType.templates);
            if (locale == null) {
                locale = CoreSpringFactory.getImpl(I18nManager.class).getCurrentThreadLocale();
            }
            taxonomyDirectorNode.setTitle(templateDirectory);
            taxonomyDirectorNode.setUserObject(taxonomyDirectory);
            root.addChild(taxonomyDirectorNode);
        }
        // taxonomy levels
        List<TaxonomyLevel> levels = taxonomyService.getTaxonomyLevels(taxonomy);
        Map<Long, TaxonomyLevel> keytoLevels = levels.stream().collect(Collectors.toMap(l -> l.getKey(), l -> l));
        Map<Long, TaxonomyTreeNode> fieldKeyToNode = new HashMap<>();
        for (TaxonomyLevel taxonomyLevel : levels) {
            Long key = taxonomyLevel.getKey();
            TaxonomyTreeNode node = fieldKeyToNode.get(key);
            if (node == null) {
                node = new TaxonomyTreeNode(taxonomy, taxonomyLevel, getType(taxonomyLevel));
                TaxonomyLevelType type = taxonomyLevel.getType();
                if (type != null && StringHelper.containsNonWhitespace(type.getCssClass())) {
                    node.setIconCssClass(type.getCssClass());
                }
                fieldKeyToNode.put(key, node);
            }
            TaxonomyLevel parentLevel = taxonomyLevel.getParent();
            if (parentLevel == null) {
                // this is a root
                root.addChild(node);
            } else {
                Long parentKey = parentLevel.getKey();
                TaxonomyTreeNode parentNode = fieldKeyToNode.get(parentKey);
                if (parentNode == null) {
                    // to use the fetched type
                    parentLevel = keytoLevels.get(parentKey);
                    parentNode = new TaxonomyTreeNode(taxonomy, parentLevel, getType(parentLevel));
                    TaxonomyLevelType type = parentLevel.getType();
                    if (type != null && StringHelper.containsNonWhitespace(type.getCssClass())) {
                        parentNode.setIconCssClass(type.getCssClass());
                    }
                    fieldKeyToNode.put(parentKey, parentNode);
                }
                parentNode.addChild(node);
            }
        }
        computePermissions(root);
        trimVisiblity(root);
        sort(root);
    }
    return gtm;
}
Also used : TreeModel(org.olat.core.gui.components.tree.TreeModel) Date(java.util.Date) I18nManager(org.olat.core.util.i18n.I18nManager) CoreSpringFactory(org.olat.core.CoreSpringFactory) HashMap(java.util.HashMap) TaxonomyCompetence(org.olat.modules.taxonomy.TaxonomyCompetence) Collectors(java.util.stream.Collectors) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) TaxonomyTreeNodeType(org.olat.modules.taxonomy.model.TaxonomyTreeNodeType) List(java.util.List) Locale(java.util.Locale) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) Identity(org.olat.core.id.Identity) TaxonomyModule(org.olat.modules.taxonomy.TaxonomyModule) TaxonomyService(org.olat.modules.taxonomy.TaxonomyService) Map(java.util.Map) StringHelper(org.olat.core.util.StringHelper) TaxonomyCompetenceTypes(org.olat.modules.taxonomy.TaxonomyCompetenceTypes) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) HashMap(java.util.HashMap) VFSContainer(org.olat.core.util.vfs.VFSContainer) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel)

Example 17 with TaxonomyTreeNode

use of org.olat.modules.taxonomy.model.TaxonomyTreeNode in project OpenOLAT by OpenOLAT.

the class DocumentPoolNotificationsHandler method createSubscriptionInfo.

@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    Publisher p = subscriber.getPublisher();
    Date latestNews = p.getLatestNewsDate();
    try {
        SubscriptionInfo si;
        String taxonomyKey = documentPoolModule.getTaxonomyTreeKey();
        if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews) && StringHelper.isLong(taxonomyKey)) {
            Taxonomy taxonomy = taxonomyService.getTaxonomy(new TaxonomyRefImpl(new Long(taxonomyKey)));
            if (taxonomy == null) {
                return notificationsManager.getNoSubscriptionInfo();
            }
            Identity identity = subscriber.getIdentity();
            Roles roles = securityManager.getRoles(identity);
            boolean isTaxonomyAdmin = roles.isOLATAdmin();
            Translator translator = Util.createPackageTranslator(DocumentPoolMainController.class, locale);
            String templates = translator.translate("document.pool.templates");
            TaxonomyTreeBuilder builder = new TaxonomyTreeBuilder(taxonomy, identity, null, isTaxonomyAdmin, documentPoolModule.isTemplatesDirectoryEnabled(), templates, locale);
            TreeModel model = builder.buildTreeModel();
            si = new SubscriptionInfo(subscriber.getKey(), p.getType(), getTitleItemForPublisher(), null);
            new TreeVisitor(node -> {
                TaxonomyTreeNode tNode = (TaxonomyTreeNode) node;
                if (tNode.getTaxonomyLevel() != null && tNode.isDocumentsLibraryEnabled() && tNode.isCanRead()) {
                    VFSContainer container = taxonomyService.getDocumentsLibrary(tNode.getTaxonomyLevel());
                    String prefixBusinessPath = "[DocumentPool:" + taxonomy.getKey() + "][TaxonomyLevel:" + tNode.getTaxonomyLevel().getKey() + "][path=";
                    createSubscriptionInfo(container, prefixBusinessPath, compareDate, si, p, translator);
                } else if (tNode.getType() == TaxonomyTreeNodeType.templates) {
                    VFSContainer container = taxonomyService.getDocumentsLibrary(taxonomy);
                    String prefixBusinessPath = "[DocumentPool:" + taxonomy.getKey() + "][Templates:0s][path=";
                    createSubscriptionInfo(container, prefixBusinessPath, compareDate, si, p, translator);
                }
            }, model.getRootNode(), false).visitAll();
        } else {
            si = NotificationsManager.getInstance().getNoSubscriptionInfo();
        }
        return si;
    } catch (Exception e) {
        log.error("Cannot create document pool notifications for subscriber: " + subscriber.getKey(), e);
        return notificationsManager.getNoSubscriptionInfo();
    }
}
Also used : TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) Util(org.olat.core.util.Util) TreeVisitor(org.olat.core.util.tree.TreeVisitor) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) NotificationHelper(org.olat.core.commons.services.notifications.NotificationHelper) OlatRelPathImpl(org.olat.core.util.vfs.OlatRelPathImpl) Date(java.util.Date) FileInfo(org.olat.core.commons.modules.bc.FileInfo) DocumentPoolModule(org.olat.modules.docpool.DocumentPoolModule) Autowired(org.springframework.beans.factory.annotation.Autowired) TaxonomyTreeNodeType(org.olat.modules.taxonomy.model.TaxonomyTreeNodeType) NotificationsHandler(org.olat.core.commons.services.notifications.NotificationsHandler) Locale(java.util.Locale) TaxonomyService(org.olat.modules.taxonomy.TaxonomyService) Service(org.springframework.stereotype.Service) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) FileUtils(org.olat.core.util.FileUtils) FolderManager(org.olat.core.commons.modules.bc.FolderManager) StringHelper(org.olat.core.util.StringHelper) OLog(org.olat.core.logging.OLog) Taxonomy(org.olat.modules.taxonomy.Taxonomy) Translator(org.olat.core.gui.translator.Translator) TaxonomyRefImpl(org.olat.modules.taxonomy.model.TaxonomyRefImpl) TaxonomyTreeBuilder(org.olat.modules.taxonomy.manager.TaxonomyTreeBuilder) TreeModel(org.olat.core.gui.components.tree.TreeModel) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) Publisher(org.olat.core.commons.services.notifications.Publisher) VFSContainer(org.olat.core.util.vfs.VFSContainer) BusinessControlFactory(org.olat.core.id.context.BusinessControlFactory) DocumentPoolMainController(org.olat.modules.docpool.ui.DocumentPoolMainController) List(java.util.List) Subscriber(org.olat.core.commons.services.notifications.Subscriber) Identity(org.olat.core.id.Identity) PublisherData(org.olat.core.commons.services.notifications.PublisherData) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) BaseSecurity(org.olat.basesecurity.BaseSecurity) Tracing(org.olat.core.logging.Tracing) Roles(org.olat.core.id.Roles) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) TaxonomyRefImpl(org.olat.modules.taxonomy.model.TaxonomyRefImpl) Taxonomy(org.olat.modules.taxonomy.Taxonomy) VFSContainer(org.olat.core.util.vfs.VFSContainer) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) Roles(org.olat.core.id.Roles) Publisher(org.olat.core.commons.services.notifications.Publisher) Date(java.util.Date) TreeVisitor(org.olat.core.util.tree.TreeVisitor) TreeModel(org.olat.core.gui.components.tree.TreeModel) Translator(org.olat.core.gui.translator.Translator) Identity(org.olat.core.id.Identity) TaxonomyTreeBuilder(org.olat.modules.taxonomy.manager.TaxonomyTreeBuilder)

Example 18 with TaxonomyTreeNode

use of org.olat.modules.taxonomy.model.TaxonomyTreeNode in project OpenOLAT by OpenOLAT.

the class DocumentPoolMainController method event.

@Override
protected void event(UserRequest ureq, Component source, Event event) {
    if (taxonomyTree == source) {
        if (event instanceof TreeEvent) {
            TreeEvent te = (TreeEvent) event;
            if (MenuTree.COMMAND_TREENODE_CLICKED.equals(te.getCommand())) {
                TaxonomyTreeNode node = (TaxonomyTreeNode) taxonomyTree.getTreeModel().getNodeById(te.getNodeId());
                doSelect(ureq, node);
            }
        }
    } else if (content == source) {
        if (event instanceof PopEvent) {
            PopEvent popEvent = (PopEvent) event;
            if (popEvent.getController() instanceof DocumentPoolLevelController) {
                DocumentPoolLevelController taxonomyLevelCtrl = (DocumentPoolLevelController) popEvent.getController();
                TaxonomyLevel level = taxonomyLevelCtrl.getTaxonomyLevel();
                TaxonomyTreeNode node = (TaxonomyTreeNode) TreeHelper.findNodeByUserObject(level, taxonomyTree.getTreeModel().getRootNode());
                TaxonomyTreeNode parentNode = (TaxonomyTreeNode) node.getParent();
                if (parentNode == null) {
                    doSelectTaxonomy(ureq);
                    taxonomyTree.setSelectedNode(taxonomyTree.getTreeModel().getRootNode());
                } else {
                    doSelect(ureq, parentNode);
                    taxonomyTree.setSelectedNode(parentNode);
                }
            } else if (popEvent.getUserObject() instanceof TaxonomyTreeNode) {
                TaxonomyTreeNode node = (TaxonomyTreeNode) popEvent.getUserObject();
                doSelect(ureq, node);
                taxonomyTree.setSelectedNode(node);
            } else if (popEvent.getController() instanceof DocumentDirectoryController) {
                // pop the templates
                taxonomyTree.setSelectedNode(taxonomyTree.getTreeModel().getRootNode());
            }
        }
    }
}
Also used : TreeEvent(org.olat.core.gui.components.tree.TreeEvent) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) PopEvent(org.olat.core.gui.components.stack.PopEvent)

Example 19 with TaxonomyTreeNode

use of org.olat.modules.taxonomy.model.TaxonomyTreeNode in project OpenOLAT by OpenOLAT.

the class DocumentPoolWebDAVMergeSource method loadRecursiveMergedContainers.

private VFSContainer loadRecursiveMergedContainers(Taxonomy taxonomy, INode node) {
    VFSContainer container = null;
    if (node instanceof TaxonomyTreeNode) {
        TaxonomyTreeNode taxonomyNode = (TaxonomyTreeNode) node;
        String name = RequestUtil.normalizeFilename(taxonomyNode.getTitle());
        VirtualContainer levelContainer = new VirtualContainer(name);
        levelContainer.setLocalSecurityCallback(new DefaultVFSSecurityCallback());
        boolean hasDocuments = false;
        if (taxonomyNode.getType() == TaxonomyTreeNodeType.templates) {
            // the templates
            return addTemplates(taxonomyNode, taxonomy);
        } else if (taxonomyNode.getTaxonomyLevel() != null && taxonomyNode.isDocumentsLibraryEnabled() && taxonomyNode.isCanRead()) {
            // the real thing
            levelContainer.addItem(addDocument(taxonomyNode));
            hasDocuments = true;
        }
        for (int i = 0; i < node.getChildCount(); i++) {
            VFSContainer childContainer = loadRecursiveMergedContainers(taxonomy, node.getChildAt(i));
            if (childContainer != null) {
                levelContainer.addItem(childContainer);
                hasDocuments = true;
            }
        }
        container = hasDocuments ? levelContainer : null;
    }
    return container;
}
Also used : DefaultVFSSecurityCallback(org.olat.core.util.vfs.callbacks.DefaultVFSSecurityCallback) VFSContainer(org.olat.core.util.vfs.VFSContainer) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) VirtualContainer(org.olat.core.util.vfs.VirtualContainer)

Example 20 with TaxonomyTreeNode

use of org.olat.modules.taxonomy.model.TaxonomyTreeNode in project openolat by klemens.

the class TaxonomyTreeBuilder method trimRecursive.

/**
 * Propagate read and write permissions to the children or remove nodes without
 * permissions.
 *
 * @param node The start of a sub tree
 * @return True if some node as some permissions
 */
private boolean trimRecursive(TaxonomyTreeNode node) {
    boolean canRead = node.isCanRead();
    boolean canWrite = node.isCanWrite();
    boolean someAllowed = false;
    for (int i = node.getChildCount(); i-- > 0; ) {
        TaxonomyTreeNode child = (TaxonomyTreeNode) node.getChildAt(i);
        child.setCanRead(canRead || child.isCanRead());
        child.setCanWrite(canWrite || child.isCanWrite());
        boolean subChildAllowed = trimRecursive(child);
        if (!subChildAllowed && !child.isCanRead() && !child.isCanWrite()) {
            node.remove(child);
        } else {
            someAllowed |= true;
        }
    }
    return someAllowed || canRead || canWrite;
}
Also used : TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode)

Aggregations

TaxonomyTreeNode (org.olat.modules.taxonomy.model.TaxonomyTreeNode)22 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)12 List (java.util.List)8 ArrayList (java.util.ArrayList)6 TreeModel (org.olat.core.gui.components.tree.TreeModel)6 TreeNode (org.olat.core.gui.components.tree.TreeNode)6 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 TaxonomyTreeNodeType (org.olat.modules.taxonomy.model.TaxonomyTreeNodeType)6 Date (java.util.Date)4 Locale (java.util.Locale)4 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)4 Identity (org.olat.core.id.Identity)4 StringHelper (org.olat.core.util.StringHelper)4 Taxonomy (org.olat.modules.taxonomy.Taxonomy)4 TaxonomyCompetenceTypes (org.olat.modules.taxonomy.TaxonomyCompetenceTypes)4 TaxonomyLevelType (org.olat.modules.taxonomy.TaxonomyLevelType)4 TaxonomyService (org.olat.modules.taxonomy.TaxonomyService)4 TaxonomyTreeBuilder (org.olat.modules.taxonomy.manager.TaxonomyTreeBuilder)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2