Search in sources :

Example 11 with TaxonomyLevelTypeToType

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;
}
Also used : TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyLevelTypeToType(org.olat.modules.taxonomy.TaxonomyLevelTypeToType)

Example 12 with TaxonomyLevelTypeToType

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

Example 13 with TaxonomyLevelTypeToType

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);
}
Also used : FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) TaxonomyLevelTypeToType(org.olat.modules.taxonomy.TaxonomyLevelTypeToType)

Example 14 with TaxonomyLevelTypeToType

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);
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) HttpResponse(org.apache.http.HttpResponse) TaxonomyLevelTypeToType(org.olat.modules.taxonomy.TaxonomyLevelTypeToType) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 15 with TaxonomyLevelTypeToType

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);
}
Also used : FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) TaxonomyLevelTypeToType(org.olat.modules.taxonomy.TaxonomyLevelTypeToType)

Aggregations

TaxonomyLevelTypeToType (org.olat.modules.taxonomy.TaxonomyLevelTypeToType)18 TaxonomyLevelType (org.olat.modules.taxonomy.TaxonomyLevelType)16 ArrayList (java.util.ArrayList)10 Taxonomy (org.olat.modules.taxonomy.Taxonomy)8 Test (org.junit.Test)6 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)6 URI (java.net.URI)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 HttpResponse (org.apache.http.HttpResponse)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 HttpDelete (org.apache.http.client.methods.HttpDelete)2 HttpPut (org.apache.http.client.methods.HttpPut)2