Search in sources :

Example 11 with TaxonomyTreeNode

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

the class DocumentPoolMainController method activate.

@Override
public void activate(UserRequest ureq, List<ContextEntry> entries, StateEntry state) {
    if (entries == null || entries.isEmpty()) {
        if (taxonomyTree.getTreeModel().getRootNode().getChildCount() > 0) {
            doSelectTaxonomy(ureq);
        }
    } else {
        String resourceName = entries.get(0).getOLATResourceable().getResourceableTypeName();
        if ("Templates".equals(resourceName) || resourceName.startsWith("path=")) {
            TreeNode rootNode = taxonomyTree.getTreeModel().getRootNode();
            if (rootNode.getChildCount() > 0) {
                TaxonomyTreeNode node = (TaxonomyTreeNode) rootNode.getChildAt(0);
                if (node.getType() == TaxonomyTreeNodeType.templates) {
                    DocumentDirectoryController directoryCtrl = doSelectTemplatesDirectory(ureq, node);
                    if (directoryCtrl != null) {
                        taxonomyTree.setSelectedNode(node);
                        List<ContextEntry> subEntries = entries.subList(1, entries.size());
                        directoryCtrl.activate(ureq, subEntries, entries.get(0).getTransientState());
                    }
                }
            }
        } else if ("TaxonomyLevel".equalsIgnoreCase(resourceName)) {
            String levelKey = entries.get(0).getOLATResourceable().getResourceableId().toString();
            TaxonomyTreeNode node = (TaxonomyTreeNode) taxonomyTree.getTreeModel().getNodeById(levelKey);
            if (node != null) {
                DocumentPoolLevelController levelCtrl = doSelectTaxonomyLevel(ureq, node);
                if (levelCtrl != null) {
                    taxonomyTree.setSelectedNode(node);
                    List<ContextEntry> subEntries = entries.subList(1, entries.size());
                    levelCtrl.activate(ureq, subEntries, entries.get(0).getTransientState());
                }
            }
        }
    }
}
Also used : TreeNode(org.olat.core.gui.components.tree.TreeNode) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) List(java.util.List) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 12 with TaxonomyTreeNode

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

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 13 with TaxonomyTreeNode

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

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 14 with TaxonomyTreeNode

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

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 15 with TaxonomyTreeNode

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

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)

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