Search in sources :

Example 11 with TaxonomyLevelRefImpl

use of org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl in project openolat by klemens.

the class SearchControllerFactory method getBusinessPathLabel.

@Override
public String getBusinessPathLabel(String token, List<String> allTokens, Locale locale) {
    try {
        String[] splitted = token.split("[:]");
        if (splitted != null && splitted.length == 2) {
            String tokenType = splitted[0];
            String tokenKey = splitted[1];
            if ("RepositoryEntry".equals(tokenType)) {
                RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(Long.parseLong(tokenKey));
                return re.getDisplayname();
            }
            if ("CourseNode".equals(tokenType)) {
                String repoKey = allTokens.get(0).split("[:]")[1];
                RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(Long.parseLong(repoKey));
                if (re != null) {
                    ICourse course = CourseFactory.loadCourse(re);
                    CourseNode courseNode = course.getRunStructure().getNode(tokenKey);
                    return courseNode.getShortTitle();
                }
            }
            if ("Identity".equals(tokenType)) {
                IdentityShort identity = BaseSecurityManager.getInstance().loadIdentityShortByKey(Long.parseLong(tokenKey));
                return UserManager.getInstance().getUserDisplayName(identity);
            }
            if ("BusinessGroup".equals(tokenType)) {
                BusinessGroup bg = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(Long.parseLong(tokenKey));
                return bg == null ? "" : bg.getName();
            }
            if ("Taxonomy".equals(tokenType)) {
                Taxonomy taxonomy = CoreSpringFactory.getImpl(TaxonomyService.class).getTaxonomy(new TaxonomyRefImpl(Long.parseLong(tokenKey)));
                return taxonomy == null ? "" : taxonomy.getDisplayName();
            }
            if ("TaxonomyLevel".equals(tokenType)) {
                TaxonomyLevel level = CoreSpringFactory.getImpl(TaxonomyService.class).getTaxonomyLevel(new TaxonomyLevelRefImpl(Long.parseLong(tokenKey)));
                return level == null ? "" : level.getDisplayName();
            }
            Translator translator = Util.createPackageTranslator(this.getClass(), locale);
            if ("DocumentPool".equals(tokenType)) {
                return translator.translate("DocumentPool");
            }
            if ("Templates".equals(tokenType)) {
                return translator.translate("Templates");
            }
            if ("userfolder".equals(tokenType)) {
                return translator.translate("type.identity.publicfolder");
            }
            String translated = translator.translate(tokenType);
            if (translated == null || translated.length() > 64) {
                // no translation, translator return an error
                return token;
            }
            return translated;
        }
    } catch (Exception ex) {
        log.warn("Problem to decipher business path token: " + token, ex);
    }
    return token;
}
Also used : TaxonomyService(org.olat.modules.taxonomy.TaxonomyService) TaxonomyRefImpl(org.olat.modules.taxonomy.model.TaxonomyRefImpl) BusinessGroup(org.olat.group.BusinessGroup) Taxonomy(org.olat.modules.taxonomy.Taxonomy) IdentityShort(org.olat.basesecurity.IdentityShort) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) BusinessGroupService(org.olat.group.BusinessGroupService) Translator(org.olat.core.gui.translator.Translator) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) CourseNode(org.olat.course.nodes.CourseNode)

Example 12 with TaxonomyLevelRefImpl

use of org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl in project OpenOLAT by OpenOLAT.

the class TaxonomyWebService method deleteTaxonomyLevel.

/**
 * Delete the taxonomy level definitively.
 *
 * @response.representation.200.doc The level was successfully deleted
 * @response.representation.304.doc The level cannot be deleted and was not modified
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The level was not found
 * @response.representation.404.doc The level taxonomy doesn't match the taxonomy of the web service
 *
 * @param taxonomyKey The taxonomy tree
 * @param taxonomyLevelKey The level of the taxonomy to delete
 * @return Nothing
 */
@DELETE
@Path("levels/{taxonomyLevelKey}")
public Response deleteTaxonomyLevel(@PathParam("taxonomyLevelKey") String taxonomyLevelKey) {
    TaxonomyLevel level = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(new Long(taxonomyLevelKey)));
    if (level == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    if (level.getTaxonomy() != null && !level.getTaxonomy().equals(taxonomy)) {
        return Response.serverError().status(Status.CONFLICT).build();
    }
    boolean canDelete = taxonomyService.deleteTaxonomyLevel(level, null);
    if (canDelete) {
        return Response.ok().build();
    }
    return Response.notModified().build();
}
Also used : TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 13 with TaxonomyLevelRefImpl

use of org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl 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)

Example 14 with TaxonomyLevelRefImpl

use of org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl in project OpenOLAT by OpenOLAT.

the class TaxonomyWebService method getTaxonomyLevelComptences.

/**
 * Return the competences of users on the taxonomy level specified in the key in path.
 *
 * @response.representation.200.qname {http://www.example.com}taxonomyCompetenceVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc An array of competences
 * @response.representation.200.example {@link org.olat.modules.taxonomy.restapi.Examples#SAMPLE_TAXONOMYCOMPETENCEVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param taxonomyKey The taxonomy tree
 * @param taxonomyLevelKey The level of the taxonomy
 * @param httpRequest  The HTTP request
 * @return An array of competences
 */
@GET
@Path("levels/{taxonomyLevelKey}/competences")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getTaxonomyLevelComptences(@PathParam("taxonomyLevelKey") Long taxonomyLevelKey) {
    TaxonomyLevel level = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(new Long(taxonomyLevelKey)));
    if (level == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    List<TaxonomyCompetence> competences = taxonomyService.getTaxonomyLevelCompetences(level);
    List<TaxonomyCompetenceVO> competenceVOes = new ArrayList<>(competences.size());
    for (TaxonomyCompetence competence : competences) {
        competenceVOes.add(new TaxonomyCompetenceVO(competence));
    }
    return Response.ok(competenceVOes.toArray(new TaxonomyCompetenceVO[competenceVOes.size()])).build();
}
Also used : TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) ArrayList(java.util.ArrayList) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) TaxonomyCompetence(org.olat.modules.taxonomy.TaxonomyCompetence) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 15 with TaxonomyLevelRefImpl

use of org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl 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);
}
Also used : TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) TaxonomyLevelTypeRef(org.olat.modules.taxonomy.TaxonomyLevelTypeRef) TaxonomyLevelTypeRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl) TaxonomyLevelRef(org.olat.modules.taxonomy.TaxonomyLevelRef)

Aggregations

TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)24 TaxonomyLevelRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl)24 Taxonomy (org.olat.modules.taxonomy.Taxonomy)10 URI (java.net.URI)8 Path (javax.ws.rs.Path)8 HttpResponse (org.apache.http.HttpResponse)8 Test (org.junit.Test)8 TaxonomyLevelType (org.olat.modules.taxonomy.TaxonomyLevelType)8 ArrayList (java.util.ArrayList)6 Consumes (javax.ws.rs.Consumes)6 Produces (javax.ws.rs.Produces)6 TaxonomyCompetence (org.olat.modules.taxonomy.TaxonomyCompetence)6 GET (javax.ws.rs.GET)4 HttpDelete (org.apache.http.client.methods.HttpDelete)4 HttpPut (org.apache.http.client.methods.HttpPut)4 Identity (org.olat.core.id.Identity)4 TaxonomyLevelTypeRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl)4 TaxonomyLevelVO (org.olat.modules.taxonomy.restapi.TaxonomyLevelVO)4 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)4 DELETE (javax.ws.rs.DELETE)2