Search in sources :

Example 61 with TaxonomyLevelType

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

the class EditTaxonomyLevelController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (level == null) {
        TaxonomyLevel selectedParentLevel = null;
        if (parentLevel == null) {
            if (pathEl != null && pathEl.isEnabled() && pathEl.isOneSelected() && !"-".equals(pathEl.getSelectedKey())) {
                TaxonomyLevelRef ref = new TaxonomyLevelRefImpl(new Long(pathEl.getSelectedKey()));
                selectedParentLevel = taxonomyService.getTaxonomyLevel(ref);
            }
        } else {
            selectedParentLevel = parentLevel;
        }
        level = taxonomyService.createTaxonomyLevel(identifierEl.getValue(), displayNameEl.getValue(), descriptionEl.getValue(), null, null, selectedParentLevel, taxonomy);
    } else {
        level = taxonomyService.getTaxonomyLevel(level);
        level.setIdentifier(identifierEl.getValue());
        level.setDisplayName(displayNameEl.getValue());
        level.setDescription(descriptionEl.getValue());
    }
    String selectedTypeKey = taxonomyLevelTypeEl.getSelectedKey();
    if (StringHelper.containsNonWhitespace(selectedTypeKey)) {
        TaxonomyLevelTypeRef typeRef = new TaxonomyLevelTypeRefImpl(new Long(selectedTypeKey));
        TaxonomyLevelType type = taxonomyService.getTaxonomyLevelType(typeRef);
        level.setType(type);
    } else {
        level.setType(null);
    }
    if (StringHelper.isLong(sortOrderEl.getValue())) {
        level.setSortOrder(new Integer(sortOrderEl.getValue()));
    } else {
        level.setSortOrder(null);
    }
    level = taxonomyService.updateTaxonomyLevel(level);
    fireEvent(ureq, Event.DONE_EVENT);
}
Also used : TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) TaxonomyLevelTypeRef(org.olat.modules.taxonomy.TaxonomyLevelTypeRef) TaxonomyLevelTypeRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl) TaxonomyLevelRef(org.olat.modules.taxonomy.TaxonomyLevelRef)

Example 62 with TaxonomyLevelType

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

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

Example 63 with TaxonomyLevelType

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

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;
}
Also used : TreeModel(org.olat.core.gui.components.tree.TreeModel) Date(java.util.Date) I18nManager(org.olat.core.util.i18n.I18nManager) CoreSpringFactory(org.olat.core.CoreSpringFactory) HashMap(java.util.HashMap) TaxonomyCompetence(org.olat.modules.taxonomy.TaxonomyCompetence) Collectors(java.util.stream.Collectors) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) TaxonomyTreeNodeType(org.olat.modules.taxonomy.model.TaxonomyTreeNodeType) List(java.util.List) Locale(java.util.Locale) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) Identity(org.olat.core.id.Identity) TaxonomyModule(org.olat.modules.taxonomy.TaxonomyModule) TaxonomyService(org.olat.modules.taxonomy.TaxonomyService) Map(java.util.Map) StringHelper(org.olat.core.util.StringHelper) TaxonomyCompetenceTypes(org.olat.modules.taxonomy.TaxonomyCompetenceTypes) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) HashMap(java.util.HashMap) VFSContainer(org.olat.core.util.vfs.VFSContainer) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel)

Example 64 with TaxonomyLevelType

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

the class TaxonomyLevelTypeDAOTest method createAndLoadTaxonomyLevelType.

@Test
public void createAndLoadTaxonomyLevelType() {
    Taxonomy taxonomy = taxonomyDao.createTaxonomy("Tax-type", "Typed taxonomy", "A typed taxonomy", "");
    TaxonomyLevelType type = taxonomyLevelTypeDao.createTaxonomyLevelType("Type-reload", "A first reloaded type", "Typed", "TYP-1", taxonomy);
    dbInstance.commitAndCloseSession();
    TaxonomyLevelType reloadedType = taxonomyLevelTypeDao.loadTaxonomyLevelTypeByKey(type.getKey());
    Assert.assertNotNull(reloadedType);
    Assert.assertEquals(type, reloadedType);
    Assert.assertEquals("Type-reload", reloadedType.getIdentifier());
    Assert.assertEquals("A first reloaded type", reloadedType.getDisplayName());
    Assert.assertEquals("Typed", reloadedType.getDescription());
    Assert.assertEquals("TYP-1", reloadedType.getExternalId());
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) Test(org.junit.Test)

Example 65 with TaxonomyLevelType

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

the class TaxonomyLevelTypeDAOTest method createTaxonomyLevelType.

@Test
public void createTaxonomyLevelType() {
    Taxonomy taxonomy = taxonomyDao.createTaxonomy("Tax-type", "Typed taxonomy", "A typed taxonomy", "");
    TaxonomyLevelType type = taxonomyLevelTypeDao.createTaxonomyLevelType("Type-0", "A first type", "Typed", "TYP-0", taxonomy);
    dbInstance.commit();
    Assert.assertNotNull(type);
    Assert.assertNotNull(type.getKey());
    Assert.assertNotNull(type.getCreationDate());
    Assert.assertEquals("Type-0", type.getIdentifier());
    Assert.assertEquals("A first type", type.getDisplayName());
    Assert.assertEquals("Typed", type.getDescription());
    Assert.assertEquals("TYP-0", type.getExternalId());
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) Test(org.junit.Test)

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