Search in sources :

Example 6 with TaxonomyLevelTypeToType

use of org.olat.modules.taxonomy.TaxonomyLevelTypeToType in project OpenOLAT by OpenOLAT.

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 7 with TaxonomyLevelTypeToType

use of org.olat.modules.taxonomy.TaxonomyLevelTypeToType in project OpenOLAT by OpenOLAT.

the class TypeTaxonomyLevelController method getAvailableTypes.

private List<TaxonomyLevelType> getAvailableTypes() {
    List<TaxonomyLevelType> allowedTypes = new ArrayList<>(taxonomyService.getTaxonomyLevelTypes(taxonomy));
    Set<TaxonomyLevelType> analyzedTypes = new HashSet<>();
    for (TaxonomyLevel level : levels) {
        TaxonomyLevel parentLevel = level.getParent();
        if (parentLevel != null && parentLevel.getType() != null && !analyzedTypes.contains(parentLevel.getType())) {
            TaxonomyLevelType parentType = parentLevel.getType();
            List<TaxonomyLevelType> allowedSubTypes = new ArrayList<>();
            Set<TaxonomyLevelTypeToType> typesToTypes = parentType.getAllowedTaxonomyLevelSubTypes();
            for (TaxonomyLevelTypeToType typeToType : typesToTypes) {
                allowedSubTypes.add(typeToType.getAllowedSubTaxonomyLevelType());
            }
            if (allowedSubTypes.size() > 0) {
                allowedTypes.retainAll(allowedSubTypes);
            }
        }
    }
    return allowedTypes;
}
Also used : 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 8 with TaxonomyLevelTypeToType

use of org.olat.modules.taxonomy.TaxonomyLevelTypeToType 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 9 with TaxonomyLevelTypeToType

use of org.olat.modules.taxonomy.TaxonomyLevelTypeToType 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 10 with TaxonomyLevelTypeToType

use of org.olat.modules.taxonomy.TaxonomyLevelTypeToType 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

TaxonomyLevelTypeToType (org.olat.modules.taxonomy.TaxonomyLevelTypeToType)18 TaxonomyLevelType (org.olat.modules.taxonomy.TaxonomyLevelType)16 ArrayList (java.util.ArrayList)10 Taxonomy (org.olat.modules.taxonomy.Taxonomy)8 Test (org.junit.Test)6 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)6 URI (java.net.URI)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 HttpResponse (org.apache.http.HttpResponse)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 HttpDelete (org.apache.http.client.methods.HttpDelete)2 HttpPut (org.apache.http.client.methods.HttpPut)2