Search in sources :

Example 6 with TaxonomyTreeNode

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

the class DocumentPoolMainController method doSelectTaxonomyLevel.

private DocumentPoolLevelController doSelectTaxonomyLevel(UserRequest ureq, TaxonomyTreeNode node) {
    if (isTaxonomyAdmin || node.isCanRead() || node.isCanWrite()) {
        TaxonomyLevel level = node.getTaxonomyLevel();
        SubscriptionContext subscriptionCtx = notificationsHandler.getTaxonomyDocumentsLibrarySubscriptionContext();
        TaxonomyVFSSecurityCallback secCallback = new TaxonomyVFSSecurityCallback(node, subscriptionCtx);
        OLATResourceable ores = OresHelper.createOLATResourceableInstance("TaxonomyLevel", node.getTaxonomyLevel().getKey());
        WindowControl bwControl = addToHistory(ureq, ores, null);
        DocumentPoolLevelController levelCtrl = new DocumentPoolLevelController(ureq, bwControl, level, node, secCallback);
        listenTo(levelCtrl);
        String displayName = level.getDisplayName();
        content.popUpToRootController(ureq);
        List<TreeNode> parentLines = TreeHelper.getTreePath(node);
        for (int i = 1; i < parentLines.size() - 1; i++) {
            TreeNode parent = parentLines.get(i);
            content.pushController(parent.getTitle(), null, parent);
        }
        content.pushController(displayName, levelCtrl);
        return levelCtrl;
    }
    return null;
}
Also used : TaxonomyVFSSecurityCallback(org.olat.modules.taxonomy.ui.component.TaxonomyVFSSecurityCallback) OLATResourceable(org.olat.core.id.OLATResourceable) TreeNode(org.olat.core.gui.components.tree.TreeNode) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) WindowControl(org.olat.core.gui.control.WindowControl)

Example 7 with TaxonomyTreeNode

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

the class TaxonomyLevelLibraryIndexer method checkAccess.

@Override
public boolean checkAccess(ContextEntry contextEntry, BusinessControl businessControl, Identity identity, Roles roles) {
    if (roles.isOLATAdmin())
        return true;
    if ("TaxonomyLevel".equals(contextEntry.getOLATResourceable().getResourceableTypeName())) {
        Long levelKey = contextEntry.getOLATResourceable().getResourceableId();
        TaxonomyLevel level = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(levelKey));
        TaxonomyTreeBuilder builder = new TaxonomyTreeBuilder(level.getTaxonomy(), identity, null, false, true, "Templates", null);
        TreeModel model = builder.buildTreeModel();
        List<TreeNode> flat = new ArrayList<>();
        TreeHelper.makeTreeFlat(model.getRootNode(), flat);
        for (TreeNode node : flat) {
            TaxonomyTreeNode taxonomyNode = (TaxonomyTreeNode) node;
            if (taxonomyNode.getType() == TaxonomyTreeNodeType.taxonomyLevel && level.equals(taxonomyNode.getTaxonomyLevel())) {
                if (taxonomyNode.isDocumentsLibraryEnabled() && taxonomyNode.isCanRead()) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : TreeModel(org.olat.core.gui.components.tree.TreeModel) TreeNode(org.olat.core.gui.components.tree.TreeNode) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) ArrayList(java.util.ArrayList) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) TaxonomyTreeBuilder(org.olat.modules.taxonomy.manager.TaxonomyTreeBuilder)

Example 8 with TaxonomyTreeNode

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

the class TaxonomyTreeBuilder method computePermissionsRecursive.

private void computePermissionsRecursive(TaxonomyTreeNode node, Map<TaxonomyLevel, List<TaxonomyCompetenceTypes>> levelToCompetences) {
    boolean hasRead = node.isCanRead();
    boolean hasWrite = node.isCanWrite();
    if (node.getType() == TaxonomyTreeNodeType.lostAndFound) {
        hasRead = isTaxonomyAdmin;
        hasWrite = isTaxonomyAdmin;
        node.setCanRead(hasRead);
        node.setCanWrite(hasWrite);
    } else if (node.getTaxonomyLevel() != null) {
        TaxonomyLevel level = node.getTaxonomyLevel();
        TaxonomyLevelType type = level.getType();
        if (type != null) {
            List<TaxonomyCompetenceTypes> competences = levelToCompetences.get(level);
            if (competences != null && competences.size() > 0) {
                for (TaxonomyCompetenceTypes competence : competences) {
                    hasRead |= hasReadAccess(type, competence);
                    hasWrite |= hasWriteAccess(type, competence);
                    if (competence == TaxonomyCompetenceTypes.teach && type.getDocumentsLibraryTeachCompetenceReadParentLevels() > 0) {
                        int parentLevels = type.getDocumentsLibraryTeachCompetenceReadParentLevels();
                        TaxonomyTreeNode parent = (TaxonomyTreeNode) node.getParent();
                        for (int i = parentLevels; i-- > 0 && parent != null; ) {
                            parent.setCanRead(true);
                            parent = (TaxonomyTreeNode) parent.getParent();
                        }
                    }
                }
            } else if (isTaxonomyAdmin) {
                hasRead |= hasReadAccess(type, null);
                hasWrite |= hasWriteAccess(type, null);
            }
        }
        node.setCanRead(hasRead);
        node.setCanWrite(hasWrite);
    } else if (node.getType() == TaxonomyTreeNodeType.templates) {
        hasRead = true;
        hasWrite = isTaxonomyAdmin;
        node.setCanRead(hasRead);
        node.setCanWrite(hasWrite);
    }
    for (int i = node.getChildCount(); i-- > 0; ) {
        TaxonomyTreeNode child = (TaxonomyTreeNode) node.getChildAt(i);
        child.setCanRead(hasRead);
        child.setCanWrite(hasWrite);
        computePermissionsRecursive(child, levelToCompetences);
    }
}
Also used : TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) ArrayList(java.util.ArrayList) List(java.util.List) TaxonomyCompetenceTypes(org.olat.modules.taxonomy.TaxonomyCompetenceTypes)

Example 9 with TaxonomyTreeNode

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

the class TaxonomyTreeBuilder method trimVisiblity.

private void trimVisiblity(TaxonomyTreeNode parent) {
    boolean someInvisible;
    do {
        someInvisible = false;
        List<TaxonomyTreeNode> children = listChildren(parent);
        for (TaxonomyTreeNode child : children) {
            // remove invisible nodes and lost+found
            if (!child.isVisible() || child.getType() == TaxonomyTreeNodeType.lostAndFound) {
                List<TaxonomyTreeNode> childrenOfChild = listChildren(child);
                parent.remove(child);
                for (TaxonomyTreeNode childOfChild : childrenOfChild) {
                    parent.addChild(childOfChild);
                }
                someInvisible = true;
            }
        }
    } while (someInvisible);
    for (int i = 0; i < parent.getChildCount(); i++) {
        trimVisiblity((TaxonomyTreeNode) parent.getChildAt(i));
    }
}
Also used : TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode)

Example 10 with TaxonomyTreeNode

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

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)

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