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;
}
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;
}
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));
}
}
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;
}
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());
}
}
}
}
}
Aggregations