use of org.olat.modules.taxonomy.TaxonomyLevelType in project OpenOLAT by OpenOLAT.
the class QPoolTaxonomyTreeBuilder method buildTreeModel.
public TreeModel buildTreeModel() {
GenericTreeModel gtm = new GenericTreeModel();
TaxonomyLevelNode root = new TaxonomyLevelNode();
gtm.setRootNode(root);
List<TaxonomyLevel> taxonomyLevels = qpoolService.getTaxonomyLevels();
Map<Long, TaxonomyLevel> keytoLevels = taxonomyLevels.stream().collect(Collectors.toMap(l -> l.getKey(), l -> l));
Map<Long, TaxonomyLevelNode> fieldKeyToNode = new HashMap<>();
for (TaxonomyLevel taxonomyLevel : taxonomyLevels) {
Long key = taxonomyLevel.getKey();
TaxonomyLevelNode node = fieldKeyToNode.get(key);
if (node == null) {
node = new TaxonomyLevelNode(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();
TaxonomyLevelNode parentNode = fieldKeyToNode.get(parentKey);
if (parentNode == null) {
// to use the fetched type
parentLevel = keytoLevels.get(parentKey);
parentNode = new TaxonomyLevelNode(parentLevel);
TaxonomyLevelType type = parentLevel.getType();
if (type != null && StringHelper.containsNonWhitespace(type.getCssClass())) {
parentNode.setIconCssClass(type.getCssClass());
}
fieldKeyToNode.put(parentKey, parentNode);
}
parentNode.addChild(node);
}
}
sort(root);
return gtm;
}
use of org.olat.modules.taxonomy.TaxonomyLevelType in project OpenOLAT by OpenOLAT.
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();
}
use of org.olat.modules.taxonomy.TaxonomyLevelType in project OpenOLAT by OpenOLAT.
the class TaxonomyWebService method disalloweSubTaxonomyLevelType.
/**
* Remove a sub-type to a specified taxonomy level's type.
*
* @response.representation.200.doc The sub type was removed sucessfully
* @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 to remove
* @param httpRequest The HTTP request
* @return Nothing
*/
@DELETE
@Path("types/{typeKey}/allowedSubTypes/{subTypeKey}")
public Response disalloweSubTaxonomyLevelType(@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.taxonomyLevelTypeDisallowSubType(type, subType);
return Response.ok().build();
}
use of org.olat.modules.taxonomy.TaxonomyLevelType in project OpenOLAT by OpenOLAT.
the class TaxonomyWebService method putTaxonomyLevelType.
/**
* Create or Update a 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 A taxonomy level type
* @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 to update was not found
* @param taxonomyKey The taxonomy tree
* @param httpRequest The HTTP request
* @param typeVo The taxonomy level type to create or update
* @return The created/updated taxonomy level type
*/
@PUT
@Path("types")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response putTaxonomyLevelType(TaxonomyLevelTypeVO typeVo) {
TaxonomyLevelType type;
if (typeVo.getKey() != null) {
type = taxonomyService.getTaxonomyLevelType(new TaxonomyLevelTypeRefImpl(typeVo.getKey()));
if (type == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
if (typeVo.getIdentifier() != null) {
type.setIdentifier(typeVo.getIdentifier());
}
if (typeVo.getDisplayName() != null) {
type.setDisplayName(typeVo.getDisplayName());
}
if (typeVo.getDescription() != null) {
type.setDescription(typeVo.getDescription());
}
if (typeVo.getExternalId() != null) {
type.setExternalId(typeVo.getExternalId());
}
} else {
type = taxonomyService.createTaxonomyLevelType(typeVo.getIdentifier(), typeVo.getDisplayName(), typeVo.getDescription(), typeVo.getExternalId(), taxonomy);
}
if (typeVo.getManagedFlags() != null) {
type.setManagedFlags(TaxonomyLevelTypeManagedFlag.toEnum(typeVo.getManagedFlags()));
}
if (typeVo.getCssClass() != null) {
type.setCssClass(typeVo.getCssClass());
}
if (typeVo.getVisible() != null) {
type.setVisible(typeVo.getVisible().booleanValue());
}
if (typeVo.getDocumentsLibraryEnabled() != null) {
type.setDocumentsLibraryEnabled(typeVo.getDocumentsLibraryEnabled().booleanValue());
}
if (typeVo.getDocumentsLibraryManagerCompetenceEnabled() != null) {
type.setDocumentsLibraryManageCompetenceEnabled(typeVo.getDocumentsLibraryManagerCompetenceEnabled().booleanValue());
}
if (typeVo.getDocumentsLibraryTeachCompetenceReadEnabled() != null) {
type.setDocumentsLibraryTeachCompetenceReadEnabled(typeVo.getDocumentsLibraryTeachCompetenceReadEnabled().booleanValue());
}
if (typeVo.getDocumentsLibraryTeachCompetenceReadParentLevels() != null) {
type.setDocumentsLibraryTeachCompetenceReadParentLevels(typeVo.getDocumentsLibraryTeachCompetenceReadParentLevels().intValue());
}
if (typeVo.getDocumentsLibraryTeachCompetenceWriteEnabled() != null) {
type.setDocumentsLibraryTeachCompetenceWriteEnabled(typeVo.getDocumentsLibraryTeachCompetenceWriteEnabled().booleanValue());
}
if (typeVo.getDocumentsLibraryHaveCompetenceReadEnabled() != null) {
type.setDocumentsLibraryHaveCompetenceReadEnabled(typeVo.getDocumentsLibraryHaveCompetenceReadEnabled().booleanValue());
}
if (typeVo.getDocumentsLibraryTargetCompetenceReadEnabled() != null) {
type.setDocumentsLibraryTargetCompetenceReadEnabled(typeVo.getDocumentsLibraryTargetCompetenceReadEnabled().booleanValue());
}
type = taxonomyService.updateTaxonomyLevelType(type);
return Response.ok(new TaxonomyLevelTypeVO(type)).build();
}
use of org.olat.modules.taxonomy.TaxonomyLevelType in project OpenOLAT by OpenOLAT.
the class TaxonomyWebService method putTaxonomyLevel.
/**
* Create or update a taxonomy level. The method changes to tree structure, a
* null parent key will make the level a root one, a new parent key will move
* the level.
*
* @response.representation.200.qname {http://www.example.com}taxonomyLevelVO
* @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_TAXONOMYLEVELVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc An existant level was not found
* @param taxonomyKey The taxonomy tree where this level is
* @param httpRequest The HTTP request
* @param levelVo The roll call to update
* @return The updated roll call
*/
@PUT
@Path("levels")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response putTaxonomyLevel(TaxonomyLevelVO levelVo) {
TaxonomyLevel parentLevel = null;
if (levelVo.getParentKey() != null) {
parentLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(levelVo.getParentKey()));
}
TaxonomyLevel level;
if (levelVo.getKey() != null) {
level = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(levelVo.getKey()));
if (levelVo.getIdentifier() != null) {
level.setIdentifier(levelVo.getIdentifier());
}
if (levelVo.getDisplayName() != null) {
level.setDisplayName(levelVo.getDisplayName());
}
if (levelVo.getDescription() != null) {
level.setDescription(levelVo.getDescription());
}
if (levelVo.getExternalId() != null) {
level.setExternalId(levelVo.getExternalId());
}
if (levelVo.getTypeKey() != null) {
TaxonomyLevelType type = taxonomyService.getTaxonomyLevelType(new TaxonomyLevelTypeRefImpl(levelVo.getTypeKey()));
level.setType(type);
}
if (levelVo.getManagedFlags() != null) {
level.setManagedFlags(TaxonomyLevelManagedFlag.toEnum(levelVo.getManagedFlags()));
}
level = taxonomyService.updateTaxonomyLevel(level);
} else {
level = taxonomyService.createTaxonomyLevel(levelVo.getIdentifier(), levelVo.getDisplayName(), levelVo.getDescription(), levelVo.getExternalId(), TaxonomyLevelManagedFlag.toEnum(levelVo.getManagedFlags()), parentLevel, taxonomy);
if (levelVo.getTypeKey() != null) {
TaxonomyLevelType type = taxonomyService.getTaxonomyLevelType(new TaxonomyLevelTypeRefImpl(levelVo.getTypeKey()));
level.setType(type);
level = taxonomyService.updateTaxonomyLevel(level);
}
}
if ((level.getParent() != null && levelVo.getParentKey() == null) || (level.getParent() == null && levelVo.getParentKey() != null) || (level.getParent() != null && !level.getParent().getKey().equals(levelVo.getParentKey()))) {
TaxonomyLevel newParentLevel = null;
if (levelVo.getParentKey() != null) {
newParentLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(levelVo.getParentKey()));
}
level = taxonomyService.moveTaxonomyLevel(level, newParentLevel);
}
TaxonomyLevelVO newLevelVo = new TaxonomyLevelVO(level);
return Response.ok(newLevelVo).build();
}
Aggregations