Search in sources :

Example 1 with TaxonomyTreeNode

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

the class TaxonomyTreeNodeComparator method compare.

@Override
public int compare(INode i1, INode i2) {
    if (i1 == null || i2 == null) {
        return compareNullObjects(i1, i2);
    }
    Integer s1 = null;
    Integer s2 = null;
    String title1 = null;
    String title2 = null;
    TaxonomyTreeNodeType type1 = null;
    TaxonomyTreeNodeType type2 = null;
    if (i1 instanceof TaxonomyTreeNode) {
        TaxonomyTreeNode t1 = (TaxonomyTreeNode) i1;
        title1 = t1.getTitle();
        type1 = t1.getType();
        if (t1.getTaxonomyLevel() != null) {
            s1 = t1.getTaxonomyLevel().getSortOrder();
        }
    } else if (i1 instanceof GenericTreeNode) {
        GenericTreeNode node = (GenericTreeNode) i1;
        title1 = node.getTitle();
        Object uobject = node.getUserObject();
        if (uobject instanceof TaxonomyLevel) {
            TaxonomyLevel level = (TaxonomyLevel) uobject;
            type1 = TaxonomyTreeNodeType.taxonomyLevel;
            s1 = level.getSortOrder();
        }
    }
    if (i2 instanceof TaxonomyTreeNode) {
        TaxonomyTreeNode t2 = (TaxonomyTreeNode) i2;
        title2 = t2.getTitle();
        type2 = t2.getType();
        if (t2.getTaxonomyLevel() != null) {
            s2 = t2.getTaxonomyLevel().getSortOrder();
        }
    } else if (i1 instanceof GenericTreeNode) {
        GenericTreeNode node = (GenericTreeNode) i2;
        title2 = node.getTitle();
        Object uobject = node.getUserObject();
        if (uobject instanceof TaxonomyLevel) {
            TaxonomyLevel level = (TaxonomyLevel) uobject;
            type2 = TaxonomyTreeNodeType.taxonomyLevel;
            s2 = level.getSortOrder();
        }
    }
    int c = 0;
    if (type1 == TaxonomyTreeNodeType.templates && type2 == TaxonomyTreeNodeType.templates) {
        c = 0;
    } else if (type1 == TaxonomyTreeNodeType.templates) {
        return -1;
    } else if (type2 == TaxonomyTreeNodeType.templates) {
        return 1;
    }
    if (type1 == TaxonomyTreeNodeType.lostAndFound && type2 == TaxonomyTreeNodeType.lostAndFound) {
        c = 0;
    } else if (type1 == TaxonomyTreeNodeType.lostAndFound) {
        return 1;
    } else if (type2 == TaxonomyTreeNodeType.lostAndFound) {
        return -1;
    }
    if (c == 0) {
        if (s1 == null || s2 == null) {
            c = compareNullObjects(s1, s2);
        } else {
            c = s1.compareTo(s2);
        }
    }
    if (c == 0) {
        if (title1 == null || title2 == null) {
            c = compareNullObjects(title1, title2);
        } else {
            c = title1.compareTo(title2);
        }
    }
    return c;
}
Also used : GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) TaxonomyTreeNodeType(org.olat.modules.taxonomy.model.TaxonomyTreeNodeType)

Example 2 with TaxonomyTreeNode

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

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

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

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

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)

Example 5 with TaxonomyTreeNode

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

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)

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