use of org.olat.modules.taxonomy.TaxonomyLevelType in project openolat by klemens.
the class TaxonomyWebServiceTest method disallowTaxonomyLevelTypeAllowedSubType.
@Test
public void disallowTaxonomyLevelTypeAllowedSubType() throws IOException, URISyntaxException {
Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-6", "Taxonomy on rest", "Rest is cool", "Ext-tax-6");
TaxonomyLevelType type = taxonomyService.createTaxonomyLevelType("REST-Type-6", "Type 6 on rest", "Type", "EXT-Type-6", taxonomy);
TaxonomyLevelType subType1 = taxonomyService.createTaxonomyLevelType("REST-Type-6-1", "Type 6.1 on rest", "Type", "EXT-Type-6-1", taxonomy);
TaxonomyLevelType subType2 = taxonomyService.createTaxonomyLevelType("REST-Type-6-2", "Type 6.2 on rest", "Type", "EXT-Type-6-2", taxonomy);
TaxonomyLevelType subType3 = taxonomyService.createTaxonomyLevelType("REST-Type-6-3", "Type 6.3 on rest", "Type", "EXT-Type-6-3", taxonomy);
dbInstance.commit();
List<TaxonomyLevelType> allowedSubTypes = new ArrayList<>();
allowedSubTypes.add(subType1);
allowedSubTypes.add(subType2);
allowedSubTypes.add(subType3);
type = taxonomyService.updateTaxonomyLevelType(type, allowedSubTypes);
dbInstance.commitAndCloseSession();
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("types").path(type.getKey().toString()).path("allowedSubTypes").path(subType2.getKey().toString()).build();
HttpDelete method = conn.createDelete(request, MediaType.APPLICATION_JSON);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
TaxonomyLevelType reloadedType = taxonomyService.getTaxonomyLevelType(type);
Set<TaxonomyLevelTypeToType> typeToTypes = reloadedType.getAllowedTaxonomyLevelSubTypes();
Assert.assertEquals(2, typeToTypes.size());
boolean found1 = false;
boolean found2 = false;
boolean found3 = false;
for (TaxonomyLevelTypeToType typeToType : typeToTypes) {
TaxonomyLevelType subType = typeToType.getAllowedSubTaxonomyLevelType();
if (subType1.getKey().equals(subType.getKey())) {
found1 = true;
} else if (subType2.getKey().equals(subType.getKey())) {
found2 = true;
} else if (subType3.getKey().equals(subType.getKey())) {
found3 = true;
}
}
Assert.assertTrue(found1);
Assert.assertFalse(found2);
Assert.assertTrue(found3);
}
use of org.olat.modules.taxonomy.TaxonomyLevelType in project openolat by klemens.
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 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.TaxonomyLevelType in project openolat by klemens.
the class TaxonomyLibraryIndexer method doIndexTaxonomyLibrary.
protected void doIndexTaxonomyLibrary(SearchResourceContext searchResourceContext, Taxonomy taxonomy, OlatFullIndexer indexerWriter) throws InterruptedException {
VFSContainer templatesContainer = taxonomyService.getDocumentsLibrary(taxonomy);
if (templatesContainer != null) {
try {
taxonomyTemplatesLibraryIndexer.doIndex(searchResourceContext, taxonomy, indexerWriter);
} catch (InterruptedException e) {
throw e;
} catch (Exception e) {
logError("", e);
}
}
List<TaxonomyLevel> levels = taxonomyService.getTaxonomyLevels(taxonomy);
for (TaxonomyLevel level : levels) {
TaxonomyLevelType type = level.getType();
if (type != null && hasDocumentLibraryEnabled(type)) {
try {
taxonomyLevelLibraryIndexer.doIndex(searchResourceContext, level, indexerWriter);
} catch (InterruptedException e) {
throw e;
} catch (Exception e) {
logError("", e);
}
}
}
}
use of org.olat.modules.taxonomy.TaxonomyLevelType in project openolat by klemens.
the class EditTaxonomyLevelController method getTypes.
private List<TaxonomyLevelType> getTypes() {
List<TaxonomyLevelType> types = new ArrayList<>();
if (level != null) {
List<TaxonomyLevel> parentLine = taxonomyService.getTaxonomyLevelParentLine(level, taxonomy);
for (int i = parentLine.size() - 1; i-- > 0; ) {
TaxonomyLevel parent = parentLine.get(i);
TaxonomyLevelType parentType = parent.getType();
if (parentType != null) {
Set<TaxonomyLevelTypeToType> typeToTypes = parentType.getAllowedTaxonomyLevelSubTypes();
for (TaxonomyLevelTypeToType typeToType : typeToTypes) {
if (typeToType != null) {
types.add(typeToType.getAllowedSubTaxonomyLevelType());
}
}
break;
}
}
}
if (types.isEmpty()) {
types.addAll(taxonomyService.getTaxonomyLevelTypes(taxonomy));
} else if (level != null && level.getType() != null) {
if (!types.contains(level.getType())) {
types.add(level.getType());
}
}
return types;
}
Aggregations