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;
}
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"));
}
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);
}
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"));
}
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);
}
Aggregations