Search in sources :

Example 26 with TaxonomyLevelType

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);
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) TaxonomyLevelTypeToType(org.olat.modules.taxonomy.TaxonomyLevelTypeToType) URI(java.net.URI) Test(org.junit.Test)

Example 27 with TaxonomyLevelType

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;
}
Also used : INode(org.olat.core.util.nodes.INode) TreeModel(org.olat.core.gui.components.tree.TreeModel) QPoolService(org.olat.modules.qpool.QPoolService) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) QuestionPoolModule(org.olat.modules.qpool.QuestionPoolModule) Collectors(java.util.stream.Collectors) Scope(org.springframework.context.annotation.Scope) ArrayList(java.util.ArrayList) List(java.util.List) Component(org.springframework.stereotype.Component) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) Identity(org.olat.core.id.Identity) Map(java.util.Map) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) StringHelper(org.olat.core.util.StringHelper) TaxonomyCompetenceTypes(org.olat.modules.taxonomy.TaxonomyCompetenceTypes) Comparator(java.util.Comparator) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) HashMap(java.util.HashMap) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel)

Example 28 with TaxonomyLevelType

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);
}
Also used : INode(org.olat.core.util.nodes.INode) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) TaxonomyModel(org.olat.modules.taxonomy.model.TaxonomyModel) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Event(org.olat.core.gui.control.Event) FormBasicController(org.olat.core.gui.components.form.flexible.impl.FormBasicController) FormItemContainer(org.olat.core.gui.components.form.flexible.FormItemContainer) TaxonomyService(org.olat.modules.taxonomy.TaxonomyService) Map(java.util.Map) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) Taxonomy(org.olat.modules.taxonomy.Taxonomy) MenuTreeItem(org.olat.core.gui.components.tree.MenuTreeItem) WindowControl(org.olat.core.gui.control.WindowControl) Set(java.util.Set) Collectors(java.util.stream.Collectors) Controller(org.olat.core.gui.control.Controller) TaxonomyLevelTypeToType(org.olat.modules.taxonomy.TaxonomyLevelTypeToType) List(java.util.List) TaxonomyAllTreesBuilder(org.olat.modules.taxonomy.manager.TaxonomyAllTreesBuilder) TreeNode(org.olat.core.gui.components.tree.TreeNode) UserRequest(org.olat.core.gui.UserRequest) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) ArrayList(java.util.ArrayList) TaxonomyLevelTypeToType(org.olat.modules.taxonomy.TaxonomyLevelTypeToType) HashSet(java.util.HashSet)

Example 29 with TaxonomyLevelType

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);
            }
        }
    }
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType)

Example 30 with TaxonomyLevelType

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;
}
Also used : TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) ArrayList(java.util.ArrayList) TaxonomyLevelTypeToType(org.olat.modules.taxonomy.TaxonomyLevelTypeToType)

Aggregations

TaxonomyLevelType (org.olat.modules.taxonomy.TaxonomyLevelType)92 Test (org.junit.Test)40 Taxonomy (org.olat.modules.taxonomy.Taxonomy)32 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)32 ArrayList (java.util.ArrayList)26 Identity (org.olat.core.id.Identity)20 TaxonomyLevelTypeToType (org.olat.modules.taxonomy.TaxonomyLevelTypeToType)16 URI (java.net.URI)14 HttpResponse (org.apache.http.HttpResponse)14 TaxonomyLevelTypeRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl)14 Path (javax.ws.rs.Path)12 List (java.util.List)10 Produces (javax.ws.rs.Produces)10 Collectors (java.util.stream.Collectors)8 TaxonomyLevelRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 PUT (javax.ws.rs.PUT)6 HttpGet (org.apache.http.client.methods.HttpGet)6 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)6