Search in sources :

Example 41 with TaxonomyLevelType

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

the class QPoolTaxonomyTreeBuilder method buildTreeModel.

public TreeModel buildTreeModel() {
    GenericTreeModel gtm = new GenericTreeModel();
    TaxonomyLevelNode root = new TaxonomyLevelNode();
    gtm.setRootNode(root);
    List<TaxonomyLevel> taxonomyLevels = qpoolService.getTaxonomyLevels();
    Map<Long, TaxonomyLevel> keytoLevels = taxonomyLevels.stream().collect(Collectors.toMap(l -> l.getKey(), l -> l));
    Map<Long, TaxonomyLevelNode> fieldKeyToNode = new HashMap<>();
    for (TaxonomyLevel taxonomyLevel : taxonomyLevels) {
        Long key = taxonomyLevel.getKey();
        TaxonomyLevelNode node = fieldKeyToNode.get(key);
        if (node == null) {
            node = new TaxonomyLevelNode(taxonomyLevel);
            TaxonomyLevelType type = taxonomyLevel.getType();
            if (type != null && StringHelper.containsNonWhitespace(type.getCssClass())) {
                node.setIconCssClass(type.getCssClass());
            }
            fieldKeyToNode.put(key, node);
        }
        TaxonomyLevel parentLevel = taxonomyLevel.getParent();
        if (parentLevel == null) {
            // this is a root
            root.addChild(node);
        } else {
            Long parentKey = parentLevel.getKey();
            TaxonomyLevelNode parentNode = fieldKeyToNode.get(parentKey);
            if (parentNode == null) {
                // to use the fetched type
                parentLevel = keytoLevels.get(parentKey);
                parentNode = new TaxonomyLevelNode(parentLevel);
                TaxonomyLevelType type = parentLevel.getType();
                if (type != null && StringHelper.containsNonWhitespace(type.getCssClass())) {
                    parentNode.setIconCssClass(type.getCssClass());
                }
                fieldKeyToNode.put(parentKey, parentNode);
            }
            parentNode.addChild(node);
        }
    }
    sort(root);
    return gtm;
}
Also used : INode(org.olat.core.util.nodes.INode) TreeModel(org.olat.core.gui.components.tree.TreeModel) QPoolService(org.olat.modules.qpool.QPoolService) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) QuestionPoolModule(org.olat.modules.qpool.QuestionPoolModule) Collectors(java.util.stream.Collectors) Scope(org.springframework.context.annotation.Scope) ArrayList(java.util.ArrayList) List(java.util.List) Component(org.springframework.stereotype.Component) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) Identity(org.olat.core.id.Identity) Map(java.util.Map) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) StringHelper(org.olat.core.util.StringHelper) TaxonomyCompetenceTypes(org.olat.modules.taxonomy.TaxonomyCompetenceTypes) Comparator(java.util.Comparator) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) HashMap(java.util.HashMap) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel)

Example 42 with TaxonomyLevelType

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

the class TaxonomyWebService method allowSubTaxonomyLevelType.

/**
 * Add a sub-type to 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 The sub type was added to the allowed sub 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 typeKey The type
 * @param subTypeKey The sub type
 * @param httpRequest  The HTTP request
 * @return Nothing
 */
@PUT
@Path("types/{typeKey}/allowedSubTypes/{subTypeKey}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response allowSubTaxonomyLevelType(@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.taxonomyLevelTypeAllowSubType(type, subType);
    return Response.ok().build();
}
Also used : TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyLevelTypeRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 43 with TaxonomyLevelType

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

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();
}
Also used : TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyLevelTypeRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 44 with TaxonomyLevelType

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

the class TaxonomyWebService method putTaxonomyLevelType.

/**
 * Create or Update a 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 A taxonomy level type
 * @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 to update was not found
 * @param taxonomyKey The taxonomy tree
 * @param httpRequest  The HTTP request
 * @param typeVo The taxonomy level type to create or update
 * @return The created/updated taxonomy level type
 */
@PUT
@Path("types")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response putTaxonomyLevelType(TaxonomyLevelTypeVO typeVo) {
    TaxonomyLevelType type;
    if (typeVo.getKey() != null) {
        type = taxonomyService.getTaxonomyLevelType(new TaxonomyLevelTypeRefImpl(typeVo.getKey()));
        if (type == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        }
        if (typeVo.getIdentifier() != null) {
            type.setIdentifier(typeVo.getIdentifier());
        }
        if (typeVo.getDisplayName() != null) {
            type.setDisplayName(typeVo.getDisplayName());
        }
        if (typeVo.getDescription() != null) {
            type.setDescription(typeVo.getDescription());
        }
        if (typeVo.getExternalId() != null) {
            type.setExternalId(typeVo.getExternalId());
        }
    } else {
        type = taxonomyService.createTaxonomyLevelType(typeVo.getIdentifier(), typeVo.getDisplayName(), typeVo.getDescription(), typeVo.getExternalId(), taxonomy);
    }
    if (typeVo.getManagedFlags() != null) {
        type.setManagedFlags(TaxonomyLevelTypeManagedFlag.toEnum(typeVo.getManagedFlags()));
    }
    if (typeVo.getCssClass() != null) {
        type.setCssClass(typeVo.getCssClass());
    }
    if (typeVo.getVisible() != null) {
        type.setVisible(typeVo.getVisible().booleanValue());
    }
    if (typeVo.getDocumentsLibraryEnabled() != null) {
        type.setDocumentsLibraryEnabled(typeVo.getDocumentsLibraryEnabled().booleanValue());
    }
    if (typeVo.getDocumentsLibraryManagerCompetenceEnabled() != null) {
        type.setDocumentsLibraryManageCompetenceEnabled(typeVo.getDocumentsLibraryManagerCompetenceEnabled().booleanValue());
    }
    if (typeVo.getDocumentsLibraryTeachCompetenceReadEnabled() != null) {
        type.setDocumentsLibraryTeachCompetenceReadEnabled(typeVo.getDocumentsLibraryTeachCompetenceReadEnabled().booleanValue());
    }
    if (typeVo.getDocumentsLibraryTeachCompetenceReadParentLevels() != null) {
        type.setDocumentsLibraryTeachCompetenceReadParentLevels(typeVo.getDocumentsLibraryTeachCompetenceReadParentLevels().intValue());
    }
    if (typeVo.getDocumentsLibraryTeachCompetenceWriteEnabled() != null) {
        type.setDocumentsLibraryTeachCompetenceWriteEnabled(typeVo.getDocumentsLibraryTeachCompetenceWriteEnabled().booleanValue());
    }
    if (typeVo.getDocumentsLibraryHaveCompetenceReadEnabled() != null) {
        type.setDocumentsLibraryHaveCompetenceReadEnabled(typeVo.getDocumentsLibraryHaveCompetenceReadEnabled().booleanValue());
    }
    if (typeVo.getDocumentsLibraryTargetCompetenceReadEnabled() != null) {
        type.setDocumentsLibraryTargetCompetenceReadEnabled(typeVo.getDocumentsLibraryTargetCompetenceReadEnabled().booleanValue());
    }
    type = taxonomyService.updateTaxonomyLevelType(type);
    return Response.ok(new TaxonomyLevelTypeVO(type)).build();
}
Also used : TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyLevelTypeRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 45 with TaxonomyLevelType

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

