use of org.olat.modules.taxonomy.TaxonomyLevelTypeToType in project openolat by klemens.
the class TaxonomyServiceImpl method cloneTaxonomyLevelType.
@Override
public TaxonomyLevelType cloneTaxonomyLevelType(TaxonomyLevelTypeRef levelType) {
TaxonomyLevelType clonedType = taxonomyLevelTypeDao.cloneTaxonomyLevelType(levelType);
List<TaxonomyLevelTypeToType> allowSubTypesToTypes = taxonomyLevelTypeToTypeDao.getAllowedSubTypes(levelType);
if (allowSubTypesToTypes.size() > 0) {
for (TaxonomyLevelTypeToType allowSubTypeToType : allowSubTypesToTypes) {
taxonomyLevelTypeToTypeDao.addAllowedSubType(clonedType, allowSubTypeToType.getAllowedSubTaxonomyLevelType());
}
}
return clonedType;
}
use of org.olat.modules.taxonomy.TaxonomyLevelTypeToType in project openolat by klemens.
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;
}
use of org.olat.modules.taxonomy.TaxonomyLevelTypeToType in project OpenOLAT by OpenOLAT.
the class EditTaxonomyLevelTypeController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
String identifier = levelType == null ? "" : levelType.getIdentifier();
identifierEl = uifactory.addTextElement("level.identifier", "level.identifier", 255, identifier, formLayout);
identifierEl.setEnabled(!TaxonomyLevelTypeManagedFlag.isManaged(levelType, TaxonomyLevelTypeManagedFlag.identifier));
identifierEl.setMandatory(true);
if (!StringHelper.containsNonWhitespace(identifier)) {
identifierEl.setFocus(true);
}
String displayName = levelType == null ? "" : levelType.getDisplayName();
displayNameEl = uifactory.addTextElement("level.displayname", "level.displayname", 255, displayName, formLayout);
displayNameEl.setEnabled(!TaxonomyLevelTypeManagedFlag.isManaged(levelType, TaxonomyLevelTypeManagedFlag.displayName));
displayNameEl.setMandatory(true);
String cssClass = levelType == null ? "" : levelType.getCssClass();
cssClassEl = uifactory.addTextElement("level.type.cssClass", "level.type.cssClass", 255, cssClass, formLayout);
cssClassEl.setEnabled(!TaxonomyLevelTypeManagedFlag.isManaged(levelType, TaxonomyLevelTypeManagedFlag.cssClass));
visibleEl = uifactory.addCheckboxesHorizontal("level.visible", "level.visible", formLayout, onKeys, new String[] { "" });
visibleEl.setEnabled(!TaxonomyLevelTypeManagedFlag.isManaged(levelType, TaxonomyLevelTypeManagedFlag.visibility));
if (levelType != null && levelType.isVisible()) {
visibleEl.select(onKeys[0], true);
}
String description = levelType == null ? "" : levelType.getDescription();
descriptionEl = uifactory.addRichTextElementForStringDataMinimalistic("level.description", "level.description", description, 10, 60, formLayout, getWindowControl());
descriptionEl.setEnabled(!TaxonomyLevelTypeManagedFlag.isManaged(levelType, TaxonomyLevelTypeManagedFlag.description));
types = taxonomyService.getTaxonomyLevelTypes(taxonomy);
types.remove(levelType);
String[] subTypeKeys = new String[types.size()];
String[] subTypeValues = new String[types.size()];
for (int i = types.size(); i-- > 0; ) {
subTypeKeys[i] = types.get(i).getKey().toString();
subTypeValues[i] = types.get(i).getDisplayName();
}
allowedSubTypesEl = uifactory.addCheckboxesVertical("level.type.allowed.sub.types", formLayout, subTypeKeys, subTypeValues, 2);
allowedSubTypesEl.setEnabled(!TaxonomyLevelTypeManagedFlag.isManaged(levelType, TaxonomyLevelTypeManagedFlag.subTypes));
if (levelType != null) {
Set<TaxonomyLevelTypeToType> typeToTypes = levelType.getAllowedTaxonomyLevelSubTypes();
for (TaxonomyLevelTypeToType typeToType : typeToTypes) {
String subTypeKey = typeToType.getAllowedSubTaxonomyLevelType().getKey().toString();
allowedSubTypesEl.select(subTypeKey, true);
}
}
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.TaxonomyLevelTypeToType in project OpenOLAT by OpenOLAT.
the class TaxonomyWebServiceTest method allowTaxonomyLevelTypeAllowedSubType.
@Test
public void allowTaxonomyLevelTypeAllowedSubType() throws IOException, URISyntaxException {
Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-4", "Taxonomy on rest", "Rest is cool", "Ext-tax-1");
TaxonomyLevelType type = taxonomyService.createTaxonomyLevelType("REST-Type-4", "Type 4 on rest", "Type", "EXT-Type-4", taxonomy);
TaxonomyLevelType subType1 = taxonomyService.createTaxonomyLevelType("REST-Type-4-1", "Type 4.1 on rest", "Type", "EXT-Type-4-1", taxonomy);
TaxonomyLevelType subType2 = taxonomyService.createTaxonomyLevelType("REST-Type-4-2", "Type 4.2 on rest", "Type", "EXT-Type-4-2", taxonomy);
dbInstance.commit();
type = taxonomyService.updateTaxonomyLevelType(type, Collections.singletonList(subType1));
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();
HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
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;
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;
}
}
Assert.assertTrue(found1);
Assert.assertTrue(found2);
}
use of org.olat.modules.taxonomy.TaxonomyLevelTypeToType in project openolat by klemens.
the class EditTaxonomyLevelTypeController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
String identifier = levelType == null ? "" : levelType.getIdentifier();
identifierEl = uifactory.addTextElement("level.identifier", "level.identifier", 255, identifier, formLayout);
identifierEl.setEnabled(!TaxonomyLevelTypeManagedFlag.isManaged(levelType, TaxonomyLevelTypeManagedFlag.identifier));
identifierEl.setMandatory(true);
if (!StringHelper.containsNonWhitespace(identifier)) {
identifierEl.setFocus(true);
}
String displayName = levelType == null ? "" : levelType.getDisplayName();
displayNameEl = uifactory.addTextElement("level.displayname", "level.displayname", 255, displayName, formLayout);
displayNameEl.setEnabled(!TaxonomyLevelTypeManagedFlag.isManaged(levelType, TaxonomyLevelTypeManagedFlag.displayName));
displayNameEl.setMandatory(true);
String cssClass = levelType == null ? "" : levelType.getCssClass();
cssClassEl = uifactory.addTextElement("level.type.cssClass", "level.type.cssClass", 255, cssClass, formLayout);
cssClassEl.setEnabled(!TaxonomyLevelTypeManagedFlag.isManaged(levelType, TaxonomyLevelTypeManagedFlag.cssClass));
visibleEl = uifactory.addCheckboxesHorizontal("level.visible", "level.visible", formLayout, onKeys, new String[] { "" });
visibleEl.setEnabled(!TaxonomyLevelTypeManagedFlag.isManaged(levelType, TaxonomyLevelTypeManagedFlag.visibility));
if (levelType != null && levelType.isVisible()) {
visibleEl.select(onKeys[0], true);
}
String description = levelType == null ? "" : levelType.getDescription();
descriptionEl = uifactory.addRichTextElementForStringDataMinimalistic("level.description", "level.description", description, 10, 60, formLayout, getWindowControl());
descriptionEl.setEnabled(!TaxonomyLevelTypeManagedFlag.isManaged(levelType, TaxonomyLevelTypeManagedFlag.description));
types = taxonomyService.getTaxonomyLevelTypes(taxonomy);
types.remove(levelType);
String[] subTypeKeys = new String[types.size()];
String[] subTypeValues = new String[types.size()];
for (int i = types.size(); i-- > 0; ) {
subTypeKeys[i] = types.get(i).getKey().toString();
subTypeValues[i] = types.get(i).getDisplayName();
}
allowedSubTypesEl = uifactory.addCheckboxesVertical("level.type.allowed.sub.types", formLayout, subTypeKeys, subTypeValues, 2);
allowedSubTypesEl.setEnabled(!TaxonomyLevelTypeManagedFlag.isManaged(levelType, TaxonomyLevelTypeManagedFlag.subTypes));
if (levelType != null) {
Set<TaxonomyLevelTypeToType> typeToTypes = levelType.getAllowedTaxonomyLevelSubTypes();
for (TaxonomyLevelTypeToType typeToType : typeToTypes) {
String subTypeKey = typeToType.getAllowedSubTaxonomyLevelType().getKey().toString();
allowedSubTypesEl.select(subTypeKey, true);
}
}
FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
formLayout.add(buttonsCont);
uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
uifactory.addFormSubmitButton("save", buttonsCont);
}
Aggregations