use of org.olat.modules.taxonomy.TaxonomyLevelType in project openolat by klemens.
the class TaxonomyServiceImpl method cloneTaxonomyLevelType.
@Override
public TaxonomyLevelType cloneTaxonomyLevelType(TaxonomyLevelTypeRef levelType) {
TaxonomyLevelType clonedType = taxonomyLevelTypeDao.cloneTaxonomyLevelType(levelType);
List<TaxonomyLevelTypeToType> allowSubTypesToTypes = taxonomyLevelTypeToTypeDao.getAllowedSubTypes(levelType);
if (allowSubTypesToTypes.size() > 0) {
for (TaxonomyLevelTypeToType allowSubTypeToType : allowSubTypesToTypes) {
taxonomyLevelTypeToTypeDao.addAllowedSubType(clonedType, allowSubTypeToType.getAllowedSubTaxonomyLevelType());
}
}
return clonedType;
}
use of org.olat.modules.taxonomy.TaxonomyLevelType in project openolat by klemens.
the class TaxonomyTreeBuilder method computePermissionsRecursive.
private void computePermissionsRecursive(TaxonomyTreeNode node, Map<TaxonomyLevel, List<TaxonomyCompetenceTypes>> levelToCompetences) {
boolean hasRead = node.isCanRead();
boolean hasWrite = node.isCanWrite();
if (node.getType() == TaxonomyTreeNodeType.lostAndFound) {
hasRead = isTaxonomyAdmin;
hasWrite = isTaxonomyAdmin;
node.setCanRead(hasRead);
node.setCanWrite(hasWrite);
} else if (node.getTaxonomyLevel() != null) {
TaxonomyLevel level = node.getTaxonomyLevel();
TaxonomyLevelType type = level.getType();
if (type != null) {
List<TaxonomyCompetenceTypes> competences = levelToCompetences.get(level);
if (competences != null && competences.size() > 0) {
for (TaxonomyCompetenceTypes competence : competences) {
hasRead |= hasReadAccess(type, competence);
hasWrite |= hasWriteAccess(type, competence);
if (competence == TaxonomyCompetenceTypes.teach && type.getDocumentsLibraryTeachCompetenceReadParentLevels() > 0) {
int parentLevels = type.getDocumentsLibraryTeachCompetenceReadParentLevels();
TaxonomyTreeNode parent = (TaxonomyTreeNode) node.getParent();
for (int i = parentLevels; i-- > 0 && parent != null; ) {
parent.setCanRead(true);
parent = (TaxonomyTreeNode) parent.getParent();
}
}
}
} else if (isTaxonomyAdmin) {
hasRead |= hasReadAccess(type, null);
hasWrite |= hasWriteAccess(type, null);
}
}
node.setCanRead(hasRead);
node.setCanWrite(hasWrite);
} else if (node.getType() == TaxonomyTreeNodeType.templates) {
hasRead = true;
hasWrite = isTaxonomyAdmin;
node.setCanRead(hasRead);
node.setCanWrite(hasWrite);
}
for (int i = node.getChildCount(); i-- > 0; ) {
TaxonomyTreeNode child = (TaxonomyTreeNode) node.getChildAt(i);
child.setCanRead(hasRead);
child.setCanWrite(hasWrite);
computePermissionsRecursive(child, levelToCompetences);
}
}
use of org.olat.modules.taxonomy.TaxonomyLevelType in project openolat by klemens.
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.TaxonomyLevelType in project openolat by klemens.
the class TaxonomyWebService method getTaxonomyLevelTypes.
/**
* Get the configurations for taxonomy levels for the whole taxonomy.
*
* @response.representation.200.qname {http://www.example.com}taxonomyLevelTypeVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc A taxonomy level
* @response.representation.200.example {@link org.olat.modules.taxonomy.restapi.Examples#SAMPLE_TAXONOMYLEVELTYPEVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The taxonomy was not found
* @param taxonomyKey The taxonomy tree
* @param httpRequest The HTTP request
* @return An array of taxonomy levels types
*/
@GET
@Path("types")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getTaxonomyLevelTypes() {
List<TaxonomyLevelType> types = taxonomyService.getTaxonomyLevelTypes(taxonomy);
List<TaxonomyLevelTypeVO> typeVOes = new ArrayList<>(types.size());
for (TaxonomyLevelType type : types) {
typeVOes.add(new TaxonomyLevelTypeVO(type));
}
return Response.ok(typeVOes.toArray(new TaxonomyLevelTypeVO[typeVOes.size()])).build();
}
use of org.olat.modules.taxonomy.TaxonomyLevelType in project openolat by klemens.
the class TaxonomyWebService method allowSubTaxonomyLevelType.
/**
* Add a sub-type to a specified taxonomy level's type.
*
* @response.representation.200.qname {http://www.example.com}taxonomyLevelTypeVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The sub type was added to the allowed sub types
* @response.representation.200.example {@link org.olat.modules.taxonomy.restapi.Examples#SAMPLE_TAXONOMYLEVELTYPEVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The taxonomy level type was not found
* @param taxonomyKey The taxonomy tree
* @param typeKey The type
* @param subTypeKey The sub type
* @param httpRequest The HTTP request
* @return Nothing
*/
@PUT
@Path("types/{typeKey}/allowedSubTypes/{subTypeKey}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response allowSubTaxonomyLevelType(@PathParam("typeKey") Long typeKey, @PathParam("subTypeKey") Long subTypeKey) {
TaxonomyLevelType type = taxonomyService.getTaxonomyLevelType(new TaxonomyLevelTypeRefImpl(typeKey));
TaxonomyLevelType subType = taxonomyService.getTaxonomyLevelType(new TaxonomyLevelTypeRefImpl(subTypeKey));
if (type == null || subType == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
taxonomyService.taxonomyLevelTypeAllowSubType(type, subType);
return Response.ok().build();
}
Aggregations