use of org.olat.modules.taxonomy.TaxonomyLevelType in project openolat by klemens.
the class MoveTaxonomyLevelController method filterByAllowedTypes.
private boolean filterByAllowedTypes(TreeNode node, List<TreeNode> openedNodes) {
((GenericTreeNode) node).setIconCssClass(null);
for (int i = node.getChildCount(); i-- > 0; ) {
boolean ok = filterByAllowedTypes((TreeNode) node.getChildAt(i), openedNodes);
if (!ok) {
node.remove(node.getChildAt(i));
}
}
boolean ok = false;
Object uobject = node.getUserObject();
if (uobject instanceof TaxonomyLevel) {
TaxonomyLevel level = (TaxonomyLevel) uobject;
TaxonomyLevelType type = level.getType();
if (type == null || allowedTypes.contains(type)) {
openedNodes.add(node);
((GenericTreeNode) node).setIconCssClass("o_icon_node_under o_icon-rotate-180");
targetableNodes.add(node);
ok = true;
} else if (node.getChildCount() > 0) {
openedNodes.add(node);
ok = true;
}
} else {
targetableNodes.add(node);
openedNodes.add(node);
ok = true;
}
return ok;
}
use of org.olat.modules.taxonomy.TaxonomyLevelType in project openolat by klemens.
the class EditTaxonomyLevelController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
if (level == null || level.getKey() == null) {
String[] pathKeys;
String[] pathValues;
if (parentLevel == null) {
List<String> pathKeyList = new ArrayList<>();
List<String> pathValueList = new ArrayList<>();
buildPathKeysAndValues(pathKeyList, pathValueList);
pathKeys = pathKeyList.toArray(new String[pathKeyList.size()]);
pathValues = pathValueList.toArray(new String[pathValueList.size()]);
} else {
pathKeys = new String[] { parentLevel.getKey().toString() };
pathValues = new String[] { parentLevel.getMaterializedPathIdentifiers() };
}
pathEl = uifactory.addDropdownSingleselect("level.path", "taxonomy.level.path", formLayout, pathKeys, pathValues, null);
pathEl.setEnabled(parentLevel == null);
}
String identifier = level == null ? "" : level.getIdentifier();
identifierEl = uifactory.addTextElement("level.identifier", "level.identifier", 255, identifier, formLayout);
identifierEl.setEnabled(!TaxonomyLevelManagedFlag.isManaged(level, TaxonomyLevelManagedFlag.identifier));
identifierEl.setMandatory(true);
String displayName = level == null ? "" : level.getDisplayName();
displayNameEl = uifactory.addTextElement("level.displayname", "level.displayname", 255, displayName, formLayout);
displayNameEl.setMandatory(true);
displayNameEl.setEnabled(!TaxonomyLevelManagedFlag.isManaged(level, TaxonomyLevelManagedFlag.displayName));
if (!StringHelper.containsNonWhitespace(displayName)) {
displayNameEl.setFocus(true);
}
List<TaxonomyLevelType> types = getTypes();
String[] typeKeys = new String[types.size() + 1];
String[] typeValues = new String[types.size() + 1];
typeKeys[0] = "";
typeValues[0] = "-";
for (int i = types.size(); i-- > 0; ) {
typeKeys[i + 1] = types.get(i).getKey().toString();
typeValues[i + 1] = types.get(i).getDisplayName();
}
taxonomyLevelTypeEl = uifactory.addDropdownSingleselect("level.type", "level.type", formLayout, typeKeys, typeValues, null);
taxonomyLevelTypeEl.setEnabled(!TaxonomyLevelManagedFlag.isManaged(level, TaxonomyLevelManagedFlag.type));
boolean typeFound = false;
if (level != null && level.getType() != null) {
String selectedTypeKey = level.getType().getKey().toString();
for (String typeKey : typeKeys) {
if (typeKey.equals(selectedTypeKey)) {
taxonomyLevelTypeEl.select(selectedTypeKey, true);
typeFound = true;
break;
}
}
}
if (!typeFound) {
taxonomyLevelTypeEl.select(typeKeys[0], true);
}
String sortOrder = level == null || level.getSortOrder() == null ? "" : level.getSortOrder().toString();
sortOrderEl = uifactory.addTextElement("level.sort.order", "level.sort.order", 255, sortOrder, formLayout);
sortOrderEl.setEnabled(!TaxonomyLevelManagedFlag.isManaged(level, TaxonomyLevelManagedFlag.displayName));
String description = level == null ? "" : level.getDescription();
descriptionEl = uifactory.addRichTextElementForStringDataCompact("level.description", "level.description", description, 10, 60, null, formLayout, ureq.getUserSession(), getWindowControl());
descriptionEl.setEnabled(!TaxonomyLevelManagedFlag.isManaged(level, TaxonomyLevelManagedFlag.description));
FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
formLayout.add(buttonsCont);
uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
uifactory.addFormSubmitButton("save", buttonsCont);
}
use of org.olat.modules.taxonomy.TaxonomyLevelType 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);
}
use of org.olat.modules.taxonomy.TaxonomyLevelType in project openolat by klemens.
the class TaxonomyWebService method getAllowedSubTaxonomyLevelTypes.
/**
* Get the allowed sub-types of a specified taxonomy level's type.
*
* @response.representation.200.qname {http://www.example.com}taxonomyLevelTypeVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc An array of taxonomy level types
* @response.representation.200.example {@link org.olat.modules.taxonomy.restapi.Examples#SAMPLE_TAXONOMYLEVELTYPEVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The taxonomy level type was not found
* @param taxonomyKey The taxonomy tree
* @param httpRequest The HTTP request
* @param typeKey The primary key of the taxonomy level type
* @return An array of taxonomy level types
*/
@GET
@Path("types/{typeKey}/allowedSubTypes")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getAllowedSubTaxonomyLevelTypes(@PathParam("typeKey") Long typeKey) {
TaxonomyLevelType type = taxonomyService.getTaxonomyLevelType(new TaxonomyLevelTypeRefImpl(typeKey));
if (type == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
Set<TaxonomyLevelTypeToType> typeToTypes = type.getAllowedTaxonomyLevelSubTypes();
List<TaxonomyLevelTypeVO> subTypeVOes = new ArrayList<>(typeToTypes.size());
for (TaxonomyLevelTypeToType typeToType : typeToTypes) {
TaxonomyLevelType subType = typeToType.getAllowedSubTaxonomyLevelType();
subTypeVOes.add(new TaxonomyLevelTypeVO(subType));
}
return Response.ok(subTypeVOes.toArray(new TaxonomyLevelTypeVO[subTypeVOes.size()])).build();
}
use of org.olat.modules.taxonomy.TaxonomyLevelType in project openolat by klemens.
the class TaxonomyWebService method disalloweSubTaxonomyLevelType.
/**
* Remove a sub-type to a specified taxonomy level's type.
*
* @response.representation.200.doc The sub type was removed sucessfully
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The taxonomy level type was not found
* @param taxonomyKey The taxonomy tree
* @param typeKey The type
* @param subTypeKey The sub type to remove
* @param httpRequest The HTTP request
* @return Nothing
*/
@DELETE
@Path("types/{typeKey}/allowedSubTypes/{subTypeKey}")
public Response disalloweSubTaxonomyLevelType(@PathParam("typeKey") Long typeKey, @PathParam("subTypeKey") Long subTypeKey) {
TaxonomyLevelType type = taxonomyService.getTaxonomyLevelType(new TaxonomyLevelTypeRefImpl(typeKey));
TaxonomyLevelType subType = taxonomyService.getTaxonomyLevelType(new TaxonomyLevelTypeRefImpl(subTypeKey));
if (type == null || subType == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
taxonomyService.taxonomyLevelTypeDisallowSubType(type, subType);
return Response.ok().build();
}
Aggregations