Search in sources :

Example 16 with TaxonomyLevelRefImpl

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

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 17 with TaxonomyLevelRefImpl

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

the class TaxonomyWebServiceTest method deleteTaxonomyLevel_notPossible.

/**
 * The REST method only delete something if possible. If the level
 * has some children, competences... the call will not delete it.
 *
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void deleteTaxonomyLevel_notPossible() throws IOException, URISyntaxException {
    Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Del-2", "Taxonomy on rest", "Delete is sad! But there is some hope.", "DELETE-tax-2");
    TaxonomyLevel rootLevel = taxonomyService.createTaxonomyLevel("REST-Del-root", "Root level on rest", "Level", "Ext-57", null, null, taxonomy);
    TaxonomyLevel levelToDelete = taxonomyService.createTaxonomyLevel("REST-Del-u-2", "Sub level on rest", "Level", "Ext-58", null, rootLevel, taxonomy);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(taxonomy);
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("levels").path(rootLevel.getKey().toString()).build();
    HttpDelete method = conn.createDelete(request, MediaType.APPLICATION_JSON);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(304, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    // check the updated value
    TaxonomyLevel survivingLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(levelToDelete.getKey()));
    Assert.assertNotNull(survivingLevel);
    TaxonomyLevel survivingRootLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(rootLevel.getKey()));
    Assert.assertNotNull(survivingRootLevel);
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) HttpResponse(org.apache.http.HttpResponse) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) URI(java.net.URI) Test(org.junit.Test)

Example 18 with TaxonomyLevelRefImpl

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

the class TaxonomyWebServiceTest method putTaxonomyLevel_subLevel.

@Test
public void putTaxonomyLevel_subLevel() throws IOException, URISyntaxException {
    Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-3", "Taxonomy on rest", "PUT is cool, yes!", "PUT-tax-2");
    TaxonomyLevel rootLevel = taxonomyService.createTaxonomyLevel("REST-Tax-r-1", "Root level on rest", "Level", "Ext-23", null, null, taxonomy);
    TaxonomyLevelType type = taxonomyService.createTaxonomyLevelType("Sub-type", "Type for a sub level", "All is in the title", "TYP-23", taxonomy);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(taxonomy);
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    String uid = UUID.randomUUID().toString();
    TaxonomyLevelVO levelVo = new TaxonomyLevelVO();
    levelVo.setIdentifier(uid);
    levelVo.setDisplayName("PUT a sub level");
    levelVo.setDescription("Try to PUT a level above the root");
    levelVo.setExternalId("EXT-191");
    levelVo.setParentKey(rootLevel.getKey());
    levelVo.setTypeKey(type.getKey());
    URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("levels").build();
    HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(method, levelVo);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    // check the returned value
    TaxonomyLevelVO newTaxonomyLevelVo = conn.parse(response, TaxonomyLevelVO.class);
    Assert.assertNotNull(newTaxonomyLevelVo);
    Assert.assertNotNull(newTaxonomyLevelVo.getKey());
    Assert.assertEquals(uid, newTaxonomyLevelVo.getIdentifier());
    Assert.assertEquals("PUT a sub level", newTaxonomyLevelVo.getDisplayName());
    Assert.assertEquals("EXT-191", newTaxonomyLevelVo.getExternalId());
    Assert.assertEquals(rootLevel.getKey(), newTaxonomyLevelVo.getParentKey());
    Assert.assertEquals(type.getKey(), newTaxonomyLevelVo.getTypeKey());
    // check the database
    TaxonomyLevel savedLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(newTaxonomyLevelVo.getKey()));
    Assert.assertNotNull(savedLevel);
    Assert.assertEquals(newTaxonomyLevelVo.getKey(), savedLevel.getKey());
    Assert.assertEquals(newTaxonomyLevelVo.getParentKey(), savedLevel.getParent().getKey());
    // check parent line
    List<TaxonomyLevel> parentLine = taxonomyService.getTaxonomyLevelParentLine(savedLevel, taxonomy);
    Assert.assertNotNull(parentLine);
    Assert.assertEquals(2, parentLine.size());
    Assert.assertEquals(rootLevel, parentLine.get(0));
    Assert.assertEquals(savedLevel, parentLine.get(1));
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelVO(org.olat.modules.taxonomy.restapi.TaxonomyLevelVO) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) HttpResponse(org.apache.http.HttpResponse) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 19 with TaxonomyLevelRefImpl

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

Example 20 with TaxonomyLevelRefImpl

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

the class TaxonomyWebService method getTaxonomyLevelComptencesByIdentity.

/**
 * Return the competences of a specific user 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 identityKey The user
 * @param httpRequest  The HTTP request
 * @return An array of competences
 */
@GET
@Path("levels/{taxonomyLevelKey}/competences/{identityKey}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getTaxonomyLevelComptencesByIdentity(@PathParam("taxonomyLevelKey") Long taxonomyLevelKey, @PathParam("identityKey") Long identityKey) {
    TaxonomyLevel level = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(new Long(taxonomyLevelKey)));
    if (level == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    Identity identity = securityManager.loadIdentityByKey(identityKey);
    if (identity == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    List<TaxonomyCompetence> competences = taxonomyService.getTaxonomyLevelCompetences(level, identity);
    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) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) Identity(org.olat.core.id.Identity) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

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