use of org.olat.modules.taxonomy.TaxonomyLevel in project openolat by klemens.
the class MergeTaxonomyLevelController method formOK.
@Override
protected void formOK(UserRequest ureq) {
if (levels.size() > 1) {
Collections.sort(levels, new TaxonomyLevelDepthComparator());
}
String selectedNodeKey = mergeToEl.getSelectedKey();
TreeNode selectedNode = treeModel.getNodeById(selectedNodeKey);
TaxonomyLevel mergeTo = (TaxonomyLevel) selectedNode.getUserObject();
StringBuilder sb = new StringBuilder();
for (TaxonomyLevel level : levels) {
TaxonomyLevel taxonomyLevel = taxonomyService.getTaxonomyLevel(level);
if (taxonomyService.deleteTaxonomyLevel(taxonomyLevel, mergeTo)) {
if (sb.length() > 0)
sb.append(", ");
sb.append(StringHelper.escapeHtml(taxonomyLevel.getDisplayName()));
}
}
// commit before sending event
dbInstance.commit();
fireEvent(ureq, new DeleteTaxonomyLevelEvent());
showInfo("confirm.merge.level", new String[] { sb.toString() });
}
use of org.olat.modules.taxonomy.TaxonomyLevel in project openolat by klemens.
the class MoveTaxonomyLevelController method loadModel.
private void loadModel() {
new TaxonomyAllTreesBuilder().loadTreeModel(taxonomyModel, taxonomy);
// remove children of the level to move
for (TaxonomyLevel levelToMove : levelsToMove) {
TreeNode nodeToMove = taxonomyModel.getNodeById(TaxonomyAllTreesBuilder.nodeKey(levelToMove));
nodeToMove.removeAllChildren();
}
// remove the level with
List<TreeNode> openedNodes = new ArrayList<>();
filterByAllowedTypes(taxonomyModel.getRootNode(), openedNodes);
taxonomyModel.sort(taxonomyModel.getRootNode());
List<String> nodeIds = openedNodes.stream().map(node -> node.getIdent()).collect(Collectors.toList());
taxonomyEl.setOpenNodeIds(nodeIds);
}
use of org.olat.modules.taxonomy.TaxonomyLevel in project openolat by klemens.
the class MoveTaxonomyLevelController method getAllowedTypes.
private Set<TaxonomyLevelType> getAllowedTypes() {
List<TaxonomyLevelType> allTypes = new ArrayList<>(taxonomyService.getTaxonomyLevelTypes(taxonomy));
Map<TaxonomyLevelType, Set<TaxonomyLevelType>> subToParentTypes = new HashMap<>();
for (TaxonomyLevelType type : allTypes) {
Set<TaxonomyLevelTypeToType> typesToTypes = type.getAllowedTaxonomyLevelSubTypes();
for (TaxonomyLevelTypeToType typeToType : typesToTypes) {
TaxonomyLevelType subTyp = typeToType.getAllowedSubTaxonomyLevelType();
subToParentTypes.computeIfAbsent(subTyp, t -> new HashSet<>()).add(type);
}
}
Set<TaxonomyLevelType> analyzedTypes = new HashSet<>();
for (TaxonomyLevel level : levelsToMove) {
TaxonomyLevelType levelType = level.getType();
if (levelType != null && !analyzedTypes.contains(levelType)) {
analyzedTypes.add(levelType);
Set<TaxonomyLevelType> allowed = subToParentTypes.get(levelType);
if (allowed != null) {
allTypes.retainAll(allowed);
}
}
}
return new HashSet<>(allTypes);
}
use of org.olat.modules.taxonomy.TaxonomyLevel 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;
}
use of org.olat.modules.taxonomy.TaxonomyLevel in project openolat by klemens.
the class TaxonomyLevelLibraryIndexer method doIndex.
@Override
public void doIndex(SearchResourceContext parentResourceContext, Object object, OlatFullIndexer indexerWriter) throws IOException, InterruptedException {
if (object instanceof TaxonomyLevel) {
TaxonomyLevel level = (TaxonomyLevel) object;
VFSContainer library = taxonomyService.getDocumentsLibrary(level);
if (library != null) {
SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext);
searchResourceContext.setBusinessControlFor(level);
searchResourceContext.setTitle(level.getDisplayName());
searchResourceContext.setDescription(level.getDescription());
searchResourceContext.setLastModified(level.getLastModified());
searchResourceContext.setCreatedDate(level.getCreationDate());
FolderIndexerWorker runnableFolderIndexer = new FolderIndexerWorker();
runnableFolderIndexer.setAccessRule(FolderIndexerAccess.FULL_ACCESS);
runnableFolderIndexer.setParentResourceContext(searchResourceContext);
runnableFolderIndexer.setContainer(library);
runnableFolderIndexer.setIndexWriter(indexerWriter);
runnableFolderIndexer.setFilePath("");
indexerWriter.submit(runnableFolderIndexer);
}
}
}
Aggregations