Search in sources :

Example 1 with TaxonomyLevelRef

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

the class TaxonomyModel method validateContinuousSelection.

/**
 * Check the selection of levels doesn't contains
 * a select parent with only part of its children selected.
 * No children selected is allowed, all children selected
 * are allowed but not part of them.
 *
 * @param levels The list of levels
 * @return true if the selection is continous
 */
public boolean validateContinuousSelection(List<? extends TaxonomyLevelRef> levels) {
    boolean allOk = true;
    Set<String> selectedNodeIds = new HashSet<>();
    for (TaxonomyLevelRef level : levels) {
        selectedNodeIds.add(nodeKey(level));
    }
    for (TaxonomyLevelRef level : levels) {
        String nodeId = nodeKey(level);
        TreeNode node = getNodeById(nodeId);
        if (node.getChildCount() > 0) {
            int count = node.getChildCount();
            for (int i = count; i-- > 0; ) {
                String childId = node.getChildAt(i).getIdent();
                if (selectedNodeIds.contains(childId)) {
                    count--;
                }
            }
            if (count > 0 && count != node.getChildCount()) {
                allOk &= false;
            }
        }
    }
    return allOk;
}
Also used : TreeNode(org.olat.core.gui.components.tree.TreeNode) TaxonomyLevelRef(org.olat.modules.taxonomy.TaxonomyLevelRef) HashSet(java.util.HashSet)

Example 2 with TaxonomyLevelRef

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

the class DeleteTaxonomyLevelController method buildDangerMessage.

private void buildDangerMessage(FormLayoutContainer layoutCont) {
    List<String> messages = new ArrayList<>();
    // child (no partially selection allowed for deletion)
    Set<TreeNode> childrenToDelete = new HashSet<>();
    for (TaxonomyLevel level : levels) {
        String nodeId = treeModel.nodeKey(level);
        TreeNode node = treeModel.getNodeById(nodeId);
        childrenToDelete.addAll(treeModel.getDescendants(node));
    }
    if (childrenToDelete.size() > 0) {
        messages.add(translate("error.delete.num.child.levels", new String[] { Integer.toString(childrenToDelete.size()) }));
    }
    List<TaxonomyLevelRef> refs = new ArrayList<>(levels);
    childrenToDelete.stream().forEach(c -> refs.add((TaxonomyLevelRef) c.getUserObject()));
    // questions / relations / references
    int relations = taxonomyService.countRelations(refs);
    if (relations > 0) {
        messages.add(translate("error.delete.num.relations", new String[] { Integer.toString(relations) }));
    }
    // competences
    int competences = taxonomyService.countTaxonomyCompetences(refs);
    if (competences > 0) {
        messages.add(translate("error.delete.num.competences", new String[] { Integer.toString(competences) }));
    }
    layoutCont.contextPut("messages", messages);
    layoutCont.contextPut("mergeToMessage", translate("info.delete.merge.to"));
}
Also used : TreeNode(org.olat.core.gui.components.tree.TreeNode) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) ArrayList(java.util.ArrayList) TaxonomyLevelRef(org.olat.modules.taxonomy.TaxonomyLevelRef) HashSet(java.util.HashSet)

Example 3 with TaxonomyLevelRef

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

use of org.olat.modules.taxonomy.TaxonomyLevelRef in project openolat by klemens.

the class DeleteTaxonomyLevelController method buildDangerMessage.

private void buildDangerMessage(FormLayoutContainer layoutCont) {
    List<String> messages = new ArrayList<>();
    // child (no partially selection allowed for deletion)
    Set<TreeNode> childrenToDelete = new HashSet<>();
    for (TaxonomyLevel level : levels) {
        String nodeId = treeModel.nodeKey(level);
        TreeNode node = treeModel.getNodeById(nodeId);
        childrenToDelete.addAll(treeModel.getDescendants(node));
    }
    if (childrenToDelete.size() > 0) {
        messages.add(translate("error.delete.num.child.levels", new String[] { Integer.toString(childrenToDelete.size()) }));
    }
    List<TaxonomyLevelRef> refs = new ArrayList<>(levels);
    childrenToDelete.stream().forEach(c -> refs.add((TaxonomyLevelRef) c.getUserObject()));
    // questions / relations / references
    int relations = taxonomyService.countRelations(refs);
    if (relations > 0) {
        messages.add(translate("error.delete.num.relations", new String[] { Integer.toString(relations) }));
    }
    // competences
    int competences = taxonomyService.countTaxonomyCompetences(refs);
    if (competences > 0) {
        messages.add(translate("error.delete.num.competences", new String[] { Integer.toString(competences) }));
    }
    layoutCont.contextPut("messages", messages);
    layoutCont.contextPut("mergeToMessage", translate("info.delete.merge.to"));
}
Also used : TreeNode(org.olat.core.gui.components.tree.TreeNode) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) ArrayList(java.util.ArrayList) TaxonomyLevelRef(org.olat.modules.taxonomy.TaxonomyLevelRef) HashSet(java.util.HashSet)

Example 5 with TaxonomyLevelRef

use of org.olat.modules.taxonomy.TaxonomyLevelRef in project openolat by klemens.

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)

Aggregations

TaxonomyLevelRef (org.olat.modules.taxonomy.TaxonomyLevelRef)6 HashSet (java.util.HashSet)4 TreeNode (org.olat.core.gui.components.tree.TreeNode)4 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)4 ArrayList (java.util.ArrayList)2 TaxonomyLevelType (org.olat.modules.taxonomy.TaxonomyLevelType)2 TaxonomyLevelTypeRef (org.olat.modules.taxonomy.TaxonomyLevelTypeRef)2 TaxonomyLevelRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl)2 TaxonomyLevelTypeRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl)2