Search in sources :

Example 1 with TaxonomyTreeBuilder

use of org.olat.modules.taxonomy.manager.TaxonomyTreeBuilder in project OpenOLAT by OpenOLAT.

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 2 with TaxonomyTreeBuilder

use of org.olat.modules.taxonomy.manager.TaxonomyTreeBuilder 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 3 with TaxonomyTreeBuilder

use of org.olat.modules.taxonomy.manager.TaxonomyTreeBuilder 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 4 with TaxonomyTreeBuilder

use of org.olat.modules.taxonomy.manager.TaxonomyTreeBuilder 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 5 with TaxonomyTreeBuilder

use of org.olat.modules.taxonomy.manager.TaxonomyTreeBuilder in project OpenOLAT by OpenOLAT.

the class DocumentPoolWebDAVMergeSource method loadMergedContainers.

@Override
protected List<VFSContainer> loadMergedContainers() {
    List<VFSContainer> containers = new ArrayList<>();
    String taxonomyTreeKey = docPoolModule.getTaxonomyTreeKey();
    if (StringHelper.isLong(taxonomyTreeKey)) {
        Taxonomy taxonomy = taxonomyService.getTaxonomy(new TaxonomyRefImpl(new Long(taxonomyTreeKey)));
        if (taxonomy != null) {
            String templatesDir = Util.createPackageTranslator(DocumentPoolMainController.class, identityEnv.getLocale()).translate("document.pool.templates");
            TaxonomyTreeBuilder builder = new TaxonomyTreeBuilder(taxonomy, identityEnv.getIdentity(), null, identityEnv.getRoles().isOLATAdmin(), docPoolModule.isTemplatesDirectoryEnabled(), templatesDir, null);
            TreeModel model = builder.buildTreeModel();
            TreeNode rootNode = model.getRootNode();
            for (int i = 0; i < rootNode.getChildCount(); i++) {
                VFSContainer container = loadRecursiveMergedContainers(taxonomy, rootNode.getChildAt(i));
                if (container != null) {
                    containers.add(container);
                }
            }
        }
    }
    return containers;
}
Also used : TreeModel(org.olat.core.gui.components.tree.TreeModel) TaxonomyRefImpl(org.olat.modules.taxonomy.model.TaxonomyRefImpl) Taxonomy(org.olat.modules.taxonomy.Taxonomy) TreeNode(org.olat.core.gui.components.tree.TreeNode) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) DocumentPoolMainController(org.olat.modules.docpool.ui.DocumentPoolMainController) TaxonomyTreeBuilder(org.olat.modules.taxonomy.manager.TaxonomyTreeBuilder)

Aggregations

TreeModel (org.olat.core.gui.components.tree.TreeModel)6 TaxonomyTreeBuilder (org.olat.modules.taxonomy.manager.TaxonomyTreeBuilder)6 TaxonomyTreeNode (org.olat.modules.taxonomy.model.TaxonomyTreeNode)6 ArrayList (java.util.ArrayList)4 TreeNode (org.olat.core.gui.components.tree.TreeNode)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 DocumentPoolMainController (org.olat.modules.docpool.ui.DocumentPoolMainController)4 Taxonomy (org.olat.modules.taxonomy.Taxonomy)4 TaxonomyRefImpl (org.olat.modules.taxonomy.model.TaxonomyRefImpl)3 Date (java.util.Date)2 List (java.util.List)2 Locale (java.util.Locale)2 BaseSecurity (org.olat.basesecurity.BaseSecurity)2 FileInfo (org.olat.core.commons.modules.bc.FileInfo)2 FolderManager (org.olat.core.commons.modules.bc.FolderManager)2 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)2 NotificationHelper (org.olat.core.commons.services.notifications.NotificationHelper)2 NotificationsHandler (org.olat.core.commons.services.notifications.NotificationsHandler)2 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)2 Publisher (org.olat.core.commons.services.notifications.Publisher)2