use of org.olat.modules.taxonomy.model.TaxonomyTreeNode in project OpenOLAT by OpenOLAT.
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;
}
use of org.olat.modules.taxonomy.model.TaxonomyTreeNode 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();
}
}
use of org.olat.modules.taxonomy.model.TaxonomyTreeNode in project OpenOLAT by OpenOLAT.
the class DocumentPoolMainController method event.
@Override
protected void event(UserRequest ureq, Component source, Event event) {
if (taxonomyTree == source) {
if (event instanceof TreeEvent) {
TreeEvent te = (TreeEvent) event;
if (MenuTree.COMMAND_TREENODE_CLICKED.equals(te.getCommand())) {
TaxonomyTreeNode node = (TaxonomyTreeNode) taxonomyTree.getTreeModel().getNodeById(te.getNodeId());
doSelect(ureq, node);
}
}
} else if (content == source) {
if (event instanceof PopEvent) {
PopEvent popEvent = (PopEvent) event;
if (popEvent.getController() instanceof DocumentPoolLevelController) {
DocumentPoolLevelController taxonomyLevelCtrl = (DocumentPoolLevelController) popEvent.getController();
TaxonomyLevel level = taxonomyLevelCtrl.getTaxonomyLevel();
TaxonomyTreeNode node = (TaxonomyTreeNode) TreeHelper.findNodeByUserObject(level, taxonomyTree.getTreeModel().getRootNode());
TaxonomyTreeNode parentNode = (TaxonomyTreeNode) node.getParent();
if (parentNode == null) {
doSelectTaxonomy(ureq);
taxonomyTree.setSelectedNode(taxonomyTree.getTreeModel().getRootNode());
} else {
doSelect(ureq, parentNode);
taxonomyTree.setSelectedNode(parentNode);
}
} else if (popEvent.getUserObject() instanceof TaxonomyTreeNode) {
TaxonomyTreeNode node = (TaxonomyTreeNode) popEvent.getUserObject();
doSelect(ureq, node);
taxonomyTree.setSelectedNode(node);
} else if (popEvent.getController() instanceof DocumentDirectoryController) {
// pop the templates
taxonomyTree.setSelectedNode(taxonomyTree.getTreeModel().getRootNode());
}
}
}
}
use of org.olat.modules.taxonomy.model.TaxonomyTreeNode in project OpenOLAT by OpenOLAT.
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;
}
use of org.olat.modules.taxonomy.model.TaxonomyTreeNode in project openolat by klemens.
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;
}
Aggregations