the class TaxonomyWebService method putTaxonomyLevel.

/**
 * Create or update a taxonomy level. The method changes to tree structure, a
 * null parent key will make the level a root one, a new parent key will move
 * the level.
 *
 * @response.representation.200.qname {http://www.example.com}taxonomyLevelVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc A taxonomy level
 * @response.representation.200.example {@link org.olat.modules.taxonomy.restapi.Examples#SAMPLE_TAXONOMYLEVELVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc An existant level was not found
 * @param taxonomyKey The taxonomy tree where this level is
 * @param httpRequest  The HTTP request
 * @param levelVo The roll call to update
 * @return The updated roll call
 */
@PUT
@Path("levels")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response putTaxonomyLevel(TaxonomyLevelVO levelVo) {
    TaxonomyLevel parentLevel = null;
    if (levelVo.getParentKey() != null) {
        parentLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(levelVo.getParentKey()));
    }
    TaxonomyLevel level;
    if (levelVo.getKey() != null) {
        level = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(levelVo.getKey()));
        if (levelVo.getIdentifier() != null) {
            level.setIdentifier(levelVo.getIdentifier());
        }
        if (levelVo.getDisplayName() != null) {
            level.setDisplayName(levelVo.getDisplayName());
        }
        if (levelVo.getDescription() != null) {
            level.setDescription(levelVo.getDescription());
        }
        if (levelVo.getExternalId() != null) {
            level.setExternalId(levelVo.getExternalId());
        }
        if (levelVo.getTypeKey() != null) {
            TaxonomyLevelType type = taxonomyService.getTaxonomyLevelType(new TaxonomyLevelTypeRefImpl(levelVo.getTypeKey()));
            level.setType(type);
        }
        if (levelVo.getManagedFlags() != null) {
            level.setManagedFlags(TaxonomyLevelManagedFlag.toEnum(levelVo.getManagedFlags()));
        }
        level = taxonomyService.updateTaxonomyLevel(level);
    } else {
        level = taxonomyService.createTaxonomyLevel(levelVo.getIdentifier(), levelVo.getDisplayName(), levelVo.getDescription(), levelVo.getExternalId(), TaxonomyLevelManagedFlag.toEnum(levelVo.getManagedFlags()), parentLevel, taxonomy);
        if (levelVo.getTypeKey() != null) {
            TaxonomyLevelType type = taxonomyService.getTaxonomyLevelType(new TaxonomyLevelTypeRefImpl(levelVo.getTypeKey()));
            level.setType(type);
            level = taxonomyService.updateTaxonomyLevel(level);
        }
    }
    if ((level.getParent() != null && levelVo.getParentKey() == null) || (level.getParent() == null && levelVo.getParentKey() != null) || (level.getParent() != null && !level.getParent().getKey().equals(levelVo.getParentKey()))) {
        TaxonomyLevel newParentLevel = null;
        if (levelVo.getParentKey() != null) {
            newParentLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(levelVo.getParentKey()));
        }
        level = taxonomyService.moveTaxonomyLevel(level, newParentLevel);
    }
    TaxonomyLevelVO newLevelVo = new TaxonomyLevelVO(level);
    return Response.ok(newLevelVo).build();
}
Also used : TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) TaxonomyLevelTypeRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

TaxonomyLevelType (org.olat.modules.taxonomy.TaxonomyLevelType)92 Test (org.junit.Test)40 Taxonomy (org.olat.modules.taxonomy.Taxonomy)32 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)32 ArrayList (java.util.ArrayList)26 Identity (org.olat.core.id.Identity)20 TaxonomyLevelTypeToType (org.olat.modules.taxonomy.TaxonomyLevelTypeToType)16 URI (java.net.URI)14 HttpResponse (org.apache.http.HttpResponse)14 TaxonomyLevelTypeRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl)14 Path (javax.ws.rs.Path)12 List (java.util.List)10 Produces (javax.ws.rs.Produces)10 Collectors (java.util.stream.Collectors)8 TaxonomyLevelRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 PUT (javax.ws.rs.PUT)6 HttpGet (org.apache.http.client.methods.HttpGet)6 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)6